Skip to content

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”.

fn file_handle(fd: i64) -> rawptr
fn file_fd(handle: rawptr) -> i32
fn file_open_read(path: *u8) -> rawptr
fn file_open_write(path: *u8) -> rawptr

Creates the file (mode 0644) or truncates it.

fn file_open_append(path: *u8) -> rawptr
fn file_close(handle: rawptr)
fn file_read(handle: rawptr, buf: *u8, count: i64) -> i64

Reads up to count bytes. Returns the number read, 0 at end of file, or a negative error.

fn file_write(handle: rawptr, buf: *u8, count: i64) -> i64

Writes every byte. Returns 0 on success.

fn file_get_size(handle: rawptr) -> i64
fn file_exists(path: *u8) -> i32
fn file_remove(path: *u8) -> i32
fn dir_create(path: *u8) -> i32
fn read_to_string(path: *u8) -> *String

Reads the whole file (works for pipes too, where the size is unknown).

fn finish_read(f: rawptr, content: *String, done: i64) -> *String
fn write_string_to_file(path: *u8, content: *String) -> i32