[erlang-patches] Add os:unsetenv/1

Martin Hässler <>
Sat Oct 26 21:30:26 CEST 2013


This patch adds os:unsetenv/1 which deletes an environment variable.

### Why this new feature?

With os:unsetenv/1, it is possible to delete environment variables.
This makes it easier to test code which uses os:getenv/1 to check if
an environment variable exists or not. The new function differs from
os:putenv(Value, "") as the former deletes the variable while the
latter keeps the variable with an empty value.

Example:

  1> os:putenv("foo", "").
  true
  2> os:getenv("foo").
  []
  3> os:unsetenv("foo").
  true
  4> os:getenv("foo").
  false

### Risks / uncertain artifacts

None. New function without any changes in old functionality.

### How did you solve it?

New BIF which 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.


https://github.com/erlang/otp/pull/114

-- 
Best Regards,
/Martin


More information about the erlang-patches mailing list