1 // The functions replacing the C macros use the same names as in libc. 2 #![allow(non_snake_case, unsafe_code)] 3 4 use linux_raw_sys::ctypes::c_int; 5 pub(crate) use linux_raw_sys::general::{ 6 siginfo_t, WCONTINUED, WEXITED, WNOHANG, WNOWAIT, WSTOPPED, WUNTRACED, 7 }; 8 9 #[inline] WIFSTOPPED(status: u32) -> bool10pub(crate) fn WIFSTOPPED(status: u32) -> bool { 11 (status & 0xff) == 0x7f 12 } 13 14 #[inline] WSTOPSIG(status: u32) -> u3215pub(crate) fn WSTOPSIG(status: u32) -> u32 { 16 (status >> 8) & 0xff 17 } 18 19 #[inline] WIFCONTINUED(status: u32) -> bool20pub(crate) fn WIFCONTINUED(status: u32) -> bool { 21 status == 0xffff 22 } 23 24 #[inline] WIFSIGNALED(status: u32) -> bool25pub(crate) fn WIFSIGNALED(status: u32) -> bool { 26 ((status & 0x7f) + 1) as i8 >= 2 27 } 28 29 #[inline] WTERMSIG(status: u32) -> u3230pub(crate) fn WTERMSIG(status: u32) -> u32 { 31 status & 0x7f 32 } 33 34 #[inline] WIFEXITED(status: u32) -> bool35pub(crate) fn WIFEXITED(status: u32) -> bool { 36 (status & 0x7f) == 0 37 } 38 39 #[inline] WEXITSTATUS(status: u32) -> u3240pub(crate) fn WEXITSTATUS(status: u32) -> u32 { 41 (status >> 8) & 0xff 42 } 43 44 pub(crate) trait SiginfoExt { si_code(&self) -> c_int45 fn si_code(&self) -> c_int; si_status(&self) -> c_int46 unsafe fn si_status(&self) -> c_int; 47 } 48 49 impl SiginfoExt for siginfo_t { 50 #[inline] si_code(&self) -> c_int51 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] si_status(&self) -> c_int65 unsafe fn si_status(&self) -> c_int { 66 self.__bindgen_anon_1.__bindgen_anon_1._sifields._sigchld._status 67 } 68 } 69