1
0
mirror of https://github.com/BurntSushi/ripgrep.git synced 2025-03-03 14:32:22 +02:00

ripgrep: use winapi-util for stdin_is_readable

This commit is contained in:
Andrew Gallant 2018-08-25 00:25:45 -04:00
parent 16353bad6e
commit 05a0389555
No known key found for this signature in database
GPG Key ID: B2E3A4923F8B0D44
4 changed files with 8 additions and 17 deletions

2
Cargo.lock generated
View File

@ -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]]

View File

@ -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"

View File

@ -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)
}

View File

@ -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;