1// The functions replacing the C macros use the same names as in libc.
2#![allow(non_snake_case, unsafe_code)]
3
4use linux_raw_sys::ctypes::c_int;
5pub(crate) use linux_raw_sys::general::{
6 siginfo_t, WCONTINUED, WEXITED, WNOHANG, WNOWAIT, WSTOPPED, WUNTRACED,
7};
8
9#[inline]
10pub(crate) fn WIFSTOPPED(status: u32) -> bool {
11 (status & 0xff) == 0x7f
12}
13
14#[inline]
15pub(crate) fn WSTOPSIG(status: u32) -> u32 {
16 (status >> 8) & 0xff
17}
18
19#[inline]
20pub(crate) fn WIFCONTINUED(status: u32) -> bool {
21 status == 0xffff
22}
23
24#[inline]
25pub(crate) fn WIFSIGNALED(status: u32) -> bool {
26 ((status & 0x7f) + 1) as i8 >= 2
27}
28
29#[inline]
30pub(crate) fn WTERMSIG(status: u32) -> u32 {
31 status & 0x7f
32}
33
34#[inline]
35pub(crate) fn WIFEXITED(status: u32) -> bool {
36 (status & 0x7f) == 0
37}
38
39#[inline]
40pub(crate) fn WEXITSTATUS(status: u32) -> u32 {
41 (status >> 8) & 0xff
42}
43
44pub(crate) trait SiginfoExt {
45 fn si_code(&self) -> c_int;
46 unsafe fn si_status(&self) -> c_int;
47}
48
49impl SiginfoExt for siginfo_t {
50 #[inline]
51 fn si_code(&self) -> c_int {
52 // SAFETY: This is technically a union access, but it's only a union
53 // with padding.
54 unsafe { self.__bindgen_anon_1.__bindgen_anon_1.si_code }
55 }
56
57 /// Return the exit status or signal number recorded in a `siginfo_t`.
58 ///
59 /// # Safety
60 ///
61 /// `si_signo` must equal `SIGCHLD` (as it is guaranteed to do after a
62 /// `waitid` call).
63 #[inline]
64 #[rustfmt::skip]
65 unsafe fn si_status(&self) -> c_int {
66 self.__bindgen_anon_1.__bindgen_anon_1._sifields._sigchld._status
67 }
68}
69