mirror of
https://github.com/BurntSushi/ripgrep.git
synced 2025-04-24 17:12:16 +02:00
ripgrep: use winapi-util for stdin_is_readable
This commit is contained in:
parent
16353bad6e
commit
05a0389555
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -478,7 +478,7 @@ dependencies = [
|
|||||||
"serde_derive 1.0.75 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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)",
|
"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)",
|
"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]]
|
[[package]]
|
||||||
|
@ -61,9 +61,8 @@ version = "2.32.0"
|
|||||||
default-features = false
|
default-features = false
|
||||||
features = ["suggestions"]
|
features = ["suggestions"]
|
||||||
|
|
||||||
[target.'cfg(windows)'.dependencies.winapi]
|
[target.'cfg(windows)'.dependencies.winapi-util]
|
||||||
version = "0.3"
|
version = "0.1.1"
|
||||||
features = ["std", "fileapi", "winnt"]
|
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
lazy_static = "1"
|
lazy_static = "1"
|
||||||
|
16
src/args.rs
16
src/args.rs
@ -1517,17 +1517,9 @@ fn stdin_is_readable() -> bool {
|
|||||||
/// Returns true if and only if stdin is deemed searchable.
|
/// Returns true if and only if stdin is deemed searchable.
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
fn stdin_is_readable() -> bool {
|
fn stdin_is_readable() -> bool {
|
||||||
use std::os::windows::io::AsRawHandle;
|
use winapi_util as winutil;
|
||||||
use winapi::um::fileapi::GetFileType;
|
|
||||||
use winapi::um::winbase::{FILE_TYPE_DISK, FILE_TYPE_PIPE};
|
|
||||||
|
|
||||||
let handle = match Handle::stdin() {
|
winutil::file::typ(winutil::HandleRef::stdin())
|
||||||
Err(_) => return false,
|
.map(|t| t.is_disk() || t.is_pipe())
|
||||||
Ok(handle) => handle,
|
.unwrap_or(false)
|
||||||
};
|
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ extern crate same_file;
|
|||||||
extern crate serde_json;
|
extern crate serde_json;
|
||||||
extern crate termcolor;
|
extern crate termcolor;
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
extern crate winapi;
|
extern crate winapi_util;
|
||||||
|
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::process;
|
use std::process;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user