8000 Implement CommandExt::{exec, before_exec} by alexcrichton · Pull Request #31409 · rust-lang/rust · GitHub
[go: up one dir, main page]

Skip to content

Implement CommandExt::{exec, before_exec} #31409

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Feb 11, 2016
Prev Previous commit
Next Next commit
std: Use macros from libc instead of locally
Helps cut down on #[cfg]!
  • Loading branch information
alexcrichton committed Feb 10, 2016
commit efb23db79a5cc16770a7c3d5cef7059d868dea8f
27 changes: 3 additions & 24 deletions src/libstd/sys/unix/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,30 +519,9 @@ impl fmt::Debug for Command {
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
pub struct ExitStatus(c_int);

#[cfg(any(target_os = "linux", target_os = "android",
target_os = "nacl"))]
mod status_imp {
pub fn WIFEXITED(status: i32) -> bool { (status & 0xff) == 0 }
pub fn WEXITSTATUS(status: i32) -> i32 { (status >> 8) & 0xff }
pub fn WTERMSIG(status: i32) -> i32 { status & 0x7f }
}

#[cfg(any(target_os = "macos",
target_os = "ios",
target_os = "freebsd",
target_os = "dragonfly",
target_os = "bitrig",
target_os = "netbsd",
target_os = "openbsd"))]
mod status_imp {
pub fn WIFEXITED(status: i32) -> bool { (status & 0x7f) == 0 }
pub fn WEXITSTATUS(status: i32) -> i32 { status >> 8 }
pub fn WTERMSIG(status: i32) -> i32 { status & 0o177 }
}

impl ExitStatus {
fn exited(&self) -> bool {
status_imp::WIFEXITED(self.0)
unsafe { libc::WIFEXITED(self.0) }
}

pub fn success(&self) -> bool {
Expand All @@ -551,15 +530,15 @@ impl ExitStatus {

pub fn code(&self) -> Option<i32> {
if self.exited() {
Some(status_imp::WEXITSTATUS(self.0))
Some(unsafe { libc::WEXITSTATUS(self.0) })
} else {
None
}
}

pub fn signal(&self) -> Option<i32> {
if !self.exited() {
Some(status_imp::WTERMSIG(self.0))
Some(unsafe { libc::WTERMSIG(self.0) })
} else {
None
}
Expand Down
0