package core.os
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.
Command.args :: (cmd: &Command, args: [] [] u8) -> &Command
Appends arguments to the argument array of the command.
Command.destroy :: (cmd: &Command) -> void
Destroys all internal information of a command. Automatically called by Command.wait
.
Command.dir :: (cmd: &Command, dir: [] u8) -> &Command
Sets the working directory of the command.
Command.env :: (cmd: &Command, key: [] u8, value: [] u8) -> &Command
Sets an environment variable.
Command.output :: (cmd: &Command) -> Result([] u8, ProcessResultOutput)
Runs the command, wait until it completes, and capture output.
Command.run :: (cmd: &Command) -> ProcessResult
Runs the command and waits until it completes.
Command.start_with_output :: (cmd: &Command) -> &Command
Starts the command with the mapped I/O.
DirectoryEntry :: struct {
type: FileType;
identifier: u32;
name_length: u32;
name_data: [256] u8;
}
FileStat :: struct {
size: i64;
type: FileType;
change_time: u64;
accessed_time: u64;
modified_time: u64;
}
File_Logger :: struct {
file: &File;
filename: [] u8;
allocator: Allocator;
old_logger: Logger;
}
Process :: struct {
stream: Stream;
process_handle: ProcessData;
}
Represents a spawned OS process.
ProcessResultOutput :: struct {
result: ProcessResult;
output: [] u8;
}
Represents the exit state and output of a process.
ProcessSpawnOpts :: struct {
capture_io: bool;
non_blocking_io: bool;
detach: bool;
dir: [] u8;
environment: [] Pair([] u8, [] u8);
}
Represents options for process creation.
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 :: enum {
None :: 0;
NotFound :: 1;
Exists :: 2;
Permission :: 3;
BadFile :: 4;
BadMode :: 5;
}
FileType :: enum {
Unknown :: 0;
Block :: 1;
Char :: 2;
Directory :: 3;
RegularFile :: 4;
SymLink :: 5;
Other :: 6;
}
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.
command :: () -> &Command
Produces a new Command
for the process builder.
os.command()
->path("executable_path")
->args(.["argument", "list"])
->run();
file_logger_open :: (filename: [] u8, allocator: Allocator) -> Result(&File_Logger, [] u8)
file_logger_proc :: (logger: &File_Logger, level: Log_Level, msg: [] u8, module: [] u8) -> void
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: [] 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: [] u8) -> [] u8
Returns everything but the last element in the path.
This is then cleaned and copied into the temporary allocator.
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: ..[] u8) -> [] u8
Concatenates path elements, and returns cleaned output.
This uses the temporary allocator, so a copy may be needed.
process_destroy :: (p: &Process) -> void
Frees internal resources used by a process. Should be called after process_kill or process_wait.
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.