summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2018-05-06 06:58:44 -0700
committerOri Bernstein <ori@eigenstate.org>2018-05-06 06:58:44 -0700
commitafee16c01916327f6cf229bb911e7166041063a2 (patch)
tree8c7fcbd9f842c6d37c4fe4f4c5848da199924f84
parent1ac88fcd0d2f000dac2119cf52e3bd7c60200b96 (diff)
downloadmc-afee16c01916327f6cf229bb911e7166041063a2.tar.gz
Make std.writeall api slightly nicer.
-rw-r--r--lib/std/fmt.myr9
-rw-r--r--lib/std/writeall.myr6
2 files changed, 8 insertions, 7 deletions
diff --git a/lib/std/fmt.myr b/lib/std/fmt.myr
index c7e7eda..e82aece 100644
--- a/lib/std/fmt.myr
+++ b/lib/std/fmt.myr
@@ -111,16 +111,17 @@ const fput = {fd, fmt, args
}
const fputv = {fd, fmt, ap
- var sb, s
+ var sb, s, nw
sb = mksb()
sbfmtv(sb, fmt, ap)
s = sbfin(sb)
match writeall(fd, s)
- | (n, _):
- slfree(s)
- -> n
+ | `std.Ok n: nw += n
+ | `std.Err (n, _): nw += n
;;
+ slfree(s)
+ -> nw
}
const fmt = {fmt, args
diff --git a/lib/std/writeall.myr b/lib/std/writeall.myr
index 6653741..7d335ba 100644
--- a/lib/std/writeall.myr
+++ b/lib/std/writeall.myr
@@ -5,7 +5,7 @@ use "syswrap"
use "types"
pkg std =
- const writeall : (fd : fd, src : byte[:] -> (size, option(errno)))
+ const writeall : (fd : fd, src : byte[:] -> std.result(size, (size, errno)))
;;
const writeall = {fd, src
@@ -15,8 +15,8 @@ const writeall = {fd, src
while src.len != 0
match std.write(fd, src)
| `Ok n: src = src[n:]
- | `Err e: -> (sz - src.len, `Some e)
+ | `Err e: -> `std.Err (sz, e)
;;
;;
- -> (sz, `None)
+ -> `std.Ok sz
}