shithub: mc

ref: 8cd117e55ac16cda7d40738cbd48fc8f92066da4
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[:] -> std.option(byte[:]))
;;

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], "=")
			-> `Some _environment[i][n+1:]
		;;
	;;
	-> `None
}