From 5cbad390e971ff92a7fb1b71757041ff9edeb81a Mon Sep 17 00:00:00 2001 From: Peter Lemenkov Date: Sat, 8 Nov 2014 15:11:04 +0300 Subject: Introduce os:getenv/2 Signed-off-by: Peter Lemenkov --- lib/kernel/doc/src/os.xml | 13 +++++++++++++ lib/kernel/src/os.erl | 15 ++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) (limited to 'lib') 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 @@ -99,6 +99,19 @@ DirOut = os:cmd("dir"), % on Win32 platform Value) may contain characters with codepoints > 255.

+ + + Get the value of an environment variable + +

Returns the Value of the environment variable + VarName, or DefaultValue if the environment variable + is undefined.

+

If Unicode file name encoding is in effect (see the erl manual + page), the strings (both VarName and + Value) may contain characters with codepoints > 255.

+
+
Return the process identifier of the emulator process 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(). -- cgit v1.2.3