std/sys/env
std/env — OS-standard directory lookups, in pure Axle.
Distinct from std/process::env* (which queries the inherited env
block by name). These are conventional locations the user's shell
has agreed on: home, temp, config. Each returns "" if the
platform can't determine the path so callers don't have to catch.
Every lookup here is a read of the inherited environment plus a
string join, so all of it is Axle. The one thing that diverges per
OS is which variables carry the convention, and that is a value —match target::os, whose arms all typecheck everywhere — rather
than a declaration that exists on one target only.
A variable set to the empty string counts as unset throughout:
it names no directory, so it must not shadow the fallback behind it.
A value is never cut: std/process::getEnv grows its buffer until the
value fits, because a cut path names a different directory and would be
acted on.
Cost: one environment lookup per variable consulted, plus the buffergetEnv reads it into, and nothing is cached — a program that reads a
directory in a loop should hold the answer itself. None of the five
results carries a trailing separator.
Free functions
| Type | Method and description |
|---|---|
| __envValue(name : string) : string The value of name, or "" when it is unset, empty, or unreadable.The three collapse on purpose: each leaves the caller with no directory, and std/env has no error to carry the difference in.std/process::hasEnv is the surface that tells "set to empty" from"absent". |
| __envEither(first : string, second : string) : string The value of the first of two variables that is set to something non-empty, "" when neither is. |
| __join(base : string, tail : string) : string base and tail joined by the host's separator, or "" when baseis empty — a relative tail is not a directory the caller can use, and "" is what every lookup here answers for "the host does not say".A concatenation rather than Path::join: Path emits / on outputwhatever it was given, and these lookups answer in the host's own spelling, which is what a caller hands back to the OS. The separator itself is std::sys::fileSeparator, not a second copy of the samefact. |
| homeDir() : string The current user's home directory; "" if undeterminable. |
| __windowsHome() : string %USERPROFILE%, else %HOMEDRIVE%%HOMEPATH% — the split spelling NTstill populates when the joined one is absent. Neither half names a directory on its own, so both must be present for the fallback to answer. |
| tempDir() : string The system temporary directory; "" if undeterminable.On Windows this is the environment order GetTempPathW itselfconsults, minus its last resort of the Windows directory — which an ordinary user cannot write to, so it would be a worse answer than none. Unlike that entry point, the result carries no trailing separator. |
| __windowsTempDir() : string %TMP%, then %TEMP%, then %USERPROFILE%. |
| __unixTempDir() : string $TMPDIR, then the location every unix guarantees. |
| configDir() : string Per-user config directory (%APPDATA% / $XDG_CONFIG_HOME / ~/Library/Application Support); "" if undeterminable. |
| cacheDir() : string Per-user cache directory following the host convention; "" if undeterminable. |
| dataDir() : string Per-user data directory following the host convention; "" if undeterminable. |
| __xdgDir(variable : string, fallback : string) : string The XDG variable when it names something, the conventional path under$HOME otherwise. |
| currentExe() : string Absolute path to the currently-running executable. ThrowsIOException when the platform can't resolve it (unlike thedirectory lookups above, this has no meaningful default). The four refusals are kept apart here — std/sysinfo::exePath foldsthem onto "" — because this surface throws and so has somewhere tocarry the reason. Two of the four are actionable, and a caller told only "it failed" cannot tell which it is looking at. |
Method detail
#__envValue
The value of name, or "" when it is unset, empty, or unreadable.
The three collapse on purpose: each leaves the caller with no
directory, and std/env has no error to carry the difference in.std/process::hasEnv is the surface that tells "set to empty" from
"absent".
name environment variable to read#__envEither
The value of the first of two variables that is set to something
non-empty, "" when neither is.
first variable consulted firstsecond variable consulted when first names nothing#__join
base and tail joined by the host's separator, or "" when base
is empty — a relative tail is not a directory the caller can use, and"" is what every lookup here answers for "the host does not say".
A concatenation rather than Path::join: Path emits / on output
whatever it was given, and these lookups answer in the host's own
spelling, which is what a caller hands back to the OS. The separator
itself is std::sys::fileSeparator, not a second copy of the same
fact.
base directory the join starts fromtail path appended below it, already separator-joined#homeDir
The current user's home directory; "" if undeterminable.
#__windowsHome
%USERPROFILE%, else %HOMEDRIVE%%HOMEPATH% — the split spelling NT
still populates when the joined one is absent. Neither half names a
directory on its own, so both must be present for the fallback to
answer.
#tempDir
The system temporary directory; "" if undeterminable.
On Windows this is the environment order GetTempPathW itself
consults, minus its last resort of the Windows directory — which an
ordinary user cannot write to, so it would be a worse answer than
none. Unlike that entry point, the result carries no trailing
separator.
#__windowsTempDir
%TMP%, then %TEMP%, then %USERPROFILE%.
#__unixTempDir
$TMPDIR, then the location every unix guarantees.
#configDir
Per-user config directory (%APPDATA% / $XDG_CONFIG_HOME / ~/Library/Application Support); "" if undeterminable.
#cacheDir
Per-user cache directory following the host convention; "" if undeterminable.
#dataDir
Per-user data directory following the host convention; "" if undeterminable.
#__xdgDir
The XDG variable when it names something, the conventional path under$HOME otherwise.
variable XDG environment variable carrying the overridefallback path below $HOME the spec defaults to#currentExe
Absolute path to the currently-running executable. ThrowsIOException when the platform can't resolve it (unlike the
directory lookups above, this has no meaningful default).
The four refusals are kept apart here — std/sysinfo::exePath folds
them onto "" — because this surface throws and so has somewhere to
carry the reason. Two of the four are actionable, and a caller told
only "it failed" cannot tell which it is looking at.