summaryrefslogtreecommitdiff
path: root/i/pc104/initrd/conf/busybox/debianutils/which.c
diff options
context:
space:
mode:
Diffstat (limited to 'i/pc104/initrd/conf/busybox/debianutils/which.c')
-rw-r--r--i/pc104/initrd/conf/busybox/debianutils/which.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/i/pc104/initrd/conf/busybox/debianutils/which.c b/i/pc104/initrd/conf/busybox/debianutils/which.c
new file mode 100644
index 0000000..02992d0
--- /dev/null
+++ b/i/pc104/initrd/conf/busybox/debianutils/which.c
@@ -0,0 +1,48 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * Which implementation for busybox
+ *
+ * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
+ * Copyright (C) 2006 Gabriel Somlo <somlo at cmu.edu>
+ *
+ * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
+ *
+ * Based on which from debianutils
+ */
+
+#include "busybox.h"
+
+int which_main(int argc, char **argv);
+int which_main(int argc, char **argv)
+{
+ int status = EXIT_SUCCESS;
+ char *p;
+
+ if (argc <= 1 || argv[1][0] == '-') {
+ bb_show_usage();
+ }
+
+ if (!getenv("PATH")) {
+ setenv("PATH", "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin", 1);
+ }
+
+ while (--argc > 0) {
+ argv++;
+ if (strchr(*argv, '/')) {
+ if (execable_file(*argv)) {
+ puts(*argv);
+ continue;
+ }
+ } else {
+ p = find_execable(*argv);
+ if (p) {
+ puts(p);
+ free(p);
+ continue;
+ }
+ }
+ status = EXIT_FAILURE;
+ }
+
+ fflush_stdout_and_exit(status);
+}