diff options
Diffstat (limited to 'win32')
-rw-r--r-- | win32/mingw.c | 34 | ||||
-rw-r--r-- | win32/process.c | 11 |
2 files changed, 29 insertions, 16 deletions
diff --git a/win32/mingw.c b/win32/mingw.c index c7eeea088..0a1af6b72 100644 --- a/win32/mingw.c +++ b/win32/mingw.c | |||
@@ -2001,6 +2001,15 @@ int has_exe_suffix_or_dot(const char *name) | |||
2001 | return last_char_is(name, '.') || has_win_suffix(name, 0); | 2001 | return last_char_is(name, '.') || has_win_suffix(name, 0); |
2002 | } | 2002 | } |
2003 | 2003 | ||
2004 | /* Copy path to an allocated string long enough to allow a file extension | ||
2005 | * to be added. */ | ||
2006 | char *alloc_ext_space(const char *path) | ||
2007 | { | ||
2008 | char *s = xmalloc(strlen(path) + 5); | ||
2009 | strcpy(s, path); | ||
2010 | return s; | ||
2011 | } | ||
2012 | |||
2004 | /* Check if path can be made into an executable by adding a suffix. | 2013 | /* Check if path can be made into an executable by adding a suffix. |
2005 | * The suffix is added to the end of the argument which must be | 2014 | * The suffix is added to the end of the argument which must be |
2006 | * long enough to allow this. | 2015 | * long enough to allow this. |
@@ -2024,6 +2033,22 @@ int add_win32_extension(char *p) | |||
2024 | return FALSE; | 2033 | return FALSE; |
2025 | } | 2034 | } |
2026 | 2035 | ||
2036 | /* | ||
2037 | * Determine if a path represents a WIN32 executable, adding a suffix | ||
2038 | * if necessary. Returns an allocated string if it does, NULL if not. | ||
2039 | */ | ||
2040 | char * | ||
2041 | file_is_win32_exe(const char *name) | ||
2042 | { | ||
2043 | char *path = alloc_ext_space(name); | ||
2044 | |||
2045 | if ((add_win32_extension(path) || file_is_executable(path))) | ||
2046 | return path; | ||
2047 | |||
2048 | free(path); | ||
2049 | return NULL; | ||
2050 | } | ||
2051 | |||
2027 | char * FAST_FUNC bs_to_slash(char *str) | 2052 | char * FAST_FUNC bs_to_slash(char *str) |
2028 | { | 2053 | { |
2029 | char *p; | 2054 | char *p; |
@@ -2193,15 +2218,6 @@ const char *need_system_drive(const char *path) | |||
2193 | return NULL; | 2218 | return NULL; |
2194 | } | 2219 | } |
2195 | 2220 | ||
2196 | /* Copy path to an allocated string long enough to allow a file extension | ||
2197 | * to be added. */ | ||
2198 | char *alloc_ext_space(const char *path) | ||
2199 | { | ||
2200 | char *s = xmalloc(strlen(path) + 5); | ||
2201 | strcpy(s, path); | ||
2202 | return s; | ||
2203 | } | ||
2204 | |||
2205 | int chdir_system_drive(void) | 2221 | int chdir_system_drive(void) |
2206 | { | 2222 | { |
2207 | const char *sd = get_system_drive(); | 2223 | const char *sd = get_system_drive(); |
diff --git a/win32/process.c b/win32/process.c index 0585f66a6..a0678f50d 100644 --- a/win32/process.c +++ b/win32/process.c | |||
@@ -328,14 +328,12 @@ mingw_spawn_interpreter(int mode, const char *prog, char *const *argv, | |||
328 | } | 328 | } |
329 | #endif | 329 | #endif |
330 | 330 | ||
331 | path = alloc_ext_space(interp.path); | 331 | path = file_is_win32_exe(interp.path); |
332 | if ((add_win32_extension(path) || file_is_executable(path))) { | 332 | if (path) { |
333 | new_argv[0] = path; | 333 | new_argv[0] = path; |
334 | ret = mingw_spawn_interpreter(mode, path, new_argv, envp, level); | 334 | ret = mingw_spawn_interpreter(mode, path, new_argv, envp, level); |
335 | goto done; | 335 | goto done; |
336 | } | 336 | } |
337 | free(path); | ||
338 | path = NULL; | ||
339 | 337 | ||
340 | if (unix_path(interp.path)) { | 338 | if (unix_path(interp.path)) { |
341 | if ((path = find_first_executable(interp.name)) != NULL) { | 339 | if ((path = find_first_executable(interp.name)) != NULL) { |
@@ -363,13 +361,12 @@ mingw_spawnvp(int mode, const char *cmd, char *const *argv) | |||
363 | return mingw_spawn_applet(mode, argv, NULL); | 361 | return mingw_spawn_applet(mode, argv, NULL); |
364 | #endif | 362 | #endif |
365 | if (has_path(cmd)) { | 363 | if (has_path(cmd)) { |
366 | path = alloc_ext_space(cmd); | 364 | path = file_is_win32_exe(cmd); |
367 | if (add_win32_extension(path) || file_is_executable(path)) { | 365 | if (path) { |
368 | ret = mingw_spawn_interpreter(mode, path, argv, NULL, 0); | 366 | ret = mingw_spawn_interpreter(mode, path, argv, NULL, 0); |
369 | free(path); | 367 | free(path); |
370 | return ret; | 368 | return ret; |
371 | } | 369 | } |
372 | free(path); | ||
373 | if (unix_path(cmd)) | 370 | if (unix_path(cmd)) |
374 | cmd = bb_basename(cmd); | 371 | cmd = bb_basename(cmd); |
375 | } | 372 | } |