1 /* vi: set sw=4 ts=4: */
3 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
4 * Copyright (C) 2006 Gabriel Somlo <somlo at cmu.edu>
6 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
9 //usage:#define which_trivial_usage
10 //usage: "[COMMAND]..."
11 //usage:#define which_full_usage "\n\n"
12 //usage: "Locate a COMMAND"
14 //usage:#define which_example_usage
15 //usage: "$ which login\n"
16 //usage: "/bin/login\n"
20 int which_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
21 int which_main(int argc UNUSED_PARAM, char **argv)
26 env_path = getenv("PATH");
28 env_path = bb_default_root_path;
30 opt_complementary = "-1"; /* at least one argument */
37 /* If file contains a slash don't use PATH */
38 if (strchr(*argv, '/')) {
39 if (file_is_executable(*argv)) {
48 path = tmp = xstrdup(env_path);
49 while ((p = find_executable(*argv, &tmp)) != NULL) {
53 if (!option_mask32) /* -a not set */