diff options
author | Alan Somers <asomers@gmail.com> | 2021-08-09 13:28:43 -0600 |
---|---|---|
committer | Alan Somers <asomers@gmail.com> | 2021-08-09 18:51:49 -0600 |
commit | 9df5abfab1f315d87bdacf226380d532318e9bfb (patch) | |
tree | 3a14bbb4ea859a6e46c548d3094a880b7390db96 /src/sys/signal.rs | |
parent | 68488a4508f7957b88b4ccf52886ddc5fc75b6d7 (diff) | |
download | nix-9df5abfab1f315d87bdacf226380d532318e9bfb.zip |
Optionally implement TryFrom in libc_enum!
This saves code in several separate places that need to do this
separately. At the same time, remove a few uses of mem::transmute that
were implementing TryFrom or similar functionality.
Issue #373
Diffstat (limited to 'src/sys/signal.rs')
-rw-r--r-- | src/sys/signal.rs | 18 |
1 files changed, 3 insertions, 15 deletions
diff --git a/src/sys/signal.rs b/src/sys/signal.rs index 0911cfaa..8698d14f 100644 --- a/src/sys/signal.rs +++ b/src/sys/signal.rs @@ -6,7 +6,6 @@ use crate::{Error, Result}; use crate::errno::Errno; use crate::unistd::Pid; -use std::convert::TryFrom; use std::mem; use std::fmt; use std::str::FromStr; @@ -71,6 +70,7 @@ libc_enum!{ target_os = "redox")))] SIGINFO, } + impl TryFrom<i32> } impl FromStr for Signal { @@ -335,8 +335,6 @@ const SIGNALS: [Signal; 31] = [ SIGEMT, SIGINFO]; -pub const NSIG: libc::c_int = 32; - #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] pub struct SignalIterator { next: usize, @@ -362,18 +360,6 @@ impl Signal { } } -impl TryFrom<libc::c_int> for Signal { - type Error = Error; - - fn try_from(signum: libc::c_int) -> Result<Signal> { - if 0 < signum && signum < NSIG { - Ok(unsafe { mem::transmute(signum) }) - } else { - Err(Error::from(Errno::EINVAL)) - } - } -} - pub const SIGIOT : Signal = SIGABRT; pub const SIGPOLL : Signal = SIGIO; pub const SIGUNUSED : Signal = SIGSYS; @@ -489,6 +475,8 @@ impl SigSet { /// signal mask becomes pending, and returns the accepted signal. #[cfg(not(target_os = "redox"))] // RedoxFS does not yet support sigwait pub fn wait(&self) -> Result<Signal> { + use std::convert::TryFrom; + let mut signum = mem::MaybeUninit::uninit(); let res = unsafe { libc::sigwait(&self.sigset as *const libc::sigset_t, signum.as_mut_ptr()) }; |