summaryrefslogtreecommitdiff
path: root/libstd/env+posixy.myr
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2014-12-25 15:59:01 -0800
committerOri Bernstein <ori@eigenstate.org>2014-12-25 15:59:01 -0800
commit8c15f1cba546350fd109d676f86c4267bd733b6f (patch)
tree75f75219b57fee8d3c7403f9cbb658f87a0942e5 /libstd/env+posixy.myr
parent3324a15b63cd10f880308623cfc27c69b3ed3c59 (diff)
downloadmc-8c15f1cba546350fd109d676f86c4267bd733b6f.tar.gz
Libstd now builds on plan9.
It's missing a load of functions, of course, but it buillds.
Diffstat (limited to 'libstd/env+posixy.myr')
-rw-r--r--libstd/env+posixy.myr28
1 files changed, 28 insertions, 0 deletions
diff --git a/libstd/env+posixy.myr b/libstd/env+posixy.myr
new file mode 100644
index 0000000..d7b0e5e
--- /dev/null
+++ b/libstd/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
+ ;;
+}