summaryrefslogtreecommitdiff
path: root/lib/std/readall.myr
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2016-05-02 21:21:49 -0700
committerOri Bernstein <ori@eigenstate.org>2016-05-03 21:56:20 -0700
commita986d1d8ae4c6f75384b62347c733a226edcafba (patch)
treea815f069e2772d207f3c05b84ac656fdb0a79eef /lib/std/readall.myr
parentdff9fe20898ba0d2165dd55b2e47486acbef45c1 (diff)
downloadmc-a986d1d8ae4c6f75384b62347c733a226edcafba.tar.gz
Regenerate bootstrap
Diffstat (limited to 'lib/std/readall.myr')
-rw-r--r--lib/std/readall.myr26
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/std/readall.myr b/lib/std/readall.myr
new file mode 100644
index 0000000..33fbc0c
--- /dev/null
+++ b/lib/std/readall.myr
@@ -0,0 +1,26 @@
+use "errno"
+use "result"
+use "option"
+use "syswrap"
+use "types"
+
+pkg std =
+ const readall : (fd : fd, dst : byte[:] -> result(size, errno))
+;;
+
+const readall = {fd, dst
+ var sz
+
+ sz = dst.len
+ while dst.len != 0
+ match std.read(fd, dst)
+ | `Ok 0:
+ break
+ | `Ok n:
+ dst = dst[n:]
+ | `Fail e:
+ -> `Fail e
+ ;;
+ ;;
+ -> `Ok sz - dst.len
+}