From 05a0389555ab44a2fee13c90395bc05960d388e5 Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Sat, 25 Aug 2018 00:25:45 -0400 Subject: ripgrep: use winapi-util for stdin_is_readable --- src/args.rs | 16 ++++------------ src/main.rs | 2 +- 2 files changed, 5 insertions(+), 13 deletions(-) (limited to 'src') 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; -- cgit v1.2.3