diff options
author | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2006-06-14 16:17:50 +0000 |
---|---|---|
committer | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2006-06-14 16:17:50 +0000 |
commit | 66e3a222cd430d5a0a371f351131f9dd63b158dc (patch) | |
tree | 65c23176f5405b73736655e0335ccc575138c453 | |
parent | d760560c5284f4e36d03772cc6f3bfb8aaeaef56 (diff) | |
download | busybox-w32-66e3a222cd430d5a0a371f351131f9dd63b158dc.tar.gz busybox-w32-66e3a222cd430d5a0a371f351131f9dd63b158dc.tar.bz2 busybox-w32-66e3a222cd430d5a0a371f351131f9dd63b158dc.zip |
- minor shrinkage
-rw-r--r-- | debianutils/which.c | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/debianutils/which.c b/debianutils/which.c index 62cb1dc6d..35c21e181 100644 --- a/debianutils/which.c +++ b/debianutils/which.c | |||
@@ -16,9 +16,15 @@ | |||
16 | #include <unistd.h> | 16 | #include <unistd.h> |
17 | #include <sys/stat.h> | 17 | #include <sys/stat.h> |
18 | 18 | ||
19 | |||
20 | static int is_executable_file(const char const * a, struct stat *b) | ||
21 | { | ||
22 | return (!access(a,X_OK) && !stat(a, b) && S_ISREG(b->st_mode)); | ||
23 | } | ||
24 | |||
19 | int which_main(int argc, char **argv) | 25 | int which_main(int argc, char **argv) |
20 | { | 26 | { |
21 | int status = EXIT_SUCCESS; | 27 | int status; |
22 | size_t i, count; | 28 | size_t i, count; |
23 | char *path_list; | 29 | char *path_list; |
24 | 30 | ||
@@ -63,13 +69,12 @@ int which_main(int argc, char **argv) | |||
63 | count = 5; | 69 | count = 5; |
64 | } | 70 | } |
65 | 71 | ||
72 | status = EXIT_SUCCESS; | ||
66 | while (argc-- > 0) { | 73 | while (argc-- > 0) { |
67 | struct stat stat_b; | 74 | struct stat stat_b; |
68 | char *buf; | 75 | char *buf; |
69 | char *path_n; | 76 | char *path_n; |
70 | char found = 0; | 77 | int found = 0; |
71 | #define is_executable_file(a, b) (!access(a,X_OK) && !stat(a, &b) && \ | ||
72 | S_ISREG(b.st_mode)) | ||
73 | 78 | ||
74 | argv++; | 79 | argv++; |
75 | path_n = path_list; | 80 | path_n = path_list; |
@@ -77,14 +82,14 @@ int which_main(int argc, char **argv) | |||
77 | 82 | ||
78 | /* if filename is either absolute or contains slashes, | 83 | /* if filename is either absolute or contains slashes, |
79 | * stat it */ | 84 | * stat it */ |
80 | if (strchr(buf, '/') != NULL && is_executable_file(buf, stat_b)) { | 85 | if (strchr(buf, '/') != NULL && is_executable_file(buf, &stat_b)) { |
81 | found = 1; | 86 | found++; |
82 | } else { | 87 | } else { |
83 | /* Couldn't access file and file doesn't contain slashes */ | 88 | /* Couldn't access file and file doesn't contain slashes */ |
84 | for (i = 0; i < count; i++) { | 89 | for (i = 0; i < count; i++) { |
85 | buf = concat_path_file(path_n, *argv); | 90 | buf = concat_path_file(path_n, *argv); |
86 | if (is_executable_file(buf, stat_b)) { | 91 | if (is_executable_file(buf, &stat_b)) { |
87 | found = 1; | 92 | found++; |
88 | break; | 93 | break; |
89 | } | 94 | } |
90 | free(buf); | 95 | free(buf); |