Packages

builtin
cbindgen
core
core.alloc
core.alloc.arena
core.alloc.atomic
core.alloc.fixed
core.alloc.gc
core.alloc.heap
core.alloc.log
core.alloc.memdebug
core.alloc.pool
core.alloc.ring
core.arg_parse
core.array
core.avl_tree
core.bucket_array
core.conv
core.doc
core.encoding
core.encoding.base64
core.encoding.csv
core.encoding.hex
core.encoding.json
core.encoding.kdl
core.encoding.osad
core.encoding.utf8
core.hash
core.hash.md5
core.hash.sha1
core.hash.sha256
core.heap
core.intrinsics
core.intrinsics.atomics
core.intrinsics.onyx
core.intrinsics.types
core.intrinsics.wasm
core.io
core.io.binary
core.iter
core.js
core.list
core.map
core.math
core.memory
core.misc
core.net
core.os
core.random
core.set
core.slice
core.string
core.sync
core.test
core.thread
core.time
main
runtime
runtime.info
runtime.platform
runtime.vars
simd

package core.os

Command
Command :: struct {
    _path: [] u8;
    _args: [..] [] u8;
    _env: [..] Pair([] u8, [] u8);
    _dir: [] u8;
    _process: ? Process;
    _opts: ProcessSpawnOpts;
}

Stores configuration used by the builder pattern for processes.

Methods
Command.args
Command.args :: (cmd: &Command, args: [] [] u8) -> &Command

Appends arguments to the argument array of the command.

Command.destroy
Command.destroy :: (cmd: &Command) -> void

Destroys all internal information of a command. Automatically called by Command.wait.

Command.dir
Command.dir :: (cmd: &Command, dir: [] u8) -> &Command

Sets the working directory of the command.

Command.env
Command.env :: (cmd: &Command, key: [] u8, value: [] u8) -> &Command

Sets an environment variable.

Command.output
Command.output :: (cmd: &Command) -> Result([] u8, ProcessResultOutput)

Runs the command, wait until it completes, and capture output.

Command.path
Command.path :: (cmd: &Command, path: [] u8) -> &Command

Sets the path of the command.

Command.run
Command.run :: (cmd: &Command) -> ProcessResult

Runs the command and waits until it completes.

Command.start
Command.start :: (cmd: &Command) -> &Command

Starts the command.

Command.start_with_output
Command.start_with_output :: (cmd: &Command) -> &Command

Starts the command with the mapped I/O.

Command.wait
Command.wait :: (cmd: &Command) -> ProcessResult

Wait for the command to complete.

DirectoryEntry
DirectoryEntry :: struct {
    type: FileType;
    identifier: u32;
    name_length: u32;
    name_data: [256] u8;
}
Methods
DirectoryEntry.name
DirectoryEntry.name :: (dir: &DirectoryEntry) -> [] u8
File
File :: struct {
    stream: Stream;
    data: FileData;
}
FileStat
FileStat :: struct {
    size: i64;
    type: FileType;
    change_time: u64;
    accessed_time: u64;
    modified_time: u64;
}
File_Logger
File_Logger :: struct {
    file: &File;
    filename: [] u8;
    allocator: Allocator;
    old_logger: Logger;
}
Process
Process :: struct {
    stream: Stream;
    process_handle: ProcessData;
}

Represents a spawned OS process.

ProcessResultOutput
ProcessResultOutput :: struct {
    result: ProcessResult;
    output: [] u8;
}

Represents the exit state and output of a process.

ProcessSpawnOpts
ProcessSpawnOpts :: struct {
    capture_io: bool;
    non_blocking_io: bool;
    detach: bool;
    dir: [] u8;
    environment: [] Pair([] u8, [] u8);
}

Represents options for process creation.

TTY_State
TTY_State :: struct {
    rows: i32;
    cols: i32;
    stdin_is_tty: bool;
    stdout_is_tty: bool;
    stderr_is_tty: bool;
    echo: bool;
    input_buffered: bool;
    input_linefeeds: bool;
}
FileError
FileError :: enum {
    None :: 0;
    NotFound :: 1;
    Exists :: 2;
    Permission :: 3;
    BadFile :: 4;
    BadMode :: 5;
}
FileType
FileType :: enum {
    Unknown :: 0;
    Block :: 1;
    Char :: 2;
    Directory :: 3;
    RegularFile :: 4;
    SymLink :: 5;
    Other :: 6;
}
OpenMode
OpenMode :: enum {
    Invalid :: 0;
    Read :: 1;
    Write :: 2;
    Append :: 3;
}
ProcessResult
ProcessResult :: enum {
    Success :: 0;
    FailedToRun :: 1;
    Error :: 2;
    InternalErr :: 3;
}

Represents exit states of a process.

This is not the best format for this data, as it is impossible to get the exit status.

close
close :: (file: &File) -> void
command
command :: () -> &Command

Produces a new Command for the process builder.

os.command()
    ->path("executable_path")
    ->args(.["argument", "list"])
    ->run();
dir_close
dir_close :: (dir: DirectoryData) -> void
dir_open
dir_open :: (path: [] u8) -> (DirectoryData, bool)
dir_read
dir_read :: (dir: DirectoryData, out_entry: &DirectoryEntry) -> bool
env
env :: (key: [] u8) -> ? [] u8
env_vars
env_vars :: () -> Map([] u8, [] u8)
exit
exit :: (exitcode: i32) -> void
file_logger_close
file_logger_close :: (logger: &File_Logger) -> void
file_logger_open
file_logger_open :: (filename: [] u8, allocator: Allocator) -> Result(&File_Logger, [] u8)
file_logger_proc
file_logger_proc :: (logger: &File_Logger, level: Log_Level, msg: [] u8, module: [] u8) -> void
file_logger_use
file_logger_use :: (logger: &File_Logger) -> void
from_fd
from_fd :: (fd: FileData) -> File
get_contents
get_contents :: (file: &File) -> [] u8
get_contents :: (path: [] u8) -> [] u8
get_contents_from_file
get_contents_from_file :: (file: &File) -> [] u8
is_directory
is_directory :: (path: [] u8) -> bool
is_file
is_file :: (path: [] u8) -> bool
list_directory
list_directory :: (path: [] u8) -> Iterator(DirectoryEntry)
open
open :: (path: [] u8, mode: OpenMode) -> Result(File, FileError)
path_basename
path_basename :: (path: [] u8) -> [] u8

Returns the last element of the path, sans its extension.

path_basename("foo.txt") -> "foo"
path_basename("test/bar.txt") -> "bar"
path_clean
path_clean :: (path: [] u8, allocator: Allocator) -> [] u8

Removes:

  • Stray '.' in the path
  • Stray '..'
  • Repeated '/'
  • Trailing '/'

Modifies the string in place, as the length will never be longer.

path_directory
path_directory :: (path: [] u8) -> [] u8

Returns everything but the last element in the path.

This is then cleaned and copied into the temporary allocator.

path_extension
path_extension :: (path: [] u8) -> [] u8

Returns the extension of the file on the end of the path, if present.

path_extension("foo.txt") -> "txt"
path_extension("foo/bar") -> ""
path_extension("foo/bar.txt") -> "txt"
path_join
path_join :: (path: ..[] u8) -> [] u8

Concatenates path elements, and returns cleaned output.

This uses the temporary allocator, so a copy may be needed.

path_split
path_split :: (path: [] u8) -> ([] u8, [] u8)

Splits the last path element off.

process_destroy
process_destroy :: (p: &Process) -> void

Frees internal resources used by a process. Should be called after process_kill or process_wait.

process_kill
process_kill :: (p: &Process) -> bool

Force kills a subprocess.

process_spawn
process_spawn :: (path: [] u8, args: [] [] u8, non_blocking_io: bool, starting_directory: [] u8) -> Process
process_spawn :: (path: [] u8, args: [] [] u8, opts: &ProcessSpawnOpts) -> Process

Spawns a new OS process. This operation is always assumed to succeed. To determine if the operation failed, use process_wait and look for the FailedToRun state.

process_wait
process_wait :: (p: &Process) -> ProcessResult

Waits for a process to exit.

remove_directory
remove_directory :: (path: [] u8) -> bool
tty_get
tty_get :: () -> TTY_State
tty_raw
tty_raw :: () -> void
tty_sane
tty_sane :: () -> void
tty_set
tty_set :: (state: &TTY_State) -> bool