shithub: mc

ref: b7be6fd5a31f8563949c2a7ac6db10f8b9ad0126
dir: /lib/std/blat.myr/

View raw version
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
}