ref: c39b0cd430515c79ce14792b6f815cb7dd9f6e90
parent: e9a476ebae14c3d6a806bddc1b7514b60a846fc4
parent: 1860505486ea2190d78476782e504f15ce245ff0
author: Ori Bernstein <[email protected]>
date: Sat Dec 12 21:42:13 EST 2015
Merge pull request #4 from andrewchambers/writeall Add writeall to std
--- a/lib/std/bld.sub
+++ b/lib/std/bld.sub
@@ -29,7 +29,7 @@
hassuffix.myr
htab.myr
intparse.myr
- introspect.myr
+ introspect.myr
ipparse.myr
mk.myr
mkpath.myr
@@ -63,6 +63,7 @@
units.myr
utf.myr
varargs.myr
+ writeall.myr
# asm optimizations
memops.myr
--- /dev/null
+++ b/lib/std/writeall.myr
@@ -1,0 +1,24 @@
+use "errno.use"
+use "result.use"
+use "option.use"
+use "syswrap.use"
+use "types.use"
+
+pkg std =
+ const writeall : (fd : fd, src : byte[:] -> (size, option(errno)))
+;;
+
+const writeall = {fd, src
+ var sz
+
+ sz = src.len
+ while src.len != 0
+ match std.write(fd, src)
+ | `Ok n:
+ src = src[n:]
+ | `Fail e:
+ -> (sz - src.len, `Some e)
+ ;;
+ ;;
+ -> (sz, `None)
+}