summaryrefslogtreecommitdiff
path: root/lib/std/env+posixy.myr
diff options
context:
space:
mode:
Diffstat (limited to 'lib/std/env+posixy.myr')
-rw-r--r--lib/std/env+posixy.myr28
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/std/env+posixy.myr b/lib/std/env+posixy.myr
new file mode 100644
index 0000000..d7b0e5e
--- /dev/null
+++ b/lib/std/env+posixy.myr
@@ -0,0 +1,28 @@
+use sys
+
+use "extremum.use"
+use "option.use"
+use "sleq.use"
+
+pkg std =
+ const getenv : (name : byte[:] -> option(byte[:]))
+ const getenvv : (name : byte[:], default : byte[:] -> byte[:])
+;;
+
+const getenv = {name
+ var n
+ for env in sys.__environment
+ n = min(name.len, env.len)
+ if sleq(name, env[:n]) && sleq(env[n:n+1], "=")
+ -> `Some env[n+1:]
+ ;;
+ ;;
+ -> `None
+}
+
+const getenvv = {name, default
+ match getenv(name)
+ | `Some v: -> v
+ | `None: -> default
+ ;;
+}