mirror of
https://github.com/BurntSushi/ripgrep.git
synced 2025-06-20 06:15:37 +02:00
ripgrep: use winapi-util for stdin_is_readable
This commit is contained in:
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.
|
||||
#[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)
|
||||
}
|
||||
|
@ -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;
|
||||
|
Reference in New Issue
Block a user