diff options
| author | aldot <aldot@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-06-14 16:17:50 +0000 |
|---|---|---|
| committer | aldot <aldot@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-06-14 16:17:50 +0000 |
| commit | 5ed3a243feeda967cfe6bc523eb268b186780800 (patch) | |
| tree | 65c23176f5405b73736655e0335ccc575138c453 /debianutils | |
| parent | 08f036274a602ac6c25b8190794f8eaa1d96044f (diff) | |
| download | busybox-w32-5ed3a243feeda967cfe6bc523eb268b186780800.tar.gz busybox-w32-5ed3a243feeda967cfe6bc523eb268b186780800.tar.bz2 busybox-w32-5ed3a243feeda967cfe6bc523eb268b186780800.zip | |
- minor shrinkage
git-svn-id: svn://busybox.net/trunk/busybox@15383 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'debianutils')
| -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); |
