Skip to content

Commit deda7d3

Browse files
committed
std::process (windows): refactor Stdio::to_handle slightly
We're going to want to reuse this bit of code.
1 parent fb7f1a8 commit deda7d3

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

library/std/src/sys/windows/process.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -521,17 +521,18 @@ fn program_exists(path: &Path) -> Option<Vec<u16>> {
521521

522522
impl Stdio {
523523
fn to_handle(&self, stdio_id: c::DWORD, pipe: &mut Option<AnonPipe>) -> io::Result<Handle> {
524-
match *self {
525-
Stdio::Inherit => match stdio::get_handle(stdio_id) {
526-
Ok(io) => unsafe {
527-
let io = Handle::from_raw_handle(io);
528-
let ret = io.duplicate(0, true, c::DUPLICATE_SAME_ACCESS);
529-
io.into_raw_handle();
530-
ret
531-
},
532-
// If no stdio handle is available, then propagate the null value.
533-
Err(..) => unsafe { Ok(Handle::from_raw_handle(ptr::null_mut())) },
524+
let use_stdio_id = |stdio_id| match stdio::get_handle(stdio_id) {
525+
Ok(io) => unsafe {
526+
let io = Handle::from_raw_handle(io);
527+
let ret = io.duplicate(0, true, c::DUPLICATE_SAME_ACCESS);
528+
io.into_raw_handle();
529+
ret
534530
},
531+
// If no stdio handle is available, then propagate the null value.
532+
Err(..) => unsafe { Ok(Handle::from_raw_handle(ptr::null_mut())) },
533+
};
534+
match *self {
535+
Stdio::Inherit => use_stdio_id(stdio_id),
535536

536537
Stdio::MakePipe => {
537538
let ours_readable = stdio_id != c::STD_INPUT_HANDLE;

0 commit comments

Comments
 (0)