CwdError
pub enum CwdError = { AllocationFailed, GetCwdFailed }Errors that can occur while reading the current working directory.
Variants
AllocationFailedGetCwdFailed
pub enum CwdError = { AllocationFailed, GetCwdFailed }Errors that can occur while reading the current working directory.
AllocationFailedGetCwdFailedfn cstr_heap() allocators.HeapAllocatorpub fn getenv(name: ref u8) ref u8 = trust { ... }Read an environment variable.
pub fn mkdir(path: ref u8, mode: u32) i32 = trust { ... }Create a directory.
pub fn _mkdir(path: ref u8) i32 = trust { ... }Windows-compatible one-argument directory creation.
pub fn rmdir(path: ref u8) i32 = trust { ... }Remove an empty directory.
pub fn opendir(path: ref u8) ref void = trust { ... }Open a directory stream.
pub fn closedir(dir: ref void) i32 = trust { ... }Close a directory stream.
pub fn readdir(dir: ref void) ref Dirent = trust { ... }Read the next directory entry.
extern type Dirent = { d_ino: u64, d_off: i64, d_reclen: u16, d_type: u8, d_name: [256]u8 }| Name | Type |
|---|---|
d_ino | u64 |
d_off | i64 |
d_reclen | u16 |
d_type | u8 |
d_name | [256]u8 |
extern type Dirent = { d_ino: u64, d_seekoff: u64, d_reclen: u16, d_namlen: u16, d_type: u8, d_name: [1024]u8 }| Name | Type |
|---|---|
d_ino | u64 |
d_seekoff | u64 |
d_reclen | u16 |
d_namlen | u16 |
d_type | u8 |
d_name | [1024]u8 |
extern type Dirent = { d_fileno: u64, d_off: i64, d_reclen: u16, d_type: u8, d_pad0: u8, d_namlen: u16, d_pad1: u16, d_name: [256]u8 }| Name | Type |
|---|---|
d_fileno | u64 |
d_off | i64 |
d_reclen | u16 |
d_type | u8 |
d_pad0 | u8 |
d_namlen | u16 |
d_pad1 | u16 |
d_name | [256]u8 |
extern type Dirent = { d_fileno: u64, d_off: i64, d_reclen: u16, d_type: u8, d_namlen: u8, d_name: [256]u8 }| Name | Type |
|---|---|
d_fileno | u64 |
d_off | i64 |
d_reclen | u16 |
d_type | u8 |
d_namlen | u8 |
d_name | [256]u8 |
extern type Dirent = { d_fileno: u64, d_reclen: u16, d_namlen: u16, d_type: u8, d_name: [512]u8 }| Name | Type |
|---|---|
d_fileno | u64 |
d_reclen | u16 |
d_namlen | u16 |
d_type | u8 |
d_name | [512]u8 |
extern type Dirent = { d_ino: i32, d_reclen: u16, d_namlen: u16, d_name: [260]u8 }| Name | Type |
|---|---|
d_ino | i32 |
d_reclen | u16 |
d_namlen | u16 |
d_name | [260]u8 |
pub type File = { ptr: ref void }Opaque file handle — wraps a C FILE*.
| Name | Type |
|---|---|
ptr | ref void |
fn alloc_in[A: allocators.Allocator](ac: A, len: i64) ref voidfn alloc_cstr[A: allocators.Allocator](ac: A, len: i64) ref u8fn copy_cstr[A: allocators.Allocator](ac: A, text: ref u8) ref u8fn copy_cstr_len[A: allocators.Allocator](ac: A, text: ref u8, len: i64) ref u8fn raw_alloc_cstr(len: i64) ref u8 = trust { ... }fn raw_copy_cstr_len(text: ref u8, len: i64) ref u8 = trust { ... }fn dirent_name_len(entry: ref Dirent) i64 = trust { ... }fn copy_dirent_name[A: allocators.Allocator](ac: A, entry: ref Dirent) ref u8fn raw_copy_dirent_name(entry: ref Dirent) ref u8 = trust { ... }pub fn open_cstr(path: ref u8, mode: ref u8) option[ref void] = trust { ... }Open a file. Here, mode is a C fopen mode string: "r", "w", "a", "rb", etc. Returns none if the file could not be opened.
pub fn open(path: str.StringView, mode: str.StringView) option[ref void] = trust { ... }View-taking variant of open_cstr.
pub fn file_size(path: str.StringView) option[i64] = trust { ... }View-taking variant of file_size_cstr.
pub fn read_all[A: allocators.Allocator](ac: A, path: str.StringView) option[ref u8]View-taking variant of read_all_cstr.
pub fn read_all_heap(path: str.StringView) option[ref u8] = trust { ... }View-taking variant of read_all_heap_cstr.
pub fn write(f: ref void, data: str.StringView) void = trust { ... }Write a view to an open file handle.
pub fn write_line(f: ref void, data: str.StringView) void = trust { ... }Write a view followed by a newline to an open file handle.
pub fn write_all(path: str.StringView, data: str.StringView) bool = trust { ... }View-taking variant of write_all_cstr.
pub fn write_all_bytes(path: str.StringView, data: ref void, len: i64) bool = trust { ... }View-taking variant of write_all_bytes_cstr.
pub fn append_all(path: str.StringView, data: str.StringView) bool = trust { ... }View-taking variant of append_all_cstr.
pub fn append_all_bytes(path: str.StringView, data: ref void, len: i64) bool = trust { ... }View-taking variant of append_all_bytes_cstr.
pub fn delete(path: str.StringView) bool = trust { ... }View-taking variant of delete_cstr.
pub fn rename_path(old: str.StringView, new: str.StringView) bool = trust { ... }View-taking variant of rename_path_cstr.
pub fn mkdir_path(path: str.StringView) bool = trust { ... }View-taking variant of mkdir_path_cstr.
pub fn rmdir_path(path: str.StringView) bool = trust { ... }View-taking variant of rmdir_path_cstr.
pub fn remove_dir_all(path: str.StringView) bool = trust { ... }View-taking variant of remove_dir_all_cstr.
pub fn is_directory(path: str.StringView) bool = trust { ... }View-taking variant of is_directory_cstr.
pub fn close(f: ref void) void = trust { ... }Close a file handle previously returned by open_cstr().
pub fn file_size_cstr(path: ref u8) option[i64] = trust { ... }Return the size of a file in bytes. Returns none if the file could not be opened.
pub fn read_all_cstr[A: allocators.Allocator](ac: A, path: ref u8) option[ref u8]Read the entire contents of a file into an allocator-backed buffer. Returns a null-terminated ref u8, or none on error.
pub fn read_all_heap_cstr(path: ref u8) option[ref u8] = trust { ... }pub fn read_line(f: ref void, buf: ref u8, max_len: i64) bool = trust { ... }Read the next line from an open file handle into buf (max max_len bytes). Strips the trailing newline if present. Returns true if a line was read, false on EOF.
pub fn write_cstr(f: ref void, data: ref u8) void = trust { ... }Write a string to a file opened in write mode.
pub fn write_bytes(f: ref void, data: ref void, len: i64) void = trust { ... }Write exactly len bytes to an open file. Unlike write_cstr, this does not stop at a NUL byte, so it can be used for binary data.
pub fn write_line_cstr(f: ref void, data: ref u8) void = trust { ... }Write a string followed by a newline.
pub fn write_all_cstr(path: ref u8, data: ref u8) bool = trust { ... }Write the entire contents of data to path, overwriting any existing file.
pub fn write_all_bytes_cstr(path: ref u8, data: ref void, len: i64) bool = trust { ... }Write exactly len bytes to path, overwriting any existing file. The data may contain NUL bytes.
pub fn append_all_bytes_cstr(path: ref u8, data: ref void, len: i64) bool = trust { ... }Append exactly len bytes to path, creating it if it does not exist.
pub fn append_all_cstr(path: ref u8, data: ref u8) bool = trust { ... }Append data to a file, creating it if it does not exist.
pub fn delete_cstr(path: ref u8) bool = trust { ... }Delete a file. Returns true on success.
pub fn rename_path_cstr(old: ref u8, new: ref u8) bool = trust { ... }Rename (or move) a file or directory. Returns true on success.
pub fn mkdir_path_cstr(path: ref u8) bool = trust { ... }Create a directory. Mode is ignored on Windows; use 0755 on POSIX. Returns true on success.
pub fn rmdir_path_cstr(path: ref u8) bool = trust { ... }Remove an empty directory. Returns true on success.
pub fn remove_dir_all_cstr(path: ref u8) bool = trust { ... }Remove a file or directory tree recursively. Returns true when the path no longer exists.
pub fn cwd[A: allocators.Allocator](ac: A) result[ref u8, CwdError]Return the current working directory as an allocator-backed str.
pub fn cwd_cstr() option[ref u8] = trust { ... }pub fn temp_dir[A: allocators.Allocator](ac: A) ref u8Return the system temporary directory. Falls back to "/tmp" on POSIX if TMPDIR is not set.
pub fn temp_dir_cstr() ref u8 = trust { ... }pub fn home_dir[A: allocators.Allocator](ac: A) option[ref u8]Return the current user's home directory. Uses HOME on POSIX, USERPROFILE on Windows.
pub fn home_dir_cstr() option[ref u8] = trust { ... }pub fn config_dir[A: allocators.Allocator](ac: A) option[ref u8]Return the platform configuration directory. POSIX: $XDG_CONFIG_HOME, or $HOME/.config Windows: %APPDATA% Returns none if no suitable directory can be determined.
pub fn config_dir_cstr() option[ref u8] = trust { ... }pub fn walk_dir[A: allocators.GeneralAllocator](ac: A, path: ref u8) option[list[ref u8]]Walk a directory and return an iterable list[ref u8] of entry names.
Usage: val entries = walk_dirallocators.Arena? for entry in entries { std.stdio.print("{s}\n", {entry}) }
pub fn walk_dir_cstr[A: allocators.GeneralAllocator](ac: A, path: ref u8) option[list[ref u8]]pub fn is_directory_cstr(path: ref u8) bool = trust { ... }