mirror of
https://github.com/uutils/coreutils
synced 2024-11-17 02:08:09 +00:00
Refactor check for standard stream interactivity.
Since several utilities check if the standard streams are interactive, I moved this into the uucore::fs library as is_std*_interactive(). I also added Windows support for these methods, which only return false (or at least until someone finds a way to support this).
This commit is contained in:
parent
14eccb4335
commit
9c4c9f6782
1 changed files with 31 additions and 0 deletions
|
@ -12,6 +12,7 @@
|
||||||
// be backported to stable (<= 1.1). This will likely be dropped
|
// be backported to stable (<= 1.1). This will likely be dropped
|
||||||
// when the path trait stabilizes.
|
// when the path trait stabilizes.
|
||||||
|
|
||||||
|
use ::libc;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io::{Error, ErrorKind, Result};
|
use std::io::{Error, ErrorKind, Result};
|
||||||
|
@ -142,3 +143,33 @@ pub fn canonicalize<P: AsRef<Path>>(original: P, can_mode: CanonicalizeMode) ->
|
||||||
}
|
}
|
||||||
Ok(result)
|
Ok(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(unix)]
|
||||||
|
pub fn is_stdin_interactive() -> bool {
|
||||||
|
unsafe { libc::isatty(libc::STDIN_FILENO) == 1 }
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
pub fn is_stdin_interactive() -> bool {
|
||||||
|
0
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(unix)]
|
||||||
|
pub fn is_stdout_interactive() -> bool {
|
||||||
|
unsafe { libc::isatty(libc::STDOUT_FILENO) == 1 }
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
pub fn is_stdout_interactive() -> bool {
|
||||||
|
0
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(unix)]
|
||||||
|
pub fn is_stderr_interactive() -> bool {
|
||||||
|
unsafe { libc::isatty(libc::STDERR_FILENO) == 1 }
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
pub fn is_stderr_interactive() -> bool {
|
||||||
|
0
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue