diff --git a/src/uucore/fs.rs b/src/uucore/fs.rs index e0372b357..461c70940 100644 --- a/src/uucore/fs.rs +++ b/src/uucore/fs.rs @@ -12,6 +12,7 @@ // be backported to stable (<= 1.1). This will likely be dropped // when the path trait stabilizes. +use ::libc; use std::env; use std::fs; use std::io::{Error, ErrorKind, Result}; @@ -142,3 +143,33 @@ pub fn canonicalize>(original: P, can_mode: CanonicalizeMode) -> } 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 +}