shithub: mc

ref: 4e656a4f039b9230c820f12d3b1e4a5c8e55cf47
dir: /libstd/mkpath.myr/

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

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

const mkpath = {p
	var st
	var i

	for 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
}