diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2019-03-03 13:45:38 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-03 13:45:38 +0100 |
commit | 8e54847fdf3c4e3c9ed1b4ae8a026b452419c6bf (patch) | |
tree | 2486bda1c0011c25449fead02a72858a24554357 /src | |
parent | 14c53e4cbede164fb7bbfc948625a769dfb1fa64 (diff) | |
parent | bb8ea83d755d94c4e1b259b493ebb6fe8ea084b5 (diff) | |
download | rneovim-8e54847fdf3c4e3c9ed1b4ae8a026b452419c6bf.tar.gz rneovim-8e54847fdf3c4e3c9ed1b4ae8a026b452419c6bf.tar.bz2 rneovim-8e54847fdf3c4e3c9ed1b4ae8a026b452419c6bf.zip |
Merge #9666 'Fix completion of multibyte env var names'
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/os/env.c | 35 | ||||
-rw-r--r-- | src/nvim/os/fs.c | 2 | ||||
-rw-r--r-- | src/nvim/search.c | 2 |
3 files changed, 29 insertions, 10 deletions
diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index 8a8220b6e7..e7bfbc8240 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -150,28 +150,47 @@ int os_unsetenv(const char *name) char *os_getenvname_at_index(size_t index) { +#ifdef _WIN32 + // Check if index is inside the environ array and is not the last element. + for (size_t i = 0; i <= index; i++) { + if (_wenviron[i] == NULL) { + return NULL; + } + } + wchar_t *utf16_str = _wenviron[index]; + char *utf8_str; + int conversion_result = utf16_to_utf8(utf16_str, &utf8_str); + if (conversion_result != 0) { + EMSG2("utf16_to_utf8 failed: %d", conversion_result); + return NULL; + } + size_t namesize = 0; + while (utf8_str[namesize] != '=' && utf8_str[namesize] != NUL) { + namesize++; + } + char *name = (char *)vim_strnsave((char_u *)utf8_str, namesize); + xfree(utf8_str); + return name; +#else # if defined(HAVE__NSGETENVIRON) char **environ = *_NSGetEnviron(); -# elif !defined(__WIN32__) - // Borland C++ 5.2 has this in a header file. +# else extern char **environ; # endif - // check if index is inside the environ array - for (size_t i = 0; i < index; i++) { + // Check if index is inside the environ array and is not the last element. + for (size_t i = 0; i <= index; i++) { if (environ[i] == NULL) { return NULL; } } char *str = environ[index]; - if (str == NULL) { - return NULL; - } size_t namesize = 0; while (str[namesize] != '=' && str[namesize] != NUL) { namesize++; } char *name = (char *)vim_strnsave((char_u *)str, namesize); return name; +#endif } /// Get the process ID of the Neovim process. @@ -404,7 +423,7 @@ void expand_env_esc(char_u *restrict srcp, var = NULL; } else { if (src[1] == '{') { - ++tail; + tail++; } #endif *var = NUL; diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 109ea6c487..7f2ebeec2f 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -1104,7 +1104,7 @@ char *os_resolve_shortcut(const char *fname) if (hr == S_OK && wsz[0] != NUL) { const int conversion_result = utf16_to_utf8(wsz, &rfname); if (conversion_result != 0) { - EMSG2("utf16_to_utf8 failed: %s", uv_strerror(conversion_result)); + EMSG2("utf16_to_utf8 failed: %d", conversion_result); } } diff --git a/src/nvim/search.c b/src/nvim/search.c index 6f0479cc39..f6b80d1b79 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -3913,7 +3913,7 @@ abort_search: VIsual = t; } } - return FALSE; + return false; } |