about summary refs log tree commit diff
path: root/src/libstd/sys
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2019-08-23 22:09:07 +0000
committerbors <bors@rust-lang.org>2019-08-23 22:09:07 +0000
commit49935246829165b2c4c5c69f981a300bcaa83d7f (patch)
tree455d80707593478a4ffcf53330791e386a075590 /src/libstd/sys
parent9eae1fc0ea9b00341b8fe191582c4decb5cb86a3 (diff)
parentc8838efe355df9a9834e96a0d853743d21f06ce2 (diff)
downloadrust-49935246829165b2c4c5c69f981a300bcaa83d7f.tar.gz
rust-49935246829165b2c4c5c69f981a300bcaa83d7f.zip
Auto merge of #63814 - malbarbo:wasi-error-kind, r=alexcrichton
Implement decode_error_kind for wasi

Based on the implementation for unix targets,
Diffstat (limited to 'src/libstd/sys')
-rw-r--r--src/libstd/sys/wasi/mod.rs20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/libstd/sys/wasi/mod.rs b/src/libstd/sys/wasi/mod.rs
index f842869e08e..57da81b41e7 100644
--- a/src/libstd/sys/wasi/mod.rs
+++ b/src/libstd/sys/wasi/mod.rs
@@ -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