From 7b739330bb459401f9c11f0f84912aedc7ee22cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20H=C3=A4ssler?= Date: Sat, 9 Nov 2013 21:04:06 +0100 Subject: Add os:unsetenv/1 New BIF os:unsetenv/1 which deletes an environment variable and returns 'true'. Does not change any old functionality. Calls the libc function unsetenv(3) on UNIX and SetEnvironmentVariableW(key, NULL) on Windows. The unicode support is the same as for os:getenv and os:putenv. --- erts/emulator/sys/win32/sys_env.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'erts/emulator/sys/win32') diff --git a/erts/emulator/sys/win32/sys_env.c b/erts/emulator/sys/win32/sys_env.c index 754f4c6e4c..9f977ad6c8 100644 --- a/erts/emulator/sys/win32/sys_env.c +++ b/erts/emulator/sys/win32/sys_env.c @@ -141,6 +141,24 @@ void fini_getenv_state(GETENV_STATE *state) erts_smp_rwmtx_runlock(&environ_rwmtx); } +int erts_sys_unsetenv(char *key) +{ + int res = 0; + WCHAR *wkey = (WCHAR *) key; + + SetLastError(0); + erts_smp_rwmtx_rlock(&environ_rwmtx); + GetEnvironmentVariableW(wkey, + NULL, + 0); + if (GetLastError() != ERROR_ENVVAR_NOT_FOUND) { + res = (SetEnvironmentVariableW(wkey, + NULL) ? 0 : 1); + } + erts_smp_rwmtx_runlock(&environ_rwmtx); + return res; +} + char* win_build_environment(char* new_env) { -- cgit v1.2.3