diff options
| author | Ron Yorston <rmy@pobox.com> | 2018-02-13 09:44:44 +0000 |
|---|---|---|
| committer | Ron Yorston <rmy@pobox.com> | 2018-02-13 09:44:44 +0000 |
| commit | dc19a361bd6c6df30338371532691bbc7f7126bb (patch) | |
| tree | 1fb2cd646d54b5f8e425c4f11f3e09fc21d1966b /libbb/executable.c | |
| parent | 096aee2bb468d1ab044de36e176ed1f6c7e3674d (diff) | |
| parent | 3459024bf404af814cacfe90a0deb719e282ae62 (diff) | |
| download | busybox-w32-dc19a361bd6c6df30338371532691bbc7f7126bb.tar.gz busybox-w32-dc19a361bd6c6df30338371532691bbc7f7126bb.tar.bz2 busybox-w32-dc19a361bd6c6df30338371532691bbc7f7126bb.zip | |
Merge branch 'busybox' into merge
Diffstat (limited to 'libbb/executable.c')
| -rw-r--r-- | libbb/executable.c | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/libbb/executable.c b/libbb/executable.c index b28f020e0..8e2f99732 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 | #if !ENABLE_PLATFORM_MINGW32 | 31 | #if !ENABLE_PLATFORM_MINGW32 |
| 31 | #define next_path_sep(s) strchr(s, ':') | 32 | #define next_path_sep(s) strchr(s, ':') |
| @@ -48,14 +49,30 @@ char* FAST_FUNC find_executable(const char *filename, char **PATHp) | |||
| 48 | 49 | ||
| 49 | p = *PATHp; | 50 | p = *PATHp; |
| 50 | while (p) { | 51 | while (p) { |
| 52 | int ex; | ||
| 53 | #if ENABLE_PLATFORM_MINGW32 | ||
| 54 | char sep; | ||
| 55 | |||
| 51 | n = (char*)next_path_sep(p); | 56 | n = (char*)next_path_sep(p); |
| 52 | if (n) | 57 | if (n) { |
| 53 | *n++ = '\0'; | 58 | sep = *n; |
| 59 | *n = '\0'; | ||
| 60 | } | ||
| 61 | #else | ||
| 62 | n = strchr(p, ':'); | ||
| 63 | if (n) *n = '\0'; | ||
| 64 | #endif | ||
| 54 | p = concat_path_file( | 65 | p = concat_path_file( |
| 55 | p[0] ? p : ".", /* handle "::" case */ | 66 | p[0] ? p : ".", /* handle "::" case */ |
| 56 | filename | 67 | filename |
| 57 | ); | 68 | ); |
| 58 | if (file_is_executable(p)) { | 69 | ex = file_is_executable(p); |
| 70 | #if ENABLE_PLATFORM_MINGW32 | ||
| 71 | if (n) *n++ = sep; | ||
| 72 | #else | ||
| 73 | if (n) *n++ = ':'; | ||
| 74 | #endif | ||
| 75 | if (ex) { | ||
| 59 | *PATHp = n; | 76 | *PATHp = n; |
| 60 | return p; | 77 | return p; |
| 61 | } | 78 | } |
| @@ -78,10 +95,8 @@ char* FAST_FUNC find_executable(const char *filename, char **PATHp) | |||
| 78 | */ | 95 | */ |
| 79 | int FAST_FUNC executable_exists(const char *filename) | 96 | int FAST_FUNC executable_exists(const char *filename) |
| 80 | { | 97 | { |
| 81 | char *path = xstrdup(getenv("PATH")); | 98 | char *path = getenv("PATH"); |
| 82 | char *tmp = path; | 99 | char *ret = find_executable(filename, &path); |
| 83 | char *ret = find_executable(filename, &tmp); | ||
| 84 | free(path); | ||
| 85 | free(ret); | 100 | free(ret); |
| 86 | return ret != NULL; | 101 | return ret != NULL; |
| 87 | } | 102 | } |
