ifupdown: stop emitting annoying/misleading error messages.
[oweals/busybox.git] / debianutils / which.c
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>
6  * Copyright (C) 2006 Gabriel Somlo <somlo at cmu.edu>
7  *
8  * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
9  *
10  * Based on which from debianutils
11  */
12
13 #include "busybox.h"
14
15 int which_main(int argc, char **argv)
16 {
17         int status = EXIT_SUCCESS;
18         char *p;
19
20         if (argc <= 1 || argv[1][0] == '-') {
21                 bb_show_usage();
22         }
23
24         while (--argc > 0) {
25                 argv++;
26                 if (strchr(*argv, '/')) {
27                         if (execable_file(*argv)) {
28                                 puts(*argv);
29                                 continue;
30                         }
31                 } else {
32                         p = find_execable(*argv);
33                         if (p) {
34                                 puts(p);
35                                 free(p);
36                                 continue;
37                         }
38                 }
39                 status = EXIT_FAILURE;
40         }
41
42         bb_fflush_stdout_and_exit(status);
43 }