|
1 | 1 | //! Errno numbers for `wasm32-unknown-unknown`. |
2 | 2 | //! |
3 | | -//! There is no libc errno table. The values are the Linux ABI the stdlib |
4 | | -//! and `OSError` subclasses match against. |
| 3 | +//! There is no libc errno table. The values are the Darwin/BSD numbers the |
| 4 | +//! guest `O_*` flags and `OSError` subclasses match against. |
| 5 | +
|
| 6 | +#[must_use] |
| 7 | +pub fn strerror_string(errno: i32) -> Option<String> { |
| 8 | + errors::strerror(errno).map(str::to_owned) |
| 9 | +} |
5 | 10 |
|
6 | 11 | pub mod errors { |
7 | | - pub const EAGAIN: i32 = 11; |
8 | | - pub const ECONNABORTED: i32 = 103; |
9 | | - pub const ECONNRESET: i32 = 104; |
| 12 | + pub const EPERM: i32 = 1; |
| 13 | + pub const ENOENT: i32 = 2; |
| 14 | + pub const ESRCH: i32 = 3; |
| 15 | + pub const EINTR: i32 = 4; |
| 16 | + pub const EIO: i32 = 5; |
| 17 | + pub const EBADF: i32 = 9; |
| 18 | + pub const ECHILD: i32 = 10; |
| 19 | + pub const EAGAIN: i32 = 35; |
| 20 | + pub const EWOULDBLOCK: i32 = 35; |
| 21 | + pub const EINPROGRESS: i32 = 36; |
| 22 | + pub const EALREADY: i32 = 37; |
| 23 | + pub const EPIPE: i32 = 32; |
| 24 | + pub const ENOTDIR: i32 = 20; |
| 25 | + pub const EISDIR: i32 = 21; |
| 26 | + pub const EINVAL: i32 = 22; |
| 27 | + pub const EMFILE: i32 = 24; |
| 28 | + pub const ESPIPE: i32 = 29; |
| 29 | + pub const EROFS: i32 = 30; |
| 30 | + pub const EACCES: i32 = 13; |
| 31 | + pub const EEXIST: i32 = 17; |
| 32 | + pub const ENOTSUP: i32 = 45; |
| 33 | + pub const EAFNOSUPPORT: i32 = 47; |
| 34 | + pub const ECONNABORTED: i32 = 53; |
| 35 | + pub const ECONNRESET: i32 = 54; |
| 36 | + pub const ESHUTDOWN: i32 = 58; |
| 37 | + pub const ETIMEDOUT: i32 = 60; |
| 38 | + pub const ECONNREFUSED: i32 = 61; |
| 39 | + |
| 40 | + pub fn strerror(errno: i32) -> Option<&'static str> { |
| 41 | + Some(match errno { |
| 42 | + EPERM => "Operation not permitted", |
| 43 | + ENOENT => "No such file or directory", |
| 44 | + ESRCH => "No such process", |
| 45 | + EIO => "Input/output error", |
| 46 | + EINTR => "Interrupted system call", |
| 47 | + ECHILD => "No child processes", |
| 48 | + EACCES => "Permission denied", |
| 49 | + EEXIST => "File exists", |
| 50 | + ENOTDIR => "Not a directory", |
| 51 | + EISDIR => "Is a directory", |
| 52 | + EPIPE => "Broken pipe", |
| 53 | + EAGAIN => "Resource temporarily unavailable", |
| 54 | + EINPROGRESS => "Operation now in progress", |
| 55 | + EALREADY => "Operation already in progress", |
| 56 | + ENOTSUP => "Operation not supported", |
| 57 | + EAFNOSUPPORT => "Address family not supported by protocol", |
| 58 | + ECONNABORTED => "Software caused connection abort", |
| 59 | + ECONNRESET => "Connection reset by peer", |
| 60 | + ETIMEDOUT => "Operation timed out", |
| 61 | + ECONNREFUSED => "Connection refused", |
| 62 | + EBADF => "Bad file descriptor", |
| 63 | + EINVAL => "Invalid argument", |
| 64 | + EMFILE => "Too many open files", |
| 65 | + ESPIPE => "Illegal seek", |
| 66 | + EROFS => "Read-only file system", |
| 67 | + ESHUTDOWN => "Can't send after socket shutdown", |
| 68 | + _ => return None, |
| 69 | + }) |
| 70 | + } |
| 71 | +} |
| 72 | + |
| 73 | +#[cfg(test)] |
| 74 | +mod tests { |
| 75 | + use super::errors; |
| 76 | + |
| 77 | + #[test] |
| 78 | + fn eagain_is_darwin() { |
| 79 | + assert_eq!(errors::EAGAIN, 35); |
| 80 | + assert_eq!(errors::EWOULDBLOCK, 35); |
| 81 | + assert_eq!( |
| 82 | + errors::strerror(errors::EAGAIN), |
| 83 | + Some("Resource temporarily unavailable") |
| 84 | + ); |
| 85 | + } |
10 | 86 | } |
0 commit comments