8000 os: Implement getenv(). · micropython/micropython-lib@e8813f3 · GitHub
[go: up one dir, main page]

Skip to content

Commit e8813f3

Browse files
author
Paul Sokolovsky
committed
os: Implement getenv().
1 parent f3dd9ab commit e8813f3

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

os/example_getenv.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import os
2+
3+
print(os.getenv("HOME", "def"))

os/os/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
getpid_ = libc.func("i", "getpid", "")
3333
waitpid_ = libc.func("i", "waitpid", "ipi")
3434
system_ = libc.func("i", "system", "s")
35+
getenv_ = libc.func("s", "getenv", "P")
3536

3637
R_OK = const(4)
3738
W_OK = const(2)
@@ -204,6 +205,12 @@ def system(command):
204205
check_error(r)
205206
return r
206207

208+
def getenv(var, default=None):
209+
var = getenv_(var)
210+
if var is None:
211+
return default
212+
return var
213+
207214
def fsencode(s):
208215
if type(s) is bytes:
209216
return s

0 commit comments

Comments
 (0)
0