summaryrefslogtreecommitdiff
path: root/lib/std/mkpath.myr
diff options
context:
space:
mode:
Diffstat (limited to 'lib/std/mkpath.myr')
-rw-r--r--lib/std/mkpath.myr22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/std/mkpath.myr b/lib/std/mkpath.myr
new file mode 100644
index 0000000..b7e8e24
--- /dev/null
+++ b/lib/std/mkpath.myr
@@ -0,0 +1,22 @@
+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
+}