win: os_shell_is_cmdexe() + tests

This commit is contained in:
Justin M. Keyes
2017-04-12 01:35:17 +02:00
parent d31d177a0c
commit 7c4e5dfd27
5 changed files with 60 additions and 28 deletions

View File

@@ -1,11 +1,8 @@
// env.c -- environment variable access
// Environment inspection
#include <assert.h>
#include <uv.h>
// vim.h must be included before charset.h (and possibly others) or things
// blow up
#include "nvim/vim.h"
#include "nvim/ascii.h"
#include "nvim/charset.h"
@@ -919,3 +916,20 @@ bool os_term_is_nice(void)
|| NULL != os_getenv("KONSOLE_DBUS_SESSION");
#endif
}
/// Returns true if `sh` looks like it resolves to "cmd.exe".
bool os_shell_is_cmdexe(const char *sh)
FUNC_ATTR_NONNULL_ALL
{
if (*sh == NUL) {
return false;
}
if (striequal(sh, "$COMSPEC")) {
const char *comspec = os_getenv("COMSPEC");
return striequal("cmd.exe", (char *)path_tail((char_u *)comspec));
}
if (striequal(sh, "cmd.exe") || striequal(sh, "cmd")) {
return true;
}
return striequal("cmd.exe", (char *)path_tail((char_u *)sh));
}