Changeset 2725 in MondoRescue for branches/2.2.9/mindi-busybox/debianutils/which.c
- Timestamp:
- Feb 25, 2011, 9:26:54 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.9/mindi-busybox/debianutils/which.c
r1765 r2725 6 6 * Copyright (C) 2006 Gabriel Somlo <somlo at cmu.edu> 7 7 * 8 * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.8 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 9 9 * 10 10 * Based on which from debianutils … … 13 13 #include "libbb.h" 14 14 15 int which_main(int argc, char **argv) ;16 int which_main(int argc , char **argv)15 int which_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 16 int which_main(int argc UNUSED_PARAM, char **argv) 17 17 { 18 IF_DESKTOP(int opt;) 18 19 int status = EXIT_SUCCESS; 20 char *path; 19 21 char *p; 20 22 21 if (argc <= 1 || argv[1][0] == '-') { 22 bb_show_usage(); 23 opt_complementary = "-1"; /* at least one argument */ 24 IF_DESKTOP(opt =) getopt32(argv, "a"); 25 argv += optind; 26 27 /* This matches what is seen on e.g. ubuntu. 28 * "which" there is a shell script. */ 29 path = getenv("PATH"); 30 if (!path) { 31 path = (char*)bb_PATH_root_path; 32 putenv(path); 33 path += 5; /* skip "PATH=" */ 23 34 } 24 35 25 /* We shouldn't do this. Ever. Not our business. 26 if (!getenv("PATH")) { 27 putenv((char*)bb_PATH_root_path); 28 } 29 */ 36 do { 37 #if ENABLE_DESKTOP 38 /* Much bloat just to support -a */ 39 if (strchr(*argv, '/')) { 40 if (execable_file(*argv)) { 41 puts(*argv); 42 continue; 43 } 44 status = EXIT_FAILURE; 45 } else { 46 char *path2 = xstrdup(path); 47 char *tmp = path2; 30 48 31 while (--argc > 0) { 32 argv++; 49 p = find_execable(*argv, &tmp); 50 if (!p) 51 status = EXIT_FAILURE; 52 else { 53 print: 54 puts(p); 55 free(p); 56 if (opt) { 57 /* -a: show matches in all PATH components */ 58 if (tmp) { 59 p = find_execable(*argv, &tmp); 60 if (p) 61 goto print; 62 } 63 } 64 } 65 free(path2); 66 } 67 #else 68 /* Just ignoring -a */ 33 69 if (strchr(*argv, '/')) { 34 70 if (execable_file(*argv)) { … … 37 73 } 38 74 } else { 39 p = find_execable(*argv); 75 char *path2 = xstrdup(path); 76 char *tmp = path2; 77 p = find_execable(*argv, &tmp); 78 free(path2); 40 79 if (p) { 41 80 puts(p); … … 45 84 } 46 85 status = EXIT_FAILURE; 47 } 86 #endif 87 } while (*(++argv) != NULL); 48 88 49 89 fflush_stdout_and_exit(status);
Note:
See TracChangeset
for help on using the changeset viewer.