Blame otp-0011-Introduce-os-getenv-2.patch

0156fc
From: Peter Lemenkov <lemenkov@gmail.com>
0156fc
Date: Sat, 8 Nov 2014 15:11:04 +0300
0156fc
Subject: [PATCH] Introduce os:getenv/2
0156fc
0156fc
Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>
0156fc
0156fc
diff --git a/lib/kernel/doc/src/os.xml b/lib/kernel/doc/src/os.xml
0156fc
index 2b57e75..8b85f24 100644
0156fc
--- a/lib/kernel/doc/src/os.xml
0156fc
+++ b/lib/kernel/doc/src/os.xml
0156fc
@@ -100,6 +100,19 @@ DirOut = os:cmd("dir"), % on Win32 platform
0156fc
       </desc>
0156fc
     </func>
0156fc
     <func>
0156fc
+      <name name="getenv" arity="2"/>
0156fc
+      <fsummary>Get the value of an environment variable</fsummary>
0156fc
+      <desc>
0156fc
+        

Returns the <c><anno>Value</anno></c> of the environment variable

0156fc
+          <c><anno>VarName</anno></c>, or <c>DefaultValue</c> if the environment variable
0156fc
+          is undefined.

0156fc
+	

If Unicode file name encoding is in effect (see the

0156fc
+	marker="erts:erl#file_name_encoding">erl manual
0156fc
+	page</seealso>), the strings (both <c><anno>VarName</anno></c> and
0156fc
+	<c><anno>Value</anno></c>) may contain characters with codepoints > 255.

0156fc
+      </desc>
0156fc
+    </func>
0156fc
+    <func>
0156fc
       <name name="getpid" arity="0"/>
0156fc
       <fsummary>Return the process identifier of the emulator process</fsummary>
0156fc
       <desc>
0156fc
diff --git a/lib/kernel/src/os.erl b/lib/kernel/src/os.erl
0156fc
index 187fd00..8aaf13b 100644
0156fc
--- a/lib/kernel/src/os.erl
0156fc
+++ b/lib/kernel/src/os.erl
0156fc
@@ -26,7 +26,7 @@
0156fc
 
0156fc
 %%% BIFs
0156fc
 
0156fc
--export([getenv/0, getenv/1, getpid/0, putenv/2, timestamp/0, unsetenv/1]).
0156fc
+-export([getenv/0, getenv/1, getenv/2, getpid/0, putenv/2, timestamp/0, unsetenv/1]).
0156fc
 
0156fc
 -spec getenv() -> [string()].
0156fc
 
0156fc
@@ -39,6 +39,19 @@ getenv() -> erlang:nif_error(undef).
0156fc
 getenv(_) ->
0156fc
     erlang:nif_error(undef).
0156fc
 
0156fc
+-spec getenv(VarName, DefaultValue) -> Value when
0156fc
+      VarName :: string(),
0156fc
+      DefaultValue :: string(),
0156fc
+      Value :: string().
0156fc
+
0156fc
+getenv(VarName, DefaultValue) ->
0156fc
+    case os:getenv(VarName) of
0156fc
+        false ->
0156fc
+           DefaultValue;
0156fc
+        Value ->
0156fc
+            Value
0156fc
+    end.
0156fc
+
0156fc
 -spec getpid() -> Value when
0156fc
       Value :: string().
0156fc