summaryrefslogtreecommitdiff
path: root/lib/std
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2015-09-19 12:55:47 -0400
committerOri Bernstein <ori@eigenstate.org>2015-09-19 12:55:47 -0400
commit54daa7961f3639adc9965ffa4ddf98e4ab0f2ff9 (patch)
treec74f0da8a19669c499ddff51c856680d6f461500 /lib/std
parentf0c4423afd2dc42988af0e9b7fdcd1371e2fda73 (diff)
downloadmc-54daa7961f3639adc9965ffa4ddf98e4ab0f2ff9.tar.gz
Compile on FreeBSD.
Things are still broken, but we've got a start.
Diffstat (limited to 'lib/std')
-rw-r--r--lib/std/dir+freebsd.myr60
1 files changed, 60 insertions, 0 deletions
diff --git a/lib/std/dir+freebsd.myr b/lib/std/dir+freebsd.myr
index e69de29..6190b56 100644
--- a/lib/std/dir+freebsd.myr
+++ b/lib/std/dir+freebsd.myr
@@ -0,0 +1,60 @@
+use sys
+
+use "alloc.use"
+use "die.use"
+use "option.use"
+use "result.use"
+use "slcp.use"
+use "sldup.use"
+use "types.use"
+
+pkg std =
+ type dir = struct
+ fd : sys.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 = sys.open(p, sys.Ordonly | sys.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 = sys.getdirentries(d.fd, d.buf[:], &d.base)
+ if len <= 0
+ -> `None
+ ;;
+ d.len = len
+ d.off = 0
+ ;;
+
+ dent = &d.buf[d.off] castto(sys.dirent#)
+ d.off += dent.reclen castto(int64)
+ -> `Some sldup(dent.name[:dent.namelen])
+}
+
+const dirclose = {d
+ sys.close(d.fd)
+ free(d)
+}
+