diff --git a/src/librustuv/tty.rs b/src/librustuv/tty.rs index c7c09f3480e20..1cac5872ed372 100644 --- a/src/librustuv/tty.rs +++ b/src/librustuv/tty.rs @@ -39,7 +39,8 @@ impl TtyWatcher { // Related: // - https://github.com/joyent/libuv/issues/982 // - https://github.com/joyent/libuv/issues/988 - if unsafe { uvll::guess_handle(fd) != uvll::UV_TTY as libc::c_int } { + let guess = unsafe { uvll::guess_handle(fd) }; + if readable && guess != uvll::UV_TTY as libc::c_int { return Err(UvError(uvll::EBADF)); } @@ -100,6 +101,10 @@ impl RtioTTY for TtyWatcher { n => Err(uv_error_to_io_error(UvError(n))) } } + + fn isatty(&self) -> bool { + unsafe { uvll::guess_handle(self.fd) == uvll::UV_TTY as libc::c_int } + } } impl UvHandle for TtyWatcher { diff --git a/src/libstd/io/native/file.rs b/src/libstd/io/native/file.rs index 5e39460ba6a4d..c157efa7d3821 100644 --- a/src/libstd/io/native/file.rs +++ b/src/libstd/io/native/file.rs @@ -167,6 +167,7 @@ impl rtio::RtioTTY for FileDesc { fn get_winsize(&mut self) -> Result<(int, int), IoError> { Err(super::unimpl()) } + fn isatty(&self) -> bool { false } } impl Drop for FileDesc { diff --git a/src/libstd/rt/rtio.rs b/src/libstd/rt/rtio.rs index 35fb8baa6ce68..775f9d6c3be77 100644 --- a/src/libstd/rt/rtio.rs +++ b/src/libstd/rt/rtio.rs @@ -230,6 +230,7 @@ pub trait RtioTTY { fn write(&mut self, buf: &[u8]) -> Result<(), IoError>; fn set_raw(&mut self, raw: bool) -> Result<(), IoError>; fn get_winsize(&mut self) -> Result<(int, int), IoError>; + fn isatty(&self) -> bool; } pub trait PausibleIdleCallback {