Changeset 1674 in kBuild
- Timestamp:
- Jul 11, 2008 12:49:29 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk/kmkbuiltin/redirect.c
r1577 r1674 48 48 # define LIBPATHSTRICT 3 49 49 # endif 50 #endif 50 #endif 51 52 53 static const char *name(const char *pszName) 54 { 55 const char *psz = strrchr(pszName, '/'); 56 #if defined(_MSC_VER) || defined(__OS2__) 57 const char *psz2 = strrchr(pszName, '\\'); 58 if (!psz2) 59 psz2 = strrchr(pszName, ':'); 60 if (psz2 && (!psz || psz2 > psz)) 61 psz = psz2; 62 #endif 63 return psz ? psz + 1 : pszName; 64 } 51 65 52 66 … … 93 107 */ 94 108 if (argc <= 1) 95 return usage(pStdErr, argv[0]);109 return usage(pStdErr, name(argv[0])); 96 110 for (i = 1; i < argc; i++) 97 111 { … … 127 141 if (*psz == 'h') 128 142 { 129 usage(pStdOut, argv[0]);143 usage(pStdOut, name(argv[0])); 130 144 return 0; 131 145 } … … 151 165 if (i + 1 >= argc) 152 166 { 153 fprintf(pStdErr, "%s: syntax error: no argument for %s\n", argv[0], argv[i]);167 fprintf(pStdErr, "%s: syntax error: no argument for %s\n", name(argv[0]), argv[i]); 154 168 return 1; 155 169 } … … 168 182 if (rc) 169 183 { 170 fprintf(pStdErr, "%s: error: DosSetExtLibPath(\"%s\", %.*s (%lu)): %lu\n", 171 argv[0], pszVal, pszVal - psz - 1, psz, ulVar, rc);184 fprintf(pStdErr, "%s: error: DosSetExtLibPath(\"%s\", %.*s (%lu)): %lu\n", 185 name(argv[0]), pszVal, pszVal - psz - 1, psz, ulVar, rc); 172 186 return 1; 173 187 } … … 177 191 if (putenv(psz)) 178 192 { 179 fprintf(pStdErr, "%s: error: putenv(\"%s\"): %s\n", argv[0], psz, strerror(errno));193 fprintf(pStdErr, "%s: error: putenv(\"%s\"): %s\n", name(argv[0]), psz, strerror(errno)); 180 194 return 1; 181 195 } … … 195 209 if (i + 1 >= argc) 196 210 { 197 fprintf(pStdErr, "%s: syntax error: no argument for %s\n", argv[0], argv[i]);211 fprintf(pStdErr, "%s: syntax error: no argument for %s\n", name(argv[0]), argv[i]); 198 212 return 1; 199 213 } … … 223 237 } 224 238 #endif 225 fprintf(pStdErr, "%s: error: chdir(\"%s\"): %s\n", argv[0], psz, strerror(errno));239 fprintf(pStdErr, "%s: error: chdir(\"%s\"): %s\n", name(argv[0]), psz, strerror(errno)); 226 240 return 1; 227 241 } … … 272 286 273 287 case '+': 274 fprintf(pStdErr, "%s: syntax error: Unexpected '+' in '%s'\n", argv[0], argv[i]);288 fprintf(pStdErr, "%s: syntax error: Unexpected '+' in '%s'\n", name(argv[0]), argv[i]); 275 289 return 1; 276 290 … … 342 356 if (!fd) 343 357 { 344 fprintf(pStdErr, "%s: error: failed to convert '%s' to a number\n", argv[0], argv[i]);358 fprintf(pStdErr, "%s: error: failed to convert '%s' to a number\n", name(argv[0]), argv[i]); 345 359 return 1; 346 360 … … 348 362 if (fd < 0) 349 363 { 350 fprintf(pStdErr, "%s: error: negative fd %d (%s)\n", argv[0], fd, argv[i]);364 fprintf(pStdErr, "%s: error: negative fd %d (%s)\n", name(argv[0]), fd, argv[i]); 351 365 return 1; 352 366 } … … 357 371 */ 358 372 default: 359 fprintf(pStdErr, "%s: error: failed to convert '%s' ('%s') to a file descriptor\n", argv[0], psz, argv[i]);373 fprintf(pStdErr, "%s: error: failed to convert '%s' ('%s') to a file descriptor\n", name(argv[0]), psz, argv[i]); 360 374 return 1; 361 375 } … … 368 382 if (*psz != ':' && *psz != '=') 369 383 { 370 fprintf(pStdErr, "%s: syntax error: characters following the file descriptor: '%s' ('%s')\n", argv[0], psz, argv[i]);384 fprintf(pStdErr, "%s: syntax error: characters following the file descriptor: '%s' ('%s')\n", name(argv[0]), psz, argv[i]); 371 385 return 1; 372 386 } … … 378 392 if (i >= argc) 379 393 { 380 fprintf(pStdErr, "%s: syntax error: missing filename argument.\n", argv[0]);394 fprintf(pStdErr, "%s: syntax error: missing filename argument.\n", name(argv[0])); 381 395 return 1; 382 396 } … … 397 411 if (fdOpened == -1) 398 412 { 399 fprintf(pStdErr, "%s: error: failed to dup stderr (%d): %s\n", argv[0], fileno(pStdErr), strerror(errno));413 fprintf(pStdErr, "%s: error: failed to dup stderr (%d): %s\n", name(argv[0]), fileno(pStdErr), strerror(errno)); 400 414 return 1; 401 415 } … … 407 421 if (fcntl(fdOpened, F_SETFD, FD_CLOEXEC) == -1) 408 422 { 409 fprintf(pStdErr, "%s: error: failed to make stderr (%d) close-on-exec: %s\n", argv[0], fdOpened, strerror(errno));423 fprintf(pStdErr, "%s: error: failed to make stderr (%d) close-on-exec: %s\n", name(argv[0]), fdOpened, strerror(errno)); 410 424 return 1; 411 425 } … … 415 429 if (!pNew) 416 430 { 417 fprintf(pStdErr, "%s: error: failed to fdopen the new stderr (%d): %s\n", argv[0], fdOpened, strerror(errno));431 fprintf(pStdErr, "%s: error: failed to fdopen the new stderr (%d): %s\n", name(argv[0]), fdOpened, strerror(errno)); 418 432 return 1; 419 433 } … … 436 450 if (fdOpened == -1) 437 451 { 438 fprintf(pStdErr, "%s: error: failed to open '%s' as %d: %s\n", argv[0], psz, fd, strerror(errno));452 fprintf(pStdErr, "%s: error: failed to open '%s' as %d: %s\n", name(argv[0]), psz, fd, strerror(errno)); 439 453 return 1; 440 454 } … … 444 458 if (dup2(fdOpened, fd) == -1) 445 459 { 446 fprintf(pStdErr, "%s: error: failed to dup '%s' as %d: %s\n", argv[0], psz, fd, strerror(errno));460 fprintf(pStdErr, "%s: error: failed to dup '%s' as %d: %s\n", name(argv[0]), psz, fd, strerror(errno)); 447 461 return 1; 448 462 } … … 452 466 else 453 467 { 454 fprintf(pStdErr, "%s: syntax error: Invalid argument '%s'.\n", argv[0], argv[i]);455 return usage(pStdErr, argv[0]);468 fprintf(pStdErr, "%s: syntax error: Invalid argument '%s'.\n", name(argv[0]), argv[i]); 469 return usage(pStdErr, name(argv[0])); 456 470 } 457 471 } … … 462 476 if (i >= argc) 463 477 { 464 fprintf(pStdErr, "%s: syntax error: nothing to execute!\n", argv[0]);465 return usage(pStdErr, argv[0]);478 fprintf(pStdErr, "%s: syntax error: nothing to execute!\n", name(argv[0])); 479 return usage(pStdErr, name(argv[0])); 466 480 } 467 481 468 482 #if defined(_MSC_VER) 483 if (fileno(pStdErr) != 2) /* no close-on-exec flag on windows */ 484 { 485 fclose(pStdErr); 486 pStdErr = NULL; 487 } 488 469 489 /** @todo 470 490 * We'll have to find the '--' in the commandline and pass that … … 472 492 * is gonna be messed up. 473 493 */ 474 if (fileno(pStdErr) != 2)475 fclose(pStdErr);476 494 rc = _spawnvp(_P_WAIT, argv[i], &argv[i]); 477 if (rc == -1 && fileno(pStdErr) != 2)495 if (rc == -1 && pStdErr) 478 496 { 479 fprintf(pStdErr, "%s: error: _spawnvp(_P_WAIT, %s,..) failed: %s\n", argv[0], argv[i], strerror(errno));497 fprintf(pStdErr, "%s: error: _spawnvp(_P_WAIT, \"%s\", ...) failed: %s\n", name(argv[0]), argv[i], strerror(errno)); 480 498 rc = 1; 481 499 } … … 483 501 #else 484 502 execvp(argv[i], &argv[i]); 503 fprintf(pStdErr, "%s: error: _execvp(_P_WAIT, \"%s\", ...) failed: %s\n", name(argv[0]), argv[i], strerror(errno)); 485 504 return 1; 486 505 #endif
Note:
See TracChangeset
for help on using the changeset viewer.