ref: ab64fa7f418e370e2efa075c11630e33f1f6d231
parent: 590fccdc474d26f6b004376e4423536b590ca000
author: Ori Bernstein <[email protected]>
date: Sun Dec 14 20:30:31 EST 2014
Add recursive path creation.
--- /dev/null
+++ b/libstd/mkpath.myr
@@ -1,0 +1,21 @@
+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)
+ elif st != 0 && (st castto(errno)) != Eexist
+ -> false
+ ;;
+ ;;
+
+ -> true
+}