FS
Source: std/fs.mw.
File helpers built on sys_open, sys_read and sys_write. Errors are reported as a negative value or a null pointer, never as an exception.
Files on top of raw system calls. A file handle is a rawptr holding the file descriptor plus one, so that null can mean “could not open”.
Functions
Section titled “Functions”file_handle
Section titled “file_handle”fn file_handle(fd: i64) -> rawptrfile_fd
Section titled “file_fd”fn file_fd(handle: rawptr) -> i32file_open_read
Section titled “file_open_read”fn file_open_read(path: *u8) -> rawptrfile_open_write
Section titled “file_open_write”fn file_open_write(path: *u8) -> rawptrCreates the file (mode 0644) or truncates it.
file_open_append
Section titled “file_open_append”fn file_open_append(path: *u8) -> rawptrfile_close
Section titled “file_close”fn file_close(handle: rawptr)file_read
Section titled “file_read”fn file_read(handle: rawptr, buf: *u8, count: i64) -> i64Reads up to count bytes. Returns the number read, 0 at end of file, or a negative error.
file_write
Section titled “file_write”fn file_write(handle: rawptr, buf: *u8, count: i64) -> i64Writes every byte. Returns 0 on success.
file_get_size
Section titled “file_get_size”fn file_get_size(handle: rawptr) -> i64file_exists
Section titled “file_exists”fn file_exists(path: *u8) -> i32file_remove
Section titled “file_remove”fn file_remove(path: *u8) -> i32dir_create
Section titled “dir_create”fn dir_create(path: *u8) -> i32read_to_string
Section titled “read_to_string”fn read_to_string(path: *u8) -> *StringReads the whole file (works for pipes too, where the size is unknown).
finish_read
Section titled “finish_read”fn finish_read(f: rawptr, content: *String, done: i64) -> *Stringwrite_string_to_file
Section titled “write_string_to_file”fn write_string_to_file(path: *u8, content: *String) -> i32