]> git.lizzy.rs Git - rust.git/commitdiff
Allow piped stdout/stderr use uv_tty_t
authorAlex Crichton <alex@alexcrichton.com>
Tue, 19 Nov 2013 00:26:03 +0000 (16:26 -0800)
committerAlex Crichton <alex@alexcrichton.com>
Tue, 19 Nov 2013 00:29:41 +0000 (16:29 -0800)
There are issues with reading stdin when it is actually attached to a pipe, but
I have run into no problems in writing to stdout/stderr when they are attached
to pipes.

src/librustuv/tty.rs
src/libstd/io/native/file.rs
src/libstd/rt/rtio.rs

index c7c09f3480e20b943d428ac814785b9fc74d1b48..1cac5872ed37270cadd0b92882f4fb1dba8b1e44 100644 (file)
@@ -39,7 +39,8 @@ pub fn new(loop_: &Loop, fd: libc::c_int, readable: bool)
         // 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 @@ fn get_winsize(&mut self) -> Result<(int, int), IoError> {
             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<uvll::uv_tty_t> for TtyWatcher {
index 5e39460ba6a4dc9e2361be9a85b09759f3716fed..c157efa7d3821936761ccf73e3becc65972f403d 100644 (file)
@@ -167,6 +167,7 @@ fn set_raw(&mut self, _raw: bool) -> Result<(), IoError> {
     fn get_winsize(&mut self) -> Result<(int, int), IoError> {
         Err(super::unimpl())
     }
+    fn isatty(&self) -> bool { false }
 }
 
 impl Drop for FileDesc {
index 35fb8baa6ce688db8dc9b65ee56c2f9059352ce0..775f9d6c3be77ca6710a9eaec55ab432c3b1d072 100644 (file)
@@ -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 {