diff options
Diffstat (limited to 'win32')
-rw-r--r-- | win32/mingw.c | 52 | ||||
-rw-r--r-- | win32/process.c | 4 |
2 files changed, 34 insertions, 22 deletions
diff --git a/win32/mingw.c b/win32/mingw.c index 707e6a3d2..08d955527 100644 --- a/win32/mingw.c +++ b/win32/mingw.c | |||
@@ -1160,7 +1160,7 @@ int mingw_rmdir(const char *path) | |||
1160 | return rmdir(path); | 1160 | return rmdir(path); |
1161 | } | 1161 | } |
1162 | 1162 | ||
1163 | const char win_suffix[4][4] = { "com", "exe", "bat", "cmd" }; | 1163 | static const char win_suffix[4][4] = { "com", "exe", "bat", "cmd" }; |
1164 | 1164 | ||
1165 | static int has_win_suffix(const char *name, int start) | 1165 | static int has_win_suffix(const char *name, int start) |
1166 | { | 1166 | { |
@@ -1191,33 +1191,45 @@ int has_exe_suffix_or_dot(const char *name) | |||
1191 | return last_char_is(name, '.') || has_win_suffix(name, 0); | 1191 | return last_char_is(name, '.') || has_win_suffix(name, 0); |
1192 | } | 1192 | } |
1193 | 1193 | ||
1194 | /* check if path can be made into an executable by adding a suffix; | 1194 | /* Check if path can be made into an executable by adding a suffix. |
1195 | * return an allocated string containing the path if it can; | 1195 | * The suffix is added to the end of the argument which must be |
1196 | * return NULL if not. | 1196 | * long enough to allow this. |
1197 | * | 1197 | * |
1198 | * if path already has a suffix don't even bother trying | 1198 | * If the return value is TRUE the argument contains the new path, |
1199 | * if FALSE the argument is unchanged. | ||
1199 | */ | 1200 | */ |
1200 | char *add_win32_extension(const char *p) | 1201 | int add_win32_extension(char *p) |
1201 | { | 1202 | { |
1202 | char *path; | 1203 | if (!has_exe_suffix_or_dot(p)) { |
1203 | int i, len; | 1204 | int i, len = strlen(p); |
1204 | 1205 | ||
1205 | if (has_exe_suffix_or_dot(p)) { | 1206 | p[len] = '.'; |
1206 | return NULL; | 1207 | for (i=0; i<4; ++i) { |
1208 | memcpy(p+len+1, win_suffix[i], 4); | ||
1209 | if (file_is_executable(p)) | ||
1210 | return TRUE; | ||
1211 | } | ||
1212 | p[len] = '\0'; | ||
1207 | } | 1213 | } |
1214 | return FALSE; | ||
1215 | } | ||
1208 | 1216 | ||
1209 | len = strlen(p); | 1217 | /* Check if path can be made into an executable by adding a suffix. |
1210 | path = xasprintf("%s.com", p); | 1218 | * Return an allocated string containing the path if it can; |
1219 | * return NULL if not. | ||
1220 | * | ||
1221 | * If path already has a suffix don't even bother trying. | ||
1222 | */ | ||
1223 | char *alloc_win32_extension(const char *p) | ||
1224 | { | ||
1225 | if (!has_exe_suffix_or_dot(p)) { | ||
1226 | int len = strlen(p); | ||
1227 | char *path = strcpy(xmalloc(len+5), p); | ||
1211 | 1228 | ||
1212 | for (i=0; i<4; ++i) { | 1229 | if (add_win32_extension(path)) |
1213 | memcpy(path+len+1, win_suffix[i], 4); | ||
1214 | if (file_is_executable(path)) { | ||
1215 | return path; | 1230 | return path; |
1216 | } | 1231 | free(path); |
1217 | } | 1232 | } |
1218 | |||
1219 | free(path); | ||
1220 | |||
1221 | return NULL; | 1233 | return NULL; |
1222 | } | 1234 | } |
1223 | 1235 | ||
diff --git a/win32/process.c b/win32/process.c index e9b34b56d..b7f02e431 100644 --- a/win32/process.c +++ b/win32/process.c | |||
@@ -240,7 +240,7 @@ spawnveq(int mode, const char *path, char *const *argv, char *const *env) | |||
240 | p = strdup(new_argv[0]); | 240 | p = strdup(new_argv[0]); |
241 | } | 241 | } |
242 | else { | 242 | else { |
243 | p = add_win32_extension(new_argv[0]); | 243 | p = alloc_win32_extension(new_argv[0]); |
244 | } | 244 | } |
245 | 245 | ||
246 | if (p != NULL && has_bat_suffix(p)) { | 246 | if (p != NULL && has_bat_suffix(p)) { |
@@ -307,7 +307,7 @@ mingw_spawn_interpreter(int mode, const char *prog, char *const *argv, char *con | |||
307 | new_argv[nopts+1] = (char *)prog; /* pass absolute path */ | 307 | new_argv[nopts+1] = (char *)prog; /* pass absolute path */ |
308 | memcpy(new_argv+nopts+2, argv+1, sizeof(*argv)*argc); | 308 | memcpy(new_argv+nopts+2, argv+1, sizeof(*argv)*argc); |
309 | 309 | ||
310 | if ((fullpath=add_win32_extension(interp.path)) != NULL || | 310 | if ((fullpath=alloc_win32_extension(interp.path)) != NULL || |
311 | file_is_executable(interp.path)) { | 311 | file_is_executable(interp.path)) { |
312 | new_argv[0] = fullpath ? fullpath : interp.path; | 312 | new_argv[0] = fullpath ? fullpath : interp.path; |
313 | ret = spawnveq(mode, new_argv[0], new_argv, envp); | 313 | ret = spawnveq(mode, new_argv[0], new_argv, envp); |