aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2016-02-01 02:06:49 -0500
committerJustin M. Keyes <justinkz@gmail.com>2016-02-01 02:06:49 -0500
commitfe1ba0487aab98a131e6789b6916b1aec369e8fc (patch)
tree2be654729fee806942a4e8af7b6e4f63d6eef513 /src
parente2231bc372831910c6c02efc189e4c2f384149b1 (diff)
parentda4bf813daf1d54c3cdfbeb480b7ce15a7372834 (diff)
downloadrneovim-fe1ba0487aab98a131e6789b6916b1aec369e8fc.tar.gz
rneovim-fe1ba0487aab98a131e6789b6916b1aec369e8fc.tar.bz2
rneovim-fe1ba0487aab98a131e6789b6916b1aec369e8fc.zip
Merge pull request #3994 from sethjackson/pathext
Windows: use $PATHEXT to find executables in path
Diffstat (limited to 'src')
-rw-r--r--src/nvim/os/fs.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c
index 21f0fc6f41..2e671653ed 100644
--- a/src/nvim/os/fs.c
+++ b/src/nvim/os/fs.c
@@ -146,6 +146,16 @@ static bool is_executable_in_path(const char_u *name, char_u **abspath)
}
size_t buf_len = STRLEN(name) + STRLEN(path) + 2;
+
+#ifdef WIN32
+ const char *pathext = os_getenv("PATHEXT");
+ if (!pathext) {
+ pathext = ".com;.exe;.bat;.cmd";
+ }
+
+ buf_len += STRLEN(pathext);
+#endif
+
char_u *buf = xmalloc(buf_len);
// Walk through all entries in $PATH to check if "name" exists there and
@@ -169,6 +179,38 @@ static bool is_executable_in_path(const char_u *name, char_u **abspath)
return true;
}
+#ifdef WIN32
+ // Try appending file extensions from $PATHEXT to the name.
+ char *buf_end = xstrchrnul((char *)buf, '\0');
+ for (const char *ext = pathext; *ext; ext++) {
+ // Skip the extension if there is no suffix after a '.'.
+ if (ext[0] == '.' && (ext[1] == '\0' || ext[1] == ';')) {
+ *ext++;
+
+ continue;
+ }
+
+ const char *ext_end = xstrchrnul(ext, ENV_SEPCHAR);
+ STRLCPY(buf_end, ext, ext_end - ext + 1);
+
+ if (is_executable(buf)) {
+ // Check if the caller asked for a copy of the path.
+ if (abspath != NULL) {
+ *abspath = save_absolute_path(buf);
+ }
+
+ xfree(buf);
+
+ return true;
+ }
+
+ if (*ext_end != ENV_SEPCHAR) {
+ break;
+ }
+ ext = ext_end;
+ }
+#endif
+
if (*e != ENV_SEPCHAR) {
// End of $PATH without finding any executable called name.
xfree(buf);