hush/debianutils/which.c

44 lines
768 B
C
Raw Normal View History

/* 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"
2006-06-14 16:17:50 +00:00
int which_main(int argc, char **argv)
{
int status = EXIT_SUCCESS;
char *p;
2006-10-05 21:10:53 +00:00
if (argc <= 1 || argv[1][0] == '-') {
2003-03-19 09:13:01 +00:00
bb_show_usage();
}
while (--argc > 0) {
argv++;
if (strchr(*argv, '/')) {
if (execable_file(*argv)) {
puts(*argv);
continue;
2006-10-05 21:10:53 +00:00
}
} else {
p = find_execable(*argv);
if (p) {
puts(p);
free(p);
continue;
}
}
2006-10-05 21:10:53 +00:00
status = EXIT_FAILURE;
}
2006-10-26 23:21:47 +00:00
fflush_stdout_and_exit(status);
}