summaryrefslogtreecommitdiff
path: root/lib/std/blat.myr
diff options
context:
space:
mode:
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
}