os/core

sourceos/core.sx

WinFindDataA

when windows
extern type WinFindDataA = { dwFileAttributes: u32, ftCreationLow: u32, ftCreationHigh: u32, ftLastAccessLow: u32, ftLastAccessHigh: u32, ftLastWriteLow: u32, ftLastWriteHigh: u32, nFileSizeHigh: u32, nFileSizeLow: u32, dwReserved0: u32, dwReserved1: u32, cFileName: [260]u8, cAlternateFileName: [14]u8 }

Fields

NameType
dwFileAttributesu32
ftCreationLowu32
ftCreationHighu32
ftLastAccessLowu32
ftLastAccessHighu32
ftLastWriteLowu32
ftLastWriteHighu32
nFileSizeHighu32
nFileSizeLowu32
dwReserved0u32
dwReserved1u32
cFileName[260]u8
cAlternateFileName[14]u8

CreateDirectoryA

when windowsprivate
extern (C, header) fn CreateDirectoryA(path: ref u8, security: ref void) i32 = trust { ... } = "CreateDirectoryA"

FindFirstFileA

when windowsprivate
extern (C, header) fn FindFirstFileA(pattern: ref u8, data: ref WinFindDataA) ref void = trust { ... } = "FindFirstFileA"

FindNextFileA

when windowsprivate
extern (C, header) fn FindNextFileA(handle: ref void, data: ref WinFindDataA) i32 = trust { ... } = "FindNextFileA"

FindClose

when windowsprivate
extern (C, header) fn FindClose(handle: ref void) i32 = trust { ... } = "FindClose"

CopyFileA

when windowsprivate
extern (C, header) fn CopyFileA(existing: ref u8, new_file: ref u8, fail_if_exists: i32) i32 = trust { ... } = "CopyFileA"

GetFileAttributesA

when windowsprivate
extern (C, header) fn GetFileAttributesA(path: ref u8) u32 = trust { ... } = "GetFileAttributesA"

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

getenv

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

mkdir

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

rmdir

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

opendir

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

closedir

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

readdir

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

exit

pub fn exit(code: i64) void = trust { ... }

fopen

private
fn fopen(path: ref u8, mode: ref u8) ref void = trust { ... }

fclose

private
fn fclose(file: ref void) i32 = trust { ... }

fread

private
fn fread(ptr: ref void, size: i64, nmemb: i64, file: ref void) i64 = trust { ... }

fwrite

private
fn fwrite(ptr: ref void, size: i64, nmemb: i64, file: ref void) i64 = trust { ... }

remove

private
fn remove(path: ref u8) i32 = trust { ... }

rename

private
fn rename(oldpath: ref u8, newpath: ref u8) i32 = trust { ... }

access

private
fn access(path: ref u8, mode: i32) i32 = trust { ... }

popen

private
fn popen(cmd: ref u8, mode: ref u8) ref void = trust { ... }

pclose

private
fn pclose(pipe: ref void) i32 = trust { ... }

system

private
fn system(cmd: ref u8) i32 = trust { ... }

ProcessError

pub enum ProcessError = { FailedToStart, ReadFailed }

Variants

  • FailedToStart
  • ReadFailed

env

pub fn env(var: ref u8) option[ref u8]

Get an environment variable. Returns none if not found.

exists

pub fn exists(path: ref u8) bool

Check if a file exists at the given path.

open

pub fn open(path: ref u8, mode: ref u8) option[ref void]

Open a file in the given mode ("r", "w", "a", etc.). Returns the file handle or none.

close

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

Close a file handle.

read

pub fn read(file: ref void, size: i64) ref void = trust { ... }

Read up to size bytes from a file. Returns a heap buffer.

write

pub fn write(file: ref void, buf: ref void, size: i64) i64 = trust { ... }

Write size bytes from a buffer to a file.

delete

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

Delete a file from the filesystem. Returns 0 on success.

rename_file

pub fn rename_file(oldpath: ref u8, newpath: ref u8) i32 = trust { ... }

Rename a file. Returns 0 on success.

is_dot_dir_entry

private
fn is_dot_dir_entry(name: ref u8) bool

ensure_dir

private
fn ensure_dir(path: ref u8) bool = trust { ... }

copy_file

pub fn copy_file(src_path: ref u8, dst_path: ref u8) bool = trust { ... }

Copy one file to another path.

copy_dir_recursive

pub fn copy_dir_recursive(src_dir: ref u8, dst_dir: ref u8) bool = trust { ... }

Recursively copy a directory tree.

bytes_equal

private
fn bytes_equal(buf: ref void, expected: ref u8, len: i64) bool

get_args

pub fn get_args() list[ref u8] = trust { ... }

Get command-line arguments as a List of strings.

command_for_shell

private
fn command_for_shell(cmd: ref u8) ref u8 = trust { ... }

Quote a command that starts with a quoted executable.

This is a no-op outside of Windows.

run

pub fn run(cmd: ref u8) i32 = trust { ... }

Execute a command inheriting stdout/stderr (no capture). Returns exit code.

exec

pub fn exec(cmd: ref u8) result[String, ProcessError] = trust { ... }

Execute some subprocess, capturing its output.

path_separator

private
fn path_separator() u8 = trust { ... }

in_path

pub fn in_path(binary: ref u8) bool = trust { ... }

Check if a binary is available in PATH.

exec_trim

pub fn exec_trim(cmd: ref u8) result[ref void, ProcessError] = trust { ... }

Execute and trim output.