summaryrefslogtreecommitdiff
path: root/polux/application/busybox/debianutils/which.c
diff options
context:
space:
mode:
authorJean-Philippe SAVE2012-02-20 16:38:56 +0100
committerJean-Philippe SAVE2012-02-20 16:38:56 +0100
commit55a15cc820e926219ebce47218ce1e2f35bb0c48 (patch)
treedba3ff39a766e47859ab7fd837d8da5d30b56b1f /polux/application/busybox/debianutils/which.c
parent1353d3215782b997fdec3f9182cbda547d92d7e9 (diff)
parentcfc4d43d4d19c398d994b75cb1eeda3c499bd234 (diff)
Add polux base by subtree merge
Diffstat (limited to 'polux/application/busybox/debianutils/which.c')
-rw-r--r--polux/application/busybox/debianutils/which.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/polux/application/busybox/debianutils/which.c b/polux/application/busybox/debianutils/which.c
new file mode 100644
index 0000000000..5ab67194db
--- /dev/null
+++ b/polux/application/busybox/debianutils/which.c
@@ -0,0 +1,50 @@
+/* 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 "libbb.h"
+
+int which_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
+int which_main(int argc, char **argv)
+{
+ int status = EXIT_SUCCESS;
+ char *p;
+
+ if (argc <= 1 || argv[1][0] == '-') {
+ bb_show_usage();
+ }
+
+ /* This matches what is seen on e.g. ubuntu
+ * "which" there is a shell script */
+ if (!getenv("PATH")) {
+ putenv((char*)bb_PATH_root_path);
+ }
+
+ 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);
+}