summaryrefslogtreecommitdiff
path: root/libstd/dir+osx.myr
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2014-10-03 13:22:46 -0400
committerOri Bernstein <ori@eigenstate.org>2014-10-03 13:22:46 -0400
commite898ab8413e852b6f097e047157093014246c9a2 (patch)
treeaeb8109049da225cddad3fa232edfce831bc0f76 /libstd/dir+osx.myr
parentf13090387d3a76daf8b531cb2e8bfa7e26b6f344 (diff)
downloadmc-e898ab8413e852b6f097e047157093014246c9a2.tar.gz
Use '+' as the system separator.
Diffstat (limited to 'libstd/dir+osx.myr')
-rw-r--r--libstd/dir+osx.myr59
1 files changed, 59 insertions, 0 deletions
diff --git a/libstd/dir+osx.myr b/libstd/dir+osx.myr
new file mode 100644
index 0000000..1463349
--- /dev/null
+++ b/libstd/dir+osx.myr
@@ -0,0 +1,59 @@
+use "alloc.use"
+use "die.use"
+use "option.use"
+use "result.use"
+use "slcp.use"
+use "sldup.use"
+use "sys.use"
+use "types.use"
+
+pkg std =
+ type dir = struct
+ fd : fd
+ buf : byte[16384]
+ len : int64
+ off : int64
+ base : int64
+ ;;
+
+ const diropen : (p : byte[:] -> std.result(dir#, byte[:]))
+ const dirread : (d : dir# -> std.option(byte[:]))
+ const dirclose : (d : dir# -> void)
+;;
+
+const diropen = {p
+ var fd
+ var dir
+
+ fd = open(p, Ordonly | Odir)
+ if fd < 0
+ -> `Fail "couldn't open directory"
+ ;;
+ dir = zalloc()
+ dir.fd = fd
+ -> `Ok dir
+}
+
+const dirread = {d
+ var len
+ var dent
+
+ if d.off >= d.len
+ len = getdirentries64(d.fd, d.buf[:], &d.base)
+ if len <= 0
+ -> `None
+ ;;
+ d.len = len
+ d.off = 0
+ ;;
+
+ dent = &d.buf[d.off] castto(dirent64#)
+ d.off += dent.reclen castto(int64)
+ -> `Some sldup(dent.name[:dent.namlen])
+}
+
+const dirclose = {d
+ close(d.fd)
+ free(d)
+}
+