Module sys/sysinfo

sys/sysinfo
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 `String`s from one call, so the layout stays in the runtime where it belongs. Freezing follows that rewrite, not a release count. — stable modules only change additively; this one may still change.

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

uname function
fn(buf : *u8) -> i32

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

NameTypeNotes
buf*u8

Returns: i32

gethostname function
fn(name : *u8, len : usize) -> 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

NameTypeNotes
name*u8
lenusize

Returns: i32

Constants

UTSNAME_SIZE constant usize

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

UTSNAME_FIELD_SIZE constant usize

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

UTSNAME_SYSNAME constant usize

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

UTSNAME_NODENAME constant usize

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

UTSNAME_RELEASE constant usize

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

UTSNAME_VERSION constant usize

Byte offset of version — the kernel build string. The Windows emulation writes the constant "nt".

Value: 195

UTSNAME_MACHINE constant usize

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