about summary refs log tree commit diff
path: root/library/std/src/sys/anonymous_pipe/windows.rs
blob: bdda7ffc5d2515d3c4bb64cf52d2eb2d5e03a456 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
use crate::os::windows::io::FromRawHandle;
use crate::sys::c;
use crate::sys::handle::Handle;
use crate::{io, ptr};

pub type AnonPipe = Handle;

pub fn pipe() -> io::Result<(AnonPipe, AnonPipe)> {
    let mut read_pipe = c::INVALID_HANDLE_VALUE;
    let mut write_pipe = c::INVALID_HANDLE_VALUE;

    let ret = unsafe { c::CreatePipe(&mut read_pipe, &mut write_pipe, ptr::null_mut(), 0) };

    if ret == 0 {
        Err(io::Error::last_os_error())
    } else {
        unsafe { Ok((Handle::from_raw_handle(read_pipe), Handle::from_raw_handle(write_pipe))) }
    }
}