source:
MondoRescue/branches/2.2.5/mindi-busybox/debianutils/which.c@
2669
| Last change on this file since 2669 was 1765, checked in by , 18 years ago | |
|---|---|
| File size: 921 bytes | |
| Rev | Line | |
|---|---|---|
| [821] | 1 | /* vi: set sw=4 ts=4: */ |
| 2 | /* | |
| 3 | * Which implementation for busybox | |
| 4 | * | |
| 5 | * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> | |
| [1765] | 6 | * Copyright (C) 2006 Gabriel Somlo <somlo at cmu.edu> |
| [821] | 7 | * |
| [1765] | 8 | * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. |
| [821] | 9 | * |
| 10 | * Based on which from debianutils | |
| 11 | */ | |
| 12 | ||
| [1765] | 13 | #include "libbb.h" |
| [821] | 14 | |
| [1765] | 15 | int which_main(int argc, char **argv); |
| [821] | 16 | int which_main(int argc, char **argv) |
| 17 | { | |
| [1765] | 18 | int status = EXIT_SUCCESS; |
| 19 | char *p; | |
| [821] | 20 | |
| [1765] | 21 | if (argc <= 1 || argv[1][0] == '-') { |
| [821] | 22 | bb_show_usage(); |
| 23 | } | |
| 24 | ||
| [1765] | 25 | /* We shouldn't do this. Ever. Not our business. |
| 26 | if (!getenv("PATH")) { | |
| 27 | putenv((char*)bb_PATH_root_path); | |
| [821] | 28 | } |
| [1765] | 29 | */ |
| [821] | 30 | |
| [1765] | 31 | while (--argc > 0) { |
| [821] | 32 | argv++; |
| [1765] | 33 | if (strchr(*argv, '/')) { |
| 34 | if (execable_file(*argv)) { | |
| 35 | puts(*argv); | |
| 36 | continue; | |
| 37 | } | |
| [821] | 38 | } else { |
| [1765] | 39 | p = find_execable(*argv); |
| 40 | if (p) { | |
| 41 | puts(p); | |
| 42 | free(p); | |
| 43 | continue; | |
| [821] | 44 | } |
| 45 | } | |
| [1765] | 46 | status = EXIT_FAILURE; |
| [821] | 47 | } |
| [1765] | 48 | |
| 49 | fflush_stdout_and_exit(status); | |
| [821] | 50 | } |
Note:
See TracBrowser
for help on using the repository browser.
