priv_sep

Privilege separation library.
git clone https://git.philomathiclife.com/repos/priv_sep
Log | Files | Refs | README

err.rs (76552B)


      1 use super::c;
      2 use core::{
      3     error::Error,
      4     ffi::c_int,
      5     fmt::{self, Display, Formatter},
      6 };
      7 #[cfg(feature = "std")]
      8 use std::io::Error as StdErr;
      9 /// `newtype` around a [`c_int`] that is used to contain unknown error numbers in the [`Errno::Other`]
     10 /// variant.
     11 ///
     12 /// Note this cannot be constructed directly since the purpose is to only contain unknown error codes
     13 /// ensuring that any non-[`Errno::Other`] is not equal to an `Errno::Other`.
     14 #[derive(Clone, Copy, Debug, Eq, PartialEq)]
     15 pub struct OtherErrno(c_int);
     16 impl OtherErrno {
     17     /// Returns the contained error number.
     18     ///
     19     /// # Examples
     20     ///
     21     /// ```
     22     /// # use priv_sep::{Errno, OtherErrno};
     23     /// assert!(matches!(Errno::from_raw(0), Errno::Other(err) if err.into_raw() == 0));
     24     /// ```
     25     #[inline]
     26     #[must_use]
     27     pub const fn into_raw(self) -> c_int {
     28         self.0
     29     }
     30 }
     31 impl From<OtherErrno> for c_int {
     32     #[inline]
     33     fn from(value: OtherErrno) -> Self {
     34         value.0
     35     }
     36 }
     37 /// Error returned from calls to the system's libc.
     38 ///
     39 /// Note this contains variants associated with all supported targets; thus for a given target,
     40 /// it's likely a non-empty subset of the variants will never be returned.
     41 #[derive(Clone, Copy, Debug, Eq, PartialEq)]
     42 pub enum Errno {
     43     /// Operation not permitted.
     44     EPERM,
     45     /// No such file or directory.
     46     ENOENT,
     47     /// No such process.
     48     ESRCH,
     49     /// Interrupted system call.
     50     EINTR,
     51     /// Input/output error.
     52     EIO,
     53     /// Device not configured.
     54     ENXIO,
     55     /// Argument list too long.
     56     E2BIG,
     57     /// Exec format error.
     58     ENOEXEC,
     59     /// Bad file descriptor.
     60     EBADF,
     61     /// No child processes.
     62     ECHILD,
     63     /// Resource deadlock avoided.
     64     EDEADLK,
     65     /// Cannot allocate memory.
     66     ENOMEM,
     67     /// Permission denied.
     68     EACCES,
     69     /// Bad address.
     70     EFAULT,
     71     /// Block device required.
     72     ENOTBLK,
     73     /// Device busy.
     74     EBUSY,
     75     /// File exists.
     76     EEXIST,
     77     /// Cross-device link.
     78     EXDEV,
     79     /// Operation not supported by device.
     80     ENODEV,
     81     /// Not a directory.
     82     ENOTDIR,
     83     /// Is a directory.
     84     EISDIR,
     85     /// Invalid argument.
     86     EINVAL,
     87     /// Too many open files in system.
     88     ENFILE,
     89     /// Too many open files.
     90     EMFILE,
     91     /// Inappropriate ioctl for device.
     92     ENOTTY,
     93     /// Text file busy.
     94     ETXTBSY,
     95     /// File too large.
     96     EFBIG,
     97     /// No space left on device.
     98     ENOSPC,
     99     /// Illegal seek.
    100     ESPIPE,
    101     /// Read-only file system.
    102     EROFS,
    103     /// Too many links.
    104     EMLINK,
    105     /// Broken pipe.
    106     EPIPE,
    107     /// Numerical argument out of domain.
    108     EDOM,
    109     /// Result too large.
    110     ERANGE,
    111     /// Operation would block.
    112     EWOULDBLOCK,
    113     /// Operation now in progress.
    114     EINPROGRESS,
    115     /// Operation already in progress.
    116     EALREADY,
    117     /// Socket operation on non-socket.
    118     ENOTSOCK,
    119     /// Destination address required.
    120     EDESTADDRREQ,
    121     /// Message too long.
    122     EMSGSIZE,
    123     /// Protocol wrong type for socket.
    124     EPROTOTYPE,
    125     /// Protocol not available.
    126     ENOPROTOOPT,
    127     /// Protocol not supported.
    128     EPROTONOSUPPORT,
    129     /// Socket type not supported.
    130     ESOCKTNOSUPPORT,
    131     /// Operation not supported.
    132     EOPNOTSUPP,
    133     /// Protocol family not supported.
    134     EPFNOSUPPORT,
    135     /// Address family not supported by protocol family.
    136     EAFNOSUPPORT,
    137     /// Address already in use.
    138     EADDRINUSE,
    139     /// Can't assign requested address.
    140     EADDRNOTAVAIL,
    141     /// Network is down.
    142     ENETDOWN,
    143     /// Network is unreachable.
    144     ENETUNREACH,
    145     /// Network dropped connection on reset.
    146     ENETRESET,
    147     /// Software caused connection abort.
    148     ECONNABORTED,
    149     /// Connection reset by peer.
    150     ECONNRESET,
    151     /// No buffer space available.
    152     ENOBUFS,
    153     /// Socket is already connected.
    154     EISCONN,
    155     /// Socket is not connected.
    156     ENOTCONN,
    157     /// Can't send after socket shutdown.
    158     ESHUTDOWN,
    159     /// Too many references: can't splice.
    160     ETOOMANYREFS,
    161     /// Operation timed out.
    162     ETIMEDOUT,
    163     /// Connection refused.
    164     ECONNREFUSED,
    165     /// Too many levels of symbolic links.
    166     ELOOP,
    167     /// File name too long.
    168     ENAMETOOLONG,
    169     /// Host is down.
    170     EHOSTDOWN,
    171     /// No route to host.
    172     EHOSTUNREACH,
    173     /// Directory not empty.
    174     ENOTEMPTY,
    175     /// Too many processes.
    176     EPROCLIM,
    177     /// Too many users.
    178     EUSERS,
    179     /// Disk quota exceeded.
    180     EDQUOT,
    181     /// Stale NFS file handle.
    182     ESTALE,
    183     /// Too many levels of remote in path.
    184     EREMOTE,
    185     /// RPC struct is bad.
    186     EBADRPC,
    187     /// RPC version wrong.
    188     ERPCMISMATCH,
    189     /// RPC program not available.
    190     EPROGUNAVAIL,
    191     /// Program version wrong.
    192     EPROGMISMATCH,
    193     /// Bad procedure for program.
    194     EPROCUNAVAIL,
    195     /// No locks available.
    196     ENOLCK,
    197     /// Function not implemented.
    198     ENOSYS,
    199     /// Inappropriate file type or format.
    200     EFTYPE,
    201     /// Authentication error.
    202     EAUTH,
    203     /// Need authenticator.
    204     ENEEDAUTH,
    205     /// IPsec processing failure.
    206     #[expect(clippy::doc_markdown, reason = "false positive")]
    207     EIPSEC,
    208     /// Attribute not found.
    209     ENOATTR,
    210     /// Illegal byte sequence.
    211     EILSEQ,
    212     /// No medium found.
    213     ENOMEDIUM,
    214     /// Wrong medium type.
    215     EMEDIUMTYPE,
    216     /// Value too large to be stored in data type.
    217     EOVERFLOW,
    218     /// Operation canceled.
    219     ECANCELED,
    220     /// Identifier removed.
    221     EIDRM,
    222     /// No message of desired type.
    223     ENOMSG,
    224     /// Not supported.
    225     ENOTSUP,
    226     /// Bad message.
    227     EBADMSG,
    228     /// State not recoverable.
    229     ENOTRECOVERABLE,
    230     /// Previous owner died.
    231     EOWNERDEAD,
    232     /// Protocol error.
    233     EPROTO,
    234     /// Programming error.
    235     EDOOFUS,
    236     /// Multihop attempted.
    237     EMULTIHOP,
    238     /// Link has been severed.
    239     ENOLINK,
    240     /// Capabilities insufficient.
    241     ENOTCAPABLE,
    242     /// Not permitted in capability mode.
    243     ECAPMODE,
    244     /// Integrity check failed.
    245     EINTEGRITY,
    246     /// Channel number out of range.
    247     ECHRNG,
    248     /// Level 2 not synchronized.
    249     EL2NSYNC,
    250     /// Level 3 halted.
    251     EL3HLT,
    252     /// Level 3 reset.
    253     EL3RST,
    254     /// Link number out of range.
    255     ELNRNG,
    256     /// Protocol driver not attached.
    257     EUNATCH,
    258     /// No CSI structure available.
    259     ENOCSI,
    260     /// Level 2 halted.
    261     EL2HLT,
    262     /// Invalid exchange.
    263     EBADE,
    264     /// Invalid request descriptor.
    265     EBADR,
    266     /// Exchange full.
    267     EXFULL,
    268     /// No anode.
    269     ENOANO,
    270     /// Invalid request code.
    271     EBADRQC,
    272     /// Invalid slot.
    273     EBADSLT,
    274     /// Bad font file format.
    275     EBFONT,
    276     /// Device not a stream.
    277     ENOSTR,
    278     /// No data available.
    279     ENODATA,
    280     /// Timer expired.
    281     ETIME,
    282     /// Out of streams resources.
    283     ENOSR,
    284     /// Machine is not on the network.
    285     ENONET,
    286     /// Package not installed.
    287     ENOPKG,
    288     /// Advertise error.
    289     EADV,
    290     /// Srmount error.
    291     ESRMNT,
    292     /// Communication error on send.
    293     ECOMM,
    294     /// RFS specific error.
    295     EDOTDOT,
    296     /// Name not unique on network.
    297     ENOTUNIQ,
    298     /// File descriptor in bad state.
    299     EBADFD,
    300     /// Remote address changed.
    301     EREMCHG,
    302     /// Can not access a needed shared library.
    303     ELIBACC,
    304     /// Accessing a corrupted shared library.
    305     ELIBBAD,
    306     /// .lib section in a.out corrupted.
    307     ELIBSCN,
    308     /// Attempting to link in too many shared libraries.
    309     ELIBMAX,
    310     /// Cannot exec a shared library directly.
    311     ELIBEXEC,
    312     /// Interrupted system call should be restarted.
    313     ERESTART,
    314     /// Streams pipe error.
    315     ESTRPIPE,
    316     /// Structure needs cleaning.
    317     EUCLEAN,
    318     /// Not a XENIX named type file.
    319     ENOTNAM,
    320     /// No XENIX semaphores available.
    321     ENAVAIL,
    322     /// Is a named type file.
    323     EISNAM,
    324     /// Remote I/O error.
    325     EREMOTEIO,
    326     /// Required key not available.
    327     ENOKEY,
    328     /// Key has expired.
    329     EKEYEXPIRED,
    330     /// Key has been revoked.
    331     EKEYREVOKED,
    332     /// Key was rejected by service.
    333     EKEYREJECTED,
    334     /// Operation not possible due to RF-kill.
    335     ERFKILL,
    336     /// Memory page has hardware error.
    337     EHWPOISON,
    338     /// Device power is off.
    339     EPWROFF,
    340     /// Device error, e.g. paper out.
    341     EDEVERR,
    342     /// Bad executable.
    343     EBADEXEC,
    344     /// Bad CPU type in executable.
    345     EBADARCH,
    346     /// Shared library version mismatch.
    347     ESHLIBVERS,
    348     /// Malformed Macho file.
    349     EBADMACHO,
    350     /// No such policy registered.
    351     ENOPOLICY,
    352     /// Interface output queue is full.
    353     EQFULL,
    354     /// All other error codes.
    355     ///
    356     /// Note this is guaranteed to contain an error code that is not the same as any of the above
    357     /// variants.
    358     Other(OtherErrno),
    359 }
    360 impl Errno {
    361     /// Returns a `Self` equivalent to `code`.
    362     ///
    363     /// # Examples
    364     ///
    365     /// ```
    366     /// # use priv_sep::Errno;
    367     /// assert_eq!(Errno::from_raw(1), Errno::EPERM);
    368     /// ```
    369     #[expect(clippy::too_many_lines, reason = "large match expression")]
    370     #[inline]
    371     #[must_use]
    372     pub const fn from_raw(code: c_int) -> Self {
    373         #[cfg(target_os = "dragonfly")]
    374         match code {
    375             1 => Self::EPERM,
    376             2 => Self::ENOENT,
    377             3 => Self::ESRCH,
    378             4 => Self::EINTR,
    379             5 => Self::EIO,
    380             6 => Self::ENXIO,
    381             7 => Self::E2BIG,
    382             8 => Self::ENOEXEC,
    383             9 => Self::EBADF,
    384             10 => Self::ECHILD,
    385             11 => Self::EDEADLK,
    386             12 => Self::ENOMEM,
    387             13 => Self::EACCES,
    388             14 => Self::EFAULT,
    389             15 => Self::ENOTBLK,
    390             16 => Self::EBUSY,
    391             17 => Self::EEXIST,
    392             18 => Self::EXDEV,
    393             19 => Self::ENODEV,
    394             20 => Self::ENOTDIR,
    395             21 => Self::EISDIR,
    396             22 => Self::EINVAL,
    397             23 => Self::ENFILE,
    398             24 => Self::EMFILE,
    399             25 => Self::ENOTTY,
    400             26 => Self::ETXTBSY,
    401             27 => Self::EFBIG,
    402             28 => Self::ENOSPC,
    403             29 => Self::ESPIPE,
    404             30 => Self::EROFS,
    405             31 => Self::EMLINK,
    406             32 => Self::EPIPE,
    407             33 => Self::EDOM,
    408             34 => Self::ERANGE,
    409             35 => Self::EWOULDBLOCK,
    410             36 => Self::EINPROGRESS,
    411             37 => Self::EALREADY,
    412             38 => Self::ENOTSOCK,
    413             39 => Self::EDESTADDRREQ,
    414             40 => Self::EMSGSIZE,
    415             41 => Self::EPROTOTYPE,
    416             42 => Self::ENOPROTOOPT,
    417             43 => Self::EPROTONOSUPPORT,
    418             44 => Self::ESOCKTNOSUPPORT,
    419             45 => Self::EOPNOTSUPP,
    420             46 => Self::EPFNOSUPPORT,
    421             47 => Self::EAFNOSUPPORT,
    422             48 => Self::EADDRINUSE,
    423             49 => Self::EADDRNOTAVAIL,
    424             50 => Self::ENETDOWN,
    425             51 => Self::ENETUNREACH,
    426             52 => Self::ENETRESET,
    427             53 => Self::ECONNABORTED,
    428             54 => Self::ECONNRESET,
    429             55 => Self::ENOBUFS,
    430             56 => Self::EISCONN,
    431             57 => Self::ENOTCONN,
    432             58 => Self::ESHUTDOWN,
    433             59 => Self::ETOOMANYREFS,
    434             60 => Self::ETIMEDOUT,
    435             61 => Self::ECONNREFUSED,
    436             62 => Self::ELOOP,
    437             63 => Self::ENAMETOOLONG,
    438             64 => Self::EHOSTDOWN,
    439             65 => Self::EHOSTUNREACH,
    440             66 => Self::ENOTEMPTY,
    441             67 => Self::EPROCLIM,
    442             68 => Self::EUSERS,
    443             69 => Self::EDQUOT,
    444             70 => Self::ESTALE,
    445             71 => Self::EREMOTE,
    446             72 => Self::EBADRPC,
    447             73 => Self::ERPCMISMATCH,
    448             74 => Self::EPROGUNAVAIL,
    449             75 => Self::EPROGMISMATCH,
    450             76 => Self::EPROCUNAVAIL,
    451             77 => Self::ENOLCK,
    452             78 => Self::ENOSYS,
    453             79 => Self::EFTYPE,
    454             80 => Self::EAUTH,
    455             81 => Self::ENEEDAUTH,
    456             82 => Self::EIDRM,
    457             83 => Self::ENOMSG,
    458             84 => Self::EOVERFLOW,
    459             85 => Self::ECANCELED,
    460             86 => Self::EILSEQ,
    461             87 => Self::ENOATTR,
    462             88 => Self::EDOOFUS,
    463             89 => Self::EBADMSG,
    464             90 => Self::EMULTIHOP,
    465             91 => Self::ENOLINK,
    466             92 => Self::EPROTO,
    467             93 => Self::ENOMEDIUM,
    468             94 => Self::ENOTRECOVERABLE,
    469             95 => Self::EOWNERDEAD,
    470             _ => Self::Other(OtherErrno(code)),
    471         }
    472         #[cfg(target_os = "freebsd")]
    473         match code {
    474             1 => Self::EPERM,
    475             2 => Self::ENOENT,
    476             3 => Self::ESRCH,
    477             4 => Self::EINTR,
    478             5 => Self::EIO,
    479             6 => Self::ENXIO,
    480             7 => Self::E2BIG,
    481             8 => Self::ENOEXEC,
    482             9 => Self::EBADF,
    483             10 => Self::ECHILD,
    484             11 => Self::EDEADLK,
    485             12 => Self::ENOMEM,
    486             13 => Self::EACCES,
    487             14 => Self::EFAULT,
    488             15 => Self::ENOTBLK,
    489             16 => Self::EBUSY,
    490             17 => Self::EEXIST,
    491             18 => Self::EXDEV,
    492             19 => Self::ENODEV,
    493             20 => Self::ENOTDIR,
    494             21 => Self::EISDIR,
    495             22 => Self::EINVAL,
    496             23 => Self::ENFILE,
    497             24 => Self::EMFILE,
    498             25 => Self::ENOTTY,
    499             26 => Self::ETXTBSY,
    500             27 => Self::EFBIG,
    501             28 => Self::ENOSPC,
    502             29 => Self::ESPIPE,
    503             30 => Self::EROFS,
    504             31 => Self::EMLINK,
    505             32 => Self::EPIPE,
    506             33 => Self::EDOM,
    507             34 => Self::ERANGE,
    508             35 => Self::EWOULDBLOCK,
    509             36 => Self::EINPROGRESS,
    510             37 => Self::EALREADY,
    511             38 => Self::ENOTSOCK,
    512             39 => Self::EDESTADDRREQ,
    513             40 => Self::EMSGSIZE,
    514             41 => Self::EPROTOTYPE,
    515             42 => Self::ENOPROTOOPT,
    516             43 => Self::EPROTONOSUPPORT,
    517             44 => Self::ESOCKTNOSUPPORT,
    518             45 => Self::EOPNOTSUPP,
    519             46 => Self::EPFNOSUPPORT,
    520             47 => Self::EAFNOSUPPORT,
    521             48 => Self::EADDRINUSE,
    522             49 => Self::EADDRNOTAVAIL,
    523             50 => Self::ENETDOWN,
    524             51 => Self::ENETUNREACH,
    525             52 => Self::ENETRESET,
    526             53 => Self::ECONNABORTED,
    527             54 => Self::ECONNRESET,
    528             55 => Self::ENOBUFS,
    529             56 => Self::EISCONN,
    530             57 => Self::ENOTCONN,
    531             58 => Self::ESHUTDOWN,
    532             59 => Self::ETOOMANYREFS,
    533             60 => Self::ETIMEDOUT,
    534             61 => Self::ECONNREFUSED,
    535             62 => Self::ELOOP,
    536             63 => Self::ENAMETOOLONG,
    537             64 => Self::EHOSTDOWN,
    538             65 => Self::EHOSTUNREACH,
    539             66 => Self::ENOTEMPTY,
    540             67 => Self::EPROCLIM,
    541             68 => Self::EUSERS,
    542             69 => Self::EDQUOT,
    543             70 => Self::ESTALE,
    544             71 => Self::EREMOTE,
    545             72 => Self::EBADRPC,
    546             73 => Self::ERPCMISMATCH,
    547             74 => Self::EPROGUNAVAIL,
    548             75 => Self::EPROGMISMATCH,
    549             76 => Self::EPROCUNAVAIL,
    550             77 => Self::ENOLCK,
    551             78 => Self::ENOSYS,
    552             79 => Self::EFTYPE,
    553             80 => Self::EAUTH,
    554             81 => Self::ENEEDAUTH,
    555             82 => Self::EIDRM,
    556             83 => Self::ENOMSG,
    557             84 => Self::EOVERFLOW,
    558             85 => Self::ECANCELED,
    559             86 => Self::EILSEQ,
    560             87 => Self::ENOATTR,
    561             88 => Self::EDOOFUS,
    562             89 => Self::EBADMSG,
    563             90 => Self::EMULTIHOP,
    564             91 => Self::ENOLINK,
    565             92 => Self::EPROTO,
    566             93 => Self::ENOTCAPABLE,
    567             94 => Self::ECAPMODE,
    568             95 => Self::ENOTRECOVERABLE,
    569             96 => Self::EOWNERDEAD,
    570             97 => Self::EINTEGRITY,
    571             _ => Self::Other(OtherErrno(code)),
    572         }
    573         #[cfg(target_os = "macos")]
    574         match code {
    575             1 => Self::EPERM,
    576             2 => Self::ENOENT,
    577             3 => Self::ESRCH,
    578             4 => Self::EINTR,
    579             5 => Self::EIO,
    580             6 => Self::ENXIO,
    581             7 => Self::E2BIG,
    582             8 => Self::ENOEXEC,
    583             9 => Self::EBADF,
    584             10 => Self::ECHILD,
    585             11 => Self::EDEADLK,
    586             12 => Self::ENOMEM,
    587             13 => Self::EACCES,
    588             14 => Self::EFAULT,
    589             15 => Self::ENOTBLK,
    590             16 => Self::EBUSY,
    591             17 => Self::EEXIST,
    592             18 => Self::EXDEV,
    593             19 => Self::ENODEV,
    594             20 => Self::ENOTDIR,
    595             21 => Self::EISDIR,
    596             22 => Self::EINVAL,
    597             23 => Self::ENFILE,
    598             24 => Self::EMFILE,
    599             25 => Self::ENOTTY,
    600             26 => Self::ETXTBSY,
    601             27 => Self::EFBIG,
    602             28 => Self::ENOSPC,
    603             29 => Self::ESPIPE,
    604             30 => Self::EROFS,
    605             31 => Self::EMLINK,
    606             32 => Self::EPIPE,
    607             33 => Self::EDOM,
    608             34 => Self::ERANGE,
    609             35 => Self::EWOULDBLOCK,
    610             36 => Self::EINPROGRESS,
    611             37 => Self::EALREADY,
    612             38 => Self::ENOTSOCK,
    613             39 => Self::EDESTADDRREQ,
    614             40 => Self::EMSGSIZE,
    615             41 => Self::EPROTOTYPE,
    616             42 => Self::ENOPROTOOPT,
    617             43 => Self::EPROTONOSUPPORT,
    618             44 => Self::ESOCKTNOSUPPORT,
    619             45 => Self::ENOTSUP,
    620             46 => Self::EPFNOSUPPORT,
    621             47 => Self::EAFNOSUPPORT,
    622             48 => Self::EADDRINUSE,
    623             49 => Self::EADDRNOTAVAIL,
    624             50 => Self::ENETDOWN,
    625             51 => Self::ENETUNREACH,
    626             52 => Self::ENETRESET,
    627             53 => Self::ECONNABORTED,
    628             54 => Self::ECONNRESET,
    629             55 => Self::ENOBUFS,
    630             56 => Self::EISCONN,
    631             57 => Self::ENOTCONN,
    632             58 => Self::ESHUTDOWN,
    633             59 => Self::ETOOMANYREFS,
    634             60 => Self::ETIMEDOUT,
    635             61 => Self::ECONNREFUSED,
    636             62 => Self::ELOOP,
    637             63 => Self::ENAMETOOLONG,
    638             64 => Self::EHOSTDOWN,
    639             65 => Self::EHOSTUNREACH,
    640             66 => Self::ENOTEMPTY,
    641             67 => Self::EPROCLIM,
    642             68 => Self::EUSERS,
    643             69 => Self::EDQUOT,
    644             70 => Self::ESTALE,
    645             71 => Self::EREMOTE,
    646             72 => Self::EBADRPC,
    647             73 => Self::ERPCMISMATCH,
    648             74 => Self::EPROGUNAVAIL,
    649             75 => Self::EPROGMISMATCH,
    650             76 => Self::EPROCUNAVAIL,
    651             77 => Self::ENOLCK,
    652             78 => Self::ENOSYS,
    653             79 => Self::EFTYPE,
    654             80 => Self::EAUTH,
    655             81 => Self::ENEEDAUTH,
    656             82 => Self::EPWROFF,
    657             83 => Self::EDEVERR,
    658             84 => Self::EOVERFLOW,
    659             85 => Self::EBADEXEC,
    660             86 => Self::EBADARCH,
    661             87 => Self::ESHLIBVERS,
    662             88 => Self::EBADMACHO,
    663             89 => Self::ECANCELED,
    664             90 => Self::EIDRM,
    665             91 => Self::ENOMSG,
    666             92 => Self::EILSEQ,
    667             93 => Self::ENOATTR,
    668             94 => Self::EBADMSG,
    669             95 => Self::EMULTIHOP,
    670             96 => Self::ENODATA,
    671             97 => Self::ENOLINK,
    672             98 => Self::ENOSR,
    673             99 => Self::ENOSTR,
    674             100 => Self::EPROTO,
    675             101 => Self::ETIME,
    676             102 => Self::EOPNOTSUPP,
    677             103 => Self::ENOPOLICY,
    678             104 => Self::ENOTRECOVERABLE,
    679             105 => Self::EOWNERDEAD,
    680             106 => Self::EQFULL,
    681             _ => Self::Other(OtherErrno(code)),
    682         }
    683         #[cfg(target_os = "netbsd")]
    684         match code {
    685             1 => Self::EPERM,
    686             2 => Self::ENOENT,
    687             3 => Self::ESRCH,
    688             4 => Self::EINTR,
    689             5 => Self::EIO,
    690             6 => Self::ENXIO,
    691             7 => Self::E2BIG,
    692             8 => Self::ENOEXEC,
    693             9 => Self::EBADF,
    694             10 => Self::ECHILD,
    695             11 => Self::EDEADLK,
    696             12 => Self::ENOMEM,
    697             13 => Self::EACCES,
    698             14 => Self::EFAULT,
    699             15 => Self::ENOTBLK,
    700             16 => Self::EBUSY,
    701             17 => Self::EEXIST,
    702             18 => Self::EXDEV,
    703             19 => Self::ENODEV,
    704             20 => Self::ENOTDIR,
    705             21 => Self::EISDIR,
    706             22 => Self::EINVAL,
    707             23 => Self::ENFILE,
    708             24 => Self::EMFILE,
    709             25 => Self::ENOTTY,
    710             26 => Self::ETXTBSY,
    711             27 => Self::EFBIG,
    712             28 => Self::ENOSPC,
    713             29 => Self::ESPIPE,
    714             30 => Self::EROFS,
    715             31 => Self::EMLINK,
    716             32 => Self::EPIPE,
    717             33 => Self::EDOM,
    718             34 => Self::ERANGE,
    719             35 => Self::EWOULDBLOCK,
    720             36 => Self::EINPROGRESS,
    721             37 => Self::EALREADY,
    722             38 => Self::ENOTSOCK,
    723             39 => Self::EDESTADDRREQ,
    724             40 => Self::EMSGSIZE,
    725             41 => Self::EPROTOTYPE,
    726             42 => Self::ENOPROTOOPT,
    727             43 => Self::EPROTONOSUPPORT,
    728             44 => Self::ESOCKTNOSUPPORT,
    729             45 => Self::EOPNOTSUPP,
    730             46 => Self::EPFNOSUPPORT,
    731             47 => Self::EAFNOSUPPORT,
    732             48 => Self::EADDRINUSE,
    733             49 => Self::EADDRNOTAVAIL,
    734             50 => Self::ENETDOWN,
    735             51 => Self::ENETUNREACH,
    736             52 => Self::ENETRESET,
    737             53 => Self::ECONNABORTED,
    738             54 => Self::ECONNRESET,
    739             55 => Self::ENOBUFS,
    740             56 => Self::EISCONN,
    741             57 => Self::ENOTCONN,
    742             58 => Self::ESHUTDOWN,
    743             59 => Self::ETOOMANYREFS,
    744             60 => Self::ETIMEDOUT,
    745             61 => Self::ECONNREFUSED,
    746             62 => Self::ELOOP,
    747             63 => Self::ENAMETOOLONG,
    748             64 => Self::EHOSTDOWN,
    749             65 => Self::EHOSTUNREACH,
    750             66 => Self::ENOTEMPTY,
    751             67 => Self::EPROCLIM,
    752             68 => Self::EUSERS,
    753             69 => Self::EDQUOT,
    754             70 => Self::ESTALE,
    755             71 => Self::EREMOTE,
    756             72 => Self::EBADRPC,
    757             73 => Self::ERPCMISMATCH,
    758             74 => Self::EPROGUNAVAIL,
    759             75 => Self::EPROGMISMATCH,
    760             76 => Self::EPROCUNAVAIL,
    761             77 => Self::ENOLCK,
    762             78 => Self::ENOSYS,
    763             79 => Self::EFTYPE,
    764             80 => Self::EAUTH,
    765             81 => Self::ENEEDAUTH,
    766             82 => Self::EIDRM,
    767             83 => Self::ENOMSG,
    768             84 => Self::EOVERFLOW,
    769             85 => Self::EILSEQ,
    770             86 => Self::ENOTSUP,
    771             87 => Self::ECANCELED,
    772             88 => Self::EBADMSG,
    773             89 => Self::ENODATA,
    774             90 => Self::ENOSR,
    775             91 => Self::ENOSTR,
    776             92 => Self::ETIME,
    777             93 => Self::ENOATTR,
    778             94 => Self::EMULTIHOP,
    779             95 => Self::ENOLINK,
    780             96 => Self::EPROTO,
    781             97 => Self::EOWNERDEAD,
    782             98 => Self::ENOTRECOVERABLE,
    783             _ => Self::Other(OtherErrno(code)),
    784         }
    785         #[cfg(target_os = "openbsd")]
    786         match code {
    787             1 => Self::EPERM,
    788             2 => Self::ENOENT,
    789             3 => Self::ESRCH,
    790             4 => Self::EINTR,
    791             5 => Self::EIO,
    792             6 => Self::ENXIO,
    793             7 => Self::E2BIG,
    794             8 => Self::ENOEXEC,
    795             9 => Self::EBADF,
    796             10 => Self::ECHILD,
    797             11 => Self::EDEADLK,
    798             12 => Self::ENOMEM,
    799             13 => Self::EACCES,
    800             14 => Self::EFAULT,
    801             15 => Self::ENOTBLK,
    802             16 => Self::EBUSY,
    803             17 => Self::EEXIST,
    804             18 => Self::EXDEV,
    805             19 => Self::ENODEV,
    806             20 => Self::ENOTDIR,
    807             21 => Self::EISDIR,
    808             22 => Self::EINVAL,
    809             23 => Self::ENFILE,
    810             24 => Self::EMFILE,
    811             25 => Self::ENOTTY,
    812             26 => Self::ETXTBSY,
    813             27 => Self::EFBIG,
    814             28 => Self::ENOSPC,
    815             29 => Self::ESPIPE,
    816             30 => Self::EROFS,
    817             31 => Self::EMLINK,
    818             32 => Self::EPIPE,
    819             33 => Self::EDOM,
    820             34 => Self::ERANGE,
    821             35 => Self::EWOULDBLOCK,
    822             36 => Self::EINPROGRESS,
    823             37 => Self::EALREADY,
    824             38 => Self::ENOTSOCK,
    825             39 => Self::EDESTADDRREQ,
    826             40 => Self::EMSGSIZE,
    827             41 => Self::EPROTOTYPE,
    828             42 => Self::ENOPROTOOPT,
    829             43 => Self::EPROTONOSUPPORT,
    830             44 => Self::ESOCKTNOSUPPORT,
    831             45 => Self::EOPNOTSUPP,
    832             46 => Self::EPFNOSUPPORT,
    833             47 => Self::EAFNOSUPPORT,
    834             48 => Self::EADDRINUSE,
    835             49 => Self::EADDRNOTAVAIL,
    836             50 => Self::ENETDOWN,
    837             51 => Self::ENETUNREACH,
    838             52 => Self::ENETRESET,
    839             53 => Self::ECONNABORTED,
    840             54 => Self::ECONNRESET,
    841             55 => Self::ENOBUFS,
    842             56 => Self::EISCONN,
    843             57 => Self::ENOTCONN,
    844             58 => Self::ESHUTDOWN,
    845             59 => Self::ETOOMANYREFS,
    846             60 => Self::ETIMEDOUT,
    847             61 => Self::ECONNREFUSED,
    848             62 => Self::ELOOP,
    849             63 => Self::ENAMETOOLONG,
    850             64 => Self::EHOSTDOWN,
    851             65 => Self::EHOSTUNREACH,
    852             66 => Self::ENOTEMPTY,
    853             67 => Self::EPROCLIM,
    854             68 => Self::EUSERS,
    855             69 => Self::EDQUOT,
    856             70 => Self::ESTALE,
    857             71 => Self::EREMOTE,
    858             72 => Self::EBADRPC,
    859             73 => Self::ERPCMISMATCH,
    860             74 => Self::EPROGUNAVAIL,
    861             75 => Self::EPROGMISMATCH,
    862             76 => Self::EPROCUNAVAIL,
    863             77 => Self::ENOLCK,
    864             78 => Self::ENOSYS,
    865             79 => Self::EFTYPE,
    866             80 => Self::EAUTH,
    867             81 => Self::ENEEDAUTH,
    868             82 => Self::EIPSEC,
    869             83 => Self::ENOATTR,
    870             84 => Self::EILSEQ,
    871             85 => Self::ENOMEDIUM,
    872             86 => Self::EMEDIUMTYPE,
    873             87 => Self::EOVERFLOW,
    874             88 => Self::ECANCELED,
    875             89 => Self::EIDRM,
    876             90 => Self::ENOMSG,
    877             91 => Self::ENOTSUP,
    878             92 => Self::EBADMSG,
    879             93 => Self::ENOTRECOVERABLE,
    880             94 => Self::EOWNERDEAD,
    881             95 => Self::EPROTO,
    882             _ => Self::Other(OtherErrno(code)),
    883         }
    884         #[cfg(target_os = "linux")]
    885         match code {
    886             1 => Self::EPERM,
    887             2 => Self::ENOENT,
    888             3 => Self::ESRCH,
    889             4 => Self::EINTR,
    890             5 => Self::EIO,
    891             6 => Self::ENXIO,
    892             7 => Self::E2BIG,
    893             8 => Self::ENOEXEC,
    894             9 => Self::EBADF,
    895             10 => Self::ECHILD,
    896             11 => Self::EWOULDBLOCK,
    897             12 => Self::ENOMEM,
    898             13 => Self::EACCES,
    899             14 => Self::EFAULT,
    900             15 => Self::ENOTBLK,
    901             16 => Self::EBUSY,
    902             17 => Self::EEXIST,
    903             18 => Self::EXDEV,
    904             19 => Self::ENODEV,
    905             20 => Self::ENOTDIR,
    906             21 => Self::EISDIR,
    907             22 => Self::EINVAL,
    908             23 => Self::ENFILE,
    909             24 => Self::EMFILE,
    910             25 => Self::ENOTTY,
    911             26 => Self::ETXTBSY,
    912             27 => Self::EFBIG,
    913             28 => Self::ENOSPC,
    914             29 => Self::ESPIPE,
    915             30 => Self::EROFS,
    916             31 => Self::EMLINK,
    917             32 => Self::EPIPE,
    918             33 => Self::EDOM,
    919             34 => Self::ERANGE,
    920             35 => Self::EDEADLK,
    921             36 => Self::ENAMETOOLONG,
    922             37 => Self::ENOLCK,
    923             38 => Self::ENOSYS,
    924             39 => Self::ENOTEMPTY,
    925             40 => Self::ELOOP,
    926             42 => Self::ENOMSG,
    927             43 => Self::EIDRM,
    928             44 => Self::ECHRNG,
    929             45 => Self::EL2NSYNC,
    930             46 => Self::EL3HLT,
    931             47 => Self::EL3RST,
    932             48 => Self::ELNRNG,
    933             49 => Self::EUNATCH,
    934             50 => Self::ENOCSI,
    935             51 => Self::EL2HLT,
    936             52 => Self::EBADE,
    937             53 => Self::EBADR,
    938             54 => Self::EXFULL,
    939             55 => Self::ENOANO,
    940             56 => Self::EBADRQC,
    941             57 => Self::EBADSLT,
    942             59 => Self::EBFONT,
    943             60 => Self::ENOSTR,
    944             61 => Self::ENODATA,
    945             62 => Self::ETIME,
    946             63 => Self::ENOSR,
    947             64 => Self::ENONET,
    948             65 => Self::ENOPKG,
    949             66 => Self::EREMOTE,
    950             67 => Self::ENOLINK,
    951             68 => Self::EADV,
    952             69 => Self::ESRMNT,
    953             70 => Self::ECOMM,
    954             71 => Self::EPROTO,
    955             72 => Self::EMULTIHOP,
    956             73 => Self::EDOTDOT,
    957             74 => Self::EBADMSG,
    958             75 => Self::EOVERFLOW,
    959             76 => Self::ENOTUNIQ,
    960             77 => Self::EBADFD,
    961             78 => Self::EREMCHG,
    962             79 => Self::ELIBACC,
    963             80 => Self::ELIBBAD,
    964             81 => Self::ELIBSCN,
    965             82 => Self::ELIBMAX,
    966             83 => Self::ELIBEXEC,
    967             84 => Self::EILSEQ,
    968             85 => Self::ERESTART,
    969             86 => Self::ESTRPIPE,
    970             87 => Self::EUSERS,
    971             88 => Self::ENOTSOCK,
    972             89 => Self::EDESTADDRREQ,
    973             90 => Self::EMSGSIZE,
    974             91 => Self::EPROTOTYPE,
    975             92 => Self::ENOPROTOOPT,
    976             93 => Self::EPROTONOSUPPORT,
    977             94 => Self::ESOCKTNOSUPPORT,
    978             95 => Self::EOPNOTSUPP,
    979             96 => Self::EPFNOSUPPORT,
    980             97 => Self::EAFNOSUPPORT,
    981             98 => Self::EADDRINUSE,
    982             99 => Self::EADDRNOTAVAIL,
    983             100 => Self::ENETDOWN,
    984             101 => Self::ENETUNREACH,
    985             102 => Self::ENETRESET,
    986             103 => Self::ECONNABORTED,
    987             104 => Self::ECONNRESET,
    988             105 => Self::ENOBUFS,
    989             106 => Self::EISCONN,
    990             107 => Self::ENOTCONN,
    991             108 => Self::ESHUTDOWN,
    992             109 => Self::ETOOMANYREFS,
    993             110 => Self::ETIMEDOUT,
    994             111 => Self::ECONNREFUSED,
    995             112 => Self::EHOSTDOWN,
    996             113 => Self::EHOSTUNREACH,
    997             114 => Self::EALREADY,
    998             115 => Self::EINPROGRESS,
    999             116 => Self::ESTALE,
   1000             117 => Self::EUCLEAN,
   1001             118 => Self::ENOTNAM,
   1002             119 => Self::ENAVAIL,
   1003             120 => Self::EISNAM,
   1004             121 => Self::EREMOTEIO,
   1005             122 => Self::EDQUOT,
   1006             123 => Self::ENOMEDIUM,
   1007             124 => Self::EMEDIUMTYPE,
   1008             125 => Self::ECANCELED,
   1009             126 => Self::ENOKEY,
   1010             127 => Self::EKEYEXPIRED,
   1011             128 => Self::EKEYREVOKED,
   1012             129 => Self::EKEYREJECTED,
   1013             130 => Self::EOWNERDEAD,
   1014             131 => Self::ENOTRECOVERABLE,
   1015             132 => Self::ERFKILL,
   1016             133 => Self::EHWPOISON,
   1017             _ => Self::Other(OtherErrno(code)),
   1018         }
   1019     }
   1020     /// Returns the raw error code `self` is equivalent to.
   1021     ///
   1022     /// # Examples
   1023     ///
   1024     /// ```
   1025     /// # use priv_sep::Errno;
   1026     /// assert_eq!(Errno::EPERM.into_raw(), 1);
   1027     /// ```
   1028     #[expect(clippy::too_many_lines, reason = "large match expression")]
   1029     #[inline]
   1030     #[must_use]
   1031     pub const fn into_raw(self) -> c_int {
   1032         /// Essentially `unreachable` but `const`.
   1033         macro_rules! impossible {
   1034             () => {
   1035                 panic!("there is a bug in priv_sep::Errno. Impossible variant for the target.")
   1036             };
   1037         }
   1038         #[cfg(target_os = "dragonfly")]
   1039         match self {
   1040             Self::EPERM => 1,
   1041             Self::ENOENT => 2,
   1042             Self::ESRCH => 3,
   1043             Self::EINTR => 4,
   1044             Self::EIO => 5,
   1045             Self::ENXIO => 6,
   1046             Self::E2BIG => 7,
   1047             Self::ENOEXEC => 8,
   1048             Self::EBADF => 9,
   1049             Self::ECHILD => 10,
   1050             Self::EDEADLK => 11,
   1051             Self::ENOMEM => 12,
   1052             Self::EACCES => 13,
   1053             Self::EFAULT => 14,
   1054             Self::ENOTBLK => 15,
   1055             Self::EBUSY => 16,
   1056             Self::EEXIST => 17,
   1057             Self::EXDEV => 18,
   1058             Self::ENODEV => 19,
   1059             Self::ENOTDIR => 20,
   1060             Self::EISDIR => 21,
   1061             Self::EINVAL => 22,
   1062             Self::ENFILE => 23,
   1063             Self::EMFILE => 24,
   1064             Self::ENOTTY => 25,
   1065             Self::ETXTBSY => 26,
   1066             Self::EFBIG => 27,
   1067             Self::ENOSPC => 28,
   1068             Self::ESPIPE => 29,
   1069             Self::EROFS => 30,
   1070             Self::EMLINK => 31,
   1071             Self::EPIPE => 32,
   1072             Self::EDOM => 33,
   1073             Self::ERANGE => 34,
   1074             Self::EWOULDBLOCK => 35,
   1075             Self::EINPROGRESS => 36,
   1076             Self::EALREADY => 37,
   1077             Self::ENOTSOCK => 38,
   1078             Self::EDESTADDRREQ => 39,
   1079             Self::EMSGSIZE => 40,
   1080             Self::EPROTOTYPE => 41,
   1081             Self::ENOPROTOOPT => 42,
   1082             Self::EPROTONOSUPPORT => 43,
   1083             Self::ESOCKTNOSUPPORT => 44,
   1084             Self::EOPNOTSUPP => 45,
   1085             Self::EPFNOSUPPORT => 46,
   1086             Self::EAFNOSUPPORT => 47,
   1087             Self::EADDRINUSE => 48,
   1088             Self::EADDRNOTAVAIL => 49,
   1089             Self::ENETDOWN => 50,
   1090             Self::ENETUNREACH => 51,
   1091             Self::ENETRESET => 52,
   1092             Self::ECONNABORTED => 53,
   1093             Self::ECONNRESET => 54,
   1094             Self::ENOBUFS => 55,
   1095             Self::EISCONN => 56,
   1096             Self::ENOTCONN => 57,
   1097             Self::ESHUTDOWN => 58,
   1098             Self::ETOOMANYREFS => 59,
   1099             Self::ETIMEDOUT => 60,
   1100             Self::ECONNREFUSED => 61,
   1101             Self::ELOOP => 62,
   1102             Self::ENAMETOOLONG => 63,
   1103             Self::EHOSTDOWN => 64,
   1104             Self::EHOSTUNREACH => 65,
   1105             Self::ENOTEMPTY => 66,
   1106             Self::EPROCLIM => 67,
   1107             Self::EUSERS => 68,
   1108             Self::EDQUOT => 69,
   1109             Self::ESTALE => 70,
   1110             Self::EREMOTE => 71,
   1111             Self::EBADRPC => 72,
   1112             Self::ERPCMISMATCH => 73,
   1113             Self::EPROGUNAVAIL => 74,
   1114             Self::EPROGMISMATCH => 75,
   1115             Self::EPROCUNAVAIL => 76,
   1116             Self::ENOLCK => 77,
   1117             Self::ENOSYS => 78,
   1118             Self::EFTYPE => 79,
   1119             Self::EAUTH => 80,
   1120             Self::ENEEDAUTH => 81,
   1121             Self::EIDRM => 82,
   1122             Self::ENOMSG => 83,
   1123             Self::EOVERFLOW => 84,
   1124             Self::ECANCELED => 85,
   1125             Self::EILSEQ => 86,
   1126             Self::ENOATTR => 87,
   1127             Self::EDOOFUS => 88,
   1128             Self::EBADMSG => 89,
   1129             Self::EMULTIHOP => 90,
   1130             Self::ENOLINK => 91,
   1131             Self::EPROTO => 92,
   1132             Self::ENOMEDIUM => 93,
   1133             Self::ENOTRECOVERABLE => 94,
   1134             Self::EOWNERDEAD => 95,
   1135             Self::Other(OtherErrno(code)) => code,
   1136             Self::EIPSEC
   1137             | Self::EMEDIUMTYPE
   1138             | Self::ENOTSUP
   1139             | Self::ENOTCAPABLE
   1140             | Self::ECAPMODE
   1141             | Self::EINTEGRITY
   1142             | Self::ECHRNG
   1143             | Self::EL2NSYNC
   1144             | Self::EL3HLT
   1145             | Self::EL3RST
   1146             | Self::ELNRNG
   1147             | Self::EUNATCH
   1148             | Self::ENOCSI
   1149             | Self::EL2HLT
   1150             | Self::EBADE
   1151             | Self::EBADR
   1152             | Self::EXFULL
   1153             | Self::ENOANO
   1154             | Self::EBADRQC
   1155             | Self::EBADSLT
   1156             | Self::EBFONT
   1157             | Self::ENOSTR
   1158             | Self::ENODATA
   1159             | Self::ETIME
   1160             | Self::ENOSR
   1161             | Self::ENONET
   1162             | Self::ENOPKG
   1163             | Self::EADV
   1164             | Self::ESRMNT
   1165             | Self::ECOMM
   1166             | Self::EDOTDOT
   1167             | Self::ENOTUNIQ
   1168             | Self::EBADFD
   1169             | Self::EREMCHG
   1170             | Self::ELIBACC
   1171             | Self::ELIBBAD
   1172             | Self::ELIBSCN
   1173             | Self::ELIBMAX
   1174             | Self::ELIBEXEC
   1175             | Self::ERESTART
   1176             | Self::ESTRPIPE
   1177             | Self::EUCLEAN
   1178             | Self::ENOTNAM
   1179             | Self::ENAVAIL
   1180             | Self::EISNAM
   1181             | Self::EREMOTEIO
   1182             | Self::ENOKEY
   1183             | Self::EKEYEXPIRED
   1184             | Self::EKEYREVOKED
   1185             | Self::EKEYREJECTED
   1186             | Self::ERFKILL
   1187             | Self::EHWPOISON
   1188             | Self::EPWROFF
   1189             | Self::EDEVERR
   1190             | Self::EBADEXEC
   1191             | Self::EBADARCH
   1192             | Self::ESHLIBVERS
   1193             | Self::EBADMACHO
   1194             | Self::ENOPOLICY
   1195             | Self::EQFULL => impossible!(),
   1196         }
   1197         #[cfg(target_os = "freebsd")]
   1198         match self {
   1199             Self::EPERM => 1,
   1200             Self::ENOENT => 2,
   1201             Self::ESRCH => 3,
   1202             Self::EINTR => 4,
   1203             Self::EIO => 5,
   1204             Self::ENXIO => 6,
   1205             Self::E2BIG => 7,
   1206             Self::ENOEXEC => 8,
   1207             Self::EBADF => 9,
   1208             Self::ECHILD => 10,
   1209             Self::EDEADLK => 11,
   1210             Self::ENOMEM => 12,
   1211             Self::EACCES => 13,
   1212             Self::EFAULT => 14,
   1213             Self::ENOTBLK => 15,
   1214             Self::EBUSY => 16,
   1215             Self::EEXIST => 17,
   1216             Self::EXDEV => 18,
   1217             Self::ENODEV => 19,
   1218             Self::ENOTDIR => 20,
   1219             Self::EISDIR => 21,
   1220             Self::EINVAL => 22,
   1221             Self::ENFILE => 23,
   1222             Self::EMFILE => 24,
   1223             Self::ENOTTY => 25,
   1224             Self::ETXTBSY => 26,
   1225             Self::EFBIG => 27,
   1226             Self::ENOSPC => 28,
   1227             Self::ESPIPE => 29,
   1228             Self::EROFS => 30,
   1229             Self::EMLINK => 31,
   1230             Self::EPIPE => 32,
   1231             Self::EDOM => 33,
   1232             Self::ERANGE => 34,
   1233             Self::EWOULDBLOCK => 35,
   1234             Self::EINPROGRESS => 36,
   1235             Self::EALREADY => 37,
   1236             Self::ENOTSOCK => 38,
   1237             Self::EDESTADDRREQ => 39,
   1238             Self::EMSGSIZE => 40,
   1239             Self::EPROTOTYPE => 41,
   1240             Self::ENOPROTOOPT => 42,
   1241             Self::EPROTONOSUPPORT => 43,
   1242             Self::ESOCKTNOSUPPORT => 44,
   1243             Self::EOPNOTSUPP => 45,
   1244             Self::EPFNOSUPPORT => 46,
   1245             Self::EAFNOSUPPORT => 47,
   1246             Self::EADDRINUSE => 48,
   1247             Self::EADDRNOTAVAIL => 49,
   1248             Self::ENETDOWN => 50,
   1249             Self::ENETUNREACH => 51,
   1250             Self::ENETRESET => 52,
   1251             Self::ECONNABORTED => 53,
   1252             Self::ECONNRESET => 54,
   1253             Self::ENOBUFS => 55,
   1254             Self::EISCONN => 56,
   1255             Self::ENOTCONN => 57,
   1256             Self::ESHUTDOWN => 58,
   1257             Self::ETOOMANYREFS => 59,
   1258             Self::ETIMEDOUT => 60,
   1259             Self::ECONNREFUSED => 61,
   1260             Self::ELOOP => 62,
   1261             Self::ENAMETOOLONG => 63,
   1262             Self::EHOSTDOWN => 64,
   1263             Self::EHOSTUNREACH => 65,
   1264             Self::ENOTEMPTY => 66,
   1265             Self::EPROCLIM => 67,
   1266             Self::EUSERS => 68,
   1267             Self::EDQUOT => 69,
   1268             Self::ESTALE => 70,
   1269             Self::EREMOTE => 71,
   1270             Self::EBADRPC => 72,
   1271             Self::ERPCMISMATCH => 73,
   1272             Self::EPROGUNAVAIL => 74,
   1273             Self::EPROGMISMATCH => 75,
   1274             Self::EPROCUNAVAIL => 76,
   1275             Self::ENOLCK => 77,
   1276             Self::ENOSYS => 78,
   1277             Self::EFTYPE => 79,
   1278             Self::EAUTH => 80,
   1279             Self::ENEEDAUTH => 81,
   1280             Self::EIDRM => 82,
   1281             Self::ENOMSG => 83,
   1282             Self::EOVERFLOW => 84,
   1283             Self::ECANCELED => 85,
   1284             Self::EILSEQ => 86,
   1285             Self::ENOATTR => 87,
   1286             Self::EDOOFUS => 88,
   1287             Self::EBADMSG => 89,
   1288             Self::EMULTIHOP => 90,
   1289             Self::ENOLINK => 91,
   1290             Self::EPROTO => 92,
   1291             Self::ENOTCAPABLE => 93,
   1292             Self::ECAPMODE => 94,
   1293             Self::ENOTRECOVERABLE => 95,
   1294             Self::EOWNERDEAD => 96,
   1295             Self::EINTEGRITY => 97,
   1296             Self::Other(OtherErrno(code)) => code,
   1297             Self::EIPSEC
   1298             | Self::ENOMEDIUM
   1299             | Self::EMEDIUMTYPE
   1300             | Self::ENOTSUP
   1301             | Self::ECHRNG
   1302             | Self::EL2NSYNC
   1303             | Self::EL3HLT
   1304             | Self::EL3RST
   1305             | Self::ELNRNG
   1306             | Self::EUNATCH
   1307             | Self::ENOCSI
   1308             | Self::EL2HLT
   1309             | Self::EBADE
   1310             | Self::EBADR
   1311             | Self::EXFULL
   1312             | Self::ENOANO
   1313             | Self::EBADRQC
   1314             | Self::EBADSLT
   1315             | Self::EBFONT
   1316             | Self::ENOSTR
   1317             | Self::ENODATA
   1318             | Self::ETIME
   1319             | Self::ENOSR
   1320             | Self::ENONET
   1321             | Self::ENOPKG
   1322             | Self::EADV
   1323             | Self::ESRMNT
   1324             | Self::ECOMM
   1325             | Self::EDOTDOT
   1326             | Self::ENOTUNIQ
   1327             | Self::EBADFD
   1328             | Self::EREMCHG
   1329             | Self::ELIBACC
   1330             | Self::ELIBBAD
   1331             | Self::ELIBSCN
   1332             | Self::ELIBMAX
   1333             | Self::ELIBEXEC
   1334             | Self::ERESTART
   1335             | Self::ESTRPIPE
   1336             | Self::EUCLEAN
   1337             | Self::ENOTNAM
   1338             | Self::ENAVAIL
   1339             | Self::EISNAM
   1340             | Self::EREMOTEIO
   1341             | Self::ENOKEY
   1342             | Self::EKEYEXPIRED
   1343             | Self::EKEYREVOKED
   1344             | Self::EKEYREJECTED
   1345             | Self::ERFKILL
   1346             | Self::EHWPOISON
   1347             | Self::EPWROFF
   1348             | Self::EDEVERR
   1349             | Self::EBADEXEC
   1350             | Self::EBADARCH
   1351             | Self::ESHLIBVERS
   1352             | Self::EBADMACHO
   1353             | Self::ENOPOLICY
   1354             | Self::EQFULL => impossible!(),
   1355         }
   1356         #[cfg(target_os = "macos")]
   1357         match self {
   1358             Self::EPERM => 1,
   1359             Self::ENOENT => 2,
   1360             Self::ESRCH => 3,
   1361             Self::EINTR => 4,
   1362             Self::EIO => 5,
   1363             Self::ENXIO => 6,
   1364             Self::E2BIG => 7,
   1365             Self::ENOEXEC => 8,
   1366             Self::EBADF => 9,
   1367             Self::ECHILD => 10,
   1368             Self::EDEADLK => 11,
   1369             Self::ENOMEM => 12,
   1370             Self::EACCES => 13,
   1371             Self::EFAULT => 14,
   1372             Self::ENOTBLK => 15,
   1373             Self::EBUSY => 16,
   1374             Self::EEXIST => 17,
   1375             Self::EXDEV => 18,
   1376             Self::ENODEV => 19,
   1377             Self::ENOTDIR => 20,
   1378             Self::EISDIR => 21,
   1379             Self::EINVAL => 22,
   1380             Self::ENFILE => 23,
   1381             Self::EMFILE => 24,
   1382             Self::ENOTTY => 25,
   1383             Self::ETXTBSY => 26,
   1384             Self::EFBIG => 27,
   1385             Self::ENOSPC => 28,
   1386             Self::ESPIPE => 29,
   1387             Self::EROFS => 30,
   1388             Self::EMLINK => 31,
   1389             Self::EPIPE => 32,
   1390             Self::EDOM => 33,
   1391             Self::ERANGE => 34,
   1392             Self::EWOULDBLOCK => 35,
   1393             Self::EINPROGRESS => 36,
   1394             Self::EALREADY => 37,
   1395             Self::ENOTSOCK => 38,
   1396             Self::EDESTADDRREQ => 39,
   1397             Self::EMSGSIZE => 40,
   1398             Self::EPROTOTYPE => 41,
   1399             Self::ENOPROTOOPT => 42,
   1400             Self::EPROTONOSUPPORT => 43,
   1401             Self::ESOCKTNOSUPPORT => 44,
   1402             Self::ENOTSUP => 45,
   1403             Self::EPFNOSUPPORT => 46,
   1404             Self::EAFNOSUPPORT => 47,
   1405             Self::EADDRINUSE => 48,
   1406             Self::EADDRNOTAVAIL => 49,
   1407             Self::ENETDOWN => 50,
   1408             Self::ENETUNREACH => 51,
   1409             Self::ENETRESET => 52,
   1410             Self::ECONNABORTED => 53,
   1411             Self::ECONNRESET => 54,
   1412             Self::ENOBUFS => 55,
   1413             Self::EISCONN => 56,
   1414             Self::ENOTCONN => 57,
   1415             Self::ESHUTDOWN => 58,
   1416             Self::ETOOMANYREFS => 59,
   1417             Self::ETIMEDOUT => 60,
   1418             Self::ECONNREFUSED => 61,
   1419             Self::ELOOP => 62,
   1420             Self::ENAMETOOLONG => 63,
   1421             Self::EHOSTDOWN => 64,
   1422             Self::EHOSTUNREACH => 65,
   1423             Self::ENOTEMPTY => 66,
   1424             Self::EPROCLIM => 67,
   1425             Self::EUSERS => 68,
   1426             Self::EDQUOT => 69,
   1427             Self::ESTALE => 70,
   1428             Self::EREMOTE => 71,
   1429             Self::EBADRPC => 72,
   1430             Self::ERPCMISMATCH => 73,
   1431             Self::EPROGUNAVAIL => 74,
   1432             Self::EPROGMISMATCH => 75,
   1433             Self::EPROCUNAVAIL => 76,
   1434             Self::ENOLCK => 77,
   1435             Self::ENOSYS => 78,
   1436             Self::EFTYPE => 79,
   1437             Self::EAUTH => 80,
   1438             Self::ENEEDAUTH => 81,
   1439             Self::EPWROFF => 82,
   1440             Self::EDEVERR => 83,
   1441             Self::EOVERFLOW => 84,
   1442             Self::EBADEXEC => 85,
   1443             Self::EBADARCH => 86,
   1444             Self::ESHLIBVERS => 87,
   1445             Self::EBADMACHO => 88,
   1446             Self::ECANCELED => 89,
   1447             Self::EIDRM => 90,
   1448             Self::ENOMSG => 91,
   1449             Self::EILSEQ => 92,
   1450             Self::ENOATTR => 93,
   1451             Self::EBADMSG => 94,
   1452             Self::EMULTIHOP => 95,
   1453             Self::ENODATA => 96,
   1454             Self::ENOLINK => 97,
   1455             Self::ENOSR => 98,
   1456             Self::ENOSTR => 99,
   1457             Self::EPROTO => 100,
   1458             Self::ETIME => 101,
   1459             Self::EOPNOTSUPP => 102,
   1460             Self::ENOPOLICY => 103,
   1461             Self::ENOTRECOVERABLE => 104,
   1462             Self::EOWNERDEAD => 105,
   1463             Self::EQFULL => 106,
   1464             Self::Other(OtherErrno(code)) => code,
   1465             Self::EIPSEC
   1466             | Self::ENOMEDIUM
   1467             | Self::EMEDIUMTYPE
   1468             | Self::EDOOFUS
   1469             | Self::ENOTCAPABLE
   1470             | Self::ECAPMODE
   1471             | Self::EINTEGRITY
   1472             | Self::ECHRNG
   1473             | Self::EL2NSYNC
   1474             | Self::EL3HLT
   1475             | Self::EL3RST
   1476             | Self::ELNRNG
   1477             | Self::EUNATCH
   1478             | Self::ENOCSI
   1479             | Self::EL2HLT
   1480             | Self::EBADE
   1481             | Self::EBADR
   1482             | Self::EXFULL
   1483             | Self::ENOANO
   1484             | Self::EBADRQC
   1485             | Self::EBADSLT
   1486             | Self::EBFONT
   1487             | Self::ENONET
   1488             | Self::ENOPKG
   1489             | Self::EADV
   1490             | Self::ESRMNT
   1491             | Self::ECOMM
   1492             | Self::EDOTDOT
   1493             | Self::ENOTUNIQ
   1494             | Self::EBADFD
   1495             | Self::EREMCHG
   1496             | Self::ELIBACC
   1497             | Self::ELIBBAD
   1498             | Self::ELIBSCN
   1499             | Self::ELIBMAX
   1500             | Self::ELIBEXEC
   1501             | Self::ERESTART
   1502             | Self::ESTRPIPE
   1503             | Self::EUCLEAN
   1504             | Self::ENOTNAM
   1505             | Self::ENAVAIL
   1506             | Self::EISNAM
   1507             | Self::EREMOTEIO
   1508             | Self::ENOKEY
   1509             | Self::EKEYEXPIRED
   1510             | Self::EKEYREVOKED
   1511             | Self::EKEYREJECTED
   1512             | Self::ERFKILL
   1513             | Self::EHWPOISON => impossible!(),
   1514         }
   1515         #[cfg(target_os = "netbsd")]
   1516         match self {
   1517             Self::EPERM => 1,
   1518             Self::ENOENT => 2,
   1519             Self::ESRCH => 3,
   1520             Self::EINTR => 4,
   1521             Self::EIO => 5,
   1522             Self::ENXIO => 6,
   1523             Self::E2BIG => 7,
   1524             Self::ENOEXEC => 8,
   1525             Self::EBADF => 9,
   1526             Self::ECHILD => 10,
   1527             Self::EDEADLK => 11,
   1528             Self::ENOMEM => 12,
   1529             Self::EACCES => 13,
   1530             Self::EFAULT => 14,
   1531             Self::ENOTBLK => 15,
   1532             Self::EBUSY => 16,
   1533             Self::EEXIST => 17,
   1534             Self::EXDEV => 18,
   1535             Self::ENODEV => 19,
   1536             Self::ENOTDIR => 20,
   1537             Self::EISDIR => 21,
   1538             Self::EINVAL => 22,
   1539             Self::ENFILE => 23,
   1540             Self::EMFILE => 24,
   1541             Self::ENOTTY => 25,
   1542             Self::ETXTBSY => 26,
   1543             Self::EFBIG => 27,
   1544             Self::ENOSPC => 28,
   1545             Self::ESPIPE => 29,
   1546             Self::EROFS => 30,
   1547             Self::EMLINK => 31,
   1548             Self::EPIPE => 32,
   1549             Self::EDOM => 33,
   1550             Self::ERANGE => 34,
   1551             Self::EWOULDBLOCK => 35,
   1552             Self::EINPROGRESS => 36,
   1553             Self::EALREADY => 37,
   1554             Self::ENOTSOCK => 38,
   1555             Self::EDESTADDRREQ => 39,
   1556             Self::EMSGSIZE => 40,
   1557             Self::EPROTOTYPE => 41,
   1558             Self::ENOPROTOOPT => 42,
   1559             Self::EPROTONOSUPPORT => 43,
   1560             Self::ESOCKTNOSUPPORT => 44,
   1561             Self::EOPNOTSUPP => 45,
   1562             Self::EPFNOSUPPORT => 46,
   1563             Self::EAFNOSUPPORT => 47,
   1564             Self::EADDRINUSE => 48,
   1565             Self::EADDRNOTAVAIL => 49,
   1566             Self::ENETDOWN => 50,
   1567             Self::ENETUNREACH => 51,
   1568             Self::ENETRESET => 52,
   1569             Self::ECONNABORTED => 53,
   1570             Self::ECONNRESET => 54,
   1571             Self::ENOBUFS => 55,
   1572             Self::EISCONN => 56,
   1573             Self::ENOTCONN => 57,
   1574             Self::ESHUTDOWN => 58,
   1575             Self::ETOOMANYREFS => 59,
   1576             Self::ETIMEDOUT => 60,
   1577             Self::ECONNREFUSED => 61,
   1578             Self::ELOOP => 62,
   1579             Self::ENAMETOOLONG => 63,
   1580             Self::EHOSTDOWN => 64,
   1581             Self::EHOSTUNREACH => 65,
   1582             Self::ENOTEMPTY => 66,
   1583             Self::EPROCLIM => 67,
   1584             Self::EUSERS => 68,
   1585             Self::EDQUOT => 69,
   1586             Self::ESTALE => 70,
   1587             Self::EREMOTE => 71,
   1588             Self::EBADRPC => 72,
   1589             Self::ERPCMISMATCH => 73,
   1590             Self::EPROGUNAVAIL => 74,
   1591             Self::EPROGMISMATCH => 75,
   1592             Self::EPROCUNAVAIL => 76,
   1593             Self::ENOLCK => 77,
   1594             Self::ENOSYS => 78,
   1595             Self::EFTYPE => 79,
   1596             Self::EAUTH => 80,
   1597             Self::ENEEDAUTH => 81,
   1598             Self::EIDRM => 82,
   1599             Self::ENOMSG => 83,
   1600             Self::EOVERFLOW => 84,
   1601             Self::EILSEQ => 85,
   1602             Self::ENOTSUP => 86,
   1603             Self::ECANCELED => 87,
   1604             Self::EBADMSG => 88,
   1605             Self::ENODATA => 89,
   1606             Self::ENOSR => 90,
   1607             Self::ENOSTR => 91,
   1608             Self::ETIME => 92,
   1609             Self::ENOATTR => 93,
   1610             Self::EMULTIHOP => 94,
   1611             Self::ENOLINK => 95,
   1612             Self::EPROTO => 96,
   1613             Self::EOWNERDEAD => 97,
   1614             Self::ENOTRECOVERABLE => 98,
   1615             Self::Other(OtherErrno(code)) => code,
   1616             Self::EIPSEC
   1617             | Self::ENOMEDIUM
   1618             | Self::EMEDIUMTYPE
   1619             | Self::EDOOFUS
   1620             | Self::ENOTCAPABLE
   1621             | Self::ECAPMODE
   1622             | Self::EINTEGRITY
   1623             | Self::ECHRNG
   1624             | Self::EL2NSYNC
   1625             | Self::EL3HLT
   1626             | Self::EL3RST
   1627             | Self::ELNRNG
   1628             | Self::EUNATCH
   1629             | Self::ENOCSI
   1630             | Self::EL2HLT
   1631             | Self::EBADE
   1632             | Self::EBADR
   1633             | Self::EXFULL
   1634             | Self::ENOANO
   1635             | Self::EBADRQC
   1636             | Self::EBADSLT
   1637             | Self::EBFONT
   1638             | Self::ENONET
   1639             | Self::ENOPKG
   1640             | Self::EADV
   1641             | Self::ESRMNT
   1642             | Self::ECOMM
   1643             | Self::EDOTDOT
   1644             | Self::ENOTUNIQ
   1645             | Self::EBADFD
   1646             | Self::EREMCHG
   1647             | Self::ELIBACC
   1648             | Self::ELIBBAD
   1649             | Self::ELIBSCN
   1650             | Self::ELIBMAX
   1651             | Self::ELIBEXEC
   1652             | Self::ERESTART
   1653             | Self::ESTRPIPE
   1654             | Self::EUCLEAN
   1655             | Self::ENOTNAM
   1656             | Self::ENAVAIL
   1657             | Self::EISNAM
   1658             | Self::EREMOTEIO
   1659             | Self::ENOKEY
   1660             | Self::EKEYEXPIRED
   1661             | Self::EKEYREVOKED
   1662             | Self::EKEYREJECTED
   1663             | Self::ERFKILL
   1664             | Self::EHWPOISON
   1665             | Self::EPWROFF
   1666             | Self::EDEVERR
   1667             | Self::EBADEXEC
   1668             | Self::EBADARCH
   1669             | Self::ESHLIBVERS
   1670             | Self::EBADMACHO
   1671             | Self::ENOPOLICY
   1672             | Self::EQFULL => impossible!(),
   1673         }
   1674         #[cfg(target_os = "openbsd")]
   1675         match self {
   1676             Self::EPERM => 1,
   1677             Self::ENOENT => 2,
   1678             Self::ESRCH => 3,
   1679             Self::EINTR => 4,
   1680             Self::EIO => 5,
   1681             Self::ENXIO => 6,
   1682             Self::E2BIG => 7,
   1683             Self::ENOEXEC => 8,
   1684             Self::EBADF => 9,
   1685             Self::ECHILD => 10,
   1686             Self::EDEADLK => 11,
   1687             Self::ENOMEM => 12,
   1688             Self::EACCES => 13,
   1689             Self::EFAULT => 14,
   1690             Self::ENOTBLK => 15,
   1691             Self::EBUSY => 16,
   1692             Self::EEXIST => 17,
   1693             Self::EXDEV => 18,
   1694             Self::ENODEV => 19,
   1695             Self::ENOTDIR => 20,
   1696             Self::EISDIR => 21,
   1697             Self::EINVAL => 22,
   1698             Self::ENFILE => 23,
   1699             Self::EMFILE => 24,
   1700             Self::ENOTTY => 25,
   1701             Self::ETXTBSY => 26,
   1702             Self::EFBIG => 27,
   1703             Self::ENOSPC => 28,
   1704             Self::ESPIPE => 29,
   1705             Self::EROFS => 30,
   1706             Self::EMLINK => 31,
   1707             Self::EPIPE => 32,
   1708             Self::EDOM => 33,
   1709             Self::ERANGE => 34,
   1710             Self::EWOULDBLOCK => 35,
   1711             Self::EINPROGRESS => 36,
   1712             Self::EALREADY => 37,
   1713             Self::ENOTSOCK => 38,
   1714             Self::EDESTADDRREQ => 39,
   1715             Self::EMSGSIZE => 40,
   1716             Self::EPROTOTYPE => 41,
   1717             Self::ENOPROTOOPT => 42,
   1718             Self::EPROTONOSUPPORT => 43,
   1719             Self::ESOCKTNOSUPPORT => 44,
   1720             Self::EOPNOTSUPP => 45,
   1721             Self::EPFNOSUPPORT => 46,
   1722             Self::EAFNOSUPPORT => 47,
   1723             Self::EADDRINUSE => 48,
   1724             Self::EADDRNOTAVAIL => 49,
   1725             Self::ENETDOWN => 50,
   1726             Self::ENETUNREACH => 51,
   1727             Self::ENETRESET => 52,
   1728             Self::ECONNABORTED => 53,
   1729             Self::ECONNRESET => 54,
   1730             Self::ENOBUFS => 55,
   1731             Self::EISCONN => 56,
   1732             Self::ENOTCONN => 57,
   1733             Self::ESHUTDOWN => 58,
   1734             Self::ETOOMANYREFS => 59,
   1735             Self::ETIMEDOUT => 60,
   1736             Self::ECONNREFUSED => 61,
   1737             Self::ELOOP => 62,
   1738             Self::ENAMETOOLONG => 63,
   1739             Self::EHOSTDOWN => 64,
   1740             Self::EHOSTUNREACH => 65,
   1741             Self::ENOTEMPTY => 66,
   1742             Self::EPROCLIM => 67,
   1743             Self::EUSERS => 68,
   1744             Self::EDQUOT => 69,
   1745             Self::ESTALE => 70,
   1746             Self::EREMOTE => 71,
   1747             Self::EBADRPC => 72,
   1748             Self::ERPCMISMATCH => 73,
   1749             Self::EPROGUNAVAIL => 74,
   1750             Self::EPROGMISMATCH => 75,
   1751             Self::EPROCUNAVAIL => 76,
   1752             Self::ENOLCK => 77,
   1753             Self::ENOSYS => 78,
   1754             Self::EFTYPE => 79,
   1755             Self::EAUTH => 80,
   1756             Self::ENEEDAUTH => 81,
   1757             Self::EIPSEC => 82,
   1758             Self::ENOATTR => 83,
   1759             Self::EILSEQ => 84,
   1760             Self::ENOMEDIUM => 85,
   1761             Self::EMEDIUMTYPE => 86,
   1762             Self::EOVERFLOW => 87,
   1763             Self::ECANCELED => 88,
   1764             Self::EIDRM => 89,
   1765             Self::ENOMSG => 90,
   1766             Self::ENOTSUP => 91,
   1767             Self::EBADMSG => 92,
   1768             Self::ENOTRECOVERABLE => 93,
   1769             Self::EOWNERDEAD => 94,
   1770             Self::EPROTO => 95,
   1771             Self::Other(OtherErrno(code)) => code,
   1772             Self::EDOOFUS
   1773             | Self::EMULTIHOP
   1774             | Self::ENOLINK
   1775             | Self::ENOTCAPABLE
   1776             | Self::ECAPMODE
   1777             | Self::EINTEGRITY
   1778             | Self::ECHRNG
   1779             | Self::EL2NSYNC
   1780             | Self::EL3HLT
   1781             | Self::EL3RST
   1782             | Self::ELNRNG
   1783             | Self::EUNATCH
   1784             | Self::ENOCSI
   1785             | Self::EL2HLT
   1786             | Self::EBADE
   1787             | Self::EBADR
   1788             | Self::EXFULL
   1789             | Self::ENOANO
   1790             | Self::EBADRQC
   1791             | Self::EBADSLT
   1792             | Self::EBFONT
   1793             | Self::ENOSTR
   1794             | Self::ENODATA
   1795             | Self::ETIME
   1796             | Self::ENOSR
   1797             | Self::ENONET
   1798             | Self::ENOPKG
   1799             | Self::EADV
   1800             | Self::ESRMNT
   1801             | Self::ECOMM
   1802             | Self::EDOTDOT
   1803             | Self::ENOTUNIQ
   1804             | Self::EBADFD
   1805             | Self::EREMCHG
   1806             | Self::ELIBACC
   1807             | Self::ELIBBAD
   1808             | Self::ELIBSCN
   1809             | Self::ELIBMAX
   1810             | Self::ELIBEXEC
   1811             | Self::ERESTART
   1812             | Self::ESTRPIPE
   1813             | Self::EUCLEAN
   1814             | Self::ENOTNAM
   1815             | Self::ENAVAIL
   1816             | Self::EISNAM
   1817             | Self::EREMOTEIO
   1818             | Self::ENOKEY
   1819             | Self::EKEYEXPIRED
   1820             | Self::EKEYREVOKED
   1821             | Self::EKEYREJECTED
   1822             | Self::ERFKILL
   1823             | Self::EHWPOISON
   1824             | Self::EPWROFF
   1825             | Self::EDEVERR
   1826             | Self::EBADEXEC
   1827             | Self::EBADARCH
   1828             | Self::ESHLIBVERS
   1829             | Self::EBADMACHO
   1830             | Self::ENOPOLICY
   1831             | Self::EQFULL => impossible!(),
   1832         }
   1833         #[cfg(target_os = "linux")]
   1834         match self {
   1835             Self::EPERM => 1,
   1836             Self::ENOENT => 2,
   1837             Self::ESRCH => 3,
   1838             Self::EINTR => 4,
   1839             Self::EIO => 5,
   1840             Self::ENXIO => 6,
   1841             Self::E2BIG => 7,
   1842             Self::ENOEXEC => 8,
   1843             Self::EBADF => 9,
   1844             Self::ECHILD => 10,
   1845             Self::EWOULDBLOCK => 11,
   1846             Self::ENOMEM => 12,
   1847             Self::EACCES => 13,
   1848             Self::EFAULT => 14,
   1849             Self::ENOTBLK => 15,
   1850             Self::EBUSY => 16,
   1851             Self::EEXIST => 17,
   1852             Self::EXDEV => 18,
   1853             Self::ENODEV => 19,
   1854             Self::ENOTDIR => 20,
   1855             Self::EISDIR => 21,
   1856             Self::EINVAL => 22,
   1857             Self::ENFILE => 23,
   1858             Self::EMFILE => 24,
   1859             Self::ENOTTY => 25,
   1860             Self::ETXTBSY => 26,
   1861             Self::EFBIG => 27,
   1862             Self::ENOSPC => 28,
   1863             Self::ESPIPE => 29,
   1864             Self::EROFS => 30,
   1865             Self::EMLINK => 31,
   1866             Self::EPIPE => 32,
   1867             Self::EDOM => 33,
   1868             Self::ERANGE => 34,
   1869             Self::EDEADLK => 35,
   1870             Self::ENAMETOOLONG => 36,
   1871             Self::ENOLCK => 37,
   1872             Self::ENOSYS => 38,
   1873             Self::ENOTEMPTY => 39,
   1874             Self::ELOOP => 40,
   1875             Self::ENOMSG => 42,
   1876             Self::EIDRM => 43,
   1877             Self::ECHRNG => 44,
   1878             Self::EL2NSYNC => 45,
   1879             Self::EL3HLT => 46,
   1880             Self::EL3RST => 47,
   1881             Self::ELNRNG => 48,
   1882             Self::EUNATCH => 49,
   1883             Self::ENOCSI => 50,
   1884             Self::EL2HLT => 51,
   1885             Self::EBADE => 52,
   1886             Self::EBADR => 53,
   1887             Self::EXFULL => 54,
   1888             Self::ENOANO => 55,
   1889             Self::EBADRQC => 56,
   1890             Self::EBADSLT => 57,
   1891             Self::EBFONT => 59,
   1892             Self::ENOSTR => 60,
   1893             Self::ENODATA => 61,
   1894             Self::ETIME => 62,
   1895             Self::ENOSR => 63,
   1896             Self::ENONET => 64,
   1897             Self::ENOPKG => 65,
   1898             Self::EREMOTE => 66,
   1899             Self::ENOLINK => 67,
   1900             Self::EADV => 68,
   1901             Self::ESRMNT => 69,
   1902             Self::ECOMM => 70,
   1903             Self::EPROTO => 71,
   1904             Self::EMULTIHOP => 72,
   1905             Self::EDOTDOT => 73,
   1906             Self::EBADMSG => 74,
   1907             Self::EOVERFLOW => 75,
   1908             Self::ENOTUNIQ => 76,
   1909             Self::EBADFD => 77,
   1910             Self::EREMCHG => 78,
   1911             Self::ELIBACC => 79,
   1912             Self::ELIBBAD => 80,
   1913             Self::ELIBSCN => 81,
   1914             Self::ELIBMAX => 82,
   1915             Self::ELIBEXEC => 83,
   1916             Self::EILSEQ => 84,
   1917             Self::ERESTART => 85,
   1918             Self::ESTRPIPE => 86,
   1919             Self::EUSERS => 87,
   1920             Self::ENOTSOCK => 88,
   1921             Self::EDESTADDRREQ => 89,
   1922             Self::EMSGSIZE => 90,
   1923             Self::EPROTOTYPE => 91,
   1924             Self::ENOPROTOOPT => 92,
   1925             Self::EPROTONOSUPPORT => 93,
   1926             Self::ESOCKTNOSUPPORT => 94,
   1927             Self::EOPNOTSUPP => 95,
   1928             Self::EPFNOSUPPORT => 96,
   1929             Self::EAFNOSUPPORT => 97,
   1930             Self::EADDRINUSE => 98,
   1931             Self::EADDRNOTAVAIL => 99,
   1932             Self::ENETDOWN => 100,
   1933             Self::ENETUNREACH => 101,
   1934             Self::ENETRESET => 102,
   1935             Self::ECONNABORTED => 103,
   1936             Self::ECONNRESET => 104,
   1937             Self::ENOBUFS => 105,
   1938             Self::EISCONN => 106,
   1939             Self::ENOTCONN => 107,
   1940             Self::ESHUTDOWN => 108,
   1941             Self::ETOOMANYREFS => 109,
   1942             Self::ETIMEDOUT => 110,
   1943             Self::ECONNREFUSED => 111,
   1944             Self::EHOSTDOWN => 112,
   1945             Self::EHOSTUNREACH => 113,
   1946             Self::EALREADY => 114,
   1947             Self::EINPROGRESS => 115,
   1948             Self::ESTALE => 116,
   1949             Self::EUCLEAN => 117,
   1950             Self::ENOTNAM => 118,
   1951             Self::ENAVAIL => 119,
   1952             Self::EISNAM => 120,
   1953             Self::EREMOTEIO => 121,
   1954             Self::EDQUOT => 122,
   1955             Self::ENOMEDIUM => 123,
   1956             Self::EMEDIUMTYPE => 124,
   1957             Self::ECANCELED => 125,
   1958             Self::ENOKEY => 126,
   1959             Self::EKEYEXPIRED => 127,
   1960             Self::EKEYREVOKED => 128,
   1961             Self::EKEYREJECTED => 129,
   1962             Self::EOWNERDEAD => 130,
   1963             Self::ENOTRECOVERABLE => 131,
   1964             Self::ERFKILL => 132,
   1965             Self::EHWPOISON => 133,
   1966             Self::Other(OtherErrno(code)) => code,
   1967             Self::EPROCLIM
   1968             | Self::EBADRPC
   1969             | Self::ERPCMISMATCH
   1970             | Self::EPROGUNAVAIL
   1971             | Self::EPROGMISMATCH
   1972             | Self::EPROCUNAVAIL
   1973             | Self::EFTYPE
   1974             | Self::EAUTH
   1975             | Self::ENEEDAUTH
   1976             | Self::EIPSEC
   1977             | Self::ENOATTR
   1978             | Self::ENOTSUP
   1979             | Self::EDOOFUS
   1980             | Self::ENOTCAPABLE
   1981             | Self::ECAPMODE
   1982             | Self::EINTEGRITY
   1983             | Self::EPWROFF
   1984             | Self::EDEVERR
   1985             | Self::EBADEXEC
   1986             | Self::EBADARCH
   1987             | Self::ESHLIBVERS
   1988             | Self::EBADMACHO
   1989             | Self::ENOPOLICY
   1990             | Self::EQFULL => impossible!(),
   1991         }
   1992     }
   1993     /// Returns the error pointer.
   1994     #[expect(unsafe_code, reason = "safety comment justifies correctness")]
   1995     fn get_raw_err_ptr() -> *mut c_int {
   1996         #[cfg(any(target_os = "netbsd", target_os = "openbsd"))]
   1997         // SAFETY:
   1998         // Safe because errno is a thread-local variable.
   1999         unsafe {
   2000             c::__errno()
   2001         }
   2002         #[cfg(any(target_os = "freebsd", target_os = "macos"))]
   2003         // SAFETY:
   2004         // Safe because errno is a thread-local variable.
   2005         unsafe {
   2006             c::__error()
   2007         }
   2008         #[cfg(any(target_os = "dragonfly", target_os = "linux"))]
   2009         // SAFETY:
   2010         // Safe because errno is a thread-local variable.
   2011         unsafe {
   2012             c::__errno_location()
   2013         }
   2014     }
   2015     /// Sets the platform error to `self`.
   2016     ///
   2017     /// # Examples
   2018     ///
   2019     /// ```
   2020     /// # use priv_sep::Errno;
   2021     /// Errno::ENOENT.set();
   2022     /// ```
   2023     #[expect(unsafe_code, reason = "safety comment justifies correctness")]
   2024     #[inline]
   2025     pub fn set(self) {
   2026         let ptr = Self::get_raw_err_ptr();
   2027         debug_assert!(
   2028             !ptr.is_null() && ptr.is_aligned(),
   2029             "libc errno returned a pointer that was either null or not aligned. Something is terribly wrong with your system"
   2030         );
   2031         let code = self.into_raw();
   2032         // SAFETY:
   2033         // Verified above that `ptr` is not null and aligned. Note while we only verify
   2034         // this on non-release builds, the situation is so dire that one could argue we are
   2035         // already in "undefined" territory.
   2036         unsafe { *ptr = code };
   2037     }
   2038     /// Returns the current platform error.
   2039     ///
   2040     /// # Examples
   2041     ///
   2042     /// ```
   2043     /// # use priv_sep::Errno;
   2044     /// Errno::ENOENT.set();
   2045     /// assert_eq!(Errno::last(), Errno::ENOENT);
   2046     /// ```
   2047     #[expect(unsafe_code, reason = "safety comment justifies correctness")]
   2048     #[inline]
   2049     #[must_use]
   2050     pub fn last() -> Self {
   2051         let ptr = Self::get_raw_err_ptr();
   2052         debug_assert!(
   2053             !ptr.is_null() && ptr.is_aligned(),
   2054             "libc errno returned a pointer that was either null or not aligned. Something is terribly wrong with your system"
   2055         );
   2056         // SAFETY:
   2057         // Verified above that `ptr` is not null and aligned. Note while we only verify
   2058         // this on non-release builds, the situation is so dire that one could argue we are
   2059         // already in "undefined" territory.
   2060         Self::from_raw(unsafe { *ptr })
   2061     }
   2062     /// Clears any error.
   2063     ///
   2064     /// # Examples
   2065     ///
   2066     /// ```
   2067     /// # use priv_sep::Errno;
   2068     /// Errno::clear();
   2069     /// assert!(matches!(Errno::last(), Errno::Other(other) if other.into_raw() == 0));
   2070     /// ```
   2071     #[inline]
   2072     pub fn clear() {
   2073         Self::Other(OtherErrno(0)).set();
   2074     }
   2075 }
   2076 impl From<Errno> for c_int {
   2077     #[inline]
   2078     fn from(value: Errno) -> Self {
   2079         value.into_raw()
   2080     }
   2081 }
   2082 impl From<c_int> for Errno {
   2083     #[inline]
   2084     fn from(value: c_int) -> Self {
   2085         Self::from_raw(value)
   2086     }
   2087 }
   2088 impl Display for Errno {
   2089     #[expect(clippy::too_many_lines, reason = "large match expression")]
   2090     #[inline]
   2091     fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
   2092         match *self {
   2093             Self::EPERM => f.write_str("Operation not permitted"),
   2094             Self::ENOENT => f.write_str("No such file or directory"),
   2095             Self::ESRCH => f.write_str("No such process"),
   2096             Self::EINTR => f.write_str("Interrupted system call"),
   2097             Self::EIO => f.write_str("Input/output error"),
   2098             Self::ENXIO => f.write_str("Device not configured"),
   2099             Self::E2BIG => f.write_str("Argument list too long"),
   2100             Self::ENOEXEC => f.write_str("Exec format error"),
   2101             Self::EBADF => f.write_str("Bad file descriptor"),
   2102             Self::ECHILD => f.write_str("No child processes"),
   2103             Self::EDEADLK => f.write_str("Resource deadlock avoided"),
   2104             Self::ENOMEM => f.write_str("Cannot allocate memory"),
   2105             Self::EACCES => f.write_str("Permission denied"),
   2106             Self::EFAULT => f.write_str("Bad address"),
   2107             Self::ENOTBLK => f.write_str("Block device required"),
   2108             Self::EBUSY => f.write_str("Device busy"),
   2109             Self::EEXIST => f.write_str("File exists"),
   2110             Self::EXDEV => f.write_str("Cross-device link"),
   2111             Self::ENODEV => f.write_str("Operation not supported by device"),
   2112             Self::ENOTDIR => f.write_str("Not a directory"),
   2113             Self::EISDIR => f.write_str("Is a directory"),
   2114             Self::EINVAL => f.write_str("Invalid argument"),
   2115             Self::ENFILE => f.write_str("Too many open files in system"),
   2116             Self::EMFILE => f.write_str("Too many open files"),
   2117             Self::ENOTTY => f.write_str("Inappropriate ioctl for device"),
   2118             Self::ETXTBSY => f.write_str("Text file busy"),
   2119             Self::EFBIG => f.write_str("File too large"),
   2120             Self::ENOSPC => f.write_str("No space left on device"),
   2121             Self::ESPIPE => f.write_str("Illegal seek"),
   2122             Self::EROFS => f.write_str("Read-only file system"),
   2123             Self::EMLINK => f.write_str("Too many links"),
   2124             Self::EPIPE => f.write_str("Broken pipe"),
   2125             Self::EDOM => f.write_str("Numerical argument out of domain"),
   2126             Self::ERANGE => f.write_str("Result too large"),
   2127             Self::EWOULDBLOCK => f.write_str("Operation would block"),
   2128             Self::EINPROGRESS => f.write_str("Operation now in progress"),
   2129             Self::EALREADY => f.write_str("Operation already in progress"),
   2130             Self::ENOTSOCK => f.write_str("Socket operation on non-socket"),
   2131             Self::EDESTADDRREQ => f.write_str("Destination address required"),
   2132             Self::EMSGSIZE => f.write_str("Message too long"),
   2133             Self::EPROTOTYPE => f.write_str("Protocol wrong type for socket"),
   2134             Self::ENOPROTOOPT => f.write_str("Protocol not available"),
   2135             Self::EPROTONOSUPPORT => f.write_str("Protocol not supported"),
   2136             Self::ESOCKTNOSUPPORT => f.write_str("Socket type not supported"),
   2137             Self::EOPNOTSUPP => f.write_str("Operation not supported"),
   2138             Self::EPFNOSUPPORT => f.write_str("Protocol family not supported"),
   2139             Self::EAFNOSUPPORT => f.write_str("Address family not supported by protocol family"),
   2140             Self::EADDRINUSE => f.write_str("Address already in use"),
   2141             Self::EADDRNOTAVAIL => f.write_str("Can't assign requested address"),
   2142             Self::ENETDOWN => f.write_str("Network is down"),
   2143             Self::ENETUNREACH => f.write_str("Network is unreachable"),
   2144             Self::ENETRESET => f.write_str("Network dropped connection on reset"),
   2145             Self::ECONNABORTED => f.write_str("Software caused connection abort"),
   2146             Self::ECONNRESET => f.write_str("Connection reset by peer"),
   2147             Self::ENOBUFS => f.write_str("No buffer space available"),
   2148             Self::EISCONN => f.write_str("Socket is already connected"),
   2149             Self::ENOTCONN => f.write_str("Socket is not connected"),
   2150             Self::ESHUTDOWN => f.write_str("Can't send after socket shutdown"),
   2151             Self::ETOOMANYREFS => f.write_str("Too many references: can't splice"),
   2152             Self::ETIMEDOUT => f.write_str("Operation timed out"),
   2153             Self::ECONNREFUSED => f.write_str("Connection refused"),
   2154             Self::ELOOP => f.write_str("Too many levels of symbolic links"),
   2155             Self::ENAMETOOLONG => f.write_str("File name too long"),
   2156             Self::EHOSTDOWN => f.write_str("Host is down"),
   2157             Self::EHOSTUNREACH => f.write_str("No route to host"),
   2158             Self::ENOTEMPTY => f.write_str("Directory not empty"),
   2159             Self::EPROCLIM => f.write_str("Too many processes"),
   2160             Self::EUSERS => f.write_str("Too many users"),
   2161             Self::EDQUOT => f.write_str("Disk quota exceeded"),
   2162             Self::ESTALE => f.write_str("Stale NFS file handle"),
   2163             Self::EREMOTE => f.write_str("Too many levels of remote in path"),
   2164             Self::EBADRPC => f.write_str("RPC struct is bad"),
   2165             Self::ERPCMISMATCH => f.write_str("RPC version wrong"),
   2166             Self::EPROGUNAVAIL => f.write_str("RPC program not available"),
   2167             Self::EPROGMISMATCH => f.write_str("Program version wrong"),
   2168             Self::EPROCUNAVAIL => f.write_str("Bad procedure for program"),
   2169             Self::ENOLCK => f.write_str("No locks available"),
   2170             Self::ENOSYS => f.write_str("Function not implemented"),
   2171             Self::EFTYPE => f.write_str("Inappropriate file type or format"),
   2172             Self::EAUTH => f.write_str("Authentication error"),
   2173             Self::ENEEDAUTH => f.write_str("Need authenticator"),
   2174             Self::EIPSEC => f.write_str("IPsec processing failure"),
   2175             Self::ENOATTR => f.write_str("Attribute not found"),
   2176             Self::EILSEQ => f.write_str("Illegal byte sequence"),
   2177             Self::ENOMEDIUM => f.write_str("No medium found"),
   2178             Self::EMEDIUMTYPE => f.write_str("Wrong medium type"),
   2179             Self::EOVERFLOW => f.write_str("Value too large to be stored in data type"),
   2180             Self::ECANCELED => f.write_str("Operation canceled"),
   2181             Self::EIDRM => f.write_str("Identifier removed"),
   2182             Self::ENOMSG => f.write_str("No message of desired type"),
   2183             Self::ENOTSUP => f.write_str("Not supported"),
   2184             Self::EBADMSG => f.write_str("Bad message"),
   2185             Self::ENOTRECOVERABLE => f.write_str("State not recoverable"),
   2186             Self::EOWNERDEAD => f.write_str("Previous owner died"),
   2187             Self::EPROTO => f.write_str("Protocol error"),
   2188             Self::EDOOFUS => f.write_str("Programming error"),
   2189             Self::EMULTIHOP => f.write_str("Multihop attempted"),
   2190             Self::ENOLINK => f.write_str("Link has been severed"),
   2191             Self::ENOTCAPABLE => f.write_str("Capabilities insufficient"),
   2192             Self::ECAPMODE => f.write_str("Not permitted in capability mode"),
   2193             Self::EINTEGRITY => f.write_str("Integrity check failed"),
   2194             Self::ECHRNG => f.write_str("Channel number out of range"),
   2195             Self::EL2NSYNC => f.write_str("Level 2 not synchronized"),
   2196             Self::EL3HLT => f.write_str("Level 3 halted"),
   2197             Self::EL3RST => f.write_str("Level 3 reset"),
   2198             Self::ELNRNG => f.write_str("Link number out of range"),
   2199             Self::EUNATCH => f.write_str("Protocol driver not attached"),
   2200             Self::ENOCSI => f.write_str("No CSI structure available"),
   2201             Self::EL2HLT => f.write_str("Level 2 halted"),
   2202             Self::EBADE => f.write_str("Invalid exchange"),
   2203             Self::EBADR => f.write_str("Invalid request descriptor"),
   2204             Self::EXFULL => f.write_str("Exchange full"),
   2205             Self::ENOANO => f.write_str("No anode"),
   2206             Self::EBADRQC => f.write_str("Invalid request code"),
   2207             Self::EBADSLT => f.write_str("Invalid slot"),
   2208             Self::EBFONT => f.write_str("Bad font file format"),
   2209             Self::ENOSTR => f.write_str("Device not a stream"),
   2210             Self::ENODATA => f.write_str("No data available"),
   2211             Self::ETIME => f.write_str("Timer expired"),
   2212             Self::ENOSR => f.write_str("Out of streams resources"),
   2213             Self::ENONET => f.write_str("Machine is not on the network"),
   2214             Self::ENOPKG => f.write_str("Package not installed"),
   2215             Self::EADV => f.write_str("Advertise error"),
   2216             Self::ESRMNT => f.write_str("Srmount error"),
   2217             Self::ECOMM => f.write_str("Communication error on send"),
   2218             Self::EDOTDOT => f.write_str("RFS specific error"),
   2219             Self::ENOTUNIQ => f.write_str("Name not unique on network"),
   2220             Self::EBADFD => f.write_str("File descriptor in bad state"),
   2221             Self::EREMCHG => f.write_str("Remote address changed"),
   2222             Self::ELIBACC => f.write_str("Can not access a needed shared library"),
   2223             Self::ELIBBAD => f.write_str("Accessing a corrupted shared library"),
   2224             Self::ELIBSCN => f.write_str(".lib section in a.out corrupted"),
   2225             Self::ELIBMAX => f.write_str("Attempting to link in too many shared libraries"),
   2226             Self::ELIBEXEC => f.write_str("Cannot exec a shared library directly"),
   2227             Self::ERESTART => f.write_str("Interrupted system call should be restarted"),
   2228             Self::ESTRPIPE => f.write_str("Streams pipe error"),
   2229             Self::EUCLEAN => f.write_str("Structure needs cleaning"),
   2230             Self::ENOTNAM => f.write_str("Not a XENIX named type file"),
   2231             Self::ENAVAIL => f.write_str("No XENIX semaphores available"),
   2232             Self::EISNAM => f.write_str("Is a named type file"),
   2233             Self::EREMOTEIO => f.write_str("Remote I/O error"),
   2234             Self::ENOKEY => f.write_str("Required key not available"),
   2235             Self::EKEYEXPIRED => f.write_str("Key has expired"),
   2236             Self::EKEYREVOKED => f.write_str("Key has been revoked"),
   2237             Self::EKEYREJECTED => f.write_str("Key was rejected by service"),
   2238             Self::ERFKILL => f.write_str("Operation not possible due to RF-kill"),
   2239             Self::EHWPOISON => f.write_str("Memory page has hardware error"),
   2240             Self::EPWROFF => f.write_str("Device power is off"),
   2241             Self::EDEVERR => f.write_str("Device error, e.g. paper out"),
   2242             Self::EBADEXEC => f.write_str("Bad executable"),
   2243             Self::EBADARCH => f.write_str("Bad CPU type in executable"),
   2244             Self::ESHLIBVERS => f.write_str("Shared library version mismatch"),
   2245             Self::EBADMACHO => f.write_str("Malformed Macho file"),
   2246             Self::ENOPOLICY => f.write_str("No such policy registered"),
   2247             Self::EQFULL => f.write_str("Interface output queue is full"),
   2248             Self::Other(other) => write!(f, "Unknown error code: {}", other.0),
   2249         }
   2250     }
   2251 }
   2252 impl Error for Errno {}
   2253 #[cfg_attr(docsrs, doc(cfg(feature = "std")))]
   2254 #[cfg(feature = "std")]
   2255 impl From<Errno> for StdErr {
   2256     #[inline]
   2257     fn from(value: Errno) -> Self {
   2258         // All platforms we support have `RawOsError` as `c_int`; thus no conversion is needed.
   2259         Self::from_raw_os_error(value.into_raw())
   2260     }
   2261 }
   2262 #[cfg_attr(docsrs, doc(cfg(feature = "std")))]
   2263 #[cfg(feature = "std")]
   2264 impl TryFrom<StdErr> for Errno {
   2265     type Error = StdErr;
   2266     #[inline]
   2267     fn try_from(value: StdErr) -> Result<Self, Self::Error> {
   2268         // All platforms we support have `RawOsError` as `c_int`; thus no conversion is needed.
   2269         value.raw_os_error().ok_or(value).map(Self::from_raw)
   2270     }
   2271 }