shithub: mc

Download patch

ref: 1860505486ea2190d78476782e504f15ce245ff0
parent: e9a476ebae14c3d6a806bddc1b7514b60a846fc4
author: Andrew Chambers <[email protected]>
date: Sun Dec 13 16:43:56 EST 2015

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)
+}