diff options
-rw-r--r-- | src/unistd.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/unistd.rs b/src/unistd.rs index 952040fd..579f8de9 100644 --- a/src/unistd.rs +++ b/src/unistd.rs @@ -409,6 +409,21 @@ pub fn ftruncate(fd: Fd, len: off_t) -> SysResult<()> { } } +pub fn isatty(fd: Fd) -> SysResult<bool> { + use {errno, libc}; + + if unsafe { libc::isatty(fd) } == 1 { + Ok(true) + } else { + match SysError::last() { + // ENOTTY means `fd` is a valid file descriptor, but not a TTY, so + // we return `Ok(false)` + SysError { kind: errno::ENOTTY } => Ok(false), + err => Err(err) + } + } +} + #[cfg(target_os = "linux")] mod linux { use std::path::Path; |