shithub: mc

ref: 94b6dcc7253e53f6a50396f11aa62b94d3e95d2b
dir: /lib/std/env+posixy.myr/

View raw version
use sys

use "extremum"
use "option"
use "sleq"

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
	;;
}