summaryrefslogtreecommitdiff
path: root/libstd/mkpath.myr
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2014-12-15 01:30:31 -0800
committerOri Bernstein <ori@eigenstate.org>2014-12-15 01:30:31 -0800
commit46bc8592a6cd4b2be507057f19bbb4e085e89bf2 (patch)
tree59697901bc1546814987071abd25ea878335f467 /libstd/mkpath.myr
parente72ff77facf957ccb145104b63b1757a3a4da210 (diff)
downloadmc-46bc8592a6cd4b2be507057f19bbb4e085e89bf2.tar.gz
Add recursive path creation.
Diffstat (limited to 'libstd/mkpath.myr')
-rw-r--r--libstd/mkpath.myr21
1 files changed, 21 insertions, 0 deletions
diff --git a/libstd/mkpath.myr b/libstd/mkpath.myr
new file mode 100644
index 0000000..2da5333
--- /dev/null
+++ b/libstd/mkpath.myr
@@ -0,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
+}