diff options
| author | Ron Yorston <rmy@pobox.com> | 2018-12-06 15:16:49 +0000 |
|---|---|---|
| committer | Ron Yorston <rmy@pobox.com> | 2018-12-06 15:16:49 +0000 |
| commit | 9906faf2dff6fd9033cb711619528501cae11721 (patch) | |
| tree | a85bb3ee78f5d58378f23842e0e762e879db23bc /libbb/executable.c | |
| parent | d257c7f2b6c44662c793d00d0b9286d6246b84a3 (diff) | |
| download | busybox-w32-9906faf2dff6fd9033cb711619528501cae11721.tar.gz busybox-w32-9906faf2dff6fd9033cb711619528501cae11721.tar.bz2 busybox-w32-9906faf2dff6fd9033cb711619528501cae11721.zip | |
win32: rework adding of extensions to filenames
Previously there was one function to handle adding extensions to
executable filenames, add_win32_extension(). Refactor this into
three functions:
add_win32_extension() appends the suffix to the argument string
in-place. The argument must be long enough to cope with this,
as is the case in ash where path_advance() adds 4 bytes to each
filename for just this reason.
alloc_win32_extension() is equivalent to the old add_win32_extension().
It allocates a string to hold the new filename then calls the new
add_win32_extension() function. The caller is responsible for
managing the returned string.
auto_win32_extension() calls alloc_win32_extension() and saves the
resulting string using auto_string(). It's used where the new
filename is consumed immediately or the actual value isn't needed.
Rewrite code to use the most appropriate function. Also reorder
some code in find_executable() and find_command().
Diffstat (limited to 'libbb/executable.c')
| -rw-r--r-- | libbb/executable.c | 32 |
1 files changed, 11 insertions, 21 deletions
diff --git a/libbb/executable.c b/libbb/executable.c index aec829945..835341ed9 100644 --- a/libbb/executable.c +++ b/libbb/executable.c | |||
| @@ -28,10 +28,6 @@ int FAST_FUNC file_is_executable(const char *name) | |||
| 28 | * in all cases (*PATHp) contents are temporarily modified | 28 | * in all cases (*PATHp) contents are temporarily modified |
| 29 | * but are restored on return (s/:/NUL/ and back). | 29 | * but are restored on return (s/:/NUL/ and back). |
| 30 | */ | 30 | */ |
| 31 | #if !ENABLE_PLATFORM_MINGW32 | ||
| 32 | #define next_path_sep(s) strchr(s, ':') | ||
| 33 | #endif | ||
| 34 | |||
| 35 | char* FAST_FUNC find_executable(const char *filename, char **PATHp) | 31 | char* FAST_FUNC find_executable(const char *filename, char **PATHp) |
| 36 | { | 32 | { |
| 37 | /* About empty components in $PATH: | 33 | /* About empty components in $PATH: |
| @@ -44,38 +40,32 @@ char* FAST_FUNC find_executable(const char *filename, char **PATHp) | |||
| 44 | */ | 40 | */ |
| 45 | char *p, *n; | 41 | char *p, *n; |
| 46 | #if ENABLE_PLATFORM_MINGW32 | 42 | #if ENABLE_PLATFORM_MINGW32 |
| 47 | char *w; | 43 | char sep, *w; |
| 48 | #endif | 44 | #endif |
| 49 | 45 | ||
| 50 | p = *PATHp; | 46 | p = *PATHp; |
| 51 | while (p) { | 47 | while (p) { |
| 52 | int ex; | 48 | int ex; |
| 53 | #if ENABLE_PLATFORM_MINGW32 | ||
| 54 | char sep; | ||
| 55 | 49 | ||
| 56 | n = (char*)next_path_sep(p); | 50 | #if !ENABLE_PLATFORM_MINGW32 |
| 57 | if (n) { | ||
| 58 | sep = *n; | ||
| 59 | *n = '\0'; | ||
| 60 | } | ||
| 61 | #else | ||
| 62 | n = strchr(p, ':'); | 51 | n = strchr(p, ':'); |
| 63 | if (n) *n = '\0'; | 52 | if (n) *n = '\0'; |
| 53 | #else | ||
| 54 | n = (char*)next_path_sep(p); | ||
| 55 | if (n) { sep = *n; *n = '\0'; } | ||
| 64 | #endif | 56 | #endif |
| 65 | p = concat_path_file( | 57 | p = concat_path_file( |
| 66 | p[0] ? p : ".", /* handle "::" case */ | 58 | p[0] ? p : ".", /* handle "::" case */ |
| 67 | filename | 59 | filename |
| 68 | ); | 60 | ); |
| 69 | #if ENABLE_PLATFORM_MINGW32 | 61 | #if !ENABLE_PLATFORM_MINGW32 |
| 70 | if (n) *n++ = sep; | ||
| 71 | #else | ||
| 72 | if (n) *n++ = ':'; | 62 | if (n) *n++ = ':'; |
| 73 | #endif | 63 | #else |
| 74 | #if ENABLE_PLATFORM_MINGW32 | 64 | if (n) *n++ = sep; |
| 75 | if ((w=add_win32_extension(p))) { | 65 | if ((w=alloc_win32_extension(p))) { |
| 76 | *PATHp = n; | ||
| 77 | free(p); | 66 | free(p); |
| 78 | return w; | 67 | p = w; |
| 68 | /* following test will succeed */ | ||
| 79 | } | 69 | } |
| 80 | #endif | 70 | #endif |
| 81 | ex = file_is_executable(p); | 71 | ex = file_is_executable(p); |
