diff options
author | Ron Yorston <rmy@pobox.com> | 2024-04-22 07:54:34 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2024-04-22 07:54:34 +0100 |
commit | b5131ae1c0bb7984b35c909d04e2f4a61a7b6d8f (patch) | |
tree | e1a23e01cdffe3128c44d6e41f86c17c43782202 | |
parent | acda99ca9984570b03825c295a5617e67f0c1d7c (diff) | |
download | busybox-w32-b5131ae1c0bb7984b35c909d04e2f4a61a7b6d8f.tar.gz busybox-w32-b5131ae1c0bb7984b35c909d04e2f4a61a7b6d8f.tar.bz2 busybox-w32-b5131ae1c0bb7984b35c909d04e2f4a61a7b6d8f.zip |
win32: adjust handling of executable extensions
Mixing Windows and Unix-style filename extensions was causing
problems. Tweak how extensions are handled to try and improve
matters:
- Consistently check whether the unaltered filename is an
executable before trying adding extensions.
- Check .exe and .com before .sh.
Saves up to 16 bytes.
(GitHub issue #405)
-rw-r--r-- | shell/ash.c | 2 | ||||
-rw-r--r-- | win32/mingw.c | 20 |
2 files changed, 13 insertions, 9 deletions
diff --git a/shell/ash.c b/shell/ash.c index dc2115414..e32731d41 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -15059,7 +15059,7 @@ find_command(char *name, struct cmdentry *entry, int act, const char *path) | |||
15059 | entry->u.index = -1; | 15059 | entry->u.index = -1; |
15060 | entry->cmdtype = CMDNORMAL; | 15060 | entry->cmdtype = CMDNORMAL; |
15061 | fullname = stack_add_ext_space(name); | 15061 | fullname = stack_add_ext_space(name); |
15062 | if (add_win32_extension(fullname) || file_is_executable(fullname)) { | 15062 | if (add_win32_extension(fullname)) { |
15063 | return; | 15063 | return; |
15064 | } else if (unix_path(name)) { | 15064 | } else if (unix_path(name)) { |
15065 | name = (char *)bb_basename(name); | 15065 | name = (char *)bb_basename(name); |
diff --git a/win32/mingw.c b/win32/mingw.c index b1225665c..8669cc137 100644 --- a/win32/mingw.c +++ b/win32/mingw.c | |||
@@ -2041,7 +2041,7 @@ void mingw_sync(void) | |||
2041 | } | 2041 | } |
2042 | 2042 | ||
2043 | #define NUMEXT 5 | 2043 | #define NUMEXT 5 |
2044 | static const char win_suffix[NUMEXT][4] = { "sh", "com", "exe", "bat", "cmd" }; | 2044 | static const char win_suffix[NUMEXT][4] = { "com", "exe", "sh", "bat", "cmd" }; |
2045 | 2045 | ||
2046 | static int has_win_suffix(const char *name, int start) | 2046 | static int has_win_suffix(const char *name, int start) |
2047 | { | 2047 | { |
@@ -2082,21 +2082,25 @@ char *alloc_ext_space(const char *path) | |||
2082 | return s; | 2082 | return s; |
2083 | } | 2083 | } |
2084 | 2084 | ||
2085 | /* Check if path can be made into an executable by adding a suffix. | 2085 | /* Check if path is an executable or can be made into one by adding |
2086 | * The suffix is added to the end of the argument which must be | 2086 | * a suffix. The suffix is added to the end of the argument which |
2087 | * long enough to allow this. | 2087 | * must be long enough to allow this. |
2088 | * | 2088 | * |
2089 | * If the return value is TRUE the argument contains the new path, | 2089 | * If the return value is TRUE the argument contains the new path, |
2090 | * if FALSE the argument is unchanged. | 2090 | * if FALSE the argument is unchanged. |
2091 | */ | 2091 | */ |
2092 | int add_win32_extension(char *p) | 2092 | int |
2093 | add_win32_extension(char *p) | ||
2093 | { | 2094 | { |
2095 | if (file_is_executable(p)) | ||
2096 | return TRUE; | ||
2097 | |||
2094 | if (!has_exe_suffix_or_dot(p)) { | 2098 | if (!has_exe_suffix_or_dot(p)) { |
2095 | int i, len = strlen(p); | 2099 | int i, len = strlen(p); |
2096 | 2100 | ||
2097 | p[len] = '.'; | 2101 | p[len] = '.'; |
2098 | for (i=0; i<NUMEXT; ++i) { | 2102 | for (i = 0; i < NUMEXT; ++i) { |
2099 | strcpy(p+len+1, win_suffix[i]); | 2103 | strcpy(p + len + 1, win_suffix[i]); |
2100 | if (file_is_executable(p)) | 2104 | if (file_is_executable(p)) |
2101 | return TRUE; | 2105 | return TRUE; |
2102 | } | 2106 | } |
@@ -2114,7 +2118,7 @@ file_is_win32_exe(const char *name) | |||
2114 | { | 2118 | { |
2115 | char *path = alloc_ext_space(name); | 2119 | char *path = alloc_ext_space(name); |
2116 | 2120 | ||
2117 | if ((add_win32_extension(path) || file_is_executable(path))) | 2121 | if (add_win32_extension(path)) |
2118 | return path; | 2122 | return path; |
2119 | 2123 | ||
2120 | free(path); | 2124 | free(path); |