- Timestamp:
- Nov 29, 2007 11:46:50 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk_redirect/kmk_redirect.c
r1276 r1278 52 52 "\n" 53 53 "The rwa+tb is like for fopen, if not specified it defaults to w+.\n" 54 "The <fd> is either a number or an alias for the standard handles;\n" 54 "The <fd> is either a number or an alias for the standard handles;\n" 55 55 "i - stdin, o - stdout, e - stderr.\n" 56 56 , … … 60 60 61 61 62 int main(int argc, char **argv , char **envp)62 int main(int argc, char **argv) 63 63 { 64 64 int i; 65 #if defined(_MSC_VER) 66 intptr_t rc; 67 #endif 65 68 FILE *pStdErr = stderr; 66 69 FILE *pStdOut = stdout; … … 112 115 } 113 116 114 /* 117 /* 115 118 * Parse a file descriptor argument. 116 119 */ … … 174 177 #ifdef O_TEXT 175 178 fOpen |= O_TEXT; 176 #endif 179 #endif 177 180 psz++; 178 181 break; … … 193 196 psz++; 194 197 break; 195 198 196 199 case 'e': 197 200 fd = 2; 198 201 psz++; 199 202 break; 200 203 201 204 case '0': 202 205 if (!psz[1]) … … 220 223 fprintf(pStdErr, "%s: error: failed to convert '%s' to a number\n", argv[0], argv[i]); 221 224 return 1; 222 225 223 226 } 224 227 if (fd < 0) … … 258 261 if (fd == fileno(pStdErr)) 259 262 { 260 /* 263 /* 261 264 * Move stderr to a new location, making it close on exec. 262 265 * If pStdOut has already teamed up with pStdErr, update it too. … … 270 273 } 271 274 #ifdef _MSC_VER 272 /** @todo figure out how to make the handle close-on-exec. We'll simply close it for now. 275 /** @todo figure out how to make the handle close-on-exec. We'll simply close it for now. 273 276 * SetHandleInformation + set FNOINHERIT in CRT. 274 277 */ … … 279 282 return 1; 280 283 } 281 #endif 284 #endif 282 285 283 286 pNew = fdopen(fdOpened, "w"); … … 335 338 } 336 339 337 #if 0/** @tododefined(_MSC_VER)338 / *339 * We'll have to find the '--' in the commandline and pass that 340 * on to CreateProcess or spawn. Otherwise, the argument qouting 340 #if defined(_MSC_VER) 341 /** @todo 342 * We'll have to find the '--' in the commandline and pass that 343 * on to CreateProcess or spawn. Otherwise, the argument qouting 341 344 * is gonna be messed up. 342 345 */ 346 if (fileno(pStdErr) != 2) 347 fclose(pStdErr); 348 rc = _spawnvp(_P_WAIT, argv[i], &argv[i]); 349 if (rc == -1 && fileno(pStdErr) != 2) 350 { 351 fprintf(pStdErr, "%s: error: _spawnvp(_P_WAIT,%s,..) failed: %s\n", argv[0], argv[i], strerror(errno)); 352 rc = 1; 353 } 354 return rc; 343 355 #else 344 # if defined(_MSC_VER) /* tmp hack. */ 345 if (fileno(pStdErr) != 2) 346 { 347 fclose(pStdErr); 348 execv(argv[i], &argv[i]); 349 return 1; 350 } 351 # endif 352 execv(argv[i], &argv[i]); 353 fprintf(pStdErr, "%s: error: execv(%s,..) failed: %s\n", argv[0], argv[i], strerror(errno)); 354 #endif 356 execvp(argv[i], &argv[i]); 355 357 return 1; 358 #endif 356 359 } 357 360
Note:
See TracChangeset
for help on using the changeset viewer.