ref: e31d035cf358e05158c0de708f31f9050043d997
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] }