mirror of
https://github.com/neovim/neovim.git
synced 2024-12-19 18:55:14 -07:00
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
This commit is contained in:
parent
7d664837e1
commit
6616d1d3e5
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user