diff options
author | Marcus Arendt <[email protected]> | 2014-12-01 13:45:19 +0100 |
---|---|---|
committer | Marcus Arendt <[email protected]> | 2014-12-01 13:45:19 +0100 |
commit | 5cc1a3f55e8f9a49a139234e1e6457a0020f98fe (patch) | |
tree | eec3ae540c2da1c13d591150175d3cd8d41084ec /lib | |
parent | 8e4ccfc3a9a7a1a4a7c607c88a205490bcf5d490 (diff) | |
parent | ae13f4759fd47c0db36c8a3bd9759e01d709ee02 (diff) | |
download | otp-5cc1a3f55e8f9a49a139234e1e6457a0020f98fe.tar.gz otp-5cc1a3f55e8f9a49a139234e1e6457a0020f98fe.tar.bz2 otp-5cc1a3f55e8f9a49a139234e1e6457a0020f98fe.zip |
Merge branch 'lemenkov/os_getenv_2/OTP-12342'
* lemenkov/os_getenv_2/OTP-12342:
Introduce os:getenv/2
Diffstat (limited to 'lib')
-rw-r--r-- | lib/kernel/doc/src/os.xml | 13 | ||||
-rw-r--r-- | lib/kernel/src/os.erl | 15 |
2 files changed, 27 insertions, 1 deletions
diff --git a/lib/kernel/doc/src/os.xml b/lib/kernel/doc/src/os.xml index 2b57e75023..8b85f24455 100644 --- a/lib/kernel/doc/src/os.xml +++ b/lib/kernel/doc/src/os.xml @@ -100,6 +100,19 @@ DirOut = os:cmd("dir"), % on Win32 platform</code> </desc> </func> <func> + <name name="getenv" arity="2"/> + <fsummary>Get the value of an environment variable</fsummary> + <desc> + <p>Returns the <c><anno>Value</anno></c> of the environment variable + <c><anno>VarName</anno></c>, or <c>DefaultValue</c> if the environment variable + is undefined.</p> + <p>If Unicode file name encoding is in effect (see the <seealso + marker="erts:erl#file_name_encoding">erl manual + page</seealso>), the strings (both <c><anno>VarName</anno></c> and + <c><anno>Value</anno></c>) may contain characters with codepoints > 255.</p> + </desc> + </func> + <func> <name name="getpid" arity="0"/> <fsummary>Return the process identifier of the emulator process</fsummary> <desc> diff --git a/lib/kernel/src/os.erl b/lib/kernel/src/os.erl index 187fd0001b..8aaf13b3fd 100644 --- a/lib/kernel/src/os.erl +++ b/lib/kernel/src/os.erl @@ -26,7 +26,7 @@ %%% BIFs --export([getenv/0, getenv/1, getpid/0, putenv/2, timestamp/0, unsetenv/1]). +-export([getenv/0, getenv/1, getenv/2, getpid/0, putenv/2, timestamp/0, unsetenv/1]). -spec getenv() -> [string()]. @@ -39,6 +39,19 @@ getenv() -> erlang:nif_error(undef). getenv(_) -> erlang:nif_error(undef). +-spec getenv(VarName, DefaultValue) -> Value when + VarName :: string(), + DefaultValue :: string(), + Value :: string(). + +getenv(VarName, DefaultValue) -> + case os:getenv(VarName) of + false -> + DefaultValue; + Value -> + Value + end. + -spec getpid() -> Value when Value :: string(). |