diff options
author | Andrew Gallant <jamslam@gmail.com> | 2018-08-25 00:25:45 -0400 |
---|---|---|
committer | Andrew Gallant <jamslam@gmail.com> | 2018-08-25 00:30:15 -0400 |
commit | 05a0389555ab44a2fee13c90395bc05960d388e5 (patch) | |
tree | 79da231a67ee20999f034d5baa051f2a482c5de7 /src | |
parent | 16353bad6eb626784d238a83731c5b072b922bc7 (diff) |
ripgrep: use winapi-util for stdin_is_readable
Diffstat (limited to 'src')
-rw-r--r-- | src/args.rs | 16 | ||||
-rw-r--r-- | src/main.rs | 2 |
2 files changed, 5 insertions, 13 deletions
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; |