tail: add equivalent of stdin_is_pipe_or_fifo() for Windows

* add support to determine if stdin is readable on Windows
This commit is contained in:
Jan Scheer 2022-05-19 22:55:47 +02:00
parent 6a1cf72316
commit 84480f892d
No known key found for this signature in database
GPG key ID: C62AD4C29E2B9828
4 changed files with 12 additions and 5 deletions

1
Cargo.lock generated
View file

@ -2939,6 +2939,7 @@ dependencies = [
"notify",
"uucore",
"winapi 0.3.9",
"winapi-util",
]
[[package]]

View file

@ -24,6 +24,7 @@ uucore = { version=">=0.0.11", package="uucore", path="../../uucore", features=[
[target.'cfg(windows)'.dependencies]
winapi = { version="0.3", features=["fileapi", "handleapi", "processthreadsapi", "synchapi", "winbase"] }
winapi-util = { version= "0.1.5" }
[target.'cfg(unix)'.dependencies]
nix = { version = "0.24.1", default-features = false, features=["fs"] }

View file

@ -1435,10 +1435,13 @@ pub fn stdin_is_pipe_or_fifo() -> bool {
{
platform::stdin_is_pipe_or_fifo()
}
// FIXME windows has GetFileType which can determine if the file is a pipe/FIFO
// so this check can also be performed
#[cfg(not(unix))]
false
#[cfg(windows)]
{
use winapi_util;
winapi_util::file::typ(winapi_util::HandleRef::stdin())
.map(|t| t.is_disk() || t.is_pipe())
.unwrap_or(false)
}
}
pub fn stdin_is_bad_fd() -> bool {

View file

@ -11,7 +11,9 @@ extern crate tail;
use crate::common::util::*;
use std::char::from_digit;
use std::io::{Read, Write};
#[cfg(unix)]
use std::io::Read;
use std::io::Write;
use std::process::Stdio;
#[cfg(unix)]
use std::thread::sleep;