std/ffi/runtime
Intrinsics provided by libaxle_runtime (not libc). Declared once
here and shared across the stdlib by use std::ffi::runtime::…, so
the @link(symbol = …) bindings to runtime symbols live in a single place
rather than being re-declared inline in every module.
Free functions
| Type | Method and description |
|---|---|
| panicMsg(msg : string) : void Abort the process with msg, never returning. Used on unrecoverablepaths that are not throws (e.g. an allocation failure inside amutating method), where dereferencing a NULL buffer would be worse than a clean, described abort. |
| pathKind(path : string) : i32 What exists at path: 0 = nothing, 1 = regular file, 2 = directory.Symlinks are followed; query failures report 0. |
| pathMtimeMs(path : string) : i64 Last-modification time of path in milliseconds since the Unixepoch, or -1 when the path cannot be stat-ed. |
| pathMkdir(path : string) : i32 Create the directory at path (parent must exist). 0 on success. |
| pathMkdirs(path : string) : i32 Create the directory at path and every missing ancestor. 0 on success. |
| pathRemoveRecursive(path : string) : i32 Remove path — recursively for a directory, as a single fileotherwise. 0 on success (missing path is a failure). |
| getCwd(buf : ptr, cap : i64) : i64 Write the current working directory into buf (at most capbytes, no NUL). Returns the byte length written, or one of the negative codes below. |
| getExePath(buf : ptr, cap : i64) : i64 Write the running executable's path into buf (at most capbytes, no NUL). Returns the byte length written, or one of the negative codes below. |
| setCwd(path : string) : i32 Move this process's working directory to path. 0 on success,non-zero when the platform refused it. A runtime seam and not libc's chdir / _chdir, for the reason theenvironment has one: the narrow entry point renders its argument through the process code page on Windows, so a directory whose name carries anything outside it addresses the wrong path or none. |
| fileOpen(path : string, mode : i32) : ptr Open path and return its FILE* stream, or NULL when theplatform refused it — the same report fopen makes, so a callerreads one contract. A runtime seam and not libc's fopen, for the reason setCwd isone: the narrow entry point renders its argument through the process code page on Windows, so a file whose name carries anything outside it cannot be opened at all — while Path::existson that same name answered true, because it already camethrough here. |
| envGet(name : string, buf : ptr, cap : i64) : i64 Write the value of name into buf (at most cap bytes, no NUL).Returns the byte length written, or one of the negative codes below. |
| envIsSet(name : string) : i32 1 when name is set — including when its value is the empty string,and including a value envGet would decline to render. 0 otherwise. |
| envSet(name : string, value : string) : i32 Set name to value. 0 on success, otherwise one of the writecodes below. |
| envUnset(name : string) : i32 Remove name. 0 on success, including when it was never set — thepostcondition is "not set", and it already held. |
| argCount() : i32 How many arguments this process was started with, the program name at index 0 included. 0 when the platform will not say. |
| argAtInto(index : i32, buf : ptr, cap : i64) : i64 Write the argument at index into buf (at most cap bytes, noNUL). Returns the byte length written, or one of the codes below. |
Method detail
#panicMsg
Abort the process with msg, never returning. Used on unrecoverable
paths that are not throws (e.g. an allocation failure inside a
mutating method), where dereferencing a NULL buffer would be worse
than a clean, described abort.
#pathKind
What exists at path: 0 = nothing, 1 = regular file, 2 = directory.
Symlinks are followed; query failures report 0.
#pathMtimeMs
Last-modification time of path in milliseconds since the Unix
epoch, or -1 when the path cannot be stat-ed.
#pathMkdir
Create the directory at path (parent must exist). 0 on success.
#pathMkdirs
Create the directory at path and every missing ancestor. 0 on success.
#pathRemoveRecursive
Remove path — recursively for a directory, as a single file
otherwise. 0 on success (missing path is a failure).
#getCwd
Write the current working directory into buf (at most cap
bytes, no NUL). Returns the byte length written, or one of the
negative codes below.
#getExePath
Write the running executable's path into buf (at most cap
bytes, no NUL). Returns the byte length written, or one of the
negative codes below.
#setCwd
Move this process's working directory to path. 0 on success,
non-zero when the platform refused it.
A runtime seam and not libc's chdir / _chdir, for the reason the
environment has one: the narrow entry point renders its argument
through the process code page on Windows, so a directory whose name
carries anything outside it addresses the wrong path or none.
#fileOpen
Open path and return its FILE* stream, or NULL when the
platform refused it — the same report fopen makes, so a caller
reads one contract.
A runtime seam and not libc's fopen, for the reason setCwd is
one: the narrow entry point renders its argument through the
process code page on Windows, so a file whose name carries
anything outside it cannot be opened at all — while Path::exists
on that same name answered true, because it already came
through here.
mode one of OPEN_READ / OPEN_WRITE / OPEN_APPEND;every one of them opens in binary form. A value that
is none of the three opens nothing.
#envGet
Write the value of name into buf (at most cap bytes, no NUL).
Returns the byte length written, or one of the negative codes below.
#envIsSet
1 when name is set — including when its value is the empty string,
and including a value envGet would decline to render. 0 otherwise.
#envSet
Set name to value. 0 on success, otherwise one of the write
codes below.
#envUnset
Remove name. 0 on success, including when it was never set — the
postcondition is "not set", and it already held.
#argCount
How many arguments this process was started with, the program name
at index 0 included. 0 when the platform will not say.
#argAtInto
Write the argument at index into buf (at most cap bytes, no
NUL). Returns the byte length written, or one of the codes below.