shithub: mc

ref: 79f9ac7bc6aa7d3bd82568d022ca3c4ead841873
dir: /libstd/env.myr/

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

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

	const getenv :	(name : byte[:] -> [byte[:], bool]) /* FIXME: should return an option, not a tuple, but we have a compiler bug. */
;;

const getenv = {name
	var i

	var n
	for i = 0; i < _environment.len; i++
		n = min(name.len, _environment[i].len)
		if sleq(name, _environment[i][:n]) && sleq(_environment[i][n:n+1], "=")
			-> (_environment[i][n+1:], true)
		;;
	;;
	-> ("", false)
}