diff options
author | Ori Bernstein <ori@eigenstate.org> | 2015-08-26 12:20:58 -0700 |
---|---|---|
committer | Ori Bernstein <ori@eigenstate.org> | 2015-08-26 12:20:58 -0700 |
commit | 2bc852bda98762d3bc01548bf972e3f1b137fbfb (patch) | |
tree | 74831deed3c9057c5fe0cbb8790d220e855bc792 /lib/std/syswrap-ss+plan9.myr | |
parent | 3de952510eb2a23350d24ed926f19c0cf72a12f2 (diff) | |
download | mc-2bc852bda98762d3bc01548bf972e3f1b137fbfb.tar.gz |
Move Myrddin libs to lib/ subdirectory.
Diffstat (limited to 'lib/std/syswrap-ss+plan9.myr')
-rw-r--r-- | lib/std/syswrap-ss+plan9.myr | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/lib/std/syswrap-ss+plan9.myr b/lib/std/syswrap-ss+plan9.myr new file mode 100644 index 0000000..9615a6e --- /dev/null +++ b/lib/std/syswrap-ss+plan9.myr @@ -0,0 +1,56 @@ +use sys + +use "errno.use" +use "cstrconv.use" + +pkg std = + const exit : (status : int -> void) + pkglocal const bgetcwd : (buf : byte[:] -> errno) +;; + +const bgetcwd = {buf + var fd + + fd = sys.open(".", sys.Ordonly) + if fd < 0 + -> fd castto(errno) + ;; + + if sys.fd2path(fd, buf) == 0 + /* + Because we don't return the size, the best we can do is + assume that if the buffer is completely full, we have + truncated it. Since we truncate at utf8 characters, we + can have at most 3 bytes truncated (4 bytes will fit + any utf8 char), and one byte for the nul terminator. + */ + if cstrlen(buf) + 5 == buf.len + -> Erange + else + -> cstrlen(buf) castto(errno) + ;; + ;; + -> Emisc +} + +const digitchars = "0123456789" +const exit = {status + var buf : byte[32] /* big enough for exit status numbers */ + var n, i + + if status == 0 + sys.exits("") + else + status &= 255 + i = 100 + n = 0 + while i > 0 + if status >= i + buf[n++] = digitchars[(status/i)%10] + ;; + i /= 10 + ;; + sys.exits(buf[:n]) + ;; +} + |