relibc/header/sys_utsname/mod.rs
1//! `sys/utsname.h` implementation.
2//!
3//! See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/sys_utsname.h.html>.
4
5use crate::{
6 error::ResultExt,
7 out::Out,
8 platform::{
9 Pal, Sys,
10 types::{c_char, c_int},
11 },
12};
13
14/// Non-POSIX.
15///
16/// Length of each character array in `utsname`.
17pub const UTSLENGTH: usize = 65;
18
19/// See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/sys_utsname.h.html>.
20#[repr(C)]
21#[derive(Clone, Debug, OutProject)]
22pub struct utsname {
23 /// Name of this implementation of the operating system.
24 pub sysname: [c_char; UTSLENGTH],
25 /// Name of this node within the communications network to which this node
26 /// is attached, if any.
27 pub nodename: [c_char; UTSLENGTH],
28 /// Current release level of this implementation.
29 pub release: [c_char; UTSLENGTH],
30 /// Current version level of this release.
31 pub version: [c_char; UTSLENGTH],
32 /// Name of the hardware type on which this system is running.
33 pub machine: [c_char; UTSLENGTH],
34 /// Non-POSIX.
35 pub domainname: [c_char; UTSLENGTH],
36}
37
38/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/uname.html>.
39///
40/// Stores information identifying the current system in the structure pointed
41/// to by `name`.
42///
43/// Returns a non-negative value upon success, `-1` upon failure.
44#[unsafe(no_mangle)]
45pub unsafe extern "C" fn uname(name: *mut utsname) -> c_int {
46 Sys::uname(unsafe { Out::nonnull(name) })
47 .map(|()| 0)
48 .or_minus_one_errno()
49}