aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorerw7 <erw7.github@gmail.com>2019-08-11 22:32:07 +0900
committerJustin M. Keyes <justinkz@gmail.com>2019-08-11 15:32:07 +0200
commit6616d1d3e5c98f3be78379829027adee3da67570 (patch)
treeee1b1682f0572256d99a3b7fe189ec2d29d0cc84 /src
parent7d664837e1a954c6b4aabbbf62ecc55c58454f06 (diff)
downloadrneovim-6616d1d3e5c98f3be78379829027adee3da67570.tar.gz
rneovim-6616d1d3e5c98f3be78379829027adee3da67570.tar.bz2
rneovim-6616d1d3e5c98f3be78379829027adee3da67570.zip
win/env: Vim-compat: Empty string deletes env var #10743
- Windows: `set FOO=` deletes environment variable FOO, and there is no way to set empty string expect by calling the API. - Vim-compatible: `:let $FOO=""` deletes the environment variable. - See also Test_WindowsHome(). ref: https://github.com/neovim/neovim/pull/10657#issuecomment-516368089
Diffstat (limited to 'src')
-rw-r--r--src/nvim/os/env.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c
index 915c0a1f9f..33b67a8116 100644
--- a/src/nvim/os/env.c
+++ b/src/nvim/os/env.c
@@ -111,6 +111,8 @@ bool os_env_exists(const char *name)
/// Sets an environment variable.
///
+/// Windows (Vim-compat): Empty string (:let $FOO="") undefines the env var.
+///
/// @warning Existing pointers to the result of os_getenv("foo") are
/// INVALID after os_setenv("foo", …).
int os_setenv(const char *name, const char *value, int overwrite)
@@ -123,6 +125,10 @@ int os_setenv(const char *name, const char *value, int overwrite)
if (!overwrite && os_getenv(name) != NULL) {
return 0;
}
+ if (value[0] == '\0') {
+ // Windows (Vim-compat): Empty string undefines the env var.
+ return os_unsetenv(name);
+ }
#else
if (!overwrite && os_env_exists(name)) {
return 0;