Changeset 6ea9a1d in mainline for uspace/app/bdsh/input.c
- Timestamp:
- 2011-06-11T22:32:24Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 36ab7c7
- Parents:
- ae45201
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/input.c
rae45201 r6ea9a1d 58 58 59 59 /* Private helpers */ 60 static int run_command(char **, cliuser_t *, FILE **);60 static int run_command(char **, cliuser_t *, iostate_t *); 61 61 static void print_pipe_usage(void); 62 62 … … 140 140 } 141 141 142 FILE *files[4]; 143 files[0] = stdin; 144 files[1] = stdout; 145 files[2] = stderr; 146 files[3] = 0; 142 iostate_t new_iostate = { 143 .stdin = stdin, 144 .stdout = stdout, 145 .stderr = stderr 146 }; 147 148 FILE *from = NULL; 149 FILE *to = NULL; 147 150 148 151 if (redir_from) { 149 FILE *from = fopen(redir_from, "r");152 from = fopen(redir_from, "r"); 150 153 if (from == NULL) { 151 154 printf("Cannot open file %s\n", redir_from); 152 155 rc = errno; 153 goto finit ;156 goto finit_with_files; 154 157 } 155 files[0] = from; 156 } 158 new_iostate.stdin = from; 159 } 160 157 161 158 162 if (redir_to) { 159 FILE *to = fopen(redir_to, "w");163 to = fopen(redir_to, "w"); 160 164 if (to == NULL) { 161 165 printf("Cannot open file %s\n", redir_to); 162 166 rc = errno; 163 goto finit ;167 goto finit_with_files; 164 168 } 165 files[1] = to; 166 } 167 168 rc = run_command(cmd, usr, files); 169 new_iostate.stdout = to; 170 } 171 172 rc = run_command(cmd, usr, &new_iostate); 173 174 finit_with_files: 175 if (from != NULL) { 176 fclose(from); 177 } 178 if (to != NULL) { 179 fclose(to); 180 } 169 181 170 182 finit: … … 188 200 } 189 201 190 int run_command(char **cmd, cliuser_t *usr, FILE *files[])202 int run_command(char **cmd, cliuser_t *usr, iostate_t *new_iostate) 191 203 { 192 204 int id = 0; … … 199 211 /* Is it a builtin command ? */ 200 212 if ((id = (is_builtin(cmd[0]))) > -1) { 201 return run_builtin(id, cmd, usr );213 return run_builtin(id, cmd, usr, new_iostate); 202 214 } 203 215 204 216 /* Is it a module ? */ 205 217 if ((id = (is_module(cmd[0]))) > -1) { 206 return run_module(id, cmd );218 return run_module(id, cmd, new_iostate); 207 219 } 208 220 209 221 /* See what try_exec thinks of it */ 210 return try_exec(cmd[0], cmd, files);222 return try_exec(cmd[0], cmd, new_iostate); 211 223 } 212 224
Note:
See TracChangeset
for help on using the changeset viewer.