summaryrefslogtreecommitdiff
path: root/libstd/blat.myr
blob: 90c0f945d80463a847cb888237f432e0c8e82be4 (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
27
28
29
30
31
32
use "syswrap.use"

pkg std =
	const blat : (path : byte[:], buf : byte[:], perm : int64 -> bool)
	const fblat : (f : fd, buf : byte[:] -> bool)
;;

const blat = {path, buf, perm
	var fd

	fd = openmode(path, Ocreat|Owronly, perm)
	if fd < 0
		-> false
	;;
	-> fblat(fd, buf)
}


const fblat = {fd, buf
	var written, n

	n = 0
	while true
		written = write(fd, buf[n:])
		if written <= 0
			goto done
		;;
		n += written
	;;
:done
	-> written == 0 && n == buf.len
}