Skip to content

Commit

Permalink
Switch from winapi to windows-sys
Browse files Browse the repository at this point in the history
  • Loading branch information
messense authored and oconnor663 committed Nov 25, 2022
1 parent 4950ad9 commit 3bacd8a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -14,7 +14,7 @@ edition = "2018"
libc = "0.2.62"

[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3.5", features = ["handleapi", "namedpipeapi", "processthreadsapi", "winnt"] }
windows-sys = { version = "0.42.0", features = ["Win32_Foundation", "Win32_System_Pipes", "Win32_Security", "Win32_System_Threading"] }

[features]
# Uses I/O safety features introduced in Rust 1.63
Expand Down
22 changes: 8 additions & 14 deletions src/windows.rs
Expand Up @@ -4,26 +4,20 @@ use std::fs::File;
use std::io;
use std::os::windows::prelude::*;
use std::ptr;
use winapi::shared::minwindef::BOOL;
use winapi::shared::ntdef::{HANDLE, PHANDLE};
use winapi::um::handleapi::DuplicateHandle;
use winapi::um::namedpipeapi;
use winapi::um::processthreadsapi::GetCurrentProcess;
use winapi::um::winnt::DUPLICATE_SAME_ACCESS;
use windows_sys::Win32::Foundation::{
DuplicateHandle, BOOL, DUPLICATE_SAME_ACCESS, HANDLE, INVALID_HANDLE_VALUE,
};
use windows_sys::Win32::System::Pipes::CreatePipe;
use windows_sys::Win32::System::Threading::GetCurrentProcess;

pub(crate) fn pipe() -> io::Result<(PipeReader, PipeWriter)> {
let mut read_pipe: HANDLE = ptr::null_mut();
let mut write_pipe: HANDLE = ptr::null_mut();
let mut read_pipe = INVALID_HANDLE_VALUE;
let mut write_pipe = INVALID_HANDLE_VALUE;

let ret = unsafe {
// NOTE: These pipes do not support IOCP. We might want to emulate
// anonymous pipes with CreateNamedPipe, as Rust's stdlib does.
namedpipeapi::CreatePipe(
&mut read_pipe as PHANDLE,
&mut write_pipe as PHANDLE,
ptr::null_mut(),
0,
)
CreatePipe(&mut read_pipe, &mut write_pipe, ptr::null_mut(), 0)
};

if ret == 0 {
Expand Down

0 comments on commit 3bacd8a

Please sign in to comment.