Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/backend/libc/io/errno.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1093,7 +1093,8 @@ impl Errno {
pub fn from_io_error(io_err: &std::io::Error) -> Option<Self> {
io_err
.raw_os_error()
.and_then(|raw| if raw != 0 { Some(Self(raw)) } else { None })
.filter(|&raw| raw != 0)
.map(Self)
}

/// Extract the raw OS error number from this error.
Expand Down
14 changes: 7 additions & 7 deletions src/backend/libc/net/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,13 @@ impl SocketAddrUnix {

#[inline]
fn bytes(&self) -> Option<&[u8]> {
let len = self.len();
if len != 0 {
let bytes = &self.unix.sun_path[..len - offsetof_sun_path()];
// SAFETY: `from_raw_parts` to convert from `&[c_char]` to `&[u8]`.
Some(unsafe { slice::from_raw_parts(bytes.as_ptr().cast(), bytes.len()) })
} else {
None
match self.len() {
0 => None,
len => {
let bytes = &self.unix.sun_path[..len - offsetof_sun_path()];
// SAFETY: `from_raw_parts` to convert from `&[c_char]` to `&[u8]`.
Some(unsafe { slice::from_raw_parts(bytes.as_ptr().cast(), bytes.len()) })
}
}
}
}
Expand Down
7 changes: 2 additions & 5 deletions src/net/socket_addr_any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,8 @@ impl SocketAddrBuf {
#[inline]
pub(crate) unsafe fn into_any_option(self) -> Option<SocketAddrAny> {
let len = bitcast!(self.len);
if read_sockaddr::sockaddr_nonempty(self.storage.as_ptr().cast(), len) {
Some(SocketAddrAny::new(self.storage, len))
} else {
None
}
read_sockaddr::sockaddr_nonempty(self.storage.as_ptr().cast(), len)
.then(|| SocketAddrAny::new(self.storage, len))
}
}

Expand Down
45 changes: 10 additions & 35 deletions src/process/wait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,35 +125,26 @@ impl WaitStatus {
#[inline]
#[doc(alias = "WSTOPSIG")]
pub fn stopping_signal(self) -> Option<i32> {
if self.stopped() {
Some(backend::process::wait::WSTOPSIG(self.0))
} else {
None
}
self.stopped()
.then(|| backend::process::wait::WSTOPSIG(self.0))
}

/// Returns the exit status number returned by the process, if it exited
/// normally.
#[inline]
#[doc(alias = "WEXITSTATUS")]
pub fn exit_status(self) -> Option<i32> {
if self.exited() {
Some(backend::process::wait::WEXITSTATUS(self.0))
} else {
None
}
self.exited()
.then(|| backend::process::wait::WEXITSTATUS(self.0))
}

/// Returns the number of the signal that terminated the process, if the
/// process was terminated by a signal.
#[inline]
#[doc(alias = "WTERMSIG")]
pub fn terminating_signal(self) -> Option<i32> {
if self.signaled() {
Some(backend::process::wait::WTERMSIG(self.0))
} else {
None
}
self.signaled()
.then(|| backend::process::wait::WTERMSIG(self.0))
}
}

Expand Down Expand Up @@ -247,47 +238,31 @@ impl WaitIdStatus {
#[inline]
#[cfg(not(any(target_os = "emscripten", target_os = "fuchsia", target_os = "netbsd")))]
pub fn stopping_signal(&self) -> Option<i32> {
if self.stopped() {
Some(self.si_status())
} else {
None
}
self.stopped().then(|| self.si_status())
}

/// Returns the number of the signal that trapped the process, if the
/// process was trapped by a signal.
#[inline]
#[cfg(not(any(target_os = "emscripten", target_os = "fuchsia", target_os = "netbsd")))]
pub fn trapping_signal(&self) -> Option<i32> {
if self.trapped() {
Some(self.si_status())
} else {
None
}
self.trapped().then(|| self.si_status())
}

/// Returns the exit status number returned by the process, if it exited
/// normally.
#[inline]
#[cfg(not(any(target_os = "emscripten", target_os = "fuchsia", target_os = "netbsd")))]
pub fn exit_status(&self) -> Option<i32> {
if self.exited() {
Some(self.si_status())
} else {
None
}
self.exited().then(|| self.si_status())
}

/// Returns the number of the signal that terminated the process, if the
/// process was terminated by a signal.
#[inline]
#[cfg(not(any(target_os = "emscripten", target_os = "fuchsia", target_os = "netbsd")))]
pub fn terminating_signal(&self) -> Option<i32> {
if self.killed() || self.dumped() {
Some(self.si_status())
} else {
None
}
(self.killed() || self.dumped()).then(|| self.si_status())
}

/// Return the raw `si_signo` value returned from `waitid`.
Expand Down
Loading