diff options
author | Bram Moolenaar <Bram@vim.org> | 2018-10-06 15:18:45 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2018-10-06 15:18:45 +0200 |
commit | 8295666dc2c65e42135b91d5c61e2a140d002333 (patch) | |
tree | 59b7a9be4212dc4b28b6e39ded79c051627049e4 /src/os_win32.c | |
parent | 7554c548a493cba50b2d0ea3521cac14f28a1f07 (diff) | |
download | vim-git-8295666dc2c65e42135b91d5c61e2a140d002333.tar.gz |
patch 8.1.0453: MS-Windows: executable() is not reliablev8.1.0453
Problem: MS-Windows: executable() is not reliable.
Solution: Use $PATHEXT properly. (Yasuhiro Matsumoto, closes #3412)
Diffstat (limited to 'src/os_win32.c')
-rw-r--r-- | src/os_win32.c | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/src/os_win32.c b/src/os_win32.c index 4ba060bb9..9d1d8cbc2 100644 --- a/src/os_win32.c +++ b/src/os_win32.c @@ -3535,21 +3535,44 @@ mch_can_exe(char_u *name, char_u **path, int use_path) { char_u buf[_MAX_PATH]; int len = (int)STRLEN(name); - char_u *p; + char_u *p, *saved; if (len >= _MAX_PATH) /* safety check */ return FALSE; - /* If there already is an extension try using the name directly. Also do - * this with a Unix-shell like 'shell'. */ - if (vim_strchr(gettail(name), '.') != NULL - || strstr((char *)gettail(p_sh), "sh") != NULL) + /* Ty using the name directly when a Unix-shell like 'shell'. */ + if (strstr((char *)gettail(p_sh), "sh") != NULL) if (executable_exists((char *)name, path, use_path)) return TRUE; /* * Loop over all extensions in $PATHEXT. */ + p = mch_getenv("PATHEXT"); + if (p == NULL) + p = (char_u *)".com;.exe;.bat;.cmd"; + saved = vim_strsave(p); + if (saved == NULL) + return FALSE; + p = saved; + while (*p) + { + char_u *tmp = vim_strchr(p, ';'); + + if (tmp != NULL) + *tmp = NUL; + if (_stricoll((char *)name + len - STRLEN(p), (char *)p) == 0 + && executable_exists((char *)name, path, use_path)) + { + vim_free(saved); + return TRUE; + } + if (tmp == NULL) + break; + p = tmp + 1; + } + vim_free(saved); + vim_strncpy(buf, name, _MAX_PATH - 1); p = mch_getenv("PATHEXT"); if (p == NULL) |