summaryrefslogtreecommitdiff
path: root/lib/std/readall.myr
blob: 33fbc0c2820753a5b43d1e03e5c0a931eccdad4e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
}