]>
Commit | Line | Data |
---|---|---|
fe692bf9 FG |
1 | //! libc syscalls supporting `rustix::process`. |
2 | ||
3 | use super::types::RawUname; | |
4 | use crate::backend::c; | |
5 | #[cfg(not(target_os = "wasi"))] | |
6 | use crate::backend::conv::ret_infallible; | |
7 | #[cfg(linux_kernel)] | |
8 | use crate::system::Sysinfo; | |
9 | use 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 |
16 | use {crate::backend::conv::ret, crate::io}; |
17 | ||
18 | #[cfg(not(target_os = "wasi"))] | |
19 | #[inline] | |
20 | pub(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)] | |
37 | pub(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 |
51 | pub(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 | } |