summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBernhard Reutner-Fischer2006-06-14 16:17:50 +0000
committerBernhard Reutner-Fischer2006-06-14 16:17:50 +0000
commit66e3a222cd430d5a0a371f351131f9dd63b158dc (patch)
tree65c23176f5405b73736655e0335ccc575138c453
parentd760560c5284f4e36d03772cc6f3bfb8aaeaef56 (diff)
downloadbusybox-66e3a222cd430d5a0a371f351131f9dd63b158dc.zip
busybox-66e3a222cd430d5a0a371f351131f9dd63b158dc.tar.gz
- minor shrinkage
-rw-r--r--debianutils/which.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/debianutils/which.c b/debianutils/which.c
index 62cb1dc..35c21e1 100644
--- a/debianutils/which.c
+++ b/debianutils/which.c
@@ -16,9 +16,15 @@
#include <unistd.h>
#include <sys/stat.h>
+
+static int is_executable_file(const char const * a, struct stat *b)
+{
+ return (!access(a,X_OK) && !stat(a, b) && S_ISREG(b->st_mode));
+}
+
int which_main(int argc, char **argv)
{
- int status = EXIT_SUCCESS;
+ int status;
size_t i, count;
char *path_list;
@@ -63,13 +69,12 @@ int which_main(int argc, char **argv)
count = 5;
}
+ status = EXIT_SUCCESS;
while (argc-- > 0) {
struct stat stat_b;
char *buf;
char *path_n;
- char found = 0;
-#define is_executable_file(a, b) (!access(a,X_OK) && !stat(a, &b) && \
- S_ISREG(b.st_mode))
+ int found = 0;
argv++;
path_n = path_list;
@@ -77,14 +82,14 @@ int which_main(int argc, char **argv)
/* if filename is either absolute or contains slashes,
* stat it */
- if (strchr(buf, '/') != NULL && is_executable_file(buf, stat_b)) {
- found = 1;
+ if (strchr(buf, '/') != NULL && is_executable_file(buf, &stat_b)) {
+ found++;
} else {
/* Couldn't access file and file doesn't contain slashes */
for (i = 0; i < count; i++) {
buf = concat_path_file(path_n, *argv);
- if (is_executable_file(buf, stat_b)) {
- found = 1;
+ if (is_executable_file(buf, &stat_b)) {
+ found++;
break;
}
free(buf);