diff options
author | Eric Andersen <andersen@codepoet.org> | 2003-10-22 10:38:22 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2003-10-22 10:38:22 +0000 |
commit | 514633bf3f4f941d3ba1bb47cc46c31734574cf6 (patch) | |
tree | 0b88ae3bde763d8e1ead53c018c6b1cf16a2bc4b /debianutils | |
parent | 7f6295f51604a97a61958909b652dcf1e0e49485 (diff) | |
download | busybox-w32-514633bf3f4f941d3ba1bb47cc46c31734574cf6.tar.gz busybox-w32-514633bf3f4f941d3ba1bb47cc46c31734574cf6.tar.bz2 busybox-w32-514633bf3f4f941d3ba1bb47cc46c31734574cf6.zip |
Tomasz Motylewski reported that the 'which' applet does not find
files when the full file PATH is specified.
This patch from Arthur Othieno fixes it.
Diffstat (limited to 'debianutils')
-rw-r--r-- | debianutils/which.c | 42 |
1 files changed, 30 insertions, 12 deletions
diff --git a/debianutils/which.c b/debianutils/which.c index 79a89c4eb..74b922531 100644 --- a/debianutils/which.c +++ b/debianutils/which.c | |||
@@ -26,10 +26,19 @@ | |||
26 | #include <stdlib.h> | 26 | #include <stdlib.h> |
27 | #include "busybox.h" | 27 | #include "busybox.h" |
28 | 28 | ||
29 | static int file_exists(char *file) | ||
30 | { | ||
31 | struct stat filestat; | ||
32 | |||
33 | if (stat(file, &filestat) == 0 && filestat.st_mode & S_IXUSR) | ||
34 | return 1; | ||
35 | else | ||
36 | return 0; | ||
37 | } | ||
38 | |||
29 | extern int which_main(int argc, char **argv) | 39 | extern int which_main(int argc, char **argv) |
30 | { | 40 | { |
31 | char *path_list, *path_n; | 41 | char *path_list, *path_n; |
32 | struct stat filestat; | ||
33 | int i, count=1, found, status = EXIT_SUCCESS; | 42 | int i, count=1, found, status = EXIT_SUCCESS; |
34 | 43 | ||
35 | if (argc <= 1 || **(argv + 1) == '-') | 44 | if (argc <= 1 || **(argv + 1) == '-') |
@@ -52,18 +61,27 @@ extern int which_main(int argc, char **argv) | |||
52 | path_n = path_list; | 61 | path_n = path_list; |
53 | argv++; | 62 | argv++; |
54 | found = 0; | 63 | found = 0; |
55 | for (i = 0; i < count; i++) { | 64 | char *buf; |
56 | char *buf; | 65 | |
57 | buf = concat_path_file(path_n, *argv); | 66 | /* |
58 | if (stat (buf, &filestat) == 0 | 67 | * Check if we were given the full path, first. |
59 | && filestat.st_mode & S_IXUSR) | 68 | * Otherwise see if the file exists in our $PATH. |
60 | { | 69 | */ |
61 | puts(buf); | 70 | buf = *argv; |
62 | found = 1; | 71 | if (file_exists(buf)) { |
63 | break; | 72 | puts(buf); |
73 | found = 1; | ||
74 | } else { | ||
75 | for (i = 0; i < count; i++) { | ||
76 | buf = concat_path_file(path_n, *argv); | ||
77 | if (file_exists(buf)) { | ||
78 | puts(buf); | ||
79 | found = 1; | ||
80 | break; | ||
81 | } | ||
82 | free(buf); | ||
83 | path_n += (strlen(path_n) + 1); | ||
64 | } | 84 | } |
65 | free(buf); | ||
66 | path_n += (strlen(path_n) + 1); | ||
67 | } | 85 | } |
68 | if (!found) | 86 | if (!found) |
69 | status = EXIT_FAILURE; | 87 | status = EXIT_FAILURE; |