diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2017-02-03 14:42:47 +0100 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2017-02-04 11:07:49 +0100 |
commit | cd5b1315757ed3c66aa63c6df69582503c5b81dd (patch) | |
tree | fc0ce297eef31d712c929103266014dd9a28f83e /src | |
parent | 978c95e5c484e0b6acf17cd6379a81b83721a5b1 (diff) | |
download | rneovim-cd5b1315757ed3c66aa63c6df69582503c5b81dd.tar.gz rneovim-cd5b1315757ed3c66aa63c6df69582503c5b81dd.tar.bz2 rneovim-cd5b1315757ed3c66aa63c6df69582503c5b81dd.zip |
vim-patch:8.0.0280
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Problem: On MS-Windows setting an environment variable with multi-byte
strings does not work well.
Solution: Use wputenv when possible. (Taro Muraoka, Ken Takata)
7c23d1d9d9cc
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/os/env.c | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index 4707b0a326..5a3c1ef2c8 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -9,6 +9,7 @@ #include "nvim/vim.h" #include "nvim/ascii.h" #include "nvim/charset.h" +#include "nvim/fileio.h" #include "nvim/os/os.h" #include "nvim/memory.h" #include "nvim/message.h" @@ -18,6 +19,10 @@ #include "nvim/ex_getln.h" #include "nvim/version.h" +#ifdef WIN32 +#include "nvim/mbyte.h" // for utf8_to_utf16, utf16_to_utf8 +#endif + #ifdef HAVE__NSGETENVIRON #include <crt_externs.h> #endif @@ -45,7 +50,21 @@ bool os_env_exists(const char *name) int os_setenv(const char *name, const char *value, int overwrite) FUNC_ATTR_NONNULL_ALL { -#ifdef HAVE_SETENV +#ifdef WIN32 + size_t envbuflen = strlen(name) + strlen(value) + 2; + char *envbuf = xmalloc(envbuflen); + snprintf(envbuf, envbuflen, "%s=%s", name, value); + + WCHAR *p; + utf8_to_utf16(envbuf, &p); + xfree(envbuf); + if (p == NULL) { + return -1; + } + _wputenv(p); + xfree(p); // Unlike Unix systems, we can free the string for _wputenv(). + return 0; +#elif defined(HAVE_SETENV) return setenv(name, value, overwrite); #elif defined(HAVE_PUTENV_S) if (!overwrite && os_getenv(name) != NULL) { |