24 lines
447 B
Plaintext
24 lines
447 B
Plaintext
module file
|
|
|
|
export func read_text(path: string): ^u8 {
|
|
let fd = sys::open(path.ptr 0 0o644)
|
|
if fd < 0 {
|
|
return ^u8(0) // failed to open
|
|
}
|
|
|
|
let buf_size: u64 = 4096
|
|
let buf = c::malloc(buf_size) as ^u8
|
|
if buf == ^u8(0) {
|
|
return ^u8(0)
|
|
}
|
|
|
|
let bytes_read = sys::read(fd, buf, buf_size)
|
|
if bytes_read < 0 {
|
|
c::free(buf)
|
|
return ^u8(0)
|
|
}
|
|
|
|
buf[bytes_read] = 0
|
|
|
|
return buf
|
|
} |