]> 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 4158db7bb8ea1d902ef8fe40e67a1596f4d7d60c..db5421481ee42eca7fbb8520a988ce87d4e6f347 100644 (file)
@@ -50,7 +50,9 @@
 pub mod file;
 
 #[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;
 
@@ -131,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;
@@ -166,34 +172,34 @@ impl rtio::IoFactory for IoFactory {
     // networking
     fn tcp_connect(&mut self, addr: rtio::SocketAddr,
                    timeout: Option<u64>)
-        -> IoResult<Box<rtio::RtioTcpStream:Send>>
+        -> IoResult<Box<rtio::RtioTcpStream + Send>>
     {
         net::TcpStream::connect(addr, timeout).map(|s| {
-            box s as Box<rtio::RtioTcpStream:Send>
+            box s as Box<rtio::RtioTcpStream + Send>
         })
     }
     fn tcp_bind(&mut self, addr: rtio::SocketAddr)
-                -> IoResult<Box<rtio::RtioTcpListener:Send>> {
+                -> IoResult<Box<rtio::RtioTcpListener + Send>> {
         net::TcpListener::bind(addr).map(|s| {
-            box s as Box<rtio::RtioTcpListener:Send>
+            box s as Box<rtio::RtioTcpListener + Send>
         })
     }
     fn udp_bind(&mut self, addr: rtio::SocketAddr)
-                -> IoResult<Box<rtio::RtioUdpSocket:Send>> {
+                -> IoResult<Box<rtio::RtioUdpSocket + Send>> {
         net::UdpSocket::bind(addr).map(|u| {
-            box u as Box<rtio::RtioUdpSocket:Send>
+            box u as Box<rtio::RtioUdpSocket + Send>
         })
     }
     fn unix_bind(&mut self, path: &CString)
-                 -> IoResult<Box<rtio::RtioUnixListener:Send>> {
+                 -> IoResult<Box<rtio::RtioUnixListener + Send>> {
         pipe::UnixListener::bind(path).map(|s| {
-            box s as Box<rtio::RtioUnixListener:Send>
+            box s as Box<rtio::RtioUnixListener + Send>
         })
     }
     fn unix_connect(&mut self, path: &CString,
-                    timeout: Option<u64>) -> IoResult<Box<rtio::RtioPipe:Send>> {
+                    timeout: Option<u64>) -> IoResult<Box<rtio::RtioPipe + Send>> {
         pipe::UnixStream::connect(path, timeout).map(|s| {
-            box s as Box<rtio::RtioPipe:Send>
+            box s as Box<rtio::RtioPipe + Send>
         })
     }
     fn get_host_addresses(&mut self, host: Option<&str>, servname: Option<&str>,
@@ -205,18 +211,18 @@ fn get_host_addresses(&mut self, host: Option<&str>, servname: Option<&str>,
 
     // filesystem operations
     fn fs_from_raw_fd(&mut self, fd: c_int, close: rtio::CloseBehavior)
-                      -> Box<rtio::RtioFileStream:Send> {
+                      -> Box<rtio::RtioFileStream + Send> {
         let close = match close {
             rtio::CloseSynchronously | rtio::CloseAsynchronously => true,
             rtio::DontClose => false
         };
-        box file::FileDesc::new(fd, close) as Box<rtio::RtioFileStream:Send>
+        box file::FileDesc::new(fd, close) as Box<rtio::RtioFileStream + Send>
     }
     fn fs_open(&mut self, path: &CString, fm: rtio::FileMode,
                fa: rtio::FileAccess)
-        -> IoResult<Box<rtio::RtioFileStream:Send>>
+        -> IoResult<Box<rtio::RtioFileStream + Send>>
     {
-        file::open(path, fm, fa).map(|fd| box fd as Box<rtio::RtioFileStream:Send>)
+        file::open(path, fm, fa).map(|fd| box fd as Box<rtio::RtioFileStream + Send>)
     }
     fn fs_unlink(&mut self, path: &CString) -> IoResult<()> {
         file::unlink(path)
@@ -260,41 +266,53 @@ fn fs_utime(&mut self, src: &CString, atime: u64,
     }
 
     // misc
-    fn timer_init(&mut self) -> IoResult<Box<rtio::RtioTimer:Send>> {
-        timer::Timer::new().map(|t| box t as Box<rtio::RtioTimer:Send>)
+    fn timer_init(&mut self) -> IoResult<Box<rtio::RtioTimer + Send>> {
+        timer::Timer::new().map(|t| box t as Box<rtio::RtioTimer + Send>)
     }
     fn spawn(&mut self, cfg: rtio::ProcessConfig)
-            -> IoResult<(Box<rtio::RtioProcess:Send>,
-                         Vec<Option<Box<rtio::RtioPipe:Send>>>)> {
+            -> IoResult<(Box<rtio::RtioProcess + Send>,
+                         Vec<Option<Box<rtio::RtioPipe + Send>>>)> {
         process::Process::spawn(cfg).map(|(p, io)| {
-            (box p as Box<rtio::RtioProcess:Send>,
+            (box p as Box<rtio::RtioProcess + Send>,
              io.move_iter().map(|p| p.map(|p| {
-                 box p as Box<rtio::RtioPipe:Send>
+                 box p as Box<rtio::RtioPipe + Send>
              })).collect())
         })
     }
     fn kill(&mut self, pid: libc::pid_t, signum: int) -> IoResult<()> {
         process::Process::kill(pid, signum)
     }
-    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>)
+    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;
+                -> IoResult<Box<rtio::RtioTTY + Send>> {
         if unsafe { libc::isatty(fd) } != 0 {
-            Ok(box file::FileDesc::new(fd, true) as Box<rtio::RtioTTY:Send>)
+            Ok(box file::FileDesc::new(fd, true) as Box<rtio::RtioTTY + Send>)
+        } else {
+            Err(IoError {
+                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: ERROR as uint,
+                code: libc::ERROR_INVALID_HANDLE as uint,
                 extra: 0,
                 detail: None,
             })
         }
     }
     fn signal(&mut self, _signal: int, _cb: Box<rtio::Callback>)
-              -> IoResult<Box<rtio::RtioSignal:Send>> {
+              -> IoResult<Box<rtio::RtioSignal + Send>> {
         Err(unimpl())
     }
 }