summaryrefslogtreecommitdiff
path: root/lib/std
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2017-02-16 00:34:44 -0800
committerOri Bernstein <ori@eigenstate.org>2017-02-16 00:34:44 -0800
commitb623656b7898648e82dcc0adc5c4d03a5ba9b5da (patch)
treec01b67dc1d3a205e5b376a9e136b36f018ee45de /lib/std
parentbf2829b82ba77f1f9fd5586e4216995366cf7aed (diff)
downloadmc-b623656b7898648e82dcc0adc5c4d03a5ba9b5da.tar.gz
Bulk of porting to NetBSD.
This wasn't so bad. Missing: - libthread - auditing all libsys struct types.
Diffstat (limited to 'lib/std')
-rw-r--r--lib/std/bld.sub2
-rw-r--r--lib/std/dir+netbsd.myr65
-rw-r--r--lib/std/syswrap-ss+netbsd.myr31
3 files changed, 98 insertions, 0 deletions
diff --git a/lib/std/bld.sub b/lib/std/bld.sub
index f32fb19..4b687b6 100644
--- a/lib/std/bld.sub
+++ b/lib/std/bld.sub
@@ -100,6 +100,7 @@ lib std {inc=.} =
dir+freebsd.myr
dir+linux.myr
dir+openbsd.myr
+ dir+netbsd.myr
dir+osx.myr
dir+plan9.myr
env+plan9.myr
@@ -117,6 +118,7 @@ lib std {inc=.} =
# system-specific syscall wrappers
syswrap-ss+linux.myr
+ syswrap-ss+netbsd.myr
syswrap-ss+openbsd.myr
syswrap-ss+osx.myr
syswrap-ss+plan9.myr
diff --git a/lib/std/dir+netbsd.myr b/lib/std/dir+netbsd.myr
new file mode 100644
index 0000000..274175d
--- /dev/null
+++ b/lib/std/dir+netbsd.myr
@@ -0,0 +1,65 @@
+use sys
+
+use "alloc"
+use "die"
+use "memops"
+use "option"
+use "result"
+use "slcp"
+use "sldup"
+use "types"
+
+pkg std =
+ type dir = struct
+ fd : sys.fd
+ buf : byte[16384]
+ len : int64
+ off : 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
+ -> `Err "couldn't open directory"
+ ;;
+ dir = zalloc()
+ dir.fd = fd
+ -> `Ok dir
+}
+
+const dirread = {d
+ var len
+ var dent
+ var namelen
+
+ if d.off >= d.len
+ len = sys.getdents(d.fd, d.buf[:])
+ if len <= 0
+ -> `None
+ ;;
+ d.len = len
+ d.off = 0
+ ;;
+
+ dent = (&d.buf[d.off] : sys.dirent#)
+ namelen = 0
+ d.off += (dent.reclen : int64)
+ while dent.name[namelen] != 0
+ namelen++
+ ;;
+ -> `Some sldup(dent.name[:namelen])
+}
+
+const dirclose = {d
+ sys.close(d.fd)
+ free(d)
+}
+
diff --git a/lib/std/syswrap-ss+netbsd.myr b/lib/std/syswrap-ss+netbsd.myr
new file mode 100644
index 0000000..42605ab
--- /dev/null
+++ b/lib/std/syswrap-ss+netbsd.myr
@@ -0,0 +1,31 @@
+use sys
+use "types"
+use "errno"
+use "cstrconv"
+use "slcp"
+use "die"
+
+pkg std =
+ const nanosleep : (nsecs : uint64 -> errno)
+ $noret const exit : (status:int -> void)
+
+ pkglocal const bgetcwd : (buf : byte[:] -> errno)
+;;
+
+const exit = {status; sys.exit(status)}
+
+const bgetcwd = {buf
+ -> (sys.__getcwd(buf) - 1 : errno)
+}
+
+const nanosleep = {nsecs
+ var req, rem
+ var s, ns
+
+ s = nsecs / 1_000_000_000
+ ns = nsecs % 1_000_000_000
+ req = [.sec = s, .nsec = ns]
+
+ -> (sys.nanosleep(&req, &rem) : errno)
+}
+