summaryrefslogtreecommitdiff
path: root/lib/std/mkpath.myr
blob: 75c1b9c2792811792779de0747f0e684cfcdcafd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
}