fs/core

sourcefs/core.sx

CwdError

pub enum CwdError = { AllocationFailed, GetCwdFailed }

Errors that can occur while reading the current working directory.

Variants

  • AllocationFailed
  • GetCwdFailed

cstr_heap

private
fn cstr_heap() allocators.HeapAllocator

getenv

pub fn getenv(name: ref u8) ref u8 = trust { ... }

Read an environment variable.

mkdir

pub fn mkdir(path: ref u8, mode: u32) i32 = trust { ... }

Create a directory.

_mkdir

pub fn _mkdir(path: ref u8) i32 = trust { ... }

Windows-compatible one-argument directory creation.

rmdir

pub fn rmdir(path: ref u8) i32 = trust { ... }

Remove an empty directory.

opendir

pub fn opendir(path: ref u8) ref void = trust { ... }

Open a directory stream.

closedir

pub fn closedir(dir: ref void) i32 = trust { ... }

Close a directory stream.

readdir

pub fn readdir(dir: ref void) ref Dirent = trust { ... }

Read the next directory entry.

Dirent

when linux
extern type Dirent = { d_ino: u64, d_off: i64, d_reclen: u16, d_type: u8, d_name: [256]u8 }

Fields

NameType
d_inou64
d_offi64
d_reclenu16
d_typeu8
d_name[256]u8

Dirent

when darwin
extern type Dirent = { d_ino: u64, d_seekoff: u64, d_reclen: u16, d_namlen: u16, d_type: u8, d_name: [1024]u8 }

Fields

NameType
d_inou64
d_seekoffu64
d_reclenu16
d_namlenu16
d_typeu8
d_name[1024]u8

Dirent

when freebsd
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 }

Fields

NameType
d_filenou64
d_offi64
d_reclenu16
d_typeu8
d_pad0u8
d_namlenu16
d_pad1u16
d_name[256]u8

Dirent

when openbsd
extern type Dirent = { d_fileno: u64, d_off: i64, d_reclen: u16, d_type: u8, d_namlen: u8, d_name: [256]u8 }

Fields

NameType
d_filenou64
d_offi64
d_reclenu16
d_typeu8
d_namlenu8
d_name[256]u8

Dirent

when netbsd
extern type Dirent = { d_fileno: u64, d_reclen: u16, d_namlen: u16, d_type: u8, d_name: [512]u8 }

Fields

NameType
d_filenou64
d_reclenu16
d_namlenu16
d_typeu8
d_name[512]u8

Dirent

when windows
extern type Dirent = { d_ino: i32, d_reclen: u16, d_namlen: u16, d_name: [260]u8 }

Fields

NameType
d_inoi32
d_reclenu16
d_namlenu16
d_name[260]u8

File

pub type File = { ptr: ref void }

Opaque file handle — wraps a C FILE*.

Fields

NameType
ptrref void

alloc_in

private
fn alloc_in[A: allocators.Allocator](ac: A, len: i64) ref void

alloc_cstr

private
fn alloc_cstr[A: allocators.Allocator](ac: A, len: i64) ref u8

copy_cstr

private
fn copy_cstr[A: allocators.Allocator](ac: A, text: ref u8) ref u8

copy_cstr_len

private
fn copy_cstr_len[A: allocators.Allocator](ac: A, text: ref u8, len: i64) ref u8

raw_alloc_cstr

private
fn raw_alloc_cstr(len: i64) ref u8 = trust { ... }

raw_copy_cstr_len

private
fn raw_copy_cstr_len(text: ref u8, len: i64) ref u8 = trust { ... }

dirent_name_len

private
fn dirent_name_len(entry: ref Dirent) i64 = trust { ... }

copy_dirent_name

private
fn copy_dirent_name[A: allocators.Allocator](ac: A, entry: ref Dirent) ref u8

raw_copy_dirent_name

private
fn raw_copy_dirent_name(entry: ref Dirent) ref u8 = trust { ... }

open_cstr

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.

open

pub fn open(path: str.StringView, mode: str.StringView) option[ref void] = trust { ... }

View-taking variant of open_cstr.

file_size

pub fn file_size(path: str.StringView) option[i64] = trust { ... }

View-taking variant of file_size_cstr.

read_all

pub fn read_all[A: allocators.Allocator](ac: A, path: str.StringView) option[ref u8]

View-taking variant of read_all_cstr.

read_all_heap

pub fn read_all_heap(path: str.StringView) option[ref u8] = trust { ... }

View-taking variant of read_all_heap_cstr.

write

pub fn write(f: ref void, data: str.StringView) void = trust { ... }

Write a view to an open file handle.

write_line

pub fn write_line(f: ref void, data: str.StringView) void = trust { ... }

Write a view followed by a newline to an open file handle.

write_all

pub fn write_all(path: str.StringView, data: str.StringView) bool = trust { ... }

View-taking variant of write_all_cstr.

write_all_bytes

pub fn write_all_bytes(path: str.StringView, data: ref void, len: i64) bool = trust { ... }

View-taking variant of write_all_bytes_cstr.

append_all

pub fn append_all(path: str.StringView, data: str.StringView) bool = trust { ... }

View-taking variant of append_all_cstr.

append_all_bytes

pub fn append_all_bytes(path: str.StringView, data: ref void, len: i64) bool = trust { ... }

View-taking variant of append_all_bytes_cstr.

delete

pub fn delete(path: str.StringView) bool = trust { ... }

View-taking variant of delete_cstr.

rename_path

pub fn rename_path(old: str.StringView, new: str.StringView) bool = trust { ... }

View-taking variant of rename_path_cstr.

mkdir_path

pub fn mkdir_path(path: str.StringView) bool = trust { ... }

View-taking variant of mkdir_path_cstr.

rmdir_path

pub fn rmdir_path(path: str.StringView) bool = trust { ... }

View-taking variant of rmdir_path_cstr.

remove_dir_all

pub fn remove_dir_all(path: str.StringView) bool = trust { ... }

View-taking variant of remove_dir_all_cstr.

is_directory

pub fn is_directory(path: str.StringView) bool = trust { ... }

View-taking variant of is_directory_cstr.

close

pub fn close(f: ref void) void = trust { ... }

Close a file handle previously returned by open_cstr().

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

read_all_cstr

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.

read_all_heap_cstr

pub fn read_all_heap_cstr(path: ref u8) option[ref u8] = trust { ... }

read_line

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.

write_cstr

pub fn write_cstr(f: ref void, data: ref u8) void = trust { ... }

Write a string to a file opened in write mode.

write_bytes

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.

write_line_cstr

pub fn write_line_cstr(f: ref void, data: ref u8) void = trust { ... }

Write a string followed by a newline.

write_all_cstr

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.

write_all_bytes_cstr

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.

append_all_bytes_cstr

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.

append_all_cstr

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.

delete_cstr

pub fn delete_cstr(path: ref u8) bool = trust { ... }

Delete a file. Returns true on success.

rename_path_cstr

pub fn rename_path_cstr(old: ref u8, new: ref u8) bool = trust { ... }

Rename (or move) a file or directory. Returns true on success.

mkdir_path_cstr

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.

rmdir_path_cstr

pub fn rmdir_path_cstr(path: ref u8) bool = trust { ... }

Remove an empty directory. Returns true on success.

remove_dir_all_cstr

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.

cwd

pub fn cwd[A: allocators.Allocator](ac: A) result[ref u8, CwdError]

Return the current working directory as an allocator-backed str.

cwd_cstr

pub fn cwd_cstr() option[ref u8] = trust { ... }

temp_dir

pub fn temp_dir[A: allocators.Allocator](ac: A) ref u8

Return the system temporary directory. Falls back to "/tmp" on POSIX if TMPDIR is not set.

temp_dir_cstr

pub fn temp_dir_cstr() ref u8 = trust { ... }

home_dir

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.

home_dir_cstr

pub fn home_dir_cstr() option[ref u8] = trust { ... }

config_dir

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.

config_dir_cstr

pub fn config_dir_cstr() option[ref u8] = trust { ... }

walk_dir

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}) }

walk_dir_cstr

pub fn walk_dir_cstr[A: allocators.GeneralAllocator](ac: A, path: ref u8) option[list[ref u8]]

is_directory_cstr

pub fn is_directory_cstr(path: ref u8) bool = trust { ... }