diff options
Diffstat (limited to 'libbb/executable.c')
-rw-r--r-- | libbb/executable.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/libbb/executable.c b/libbb/executable.c index 325dd0107..29d2a2c85 100644 --- a/libbb/executable.c +++ b/libbb/executable.c | |||
@@ -25,7 +25,8 @@ int FAST_FUNC file_is_executable(const char *name) | |||
25 | * you may call find_executable again with this PATHp to continue | 25 | * you may call find_executable again with this PATHp to continue |
26 | * (if it's not NULL). | 26 | * (if it's not NULL). |
27 | * return NULL otherwise; (PATHp is undefined) | 27 | * return NULL otherwise; (PATHp is undefined) |
28 | * in all cases (*PATHp) contents will be trashed (s/:/NUL/). | 28 | * in all cases (*PATHp) contents are temporarily modified |
29 | * but are restored on return (s/:/NUL/ and back). | ||
29 | */ | 30 | */ |
30 | char* FAST_FUNC find_executable(const char *filename, char **PATHp) | 31 | char* FAST_FUNC find_executable(const char *filename, char **PATHp) |
31 | { | 32 | { |
@@ -41,14 +42,17 @@ char* FAST_FUNC find_executable(const char *filename, char **PATHp) | |||
41 | 42 | ||
42 | p = *PATHp; | 43 | p = *PATHp; |
43 | while (p) { | 44 | while (p) { |
45 | int ex; | ||
46 | |||
44 | n = strchr(p, ':'); | 47 | n = strchr(p, ':'); |
45 | if (n) | 48 | if (n) *n = '\0'; |
46 | *n++ = '\0'; | ||
47 | p = concat_path_file( | 49 | p = concat_path_file( |
48 | p[0] ? p : ".", /* handle "::" case */ | 50 | p[0] ? p : ".", /* handle "::" case */ |
49 | filename | 51 | filename |
50 | ); | 52 | ); |
51 | if (file_is_executable(p)) { | 53 | ex = file_is_executable(p); |
54 | if (n) *n++ = ':'; | ||
55 | if (ex) { | ||
52 | *PATHp = n; | 56 | *PATHp = n; |
53 | return p; | 57 | return p; |
54 | } | 58 | } |
@@ -64,10 +68,8 @@ char* FAST_FUNC find_executable(const char *filename, char **PATHp) | |||
64 | */ | 68 | */ |
65 | int FAST_FUNC executable_exists(const char *filename) | 69 | int FAST_FUNC executable_exists(const char *filename) |
66 | { | 70 | { |
67 | char *path = xstrdup(getenv("PATH")); | 71 | char *path = getenv("PATH"); |
68 | char *tmp = path; | 72 | char *ret = find_executable(filename, &path); |
69 | char *ret = find_executable(filename, &tmp); | ||
70 | free(path); | ||
71 | free(ret); | 73 | free(ret); |
72 | return ret != NULL; | 74 | return ret != NULL; |
73 | } | 75 | } |