shithub: mc

ref: 690ab7aa8e6c56a4ae8a2bd5bce58d1df681234e
dir: /lib/std/writeall.myr/

View raw version
use "errno"
use "result"
use "option"
use "syswrap"
use "types"

pkg std =
	const writeall : (fd : fd, src : byte[:] -> std.result(size, (size, errno)))
;;

const writeall = {fd, src
	var sz

	sz = src.len
	while src.len != 0
		match std.write(fd, src)
		| `Err e:	-> `std.Err (sz, e)
		| `Ok 0:	-> `std.Err (sz, 0)
		| `Ok n:	src = src[n:]
		;;
	;;
	-> `std.Ok sz
}