From 1fe3f5449a4a3ea6fc8460df40d95d118ed5d4ee Mon Sep 17 00:00:00 2001 From: Ron Yorston <rmy@pobox.com> Date: Fri, 7 Dec 2018 09:37:27 +0000 Subject: win32: improve execution of batch files It appears that when a batch file is executed the first argument must contain backslashes if it's a relative path. Absolute paths work either way. In both cases the extension is optional. This allows for a considerable simplification of the special case in spawnveq. --- win32/process.c | 34 ++++++++-------------------------- 1 file changed, 8 insertions(+), 26 deletions(-) diff --git a/win32/process.c b/win32/process.c index b7f02e431..fda38318a 100644 --- a/win32/process.c +++ b/win32/process.c @@ -204,7 +204,7 @@ static intptr_t spawnveq(int mode, const char *path, char *const *argv, char *const *env) { char **new_argv; - char *new_path = NULL; + char *s, *new_path = NULL; int i, argc; intptr_t ret; struct stat st; @@ -229,31 +229,13 @@ spawnveq(int mode, const char *path, char *const *argv, char *const *env) new_argv[i] = quote_arg(argv[i]); new_argv[argc] = NULL; - /* - * Special case: spawnve won't execute a batch file when the path - * starts with a '.' and contains forward slashes. - */ - if (new_argv[0][0] == '.') { - char *s, *p; - - if (has_bat_suffix(new_argv[0])) { - p = strdup(new_argv[0]); - } - else { - p = alloc_win32_extension(new_argv[0]); - } - - if (p != NULL && has_bat_suffix(p)) { - for (s=p; *s; ++s) { - if (*s == '/') - *s = '\\'; - } - if (new_argv[0] != argv[0]) - free(new_argv[0]); - new_argv[0] = p; - } - else { - free(p); + /* Special case: spawnve won't execute a batch file if the first + * argument is a relative path containing forward slashes. Absolute + * paths are fine but there's no harm in converting them too. */ + if (has_bat_suffix(path)) { + for (s=new_argv[0]; *s; ++s) { + if (*s == '/') + *s = '\\'; } } -- cgit v1.2.3-55-g6feb