From 05a0389555ab44a2fee13c90395bc05960d388e5 Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Sat, 25 Aug 2018 00:25:45 -0400 Subject: [PATCH] ripgrep: use winapi-util for stdin_is_readable --- Cargo.lock | 2 +- Cargo.toml | 5 ++--- src/args.rs | 16 ++++------------ src/main.rs | 2 +- 4 files changed, 8 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index dcb7edbc..a85cc673 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -478,7 +478,7 @@ dependencies = [ "serde_derive 1.0.75 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)", "termcolor 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 092f86d2..3ff769c6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -61,9 +61,8 @@ version = "2.32.0" default-features = false features = ["suggestions"] -[target.'cfg(windows)'.dependencies.winapi] -version = "0.3" -features = ["std", "fileapi", "winnt"] +[target.'cfg(windows)'.dependencies.winapi-util] +version = "0.1.1" [build-dependencies] lazy_static = "1" diff --git a/src/args.rs b/src/args.rs index 20e67b67..2343102e 100644 --- a/src/args.rs +++ b/src/args.rs @@ -1517,17 +1517,9 @@ fn stdin_is_readable() -> bool { /// Returns true if and only if stdin is deemed searchable. #[cfg(windows)] fn stdin_is_readable() -> bool { - use std::os::windows::io::AsRawHandle; - use winapi::um::fileapi::GetFileType; - use winapi::um::winbase::{FILE_TYPE_DISK, FILE_TYPE_PIPE}; + use winapi_util as winutil; - let handle = match Handle::stdin() { - Err(_) => return false, - Ok(handle) => handle, - }; - let raw_handle = handle.as_raw_handle(); - // SAFETY: As far as I can tell, it's not possible to use GetFileType in - // a way that violates safety. We give it a handle and we get an integer. - let ft = unsafe { GetFileType(raw_handle) }; - ft == FILE_TYPE_DISK || ft == FILE_TYPE_PIPE + winutil::file::typ(winutil::HandleRef::stdin()) + .map(|t| t.is_disk() || t.is_pipe()) + .unwrap_or(false) } diff --git a/src/main.rs b/src/main.rs index 0c6d00f9..4a4ac5f0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,7 +15,7 @@ extern crate same_file; extern crate serde_json; extern crate termcolor; #[cfg(windows)] -extern crate winapi; +extern crate winapi_util; use std::io; use std::process;