static string literals

This commit is contained in:
nub31
2026-03-01 00:12:16 +01:00
parent 16d27c76ab
commit faf506f409
5 changed files with 112 additions and 90 deletions

View File

@@ -1,24 +0,0 @@
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
}