]> git.lizzy.rs Git - rust.git/commitdiff
Implement decode_error_kind for wasi
authorMarco A L Barbosa <malbarbo@gmail.com>
Thu, 22 Aug 2019 17:40:21 +0000 (14:40 -0300)
committerMarco A L Barbosa <malbarbo@gmail.com>
Fri, 23 Aug 2019 13:48:38 +0000 (10:48 -0300)
Based on the implementation for unix targets

src/libstd/sys/wasi/mod.rs

index f842869e08ee69e0c628a99dccceb7f662e5df38..57da81b41e7ca0840b275ef8a5089bb47f3729e3 100644 (file)
@@ -64,8 +64,24 @@ pub fn unsupported_err() -> Error {
     Error::new(ErrorKind::Other, "operation not supported on wasm yet")
 }
 
-pub fn decode_error_kind(_code: i32) -> ErrorKind {
-    ErrorKind::Other
+pub fn decode_error_kind(errno: i32) -> ErrorKind {
+    match errno as libc::c_int {
+        libc::ECONNREFUSED => ErrorKind::ConnectionRefused,
+        libc::ECONNRESET => ErrorKind::ConnectionReset,
+        libc::EPERM | libc::EACCES => ErrorKind::PermissionDenied,
+        libc::EPIPE => ErrorKind::BrokenPipe,
+        libc::ENOTCONN => ErrorKind::NotConnected,
+        libc::ECONNABORTED => ErrorKind::ConnectionAborted,
+        libc::EADDRNOTAVAIL => ErrorKind::AddrNotAvailable,
+        libc::EADDRINUSE => ErrorKind::AddrInUse,
+        libc::ENOENT => ErrorKind::NotFound,
+        libc::EINTR => ErrorKind::Interrupted,
+        libc::EINVAL => ErrorKind::InvalidInput,
+        libc::ETIMEDOUT => ErrorKind::TimedOut,
+        libc::EEXIST => ErrorKind::AlreadyExists,
+        libc::EAGAIN => ErrorKind::WouldBlock,
+        _ => ErrorKind::Other,
+    }
 }
 
 // This enum is used as the storage for a bunch of types which can't actually