diff options
Diffstat (limited to 'src/libstd/sys/vxworks/process/process_common.rs')
| -rw-r--r-- | src/libstd/sys/vxworks/process/process_common.rs | 58 |
1 files changed, 21 insertions, 37 deletions
diff --git a/src/libstd/sys/vxworks/process/process_common.rs b/src/libstd/sys/vxworks/process/process_common.rs index 13648abd1e4..a8139a27537 100644 --- a/src/libstd/sys/vxworks/process/process_common.rs +++ b/src/libstd/sys/vxworks/process/process_common.rs @@ -1,6 +1,7 @@ use crate::os::unix::prelude::*; -use crate::ffi::{OsString, OsStr, CString, CStr}; +use crate::collections::BTreeMap; +use crate::ffi::{CStr, CString, OsStr, OsString}; use crate::fmt; use crate::io; use crate::ptr; @@ -8,9 +9,8 @@ use crate::sys::fd::FileDesc; use crate::sys::fs::{File, OpenOptions}; use crate::sys::pipe::{self, AnonPipe}; use crate::sys_common::process::CommandEnv; -use crate::collections::BTreeMap; -use libc::{c_int, gid_t, uid_t, c_char, EXIT_SUCCESS, EXIT_FAILURE}; +use libc::{c_char, c_int, gid_t, uid_t, EXIT_FAILURE, EXIT_SUCCESS}; //////////////////////////////////////////////////////////////////////////////// // Command @@ -150,10 +150,7 @@ impl Command { &mut self.closures } - pub unsafe fn pre_exec( - &mut self, - _f: Box<dyn FnMut() -> io::Result<()> + Send + Sync>, - ) { + pub unsafe fn pre_exec(&mut self, _f: Box<dyn FnMut() -> io::Result<()> + Send + Sync>) { // Fork() is not supported in vxWorks so no way to run the closure in the new procecss. unimplemented!(); } @@ -183,26 +180,21 @@ impl Command { self.env.have_changed_path() } - pub fn setup_io(&self, default: Stdio, needs_stdin: bool) - -> io::Result<(StdioPipes, ChildPipes)> { + pub fn setup_io( + &self, + default: Stdio, + needs_stdin: bool, + ) -> io::Result<(StdioPipes, ChildPipes)> { let null = Stdio::Null; - let default_stdin = if needs_stdin {&default} else {&null}; + let default_stdin = if needs_stdin { &default } else { &null }; let stdin = self.stdin.as_ref().unwrap_or(default_stdin); let stdout = self.stdout.as_ref().unwrap_or(&default); let stderr = self.stderr.as_ref().unwrap_or(&default); let (their_stdin, our_stdin) = stdin.to_child_stdio(true)?; let (their_stdout, our_stdout) = stdout.to_child_stdio(false)?; let (their_stderr, our_stderr) = stderr.to_child_stdio(false)?; - let ours = StdioPipes { - stdin: our_stdin, - stdout: our_stdout, - stderr: our_stderr, - }; - let theirs = ChildPipes { - stdin: their_stdin, - stdout: their_stdout, - stderr: their_stderr, - }; + let ours = StdioPipes { stdin: our_stdin, stdout: our_stdout, stderr: our_stderr }; + let theirs = ChildPipes { stdin: their_stdin, stdout: their_stdout, stderr: their_stderr }; Ok((ours, theirs)) } } @@ -217,21 +209,21 @@ fn os2c(s: &OsStr, saw_nul: &mut bool) -> CString { // Helper type to manage ownership of the strings within a C-style array. pub struct CStringArray { items: Vec<CString>, - ptrs: Vec<*const c_char> + ptrs: Vec<*const c_char>, } impl CStringArray { pub fn with_capacity(capacity: usize) -> Self { let mut result = CStringArray { items: Vec::with_capacity(capacity), - ptrs: Vec::with_capacity(capacity+1) + ptrs: Vec::with_capacity(capacity + 1), }; result.ptrs.push(ptr::null()); result } pub fn push(&mut self, item: CString) { let l = self.ptrs.len(); - self.ptrs[l-1] = item.as_ptr(); + self.ptrs[l - 1] = item.as_ptr(); self.ptrs.push(ptr::null()); self.items.push(item); } @@ -262,12 +254,9 @@ fn construct_envp(env: BTreeMap<OsString, OsString>, saw_nul: &mut bool) -> CStr } impl Stdio { - pub fn to_child_stdio(&self, readable: bool) - -> io::Result<(ChildStdio, Option<AnonPipe>)> { + pub fn to_child_stdio(&self, readable: bool) -> io::Result<(ChildStdio, Option<AnonPipe>)> { match *self { - Stdio::Inherit => { - Ok((ChildStdio::Inherit, None)) - }, + Stdio::Inherit => Ok((ChildStdio::Inherit, None)), // Make sure that the source descriptors are not an stdio // descriptor, otherwise the order which we set the child's @@ -286,11 +275,7 @@ impl Stdio { Stdio::MakePipe => { let (reader, writer) = pipe::anon_pipe()?; - let (ours, theirs) = if readable { - (writer, reader) - } else { - (reader, writer) - }; + let (ours, theirs) = if readable { (writer, reader) } else { (reader, writer) }; Ok((ChildStdio::Owned(theirs.into_fd()), Some(ours))) } @@ -298,9 +283,7 @@ impl Stdio { let mut opts = OpenOptions::new(); opts.read(readable); opts.write(!readable); - let path = unsafe { - CStr::from_ptr("/null\0".as_ptr() as *const _) - }; + let path = unsafe { CStr::from_ptr("/null\0".as_ptr() as *const _) }; let fd = File::open_c(&path, &opts)?; Ok((ChildStdio::Owned(fd.into_fd()), None)) } @@ -350,7 +333,8 @@ impl ExitStatus { } fn exited(&self) -> bool { - /*unsafe*/ { libc::WIFEXITED(self.0) } + /*unsafe*/ + { libc::WIFEXITED(self.0) } } pub fn success(&self) -> bool { |
