comparison src/os_win32.c @ 14883:1c2ba2b0227e v8.1.0453

patch 8.1.0453: MS-Windows: executable() is not reliable commit https://github.com/vim/vim/commit/8295666dc2c65e42135b91d5c61e2a140d002333 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Oct 6 15:18:45 2018 +0200 patch 8.1.0453: MS-Windows: executable() is not reliable Problem: MS-Windows: executable() is not reliable. Solution: Use $PATHEXT properly. (Yasuhiro Matsumoto, closes https://github.com/vim/vim/issues/3412)
author Bram Moolenaar <Bram@vim.org>
date Sat, 06 Oct 2018 15:30:06 +0200
parents 35aff6b8a2c7
children 66176f8735aa
comparison
equal deleted inserted replaced
14882:32c08beec8c9 14883:1c2ba2b0227e
3533 int 3533 int
3534 mch_can_exe(char_u *name, char_u **path, int use_path) 3534 mch_can_exe(char_u *name, char_u **path, int use_path)
3535 { 3535 {
3536 char_u buf[_MAX_PATH]; 3536 char_u buf[_MAX_PATH];
3537 int len = (int)STRLEN(name); 3537 int len = (int)STRLEN(name);
3538 char_u *p; 3538 char_u *p, *saved;
3539 3539
3540 if (len >= _MAX_PATH) /* safety check */ 3540 if (len >= _MAX_PATH) /* safety check */
3541 return FALSE; 3541 return FALSE;
3542 3542
3543 /* If there already is an extension try using the name directly. Also do 3543 /* Ty using the name directly when a Unix-shell like 'shell'. */
3544 * this with a Unix-shell like 'shell'. */ 3544 if (strstr((char *)gettail(p_sh), "sh") != NULL)
3545 if (vim_strchr(gettail(name), '.') != NULL
3546 || strstr((char *)gettail(p_sh), "sh") != NULL)
3547 if (executable_exists((char *)name, path, use_path)) 3545 if (executable_exists((char *)name, path, use_path))
3548 return TRUE; 3546 return TRUE;
3549 3547
3550 /* 3548 /*
3551 * Loop over all extensions in $PATHEXT. 3549 * Loop over all extensions in $PATHEXT.
3552 */ 3550 */
3551 p = mch_getenv("PATHEXT");
3552 if (p == NULL)
3553 p = (char_u *)".com;.exe;.bat;.cmd";
3554 saved = vim_strsave(p);
3555 if (saved == NULL)
3556 return FALSE;
3557 p = saved;
3558 while (*p)
3559 {
3560 char_u *tmp = vim_strchr(p, ';');
3561
3562 if (tmp != NULL)
3563 *tmp = NUL;
3564 if (_stricoll((char *)name + len - STRLEN(p), (char *)p) == 0
3565 && executable_exists((char *)name, path, use_path))
3566 {
3567 vim_free(saved);
3568 return TRUE;
3569 }
3570 if (tmp == NULL)
3571 break;
3572 p = tmp + 1;
3573 }
3574 vim_free(saved);
3575
3553 vim_strncpy(buf, name, _MAX_PATH - 1); 3576 vim_strncpy(buf, name, _MAX_PATH - 1);
3554 p = mch_getenv("PATHEXT"); 3577 p = mch_getenv("PATHEXT");
3555 if (p == NULL) 3578 if (p == NULL)
3556 p = (char_u *)".com;.exe;.bat;.cmd"; 3579 p = (char_u *)".com;.exe;.bat;.cmd";
3557 while (*p) 3580 while (*p)