Magellan Linux

Contents of /trunk/mkinitrd-magellan/busybox/debianutils/which.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 532 - (show annotations) (download)
Sat Sep 1 22:45:15 2007 UTC (16 years, 8 months ago) by niro
File MIME type: text/plain
File size: 768 byte(s)
-import if magellan mkinitrd; it is a fork of redhats mkinitrd-5.0.8 with all magellan patches and features; deprecates magellan-src/mkinitrd

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 fflush_stdout_and_exit(status);
43 }