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