ref: b6afe89b0d5928f317e8d554cec49d6e8f40a3d8
dir: /libstd/slurp.myr/
use "alloc.use"
use "die.use"
use "error.use"
use "extremum.use"
use "fmt.use"
use "sys.use"
use "types.use"
pkg std =
const slurp : (path : byte[:] -> error(byte[:], byte[:]))
;;
const Bufinc = 4096
const slurp = {path
var fd
var n
var len
var buf
fd = open(path, Ordonly, 0o777)
if fd < 0
-> `Failure "Could not open file"
;;
len = 0
buf = slalloc(Bufinc)
while true
n = read(fd, buf[len:])
if n == 0
goto done
;;
len += n
buf = slgrow(buf, len + Bufinc)
;;
:done
-> `Success buf[:len]
}