Skip to content

Commit

Permalink
use last_os_error to get the platform-dependent error
Browse files Browse the repository at this point in the history
  • Loading branch information
stlankes committed Apr 23, 2024
1 parent 292161e commit 827c4f2
Showing 1 changed file with 1 addition and 19 deletions.
20 changes: 1 addition & 19 deletions src/sys/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,7 @@ macro_rules! syscall {
let res = unsafe { libc::$fn($($arg, )*) };
#[cfg(target_os = "hermit")]
if res < 0 {
let e = match -res {
libc::errno::EACCES => std::io::ErrorKind::PermissionDenied,
libc::errno::EADDRINUSE => std::io::ErrorKind::AddrInUse,
libc::errno::EADDRNOTAVAIL => std::io::ErrorKind::AddrNotAvailable,
libc::errno::EAGAIN => std::io::ErrorKind::WouldBlock,
libc::errno::ECONNABORTED => std::io::ErrorKind::ConnectionAborted,
libc::errno::ECONNREFUSED => std::io::ErrorKind::ConnectionRefused,
libc::errno::ECONNRESET => std::io::ErrorKind::ConnectionReset,
libc::errno::EEXIST => std::io::ErrorKind::AlreadyExists,
libc::errno::EINTR => std::io::ErrorKind::Interrupted,
libc::errno::EINVAL => std::io::ErrorKind::InvalidInput,
libc::errno::ENOENT => std::io::ErrorKind::NotFound,
libc::errno::ENOTCONN => std::io::ErrorKind::NotConnected,
libc::errno::EPERM => std::io::ErrorKind::PermissionDenied,
libc::errno::EPIPE => std::io::ErrorKind::BrokenPipe,
libc::errno::ETIMEDOUT => std::io::ErrorKind::TimedOut,
_ => panic!("Unknown error {}", res),
};
Err(std::io::Error::from(e))
Err(std::io::Error::last_os_error())
} else {
Ok(res)
}
Expand Down

0 comments on commit 827c4f2

Please sign in to comment.