std::process (windows): refactor Stdio::to_handle slightly
We're going to want to reuse this bit of code.
This commit is contained in:
parent
fb7f1a8127
commit
deda7d3301
@ -521,8 +521,7 @@ fn program_exists(path: &Path) -> Option<Vec<u16>> {
|
|||||||
|
|
||||||
impl Stdio {
|
impl Stdio {
|
||||||
fn to_handle(&self, stdio_id: c::DWORD, pipe: &mut Option<AnonPipe>) -> io::Result<Handle> {
|
fn to_handle(&self, stdio_id: c::DWORD, pipe: &mut Option<AnonPipe>) -> io::Result<Handle> {
|
||||||
match *self {
|
let use_stdio_id = |stdio_id| match stdio::get_handle(stdio_id) {
|
||||||
Stdio::Inherit => match stdio::get_handle(stdio_id) {
|
|
||||||
Ok(io) => unsafe {
|
Ok(io) => unsafe {
|
||||||
let io = Handle::from_raw_handle(io);
|
let io = Handle::from_raw_handle(io);
|
||||||
let ret = io.duplicate(0, true, c::DUPLICATE_SAME_ACCESS);
|
let ret = io.duplicate(0, true, c::DUPLICATE_SAME_ACCESS);
|
||||||
@ -531,7 +530,9 @@ fn to_handle(&self, stdio_id: c::DWORD, pipe: &mut Option<AnonPipe>) -> io::Resu
|
|||||||
},
|
},
|
||||||
// If no stdio handle is available, then propagate the null value.
|
// If no stdio handle is available, then propagate the null value.
|
||||||
Err(..) => unsafe { Ok(Handle::from_raw_handle(ptr::null_mut())) },
|
Err(..) => unsafe { Ok(Handle::from_raw_handle(ptr::null_mut())) },
|
||||||
},
|
};
|
||||||
|
match *self {
|
||||||
|
Stdio::Inherit => use_stdio_id(stdio_id),
|
||||||
|
|
||||||
Stdio::MakePipe => {
|
Stdio::MakePipe => {
|
||||||
let ours_readable = stdio_id != c::STD_INPUT_HANDLE;
|
let ours_readable = stdio_id != c::STD_INPUT_HANDLE;
|
||||||
|
Loading…
Reference in New Issue
Block a user