summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2015-10-07 05:34:42 -0700
committerOri Bernstein <ori@eigenstate.org>2015-10-07 05:34:42 -0700
commitca845d8cb698f7822497046525c1ea477a944835 (patch)
tree67d749d52ba04d2766184e573fb1f22986b42cef
parent1bb9fd59499eb6fb7e8b56e4cee72365074d172e (diff)
downloadmc-ca845d8cb698f7822497046525c1ea477a944835.tar.gz
Actually check the last error.
-rw-r--r--lib/std/syswrap+plan9.myr24
-rw-r--r--lib/sys/sys+plan9-x64.myr1
2 files changed, 24 insertions, 1 deletions
diff --git a/lib/std/syswrap+plan9.myr b/lib/std/syswrap+plan9.myr
index ac61a29..6bb2f63 100644
--- a/lib/std/syswrap+plan9.myr
+++ b/lib/std/syswrap+plan9.myr
@@ -4,6 +4,8 @@ use "option.use"
use "types.use"
use "errno.use"
use "result.use"
+use "cstrconv.use"
+use "strfind.use"
pkg std =
type fd = sys.fd
@@ -235,5 +237,25 @@ generic check = {e : @a::(integral, numeric) -> result(@b, errno)
}
const lasterr = {
- -> Emisc
+ var errbuf : byte[sys.Maxerr]
+ var err
+
+ sys.errstr(errbuf[:])
+ err = cstrconv(errbuf[:])
+ if strhas(err, "no error")
+ -> Enone
+ elif strhas(err, "already exists")
+ -> Eexist
+ elif strhas(err, "read or write too large")
+ -> Erange
+ elif strhas(err, "read or write too small")
+ -> Erange
+ elif strhas(err, "i/o error")
+ -> Eio
+ elif strhas(err, "fd out of range or not open")
+ -> Ebadf
+ else
+ -> Emisc
+ ;;
}
+
diff --git a/lib/sys/sys+plan9-x64.myr b/lib/sys/sys+plan9-x64.myr
index f183dc2..bc360ad 100644
--- a/lib/sys/sys+plan9-x64.myr
+++ b/lib/sys/sys+plan9-x64.myr
@@ -25,6 +25,7 @@ pkg sys =
what : uint32 /* plink */
;;
+ const Maxerr : size = 128
const Ordonly : fdopt = 0
const Owronly : fdopt = 1