Skip to content

Commit

Permalink
Auto merge of #63814 - malbarbo:wasi-error-kind, r=alexcrichton
Browse files Browse the repository at this point in the history
Implement decode_error_kind for wasi

Based on the implementation for unix targets,
  • Loading branch information
bors committed Aug 23, 2019
2 parents 9eae1fc + c8838ef commit 4993524
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/libstd/sys/wasi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4993524

Please sign in to comment.