shithub: mc

ref: e07b79bf077459eda3d7d59cbaf1b4f431e3b2c6
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
}