shithub: mc

ref: 90667a77d0114888cba6302b7349fe702b5cf90f
dir: /libstd/env.myr/

View raw version
use "extremum.use"
use "option.use"
use "sleq.use"

pkg std =
	extern var _environment	: byte[:][:]

	const getenv :	(name : byte[:] -> option(byte[:]))
	const getenvv :	(name : byte[:], default : byte[:] -> byte[:])
;;

const getenv = {name
	var n
	for env in _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
	;;
}