shithub: mc

ref: 4aa0e6c6b8a1a23b144b0382d6156aaa55b2c7fd
dir: /lib/std/readall.myr/

View raw version
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:]
		| `Err e:
			-> `Err e
		;;
	;;
	-> `Ok (sz - dst.len)
}