1 /* vi: set sw=4 ts=4: */
3 * Which implementation for busybox
5 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
6 * Copyright (C) 2006 Gabriel Somlo <somlo at cmu.edu>
8 * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
10 * Based on which from debianutils
15 int which_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
16 int which_main(int argc, char **argv)
18 int status = EXIT_SUCCESS;
21 if (argc <= 1 || argv[1][0] == '-') {
25 /* This matches what is seen on e.g. ubuntu
26 * "which" there is a shell script */
27 if (!getenv("PATH")) {
28 putenv((char*)bb_PATH_root_path);
33 if (strchr(*argv, '/')) {
34 if (execable_file(*argv)) {
39 p = find_execable(*argv);
46 status = EXIT_FAILURE;
49 fflush_stdout_and_exit(status);