shithub: mc

ref: f762f96f07cf2dfc7b3bb745d6a767dccda0a01a
dir: /lib/std/mkpath.myr/

View raw version
use "syswrap"
use "errno"

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

const mkpath = {p
	var st

	for var i = 0; i < p.len; i++
		if p[i] == ('/' : byte) && i != 0
			if !fexists(p[:i])
				st = mkdir(p[:i], 0o755)
				if st != 0
					-> st
				;;
			;;
		;;
	;;
	st = mkdir(p, 0o755)

	-> Enone
}