shithub: mc

ref: 49f6758a734dc98ed7764d2f2ff8dfb77d4c75b0
dir: /lib/std/mkpath.myr/

View raw version
use "syswrap.use"
use "errno.use"

pkg std =
	const mkpath	: (p : byte[:] -> bool)
;;

const mkpath = {p
	var st

	for var i = 0; i < p.len; i++
		if p[i] == '/' castto(byte) && i != 0
			st = mkdir(p[:i], 0o777)
			if st != 0 && (st castto(errno)) != Eexist
				-> false
			;;
		;;
	;;

	-> true
}