about summary refs log tree commit diff
path: root/src/libnative
diff options
context:
space:
mode:
authorHuon Wilson <dbau.pp+github@gmail.com>2014-03-25 00:39:40 +1100
committerHuon Wilson <dbau.pp+github@gmail.com>2014-04-01 20:46:09 +1100
commit119289b0f2359472ff07b4fac14188c3dc37b63c (patch)
treef14d1573479651a6f72a1b4e85fc955daffee247 /src/libnative
parentc329a17461b29da3c9f004154d32e4f153d727df (diff)
downloadrust-119289b0f2359472ff07b4fac14188c3dc37b63c.tar.gz
rust-119289b0f2359472ff07b4fac14188c3dc37b63c.zip
std: migrate the errno -> IoError converter from libnative.
This also adds a direct `errno` -> `~str` converter, rather than only
being possible to get a string for the very last error.
Diffstat (limited to 'src/libnative')
-rw-r--r--src/libnative/io/addrinfo.rs4
-rw-r--r--src/libnative/io/mod.rs67
-rw-r--r--src/libnative/io/net.rs2
-rw-r--r--src/libnative/io/process.rs2
4 files changed, 5 insertions, 70 deletions
diff --git a/src/libnative/io/addrinfo.rs b/src/libnative/io/addrinfo.rs
index ff617e5a230..bca564870e2 100644
--- a/src/libnative/io/addrinfo.rs
+++ b/src/libnative/io/addrinfo.rs
@@ -96,10 +96,8 @@ extern "system" {
 
 #[cfg(windows)]
 fn get_error(_: c_int) -> IoError {
-    use super::translate_error;
-
     unsafe {
-        translate_error(WSAGetLastError() as i32, true)
+        IoError::from_errno(WSAGetLastError() as uint, true)
     }
 }
 
diff --git a/src/libnative/io/mod.rs b/src/libnative/io/mod.rs
index e802c8f0301..e7432161003 100644
--- a/src/libnative/io/mod.rs
+++ b/src/libnative/io/mod.rs
@@ -86,73 +86,10 @@ fn unimpl() -> IoError {
     }
 }
 
-fn translate_error(errno: i32, detail: bool) -> IoError {
-    #[cfg(windows)]
-    fn get_err(errno: i32) -> (io::IoErrorKind, &'static str) {
-        match errno {
-            libc::EOF => (io::EndOfFile, "end of file"),
-            libc::ERROR_NO_DATA => (io::BrokenPipe, "the pipe is being closed"),
-            libc::ERROR_FILE_NOT_FOUND => (io::FileNotFound, "file not found"),
-            libc::ERROR_INVALID_NAME => (io::InvalidInput, "invalid file name"),
-            libc::WSAECONNREFUSED => (io::ConnectionRefused, "connection refused"),
-            libc::WSAECONNRESET => (io::ConnectionReset, "connection reset"),
-            libc::WSAEACCES => (io::PermissionDenied, "permission denied"),
-            libc::WSAEWOULDBLOCK => {
-                (io::ResourceUnavailable, "resource temporarily unavailable")
-            }
-            libc::WSAENOTCONN => (io::NotConnected, "not connected"),
-            libc::WSAECONNABORTED => (io::ConnectionAborted, "connection aborted"),
-            libc::WSAEADDRNOTAVAIL => (io::ConnectionRefused, "address not available"),
-            libc::WSAEADDRINUSE => (io::ConnectionRefused, "address in use"),
-            libc::ERROR_BROKEN_PIPE => (io::EndOfFile, "the pipe has ended"),
-
-            // libuv maps this error code to EISDIR. we do too. if it is found
-            // to be incorrect, we can add in some more machinery to only
-            // return this message when ERROR_INVALID_FUNCTION after certain
-            // win32 calls.
-            libc::ERROR_INVALID_FUNCTION => (io::InvalidInput,
-                                             "illegal operation on a directory"),
-
-            _ => (io::OtherIoError, "unknown error")
-        }
-    }
-
-    #[cfg(not(windows))]
-    fn get_err(errno: i32) -> (io::IoErrorKind, &'static str) {
-        // FIXME: this should probably be a bit more descriptive...
-        match errno {
-            libc::EOF => (io::EndOfFile, "end of file"),
-            libc::ECONNREFUSED => (io::ConnectionRefused, "connection refused"),
-            libc::ECONNRESET => (io::ConnectionReset, "connection reset"),
-            libc::EPERM | libc::EACCES =>
-                (io::PermissionDenied, "permission denied"),
-            libc::EPIPE => (io::BrokenPipe, "broken pipe"),
-            libc::ENOTCONN => (io::NotConnected, "not connected"),
-            libc::ECONNABORTED => (io::ConnectionAborted, "connection aborted"),
-            libc::EADDRNOTAVAIL => (io::ConnectionRefused, "address not available"),
-            libc::EADDRINUSE => (io::ConnectionRefused, "address in use"),
-            libc::ENOENT => (io::FileNotFound, "no such file or directory"),
-            libc::EISDIR => (io::InvalidInput, "illegal operation on a directory"),
-
-            // These two constants can have the same value on some systems, but
-            // different values on others, so we can't use a match clause
-            x if x == libc::EAGAIN || x == libc::EWOULDBLOCK =>
-                (io::ResourceUnavailable, "resource temporarily unavailable"),
-
-            _ => (io::OtherIoError, "unknown error")
-        }
-    }
-
-    let (kind, desc) = get_err(errno);
-    IoError {
-        kind: kind,
-        desc: desc,
-        detail: if detail {Some(os::last_os_error())} else {None},
-    }
+fn last_error() -> IoError {
+    IoError::last_error()
 }
 
-fn last_error() -> IoError { translate_error(os::errno() as i32, true) }
-
 // unix has nonzero values as errors
 fn mkerr_libc(ret: libc::c_int) -> IoResult<()> {
     if ret != 0 {
diff --git a/src/libnative/io/net.rs b/src/libnative/io/net.rs
index 6a711072942..832f4b8df20 100644
--- a/src/libnative/io/net.rs
+++ b/src/libnative/io/net.rs
@@ -120,7 +120,7 @@ fn last_error() -> io::IoError {
     extern "system" {
         fn WSAGetLastError() -> libc::c_int;
     }
-    super::translate_error(unsafe { WSAGetLastError() }, true)
+    io::IoError::from_errno(unsafe { WSAGetLastError() } as uint, true)
 }
 
 #[cfg(not(windows))]
diff --git a/src/libnative/io/process.rs b/src/libnative/io/process.rs
index 28f0817670b..3578c0c39ce 100644
--- a/src/libnative/io/process.rs
+++ b/src/libnative/io/process.rs
@@ -469,7 +469,7 @@ fn spawn_process_os(config: p::ProcessConfig,
                                     (bytes[1] << 16) as i32 |
                                     (bytes[2] <<  8) as i32 |
                                     (bytes[3] <<  0) as i32;
-                        Err(super::translate_error(errno, false))
+                        Err(io::IoError::from_errno(errno as uint, false))
                     }
                     Err(e) => {
                         assert!(e.kind == io::BrokenPipe ||