]> git.proxmox.com Git - rustc.git/blame - vendor/rustix/src/backend/libc/system/syscalls.rs
New upstream version 1.74.1+dfsg1
[rustc.git] / vendor / rustix / src / backend / libc / system / syscalls.rs
CommitLineData
fe692bf9
FG
1//! libc syscalls supporting `rustix::process`.
2
3use super::types::RawUname;
4use crate::backend::c;
5#[cfg(not(target_os = "wasi"))]
6use crate::backend::conv::ret_infallible;
7#[cfg(linux_kernel)]
8use crate::system::Sysinfo;
9use core::mem::MaybeUninit;
add651ee
FG
10#[cfg(not(any(
11 target_os = "emscripten",
12 target_os = "espidf",
13 target_os = "redox",
14 target_os = "wasi"
15)))]
fe692bf9
FG
16use {crate::backend::conv::ret, crate::io};
17
18#[cfg(not(target_os = "wasi"))]
19#[inline]
20pub(crate) fn uname() -> RawUname {
21 let mut uname = MaybeUninit::<RawUname>::uninit();
22 unsafe {
add651ee
FG
23 let r = c::uname(uname.as_mut_ptr());
24
25 // On POSIX, `uname` is documented to return non-negative on success
26 // instead of the usual 0, though some specific systems do document
27 // that they always use zero allowing us to skip this check.
28 #[cfg(not(any(apple, freebsdlike, linux_like, target_os = "netbsd")))]
29 let r = core::cmp::min(r, 0);
30
31 ret_infallible(r);
fe692bf9
FG
32 uname.assume_init()
33 }
34}
35
36#[cfg(linux_kernel)]
37pub(crate) fn sysinfo() -> Sysinfo {
38 let mut info = MaybeUninit::<Sysinfo>::uninit();
39 unsafe {
40 ret_infallible(c::sysinfo(info.as_mut_ptr()));
41 info.assume_init()
42 }
43}
44
add651ee
FG
45#[cfg(not(any(
46 target_os = "emscripten",
47 target_os = "espidf",
48 target_os = "redox",
49 target_os = "wasi"
50)))]
fe692bf9
FG
51pub(crate) fn sethostname(name: &[u8]) -> io::Result<()> {
52 unsafe {
53 ret(c::sethostname(
54 name.as_ptr().cast(),
55 name.len().try_into().map_err(|_| io::Errno::INVAL)?,
56 ))
57 }
58}