diff options
author | Martin Hässler <[email protected]> | 2013-11-09 21:04:06 +0100 |
---|---|---|
committer | Martin Hässler <[email protected]> | 2013-11-09 21:04:06 +0100 |
commit | 7b739330bb459401f9c11f0f84912aedc7ee22cd (patch) | |
tree | e1ffbca9adb63a1132c6c8af8236b725a8c5da56 /erts/emulator/beam | |
parent | 768a64354e3d69b3c0840a84dd072601c67ca39d (diff) | |
download | otp-7b739330bb459401f9c11f0f84912aedc7ee22cd.tar.gz otp-7b739330bb459401f9c11f0f84912aedc7ee22cd.tar.bz2 otp-7b739330bb459401f9c11f0f84912aedc7ee22cd.zip |
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.
Diffstat (limited to 'erts/emulator/beam')
-rw-r--r-- | erts/emulator/beam/bif.tab | 1 | ||||
-rw-r--r-- | erts/emulator/beam/erl_bif_os.c | 22 | ||||
-rw-r--r-- | erts/emulator/beam/sys.h | 2 |
3 files changed, 25 insertions, 0 deletions
diff --git a/erts/emulator/beam/bif.tab b/erts/emulator/beam/bif.tab index dc8e9101de..6037c08dd8 100644 --- a/erts/emulator/beam/bif.tab +++ b/erts/emulator/beam/bif.tab @@ -572,6 +572,7 @@ bif erlang:float_to_binary/2 bif erlang:binary_to_float/1 bif io:printable_range/0 +bif os:unsetenv/1 # # Obsolete diff --git a/erts/emulator/beam/erl_bif_os.c b/erts/emulator/beam/erl_bif_os.c index 1062d4379b..e07c622928 100644 --- a/erts/emulator/beam/erl_bif_os.c +++ b/erts/emulator/beam/erl_bif_os.c @@ -180,3 +180,25 @@ BIF_RETTYPE os_putenv_2(BIF_ALIST_2) BIF_RET(am_true); } +BIF_RETTYPE os_unsetenv_1(BIF_ALIST_1) +{ + char *key_buf; + char buf[STATIC_BUF_SIZE]; + + key_buf = erts_convert_filename_to_native(BIF_ARG_1,buf,STATIC_BUF_SIZE, + ERTS_ALC_T_TMP,0,0,NULL); + if (!key_buf) { + BIF_ERROR(BIF_P, BADARG); + } + + if (erts_sys_unsetenv(key_buf)) { + if (key_buf != buf) { + erts_free(ERTS_ALC_T_TMP, key_buf); + } + BIF_ERROR(BIF_P, BADARG); + } + if (key_buf != buf) { + erts_free(ERTS_ALC_T_TMP, key_buf); + } + BIF_RET(am_true); +} diff --git a/erts/emulator/beam/sys.h b/erts/emulator/beam/sys.h index 9561c0be96..d22f125945 100644 --- a/erts/emulator/beam/sys.h +++ b/erts/emulator/beam/sys.h @@ -750,6 +750,8 @@ int erts_sys_getenv(char *key, char *value, size_t *size); int erts_sys_getenv_raw(char *key, char *value, size_t *size); /* erts_sys_getenv__() is only allowed to be used in early init phase */ int erts_sys_getenv__(char *key, char *value, size_t *size); +/* erst_sys_unsetenv() returns 0 on success and a value != 0 on failure. */ +int erts_sys_unsetenv(char *key); /* Easier to use, but not as efficient, environment functions */ char *erts_read_env(char *key); |