summaryrefslogtreecommitdiff
path: root/lib/std/blat.myr
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2015-10-06 13:32:25 -0700
committerOri Bernstein <ori@eigenstate.org>2015-10-06 13:32:25 -0700
commit3400b0428b9147012553c6f2280147d8dc99bbf1 (patch)
tree0a8b3d4e904963535bff3da1b9d81a1f51084261 /lib/std/blat.myr
parentc4d04d5ed7a782baf87e5beea2a2d95e31bebc5b (diff)
downloadmc-3400b0428b9147012553c6f2280147d8dc99bbf1.tar.gz
Fix up error handling for syswrap+posixy.myr
Diffstat (limited to 'lib/std/blat.myr')
-rw-r--r--lib/std/blat.myr28
1 files changed, 14 insertions, 14 deletions
diff --git a/lib/std/blat.myr b/lib/std/blat.myr
index 90c0f94..ed27f97 100644
--- a/lib/std/blat.myr
+++ b/lib/std/blat.myr
@@ -1,4 +1,5 @@
use "syswrap.use"
+use "result.use"
pkg std =
const blat : (path : byte[:], buf : byte[:], perm : int64 -> bool)
@@ -6,27 +7,26 @@ pkg std =
;;
const blat = {path, buf, perm
- var fd
-
- fd = openmode(path, Ocreat|Owronly, perm)
- if fd < 0
- -> false
+ match openmode(path, Ocreat|Owronly, perm)
+ | `Ok fd: -> fblat(fd, buf)
+ | `Fail e: -> false
;;
- -> fblat(fd, buf)
}
const fblat = {fd, buf
- var written, n
+ var count
- n = 0
+ count = 0
while true
- written = write(fd, buf[n:])
- if written <= 0
- goto done
+ match write(fd, buf[count:])
+ | `Fail e: -> false
+ | `Ok n:
+ if n == 0
+ break
+ ;;
+ count += n
;;
- n += written
;;
-:done
- -> written == 0 && n == buf.len
+ -> count == buf.len
}