]> git.lizzy.rs Git - rust.git/blobdiff - src/libnative/io/mod.rs
auto merge of #15999 : Kimundi/rust/fix_folder, r=nikomatsakis
[rust.git] / src / libnative / io / mod.rs
index 32775e2cfb58cd8dc89ebee6838c0d3de3c9e6aa..db5421481ee42eca7fbb8520a988ce87d4e6f347 100644 (file)
@@ -52,6 +52,7 @@
 #[cfg(target_os = "macos")]
 #[cfg(target_os = "ios")]
 #[cfg(target_os = "freebsd")]
+#[cfg(target_os = "dragonfly")]
 #[cfg(target_os = "android")]
 #[cfg(target_os = "linux")]
 #[path = "timer_unix.rs"]
 #[path = "pipe_win32.rs"]
 pub mod pipe;
 
+#[cfg(windows)]
+#[path = "tty_win32.rs"]
+mod tty;
+
 #[cfg(unix)]    #[path = "c_unix.rs"]  mod c;
 #[cfg(windows)] #[path = "c_win32.rs"] mod c;
 
@@ -132,7 +137,7 @@ fn retry(f: || -> libc::c_int) -> libc::c_int {
     }
 }
 
-fn keep_going(data: &[u8], f: |*u8, uint| -> i64) -> i64 {
+fn keep_going(data: &[u8], f: |*const u8, uint| -> i64) -> i64 {
     let origamt = data.len();
     let mut data = data.as_ptr();
     let mut amt = origamt;
@@ -280,15 +285,27 @@ fn kill(&mut self, pid: libc::pid_t, signum: int) -> IoResult<()> {
     fn pipe_open(&mut self, fd: c_int) -> IoResult<Box<rtio::RtioPipe + Send>> {
         Ok(box file::FileDesc::new(fd, true) as Box<rtio::RtioPipe + Send>)
     }
+    #[cfg(unix)]
     fn tty_open(&mut self, fd: c_int, _readable: bool)
                 -> IoResult<Box<rtio::RtioTTY + Send>> {
-        #[cfg(unix)] use ERROR = libc::ENOTTY;
-        #[cfg(windows)] use ERROR = libc::ERROR_INVALID_HANDLE;
         if unsafe { libc::isatty(fd) } != 0 {
             Ok(box file::FileDesc::new(fd, true) as Box<rtio::RtioTTY + Send>)
         } else {
             Err(IoError {
-                code: ERROR as uint,
+                code: libc::ENOTTY as uint,
+                extra: 0,
+                detail: None,
+            })
+        }
+    }
+    #[cfg(windows)]
+    fn tty_open(&mut self, fd: c_int, _readable: bool)
+                -> IoResult<Box<rtio::RtioTTY + Send>> {
+        if tty::is_tty(fd) {
+            Ok(box tty::WindowsTTY::new(fd) as Box<rtio::RtioTTY + Send>)
+        } else {
+            Err(IoError {
+                code: libc::ERROR_INVALID_HANDLE as uint,
                 extra: 0,
                 detail: None,
             })