Module sys/sysinfo
System identification (uname/gethostname) — the raw syscall boundary.
uname(2) writes into a struct utsname whose FIELD LAYOUT differs per
platform, so this module exports the offsets and sizes a caller needs to
read it back — that is the only reason it is more than two functions. No
public std module reads it (std/process's platform is a compile-time
constant, not a runtime query); tests/sys/sysinfo.test.yo is the only
caller in this tree.
Stability
unstable — it hands the caller a raw C struct and a table of byte offsets
into it, which is a layout contract, not an API. Every one of these
constants is a cond on the platform, and adding a target means adding a
branch here AND auditing every call site's arithmetic. A frozen version
returns a Yo struct of Strings from one call, so the layout stays in the
runtime where it belongs. Freezing follows that rewrite, not a release
count.
Functions
Fill buf (allocate UTSNAME_SIZE bytes) with system identification
strings — POSIX uname(2). Returns 0 on success, a negative errno on
failure. Read a field with the UTSNAME_* offset constants above; each is
a NUL-terminated C string.
Windows has no uname; the runtime SYNTHESIZES the struct as described on
the offset constants, so the call always succeeds there but three of the
five fields are constants rather than measurements.
Parameters
| Name | Type | Notes |
|---|---|---|
buf | *u8 |
Returns: i32
Write the host name into name, at most len bytes — POSIX
gethostname(2). Returns 0 on success, a negative errno on failure (a
negated WSA code on Windows).
The wrapper always writes a NUL at name[len - 1], so a name longer than
the buffer is silently TRUNCATED rather than reported as -ENAMETOOLONG.
Size the buffer generously (_POSIX_HOST_NAME_MAX is 255) if the exact
name matters.
Parameters
| Name | Type | Notes |
|---|---|---|
name | *u8 | |
len | usize |
Returns: i32
Constants
Total bytes to allocate for the uname buffer. Larger than five fields on
Linux because glibc's struct carries a sixth (domainname) that this
module does not expose: 65 × 6 = 390, against 256 × 5 = 1280 on macOS and
Windows. Allocate exactly this and pass it to uname.
Value: 390
Size of ONE struct utsname field, which is where the platforms diverge:
glibc's _UTSNAME_LENGTH is 65, while macOS uses 256 and the Windows
emulation copies the macOS shape. Every offset below is a multiple of it.
Value: 65
Byte offset of sysname — the OS name ("Linux", "Darwin", and the
literal "Windows" the emulation writes). Each field is a NUL-terminated
C string within its UTSNAME_FIELD_SIZE slot.
Value: 0
Byte offset of nodename — the host name, the same value gethostname
returns. The Windows emulation fills it from gethostname and falls back
to "localhost" if that fails.
Value: 65
Byte offset of release — the kernel release ("6.8.0-40-generic",
"23.5.0"). The Windows emulation writes the constant "win32", not a
Windows version, so do not parse it for one.
Value: 130
Byte offset of version — the kernel build string. The Windows emulation
writes the constant "nt".
Value: 195
Byte offset of machine — the hardware name. This is the one field the
Windows emulation computes: GetNativeSystemInfo mapped to "x86_64",
"aarch64", "x86", "arm" or "unknown", chosen to match what Linux
and macOS report so a caller can compare the strings.
Value: 260