nix/
errno.rs

1use cfg_if::cfg_if;
2use libc::{c_int, c_void};
3use std::convert::TryFrom;
4use std::{fmt, io, error};
5use crate::{Error, Result};
6
7pub use self::consts::*;
8
9cfg_if! {
10    if #[cfg(any(target_os = "freebsd",
11                 target_os = "ios",
12                 target_os = "macos"))] {
13        unsafe fn errno_location() -> *mut c_int {
14            libc::__error()
15        }
16    } else if #[cfg(any(target_os = "android",
17                        target_os = "netbsd",
18                        target_os = "openbsd"))] {
19        unsafe fn errno_location() -> *mut c_int {
20            libc::__errno()
21        }
22    } else if #[cfg(any(target_os = "linux",
23                        target_os = "redox",
24                        target_os = "dragonfly",
25                        target_os = "fuchsia"))] {
26        unsafe fn errno_location() -> *mut c_int {
27            libc::__errno_location()
28        }
29    } else if #[cfg(any(target_os = "illumos", target_os = "solaris"))] {
30        unsafe fn errno_location() -> *mut c_int {
31            libc::___errno()
32        }
33    }
34}
35
36/// Sets the platform-specific errno to no-error
37fn clear() {
38    // Safe because errno is a thread-local variable
39    unsafe {
40        *errno_location() = 0;
41    }
42}
43
44/// Returns the platform-specific value of errno
45pub fn errno() -> i32 {
46    unsafe { *errno_location() }
47}
48
49impl Errno {
50    /// Convert this `Error` to an [`Errno`](enum.Errno.html).
51    ///
52    /// # Example
53    ///
54    /// ```
55    /// # use nix::Error;
56    /// # use nix::errno::Errno;
57    /// let e = Error::from(Errno::EPERM);
58    /// assert_eq!(Some(Errno::EPERM), e.as_errno());
59    /// ```
60    #[deprecated(
61        since = "0.22.0",
62        note = "It's a no-op now; just delete it."
63    )]
64    pub const fn as_errno(self) -> Option<Self> {
65        Some(self)
66    }
67
68    /// Create a nix Error from a given errno
69    #[deprecated(
70        since = "0.22.0",
71        note = "It's a no-op now; just delete it."
72    )]
73    #[allow(clippy::wrong_self_convention)] // False positive
74    pub fn from_errno(errno: Errno) -> Error {
75        errno
76    }
77
78    /// Create a new invalid argument error (`EINVAL`)
79    #[deprecated(
80        since = "0.22.0",
81        note = "Use Errno::EINVAL instead"
82    )]
83    pub const fn invalid_argument() -> Error {
84        Errno::EINVAL
85    }
86
87    pub fn last() -> Self {
88        last()
89    }
90
91    pub fn desc(self) -> &'static str {
92        desc(self)
93    }
94
95    pub const fn from_i32(err: i32) -> Errno {
96        from_i32(err)
97    }
98
99    pub fn clear() {
100        clear()
101    }
102
103    /// Returns `Ok(value)` if it does not contain the sentinel value. This
104    /// should not be used when `-1` is not the errno sentinel value.
105    #[inline]
106    pub fn result<S: ErrnoSentinel + PartialEq<S>>(value: S) -> Result<S> {
107        if value == S::sentinel() {
108            Err(Self::last())
109        } else {
110            Ok(value)
111        }
112    }
113
114    /// Backwards compatibility hack for Nix <= 0.21.0 users
115    ///
116    /// In older versions of Nix, `Error::Sys` was an enum variant.  Now it's a
117    /// function, which is compatible with most of the former use cases of the
118    /// enum variant.  But you should use `Error(Errno::...)` instead.
119    #[deprecated(
120        since = "0.22.0",
121        note = "Use Errno::... instead"
122    )]
123    #[allow(non_snake_case)]
124    #[inline]
125    pub const fn Sys(errno: Errno) -> Error {
126        errno
127    }
128}
129
130/// The sentinel value indicates that a function failed and more detailed
131/// information about the error can be found in `errno`
132pub trait ErrnoSentinel: Sized {
133    fn sentinel() -> Self;
134}
135
136impl ErrnoSentinel for isize {
137    fn sentinel() -> Self { -1 }
138}
139
140impl ErrnoSentinel for i32 {
141    fn sentinel() -> Self { -1 }
142}
143
144impl ErrnoSentinel for i64 {
145    fn sentinel() -> Self { -1 }
146}
147
148impl ErrnoSentinel for *mut c_void {
149    fn sentinel() -> Self { -1isize as *mut c_void }
150}
151
152impl ErrnoSentinel for libc::sighandler_t {
153    fn sentinel() -> Self { libc::SIG_ERR }
154}
155
156impl error::Error for Errno {}
157
158impl fmt::Display for Errno {
159    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
160        write!(f, "{:?}: {}", self, self.desc())
161    }
162}
163
164impl From<Errno> for io::Error {
165    fn from(err: Errno) -> Self {
166        io::Error::from_raw_os_error(err as i32)
167    }
168}
169
170impl TryFrom<io::Error> for Errno {
171    type Error = io::Error;
172
173    fn try_from(ioerror: io::Error) -> std::result::Result<Self, io::Error> {
174        ioerror.raw_os_error()
175            .map(Errno::from_i32)
176            .ok_or(ioerror)
177    }
178}
179
180fn last() -> Errno {
181    Errno::from_i32(errno())
182}
183
184fn desc(errno: Errno) -> &'static str {
185    use self::Errno::*;
186    match errno {
187        UnknownErrno    => "Unknown errno",
188        EPERM           => "Operation not permitted",
189        ENOENT          => "No such file or directory",
190        ESRCH           => "No such process",
191        EINTR           => "Interrupted system call",
192        EIO             => "I/O error",
193        ENXIO           => "No such device or address",
194        E2BIG           => "Argument list too long",
195        ENOEXEC         => "Exec format error",
196        EBADF           => "Bad file number",
197        ECHILD          => "No child processes",
198        EAGAIN          => "Try again",
199        ENOMEM          => "Out of memory",
200        EACCES          => "Permission denied",
201        EFAULT          => "Bad address",
202        ENOTBLK         => "Block device required",
203        EBUSY           => "Device or resource busy",
204        EEXIST          => "File exists",
205        EXDEV           => "Cross-device link",
206        ENODEV          => "No such device",
207        ENOTDIR         => "Not a directory",
208        EISDIR          => "Is a directory",
209        EINVAL          => "Invalid argument",
210        ENFILE          => "File table overflow",
211        EMFILE          => "Too many open files",
212        ENOTTY          => "Not a typewriter",
213        ETXTBSY         => "Text file busy",
214        EFBIG           => "File too large",
215        ENOSPC          => "No space left on device",
216        ESPIPE          => "Illegal seek",
217        EROFS           => "Read-only file system",
218        EMLINK          => "Too many links",
219        EPIPE           => "Broken pipe",
220        EDOM            => "Math argument out of domain of func",
221        ERANGE          => "Math result not representable",
222        EDEADLK         => "Resource deadlock would occur",
223        ENAMETOOLONG    => "File name too long",
224        ENOLCK          => "No record locks available",
225        ENOSYS          => "Function not implemented",
226        ENOTEMPTY       => "Directory not empty",
227        ELOOP           => "Too many symbolic links encountered",
228        ENOMSG          => "No message of desired type",
229        EIDRM           => "Identifier removed",
230        EINPROGRESS     => "Operation now in progress",
231        EALREADY        => "Operation already in progress",
232        ENOTSOCK        => "Socket operation on non-socket",
233        EDESTADDRREQ    => "Destination address required",
234        EMSGSIZE        => "Message too long",
235        EPROTOTYPE      => "Protocol wrong type for socket",
236        ENOPROTOOPT     => "Protocol not available",
237        EPROTONOSUPPORT => "Protocol not supported",
238        ESOCKTNOSUPPORT => "Socket type not supported",
239        EPFNOSUPPORT    => "Protocol family not supported",
240        EAFNOSUPPORT    => "Address family not supported by protocol",
241        EADDRINUSE      => "Address already in use",
242        EADDRNOTAVAIL   => "Cannot assign requested address",
243        ENETDOWN        => "Network is down",
244        ENETUNREACH     => "Network is unreachable",
245        ENETRESET       => "Network dropped connection because of reset",
246        ECONNABORTED    => "Software caused connection abort",
247        ECONNRESET      => "Connection reset by peer",
248        ENOBUFS         => "No buffer space available",
249        EISCONN         => "Transport endpoint is already connected",
250        ENOTCONN        => "Transport endpoint is not connected",
251        ESHUTDOWN       => "Cannot send after transport endpoint shutdown",
252        ETOOMANYREFS    => "Too many references: cannot splice",
253        ETIMEDOUT       => "Connection timed out",
254        ECONNREFUSED    => "Connection refused",
255        EHOSTDOWN       => "Host is down",
256        EHOSTUNREACH    => "No route to host",
257
258        #[cfg(any(target_os = "linux", target_os = "android",
259                  target_os = "illumos", target_os = "solaris",
260                  target_os = "fuchsia"))]
261        ECHRNG          => "Channel number out of range",
262
263        #[cfg(any(target_os = "linux", target_os = "android",
264                  target_os = "illumos", target_os = "solaris",
265                  target_os = "fuchsia"))]
266        EL2NSYNC        => "Level 2 not synchronized",
267
268        #[cfg(any(target_os = "linux", target_os = "android",
269                  target_os = "illumos", target_os = "solaris",
270                  target_os = "fuchsia"))]
271        EL3HLT          => "Level 3 halted",
272
273        #[cfg(any(target_os = "linux", target_os = "android",
274                  target_os = "illumos", target_os = "solaris",
275                  target_os = "fuchsia"))]
276        EL3RST          => "Level 3 reset",
277
278        #[cfg(any(target_os = "linux", target_os = "android",
279                  target_os = "illumos", target_os = "solaris",
280                  target_os = "fuchsia"))]
281        ELNRNG          => "Link number out of range",
282
283        #[cfg(any(target_os = "linux", target_os = "android",
284                  target_os = "illumos", target_os = "solaris",
285                  target_os = "fuchsia"))]
286        EUNATCH         => "Protocol driver not attached",
287
288        #[cfg(any(target_os = "linux", target_os = "android",
289                  target_os = "illumos", target_os = "solaris",
290                  target_os = "fuchsia"))]
291        ENOCSI          => "No CSI structure available",
292
293        #[cfg(any(target_os = "linux", target_os = "android",
294                  target_os = "illumos", target_os = "solaris",
295                  target_os = "fuchsia"))]
296        EL2HLT          => "Level 2 halted",
297
298        #[cfg(any(target_os = "linux", target_os = "android",
299                  target_os = "illumos", target_os = "solaris",
300                  target_os = "fuchsia"))]
301        EBADE           => "Invalid exchange",
302
303        #[cfg(any(target_os = "linux", target_os = "android",
304                  target_os = "illumos", target_os = "solaris",
305                  target_os = "fuchsia"))]
306        EBADR           => "Invalid request descriptor",
307
308        #[cfg(any(target_os = "linux", target_os = "android",
309                  target_os = "illumos", target_os = "solaris",
310                  target_os = "fuchsia"))]
311        EXFULL          => "Exchange full",
312
313        #[cfg(any(target_os = "linux", target_os = "android",
314                  target_os = "illumos", target_os = "solaris",
315                  target_os = "fuchsia"))]
316        ENOANO          => "No anode",
317
318        #[cfg(any(target_os = "linux", target_os = "android",
319                  target_os = "illumos", target_os = "solaris",
320                  target_os = "fuchsia"))]
321        EBADRQC         => "Invalid request code",
322
323        #[cfg(any(target_os = "linux", target_os = "android",
324                  target_os = "illumos", target_os = "solaris",
325                  target_os = "fuchsia"))]
326        EBADSLT         => "Invalid slot",
327
328        #[cfg(any(target_os = "linux", target_os = "android",
329                  target_os = "illumos", target_os = "solaris",
330                  target_os = "fuchsia"))]
331        EBFONT          => "Bad font file format",
332
333        #[cfg(any(target_os = "linux", target_os = "android",
334                  target_os = "illumos", target_os = "solaris",
335                  target_os = "fuchsia"))]
336        ENOSTR          => "Device not a stream",
337
338        #[cfg(any(target_os = "linux", target_os = "android",
339                  target_os = "illumos", target_os = "solaris",
340                  target_os = "fuchsia"))]
341        ENODATA         => "No data available",
342
343        #[cfg(any(target_os = "linux", target_os = "android",
344                  target_os = "illumos", target_os = "solaris",
345                  target_os = "fuchsia"))]
346        ETIME           => "Timer expired",
347
348        #[cfg(any(target_os = "linux", target_os = "android",
349                  target_os = "illumos", target_os = "solaris",
350                  target_os = "fuchsia"))]
351        ENOSR           => "Out of streams resources",
352
353        #[cfg(any(target_os = "linux", target_os = "android",
354                  target_os = "illumos", target_os = "solaris",
355                  target_os = "fuchsia"))]
356        ENONET          => "Machine is not on the network",
357
358        #[cfg(any(target_os = "linux", target_os = "android",
359                  target_os = "illumos", target_os = "solaris",
360                  target_os = "fuchsia"))]
361        ENOPKG          => "Package not installed",
362
363        #[cfg(any(target_os = "linux", target_os = "android",
364                  target_os = "illumos", target_os = "solaris",
365                  target_os = "fuchsia"))]
366        EREMOTE         => "Object is remote",
367
368        #[cfg(any(target_os = "linux", target_os = "android",
369                  target_os = "illumos", target_os = "solaris",
370                  target_os = "fuchsia"))]
371        ENOLINK         => "Link has been severed",
372
373        #[cfg(any(target_os = "linux", target_os = "android",
374                  target_os = "illumos", target_os = "solaris",
375                  target_os = "fuchsia"))]
376        EADV            => "Advertise error",
377
378        #[cfg(any(target_os = "linux", target_os = "android",
379                  target_os = "illumos", target_os = "solaris",
380                  target_os = "fuchsia"))]
381        ESRMNT          => "Srmount error",
382
383        #[cfg(any(target_os = "linux", target_os = "android",
384                  target_os = "illumos", target_os = "solaris",
385                  target_os = "fuchsia"))]
386        ECOMM           => "Communication error on send",
387
388        #[cfg(any(target_os = "linux", target_os = "android",
389                  target_os = "illumos", target_os = "solaris",
390                  target_os = "fuchsia"))]
391        EPROTO          => "Protocol error",
392
393        #[cfg(any(target_os = "linux", target_os = "android",
394                  target_os = "illumos", target_os = "solaris",
395                  target_os = "fuchsia"))]
396        EMULTIHOP       => "Multihop attempted",
397
398        #[cfg(any(target_os = "linux", target_os = "android",
399                  target_os = "fuchsia"))]
400        EDOTDOT         => "RFS specific error",
401
402        #[cfg(any(target_os = "linux", target_os = "android",
403                  target_os = "fuchsia"))]
404        EBADMSG         => "Not a data message",
405
406        #[cfg(any(target_os = "illumos", target_os = "solaris"))]
407        EBADMSG         => "Trying to read unreadable message",
408
409        #[cfg(any(target_os = "linux", target_os = "android",
410                  target_os = "fuchsia"))]
411        EOVERFLOW       => "Value too large for defined data type",
412
413        #[cfg(any(target_os = "linux", target_os = "android",
414                  target_os = "illumos", target_os = "solaris",
415                  target_os = "fuchsia"))]
416        ENOTUNIQ        => "Name not unique on network",
417
418        #[cfg(any(target_os = "linux", target_os = "android",
419                  target_os = "illumos", target_os = "solaris",
420                  target_os = "fuchsia"))]
421        EBADFD          => "File descriptor in bad state",
422
423        #[cfg(any(target_os = "linux", target_os = "android",
424                  target_os = "illumos", target_os = "solaris",
425                  target_os = "fuchsia"))]
426        EREMCHG         => "Remote address changed",
427
428        #[cfg(any(target_os = "linux", target_os = "android",
429                  target_os = "illumos", target_os = "solaris",
430                  target_os = "fuchsia"))]
431        ELIBACC         => "Can not access a needed shared library",
432
433        #[cfg(any(target_os = "linux", target_os = "android",
434                  target_os = "illumos", target_os = "solaris",
435                  target_os = "fuchsia"))]
436        ELIBBAD         => "Accessing a corrupted shared library",
437
438        #[cfg(any(target_os = "linux", target_os = "android",
439                  target_os = "illumos", target_os = "solaris",
440                  target_os = "fuchsia"))]
441        ELIBSCN         => ".lib section in a.out corrupted",
442
443        #[cfg(any(target_os = "linux", target_os = "android",
444                  target_os = "illumos", target_os = "solaris",
445                  target_os = "fuchsia"))]
446        ELIBMAX         => "Attempting to link in too many shared libraries",
447
448        #[cfg(any(target_os = "linux", target_os = "android",
449                  target_os = "illumos", target_os = "solaris",
450                  target_os = "fuchsia"))]
451        ELIBEXEC        => "Cannot exec a shared library directly",
452
453        #[cfg(any(target_os = "linux", target_os = "android",
454                  target_os = "illumos", target_os = "solaris",
455                  target_os = "fuchsia", target_os = "openbsd"))]
456        EILSEQ          => "Illegal byte sequence",
457
458        #[cfg(any(target_os = "linux", target_os = "android",
459                  target_os = "illumos", target_os = "solaris",
460                  target_os = "fuchsia"))]
461        ERESTART        => "Interrupted system call should be restarted",
462
463        #[cfg(any(target_os = "linux", target_os = "android",
464                  target_os = "illumos", target_os = "solaris",
465                  target_os = "fuchsia"))]
466        ESTRPIPE        => "Streams pipe error",
467
468        #[cfg(any(target_os = "linux", target_os = "android",
469                  target_os = "illumos", target_os = "solaris",
470                  target_os = "fuchsia"))]
471        EUSERS          => "Too many users",
472
473        #[cfg(any(target_os = "linux", target_os = "android",
474                  target_os = "fuchsia", target_os = "netbsd",
475                  target_os = "redox"))]
476        EOPNOTSUPP      => "Operation not supported on transport endpoint",
477
478        #[cfg(any(target_os = "linux", target_os = "android",
479                  target_os = "fuchsia"))]
480        ESTALE          => "Stale file handle",
481
482        #[cfg(any(target_os = "linux", target_os = "android",
483                  target_os = "fuchsia"))]
484        EUCLEAN         => "Structure needs cleaning",
485
486        #[cfg(any(target_os = "linux", target_os = "android",
487                  target_os = "fuchsia"))]
488        ENOTNAM         => "Not a XENIX named type file",
489
490        #[cfg(any(target_os = "linux", target_os = "android",
491                  target_os = "fuchsia"))]
492        ENAVAIL         => "No XENIX semaphores available",
493
494        #[cfg(any(target_os = "linux", target_os = "android",
495                  target_os = "fuchsia"))]
496        EISNAM          => "Is a named type file",
497
498        #[cfg(any(target_os = "linux", target_os = "android",
499                  target_os = "fuchsia"))]
500        EREMOTEIO       => "Remote I/O error",
501
502        #[cfg(any(target_os = "linux", target_os = "android",
503                  target_os = "fuchsia"))]
504        EDQUOT          => "Quota exceeded",
505
506        #[cfg(any(target_os = "linux", target_os = "android",
507                  target_os = "fuchsia", target_os = "openbsd",
508                  target_os = "dragonfly"))]
509        ENOMEDIUM       => "No medium found",
510
511        #[cfg(any(target_os = "linux", target_os = "android",
512                  target_os = "fuchsia", target_os = "openbsd"))]
513        EMEDIUMTYPE     => "Wrong medium type",
514
515        #[cfg(any(target_os = "linux", target_os = "android",
516                  target_os = "illumos", target_os = "solaris",
517                  target_os = "fuchsia"))]
518        ECANCELED       => "Operation canceled",
519
520        #[cfg(any(target_os = "linux", target_os = "android",
521                  target_os = "fuchsia"))]
522        ENOKEY          => "Required key not available",
523
524        #[cfg(any(target_os = "linux", target_os = "android",
525                  target_os = "fuchsia"))]
526        EKEYEXPIRED     => "Key has expired",
527
528        #[cfg(any(target_os = "linux", target_os = "android",
529                  target_os = "fuchsia"))]
530        EKEYREVOKED     => "Key has been revoked",
531
532        #[cfg(any(target_os = "linux", target_os = "android",
533                  target_os = "fuchsia"))]
534        EKEYREJECTED    => "Key was rejected by service",
535
536        #[cfg(any(target_os = "linux", target_os = "android",
537                  target_os = "fuchsia"))]
538        EOWNERDEAD      => "Owner died",
539
540        #[cfg(any( target_os = "illumos", target_os = "solaris"))]
541        EOWNERDEAD      => "Process died with lock",
542
543        #[cfg(any(target_os = "linux", target_os = "android",
544                  target_os = "fuchsia"))]
545        ENOTRECOVERABLE => "State not recoverable",
546
547        #[cfg(any(target_os = "illumos", target_os = "solaris"))]
548        ENOTRECOVERABLE => "Lock is not recoverable",
549
550        #[cfg(any(all(target_os = "linux", not(target_arch="mips")),
551                  target_os = "fuchsia"))]
552        ERFKILL         => "Operation not possible due to RF-kill",
553
554        #[cfg(any(all(target_os = "linux", not(target_arch="mips")),
555                  target_os = "fuchsia"))]
556        EHWPOISON       => "Memory page has hardware error",
557
558        #[cfg(any(target_os = "freebsd", target_os = "dragonfly"))]
559        EDOOFUS         => "Programming error",
560
561        #[cfg(any(target_os = "freebsd", target_os = "dragonfly", target_os = "redox"))]
562        EMULTIHOP       => "Multihop attempted",
563
564        #[cfg(any(target_os = "freebsd", target_os = "dragonfly",
565                  target_os = "redox"))]
566        ENOLINK         => "Link has been severed",
567
568        #[cfg(target_os = "freebsd")]
569        ENOTCAPABLE     => "Capabilities insufficient",
570
571        #[cfg(target_os = "freebsd")]
572        ECAPMODE        => "Not permitted in capability mode",
573
574        #[cfg(any(target_os = "macos", target_os = "freebsd",
575                  target_os = "dragonfly", target_os = "ios",
576                  target_os = "openbsd", target_os = "netbsd"))]
577        ENEEDAUTH       => "Need authenticator",
578
579        #[cfg(any(target_os = "macos", target_os = "freebsd",
580                  target_os = "dragonfly", target_os = "ios",
581                  target_os = "openbsd", target_os = "netbsd",
582                  target_os = "redox", target_os = "illumos",
583                  target_os = "solaris"))]
584        EOVERFLOW       => "Value too large to be stored in data type",
585
586        #[cfg(any(target_os = "macos", target_os = "freebsd",
587                  target_os = "dragonfly", target_os = "ios",
588                  target_os = "netbsd", target_os = "redox"))]
589        EILSEQ          => "Illegal byte sequence",
590
591        #[cfg(any(target_os = "macos", target_os = "freebsd",
592                  target_os = "dragonfly", target_os = "ios",
593                  target_os = "openbsd", target_os = "netbsd"))]
594        ENOATTR         => "Attribute not found",
595
596        #[cfg(any(target_os = "macos", target_os = "freebsd",
597                  target_os = "dragonfly", target_os = "ios",
598                  target_os = "openbsd", target_os = "netbsd",
599                  target_os = "redox"))]
600        EBADMSG         => "Bad message",
601
602        #[cfg(any(target_os = "macos", target_os = "freebsd",
603                  target_os = "dragonfly", target_os = "ios",
604                  target_os = "openbsd", target_os = "netbsd",
605                  target_os = "redox"))]
606        EPROTO          => "Protocol error",
607
608        #[cfg(any(target_os = "macos", target_os = "freebsd",
609                  target_os = "dragonfly", target_os = "ios",
610                  target_os = "openbsd"))]
611        ENOTRECOVERABLE => "State not recoverable",
612
613        #[cfg(any(target_os = "macos", target_os = "freebsd",
614                  target_os = "dragonfly", target_os = "ios",
615                  target_os = "openbsd"))]
616        EOWNERDEAD      => "Previous owner died",
617
618        #[cfg(any(target_os = "macos", target_os = "freebsd",
619                  target_os = "dragonfly", target_os = "ios",
620                  target_os = "openbsd", target_os = "netbsd",
621                  target_os = "illumos", target_os = "solaris"))]
622        ENOTSUP         => "Operation not supported",
623
624        #[cfg(any(target_os = "macos", target_os = "freebsd",
625                  target_os = "dragonfly", target_os = "ios",
626                  target_os = "openbsd", target_os = "netbsd"))]
627        EPROCLIM        => "Too many processes",
628
629        #[cfg(any(target_os = "macos", target_os = "freebsd",
630                  target_os = "dragonfly", target_os = "ios",
631                  target_os = "openbsd", target_os = "netbsd",
632                  target_os = "redox"))]
633        EUSERS          => "Too many users",
634
635        #[cfg(any(target_os = "macos", target_os = "freebsd",
636                  target_os = "dragonfly", target_os = "ios",
637                  target_os = "openbsd", target_os = "netbsd",
638                  target_os = "redox", target_os = "illumos",
639                  target_os = "solaris"))]
640        EDQUOT          => "Disc quota exceeded",
641
642        #[cfg(any(target_os = "macos", target_os = "freebsd",
643                  target_os = "dragonfly", target_os = "ios",
644                  target_os = "openbsd", target_os = "netbsd",
645                  target_os = "redox", target_os = "illumos",
646                  target_os = "solaris"))]
647        ESTALE          => "Stale NFS file handle",
648
649        #[cfg(any(target_os = "macos", target_os = "freebsd",
650                  target_os = "dragonfly", target_os = "ios",
651                  target_os = "openbsd", target_os = "netbsd",
652                  target_os = "redox"))]
653        EREMOTE         => "Too many levels of remote in path",
654
655        #[cfg(any(target_os = "macos", target_os = "freebsd",
656                  target_os = "dragonfly", target_os = "ios",
657                  target_os = "openbsd", target_os = "netbsd"))]
658        EBADRPC         => "RPC struct is bad",
659
660        #[cfg(any(target_os = "macos", target_os = "freebsd",
661                  target_os = "dragonfly", target_os = "ios",
662                  target_os = "openbsd", target_os = "netbsd"))]
663        ERPCMISMATCH    => "RPC version wrong",
664
665        #[cfg(any(target_os = "macos", target_os = "freebsd",
666                  target_os = "dragonfly", target_os = "ios",
667                  target_os = "openbsd", target_os = "netbsd"))]
668        EPROGUNAVAIL    => "RPC prog. not avail",
669
670        #[cfg(any(target_os = "macos", target_os = "freebsd",
671                  target_os = "dragonfly", target_os = "ios",
672                  target_os = "openbsd", target_os = "netbsd"))]
673        EPROGMISMATCH   => "Program version wrong",
674
675        #[cfg(any(target_os = "macos", target_os = "freebsd",
676                  target_os = "dragonfly", target_os = "ios",
677                  target_os = "openbsd", target_os = "netbsd"))]
678        EPROCUNAVAIL    => "Bad procedure for program",
679
680        #[cfg(any(target_os = "macos", target_os = "freebsd",
681                  target_os = "dragonfly", target_os = "ios",
682                  target_os = "openbsd", target_os = "netbsd"))]
683        EFTYPE          => "Inappropriate file type or format",
684
685        #[cfg(any(target_os = "macos", target_os = "freebsd",
686                  target_os = "dragonfly", target_os = "ios",
687                  target_os = "openbsd", target_os = "netbsd"))]
688        EAUTH           => "Authentication error",
689
690        #[cfg(any(target_os = "macos", target_os = "freebsd",
691                  target_os = "dragonfly", target_os = "ios",
692                  target_os = "openbsd", target_os = "netbsd",
693                  target_os = "redox"))]
694        ECANCELED       => "Operation canceled",
695
696        #[cfg(any(target_os = "macos", target_os = "ios"))]
697        EPWROFF         => "Device power is off",
698
699        #[cfg(any(target_os = "macos", target_os = "ios"))]
700        EDEVERR         => "Device error, e.g. paper out",
701
702        #[cfg(any(target_os = "macos", target_os = "ios"))]
703        EBADEXEC        => "Bad executable",
704
705        #[cfg(any(target_os = "macos", target_os = "ios"))]
706        EBADARCH        => "Bad CPU type in executable",
707
708        #[cfg(any(target_os = "macos", target_os = "ios"))]
709        ESHLIBVERS      => "Shared library version mismatch",
710
711        #[cfg(any(target_os = "macos", target_os = "ios"))]
712        EBADMACHO       => "Malformed Macho file",
713
714        #[cfg(any(target_os = "macos", target_os = "ios",
715                  target_os = "netbsd"))]
716        EMULTIHOP       => "Reserved",
717
718        #[cfg(any(target_os = "macos", target_os = "ios",
719                  target_os = "netbsd", target_os = "redox"))]
720        ENODATA         => "No message available on STREAM",
721
722        #[cfg(any(target_os = "macos", target_os = "ios",
723                  target_os = "netbsd"))]
724        ENOLINK         => "Reserved",
725
726        #[cfg(any(target_os = "macos", target_os = "ios",
727                  target_os = "netbsd", target_os = "redox"))]
728        ENOSR           => "No STREAM resources",
729
730        #[cfg(any(target_os = "macos", target_os = "ios",
731                  target_os = "netbsd", target_os = "redox"))]
732        ENOSTR          => "Not a STREAM",
733
734        #[cfg(any(target_os = "macos", target_os = "ios",
735                  target_os = "netbsd", target_os = "redox"))]
736        ETIME           => "STREAM ioctl timeout",
737
738        #[cfg(any(target_os = "macos", target_os = "ios",
739                  target_os = "illumos", target_os = "solaris"))]
740        EOPNOTSUPP      => "Operation not supported on socket",
741
742        #[cfg(any(target_os = "macos", target_os = "ios"))]
743        ENOPOLICY       => "No such policy registered",
744
745        #[cfg(any(target_os = "macos", target_os = "ios"))]
746        EQFULL          => "Interface output queue is full",
747
748        #[cfg(target_os = "openbsd")]
749        EOPNOTSUPP      => "Operation not supported",
750
751        #[cfg(target_os = "openbsd")]
752        EIPSEC          => "IPsec processing failure",
753
754        #[cfg(target_os = "dragonfly")]
755        EASYNC          => "Async",
756
757        #[cfg(any(target_os = "illumos", target_os = "solaris"))]
758        EDEADLOCK       => "Resource deadlock would occur",
759
760        #[cfg(any(target_os = "illumos", target_os = "solaris"))]
761        ELOCKUNMAPPED   => "Locked lock was unmapped",
762
763        #[cfg(any(target_os = "illumos", target_os = "solaris"))]
764        ENOTACTIVE      => "Facility is not active",
765    }
766}
767
768#[cfg(any(target_os = "linux", target_os = "android",
769          target_os = "fuchsia"))]
770mod consts {
771    #[derive(Clone, Copy, Debug, Eq, PartialEq)]
772    #[repr(i32)]
773    #[non_exhaustive]
774    pub enum Errno {
775        UnknownErrno    = 0,
776        EPERM           = libc::EPERM,
777        ENOENT          = libc::ENOENT,
778        ESRCH           = libc::ESRCH,
779        EINTR           = libc::EINTR,
780        EIO             = libc::EIO,
781        ENXIO           = libc::ENXIO,
782        E2BIG           = libc::E2BIG,
783        ENOEXEC         = libc::ENOEXEC,
784        EBADF           = libc::EBADF,
785        ECHILD          = libc::ECHILD,
786        EAGAIN          = libc::EAGAIN,
787        ENOMEM          = libc::ENOMEM,
788        EACCES          = libc::EACCES,
789        EFAULT          = libc::EFAULT,
790        ENOTBLK         = libc::ENOTBLK,
791        EBUSY           = libc::EBUSY,
792        EEXIST          = libc::EEXIST,
793        EXDEV           = libc::EXDEV,
794        ENODEV          = libc::ENODEV,
795        ENOTDIR         = libc::ENOTDIR,
796        EISDIR          = libc::EISDIR,
797        EINVAL          = libc::EINVAL,
798        ENFILE          = libc::ENFILE,
799        EMFILE          = libc::EMFILE,
800        ENOTTY          = libc::ENOTTY,
801        ETXTBSY         = libc::ETXTBSY,
802        EFBIG           = libc::EFBIG,
803        ENOSPC          = libc::ENOSPC,
804        ESPIPE          = libc::ESPIPE,
805        EROFS           = libc::EROFS,
806        EMLINK          = libc::EMLINK,
807        EPIPE           = libc::EPIPE,
808        EDOM            = libc::EDOM,
809        ERANGE          = libc::ERANGE,
810        EDEADLK         = libc::EDEADLK,
811        ENAMETOOLONG    = libc::ENAMETOOLONG,
812        ENOLCK          = libc::ENOLCK,
813        ENOSYS          = libc::ENOSYS,
814        ENOTEMPTY       = libc::ENOTEMPTY,
815        ELOOP           = libc::ELOOP,
816        ENOMSG          = libc::ENOMSG,
817        EIDRM           = libc::EIDRM,
818        ECHRNG          = libc::ECHRNG,
819        EL2NSYNC        = libc::EL2NSYNC,
820        EL3HLT          = libc::EL3HLT,
821        EL3RST          = libc::EL3RST,
822        ELNRNG          = libc::ELNRNG,
823        EUNATCH         = libc::EUNATCH,
824        ENOCSI          = libc::ENOCSI,
825        EL2HLT          = libc::EL2HLT,
826        EBADE           = libc::EBADE,
827        EBADR           = libc::EBADR,
828        EXFULL          = libc::EXFULL,
829        ENOANO          = libc::ENOANO,
830        EBADRQC         = libc::EBADRQC,
831        EBADSLT         = libc::EBADSLT,
832        EBFONT          = libc::EBFONT,
833        ENOSTR          = libc::ENOSTR,
834        ENODATA         = libc::ENODATA,
835        ETIME           = libc::ETIME,
836        ENOSR           = libc::ENOSR,
837        ENONET          = libc::ENONET,
838        ENOPKG          = libc::ENOPKG,
839        EREMOTE         = libc::EREMOTE,
840        ENOLINK         = libc::ENOLINK,
841        EADV            = libc::EADV,
842        ESRMNT          = libc::ESRMNT,
843        ECOMM           = libc::ECOMM,
844        EPROTO          = libc::EPROTO,
845        EMULTIHOP       = libc::EMULTIHOP,
846        EDOTDOT         = libc::EDOTDOT,
847        EBADMSG         = libc::EBADMSG,
848        EOVERFLOW       = libc::EOVERFLOW,
849        ENOTUNIQ        = libc::ENOTUNIQ,
850        EBADFD          = libc::EBADFD,
851        EREMCHG         = libc::EREMCHG,
852        ELIBACC         = libc::ELIBACC,
853        ELIBBAD         = libc::ELIBBAD,
854        ELIBSCN         = libc::ELIBSCN,
855        ELIBMAX         = libc::ELIBMAX,
856        ELIBEXEC        = libc::ELIBEXEC,
857        EILSEQ          = libc::EILSEQ,
858        ERESTART        = libc::ERESTART,
859        ESTRPIPE        = libc::ESTRPIPE,
860        EUSERS          = libc::EUSERS,
861        ENOTSOCK        = libc::ENOTSOCK,
862        EDESTADDRREQ    = libc::EDESTADDRREQ,
863        EMSGSIZE        = libc::EMSGSIZE,
864        EPROTOTYPE      = libc::EPROTOTYPE,
865        ENOPROTOOPT     = libc::ENOPROTOOPT,
866        EPROTONOSUPPORT = libc::EPROTONOSUPPORT,
867        ESOCKTNOSUPPORT = libc::ESOCKTNOSUPPORT,
868        EOPNOTSUPP      = libc::EOPNOTSUPP,
869        EPFNOSUPPORT    = libc::EPFNOSUPPORT,
870        EAFNOSUPPORT    = libc::EAFNOSUPPORT,
871        EADDRINUSE      = libc::EADDRINUSE,
872        EADDRNOTAVAIL   = libc::EADDRNOTAVAIL,
873        ENETDOWN        = libc::ENETDOWN,
874        ENETUNREACH     = libc::ENETUNREACH,
875        ENETRESET       = libc::ENETRESET,
876        ECONNABORTED    = libc::ECONNABORTED,
877        ECONNRESET      = libc::ECONNRESET,
878        ENOBUFS         = libc::ENOBUFS,
879        EISCONN         = libc::EISCONN,
880        ENOTCONN        = libc::ENOTCONN,
881        ESHUTDOWN       = libc::ESHUTDOWN,
882        ETOOMANYREFS    = libc::ETOOMANYREFS,
883        ETIMEDOUT       = libc::ETIMEDOUT,
884        ECONNREFUSED    = libc::ECONNREFUSED,
885        EHOSTDOWN       = libc::EHOSTDOWN,
886        EHOSTUNREACH    = libc::EHOSTUNREACH,
887        EALREADY        = libc::EALREADY,
888        EINPROGRESS     = libc::EINPROGRESS,
889        ESTALE          = libc::ESTALE,
890        EUCLEAN         = libc::EUCLEAN,
891        ENOTNAM         = libc::ENOTNAM,
892        ENAVAIL         = libc::ENAVAIL,
893        EISNAM          = libc::EISNAM,
894        EREMOTEIO       = libc::EREMOTEIO,
895        EDQUOT          = libc::EDQUOT,
896        ENOMEDIUM       = libc::ENOMEDIUM,
897        EMEDIUMTYPE     = libc::EMEDIUMTYPE,
898        ECANCELED       = libc::ECANCELED,
899        ENOKEY          = libc::ENOKEY,
900        EKEYEXPIRED     = libc::EKEYEXPIRED,
901        EKEYREVOKED     = libc::EKEYREVOKED,
902        EKEYREJECTED    = libc::EKEYREJECTED,
903        EOWNERDEAD      = libc::EOWNERDEAD,
904        ENOTRECOVERABLE = libc::ENOTRECOVERABLE,
905        #[cfg(not(any(target_os = "android", target_arch="mips")))]
906        ERFKILL         = libc::ERFKILL,
907        #[cfg(not(any(target_os = "android", target_arch="mips")))]
908        EHWPOISON       = libc::EHWPOISON,
909    }
910
911    #[deprecated(
912        since = "0.22.1",
913        note = "use nix::errno::Errno::EWOULDBLOCK instead"
914    )]
915    pub const EWOULDBLOCK: Errno = Errno::EAGAIN;
916    #[deprecated(
917        since = "0.22.1",
918        note = "use nix::errno::Errno::EDEADLOCK instead"
919    )]
920    pub const EDEADLOCK:   Errno = Errno::EDEADLK;
921    #[deprecated(
922        since = "0.22.1",
923        note = "use nix::errno::Errno::ENOTSUP instead"
924    )]
925    pub const ENOTSUP:  Errno = Errno::EOPNOTSUPP;
926
927    impl Errno {
928        pub const EWOULDBLOCK: Errno = Errno::EAGAIN;
929        pub const EDEADLOCK:   Errno = Errno::EDEADLK;
930        pub const ENOTSUP:     Errno = Errno::EOPNOTSUPP;
931    }
932
933    pub const fn from_i32(e: i32) -> Errno {
934        use self::Errno::*;
935
936        match e {
937            libc::EPERM => EPERM,
938            libc::ENOENT => ENOENT,
939            libc::ESRCH => ESRCH,
940            libc::EINTR => EINTR,
941            libc::EIO => EIO,
942            libc::ENXIO => ENXIO,
943            libc::E2BIG => E2BIG,
944            libc::ENOEXEC => ENOEXEC,
945            libc::EBADF => EBADF,
946            libc::ECHILD => ECHILD,
947            libc::EAGAIN => EAGAIN,
948            libc::ENOMEM => ENOMEM,
949            libc::EACCES => EACCES,
950            libc::EFAULT => EFAULT,
951            libc::ENOTBLK => ENOTBLK,
952            libc::EBUSY => EBUSY,
953            libc::EEXIST => EEXIST,
954            libc::EXDEV => EXDEV,
955            libc::ENODEV => ENODEV,
956            libc::ENOTDIR => ENOTDIR,
957            libc::EISDIR => EISDIR,
958            libc::EINVAL => EINVAL,
959            libc::ENFILE => ENFILE,
960            libc::EMFILE => EMFILE,
961            libc::ENOTTY => ENOTTY,
962            libc::ETXTBSY => ETXTBSY,
963            libc::EFBIG => EFBIG,
964            libc::ENOSPC => ENOSPC,
965            libc::ESPIPE => ESPIPE,
966            libc::EROFS => EROFS,
967            libc::EMLINK => EMLINK,
968            libc::EPIPE => EPIPE,
969            libc::EDOM => EDOM,
970            libc::ERANGE => ERANGE,
971            libc::EDEADLK => EDEADLK,
972            libc::ENAMETOOLONG => ENAMETOOLONG,
973            libc::ENOLCK => ENOLCK,
974            libc::ENOSYS => ENOSYS,
975            libc::ENOTEMPTY => ENOTEMPTY,
976            libc::ELOOP => ELOOP,
977            libc::ENOMSG => ENOMSG,
978            libc::EIDRM => EIDRM,
979            libc::ECHRNG => ECHRNG,
980            libc::EL2NSYNC => EL2NSYNC,
981            libc::EL3HLT => EL3HLT,
982            libc::EL3RST => EL3RST,
983            libc::ELNRNG => ELNRNG,
984            libc::EUNATCH => EUNATCH,
985            libc::ENOCSI => ENOCSI,
986            libc::EL2HLT => EL2HLT,
987            libc::EBADE => EBADE,
988            libc::EBADR => EBADR,
989            libc::EXFULL => EXFULL,
990            libc::ENOANO => ENOANO,
991            libc::EBADRQC => EBADRQC,
992            libc::EBADSLT => EBADSLT,
993            libc::EBFONT => EBFONT,
994            libc::ENOSTR => ENOSTR,
995            libc::ENODATA => ENODATA,
996            libc::ETIME => ETIME,
997            libc::ENOSR => ENOSR,
998            libc::ENONET => ENONET,
999            libc::ENOPKG => ENOPKG,
1000            libc::EREMOTE => EREMOTE,
1001            libc::ENOLINK => ENOLINK,
1002            libc::EADV => EADV,
1003            libc::ESRMNT => ESRMNT,
1004            libc::ECOMM => ECOMM,
1005            libc::EPROTO => EPROTO,
1006            libc::EMULTIHOP => EMULTIHOP,
1007            libc::EDOTDOT => EDOTDOT,
1008            libc::EBADMSG => EBADMSG,
1009            libc::EOVERFLOW => EOVERFLOW,
1010            libc::ENOTUNIQ => ENOTUNIQ,
1011            libc::EBADFD => EBADFD,
1012            libc::EREMCHG => EREMCHG,
1013            libc::ELIBACC => ELIBACC,
1014            libc::ELIBBAD => ELIBBAD,
1015            libc::ELIBSCN => ELIBSCN,
1016            libc::ELIBMAX => ELIBMAX,
1017            libc::ELIBEXEC => ELIBEXEC,
1018            libc::EILSEQ => EILSEQ,
1019            libc::ERESTART => ERESTART,
1020            libc::ESTRPIPE => ESTRPIPE,
1021            libc::EUSERS => EUSERS,
1022            libc::ENOTSOCK => ENOTSOCK,
1023            libc::EDESTADDRREQ => EDESTADDRREQ,
1024            libc::EMSGSIZE => EMSGSIZE,
1025            libc::EPROTOTYPE => EPROTOTYPE,
1026            libc::ENOPROTOOPT => ENOPROTOOPT,
1027            libc::EPROTONOSUPPORT => EPROTONOSUPPORT,
1028            libc::ESOCKTNOSUPPORT => ESOCKTNOSUPPORT,
1029            libc::EOPNOTSUPP => EOPNOTSUPP,
1030            libc::EPFNOSUPPORT => EPFNOSUPPORT,
1031            libc::EAFNOSUPPORT => EAFNOSUPPORT,
1032            libc::EADDRINUSE => EADDRINUSE,
1033            libc::EADDRNOTAVAIL => EADDRNOTAVAIL,
1034            libc::ENETDOWN => ENETDOWN,
1035            libc::ENETUNREACH => ENETUNREACH,
1036            libc::ENETRESET => ENETRESET,
1037            libc::ECONNABORTED => ECONNABORTED,
1038            libc::ECONNRESET => ECONNRESET,
1039            libc::ENOBUFS => ENOBUFS,
1040            libc::EISCONN => EISCONN,
1041            libc::ENOTCONN => ENOTCONN,
1042            libc::ESHUTDOWN => ESHUTDOWN,
1043            libc::ETOOMANYREFS => ETOOMANYREFS,
1044            libc::ETIMEDOUT => ETIMEDOUT,
1045            libc::ECONNREFUSED => ECONNREFUSED,
1046            libc::EHOSTDOWN => EHOSTDOWN,
1047            libc::EHOSTUNREACH => EHOSTUNREACH,
1048            libc::EALREADY => EALREADY,
1049            libc::EINPROGRESS => EINPROGRESS,
1050            libc::ESTALE => ESTALE,
1051            libc::EUCLEAN => EUCLEAN,
1052            libc::ENOTNAM => ENOTNAM,
1053            libc::ENAVAIL => ENAVAIL,
1054            libc::EISNAM => EISNAM,
1055            libc::EREMOTEIO => EREMOTEIO,
1056            libc::EDQUOT => EDQUOT,
1057            libc::ENOMEDIUM => ENOMEDIUM,
1058            libc::EMEDIUMTYPE => EMEDIUMTYPE,
1059            libc::ECANCELED => ECANCELED,
1060            libc::ENOKEY => ENOKEY,
1061            libc::EKEYEXPIRED => EKEYEXPIRED,
1062            libc::EKEYREVOKED => EKEYREVOKED,
1063            libc::EKEYREJECTED => EKEYREJECTED,
1064            libc::EOWNERDEAD => EOWNERDEAD,
1065            libc::ENOTRECOVERABLE => ENOTRECOVERABLE,
1066            #[cfg(not(any(target_os = "android", target_arch="mips")))]
1067            libc::ERFKILL => ERFKILL,
1068            #[cfg(not(any(target_os = "android", target_arch="mips")))]
1069            libc::EHWPOISON => EHWPOISON,
1070            _   => UnknownErrno,
1071        }
1072    }
1073}
1074
1075#[cfg(any(target_os = "macos", target_os = "ios"))]
1076mod consts {
1077    #[derive(Clone, Copy, Debug, Eq, PartialEq)]
1078    #[repr(i32)]
1079    #[non_exhaustive]
1080    pub enum Errno {
1081        UnknownErrno    = 0,
1082        EPERM           = libc::EPERM,
1083        ENOENT          = libc::ENOENT,
1084        ESRCH           = libc::ESRCH,
1085        EINTR           = libc::EINTR,
1086        EIO             = libc::EIO,
1087        ENXIO           = libc::ENXIO,
1088        E2BIG           = libc::E2BIG,
1089        ENOEXEC         = libc::ENOEXEC,
1090        EBADF           = libc::EBADF,
1091        ECHILD          = libc::ECHILD,
1092        EDEADLK         = libc::EDEADLK,
1093        ENOMEM          = libc::ENOMEM,
1094        EACCES          = libc::EACCES,
1095        EFAULT          = libc::EFAULT,
1096        ENOTBLK         = libc::ENOTBLK,
1097        EBUSY           = libc::EBUSY,
1098        EEXIST          = libc::EEXIST,
1099        EXDEV           = libc::EXDEV,
1100        ENODEV          = libc::ENODEV,
1101        ENOTDIR         = libc::ENOTDIR,
1102        EISDIR          = libc::EISDIR,
1103        EINVAL          = libc::EINVAL,
1104        ENFILE          = libc::ENFILE,
1105        EMFILE          = libc::EMFILE,
1106        ENOTTY          = libc::ENOTTY,
1107        ETXTBSY         = libc::ETXTBSY,
1108        EFBIG           = libc::EFBIG,
1109        ENOSPC          = libc::ENOSPC,
1110        ESPIPE          = libc::ESPIPE,
1111        EROFS           = libc::EROFS,
1112        EMLINK          = libc::EMLINK,
1113        EPIPE           = libc::EPIPE,
1114        EDOM            = libc::EDOM,
1115        ERANGE          = libc::ERANGE,
1116        EAGAIN          = libc::EAGAIN,
1117        EINPROGRESS     = libc::EINPROGRESS,
1118        EALREADY        = libc::EALREADY,
1119        ENOTSOCK        = libc::ENOTSOCK,
1120        EDESTADDRREQ    = libc::EDESTADDRREQ,
1121        EMSGSIZE        = libc::EMSGSIZE,
1122        EPROTOTYPE      = libc::EPROTOTYPE,
1123        ENOPROTOOPT     = libc::ENOPROTOOPT,
1124        EPROTONOSUPPORT = libc::EPROTONOSUPPORT,
1125        ESOCKTNOSUPPORT = libc::ESOCKTNOSUPPORT,
1126        ENOTSUP         = libc::ENOTSUP,
1127        EPFNOSUPPORT    = libc::EPFNOSUPPORT,
1128        EAFNOSUPPORT    = libc::EAFNOSUPPORT,
1129        EADDRINUSE      = libc::EADDRINUSE,
1130        EADDRNOTAVAIL   = libc::EADDRNOTAVAIL,
1131        ENETDOWN        = libc::ENETDOWN,
1132        ENETUNREACH     = libc::ENETUNREACH,
1133        ENETRESET       = libc::ENETRESET,
1134        ECONNABORTED    = libc::ECONNABORTED,
1135        ECONNRESET      = libc::ECONNRESET,
1136        ENOBUFS         = libc::ENOBUFS,
1137        EISCONN         = libc::EISCONN,
1138        ENOTCONN        = libc::ENOTCONN,
1139        ESHUTDOWN       = libc::ESHUTDOWN,
1140        ETOOMANYREFS    = libc::ETOOMANYREFS,
1141        ETIMEDOUT       = libc::ETIMEDOUT,
1142        ECONNREFUSED    = libc::ECONNREFUSED,
1143        ELOOP           = libc::ELOOP,
1144        ENAMETOOLONG    = libc::ENAMETOOLONG,
1145        EHOSTDOWN       = libc::EHOSTDOWN,
1146        EHOSTUNREACH    = libc::EHOSTUNREACH,
1147        ENOTEMPTY       = libc::ENOTEMPTY,
1148        EPROCLIM        = libc::EPROCLIM,
1149        EUSERS          = libc::EUSERS,
1150        EDQUOT          = libc::EDQUOT,
1151        ESTALE          = libc::ESTALE,
1152        EREMOTE         = libc::EREMOTE,
1153        EBADRPC         = libc::EBADRPC,
1154        ERPCMISMATCH    = libc::ERPCMISMATCH,
1155        EPROGUNAVAIL    = libc::EPROGUNAVAIL,
1156        EPROGMISMATCH   = libc::EPROGMISMATCH,
1157        EPROCUNAVAIL    = libc::EPROCUNAVAIL,
1158        ENOLCK          = libc::ENOLCK,
1159        ENOSYS          = libc::ENOSYS,
1160        EFTYPE          = libc::EFTYPE,
1161        EAUTH           = libc::EAUTH,
1162        ENEEDAUTH       = libc::ENEEDAUTH,
1163        EPWROFF         = libc::EPWROFF,
1164        EDEVERR         = libc::EDEVERR,
1165        EOVERFLOW       = libc::EOVERFLOW,
1166        EBADEXEC        = libc::EBADEXEC,
1167        EBADARCH        = libc::EBADARCH,
1168        ESHLIBVERS      = libc::ESHLIBVERS,
1169        EBADMACHO       = libc::EBADMACHO,
1170        ECANCELED       = libc::ECANCELED,
1171        EIDRM           = libc::EIDRM,
1172        ENOMSG          = libc::ENOMSG,
1173        EILSEQ          = libc::EILSEQ,
1174        ENOATTR         = libc::ENOATTR,
1175        EBADMSG         = libc::EBADMSG,
1176        EMULTIHOP       = libc::EMULTIHOP,
1177        ENODATA         = libc::ENODATA,
1178        ENOLINK         = libc::ENOLINK,
1179        ENOSR           = libc::ENOSR,
1180        ENOSTR          = libc::ENOSTR,
1181        EPROTO          = libc::EPROTO,
1182        ETIME           = libc::ETIME,
1183        EOPNOTSUPP      = libc::EOPNOTSUPP,
1184        ENOPOLICY       = libc::ENOPOLICY,
1185        ENOTRECOVERABLE = libc::ENOTRECOVERABLE,
1186        EOWNERDEAD      = libc::EOWNERDEAD,
1187        EQFULL          = libc::EQFULL,
1188    }
1189
1190    #[deprecated(
1191        since = "0.22.1",
1192        note = "use nix::errno::Errno::ELAST instead"
1193    )]
1194    pub const ELAST:  Errno = Errno::EQFULL;
1195    #[deprecated(
1196        since = "0.22.1",
1197        note = "use nix::errno::Errno::EWOULDBLOCK instead"
1198    )]
1199    pub const EWOULDBLOCK: Errno = Errno::EAGAIN;
1200    #[deprecated(
1201        since = "0.22.1",
1202        note = "use nix::errno::Errno::EDEADLOCK instead"
1203    )]
1204    pub const EDEADLOCK:   Errno = Errno::EDEADLK;
1205
1206    impl Errno {
1207        pub const ELAST: Errno       = Errno::EQFULL;
1208        pub const EWOULDBLOCK: Errno = Errno::EAGAIN;
1209        pub const EDEADLOCK:   Errno = Errno::EDEADLK;
1210    }
1211
1212    pub const fn from_i32(e: i32) -> Errno {
1213        use self::Errno::*;
1214
1215        match e {
1216            libc::EPERM => EPERM,
1217            libc::ENOENT => ENOENT,
1218            libc::ESRCH => ESRCH,
1219            libc::EINTR => EINTR,
1220            libc::EIO => EIO,
1221            libc::ENXIO => ENXIO,
1222            libc::E2BIG => E2BIG,
1223            libc::ENOEXEC => ENOEXEC,
1224            libc::EBADF => EBADF,
1225            libc::ECHILD => ECHILD,
1226            libc::EDEADLK => EDEADLK,
1227            libc::ENOMEM => ENOMEM,
1228            libc::EACCES => EACCES,
1229            libc::EFAULT => EFAULT,
1230            libc::ENOTBLK => ENOTBLK,
1231            libc::EBUSY => EBUSY,
1232            libc::EEXIST => EEXIST,
1233            libc::EXDEV => EXDEV,
1234            libc::ENODEV => ENODEV,
1235            libc::ENOTDIR => ENOTDIR,
1236            libc::EISDIR => EISDIR,
1237            libc::EINVAL => EINVAL,
1238            libc::ENFILE => ENFILE,
1239            libc::EMFILE => EMFILE,
1240            libc::ENOTTY => ENOTTY,
1241            libc::ETXTBSY => ETXTBSY,
1242            libc::EFBIG => EFBIG,
1243            libc::ENOSPC => ENOSPC,
1244            libc::ESPIPE => ESPIPE,
1245            libc::EROFS => EROFS,
1246            libc::EMLINK => EMLINK,
1247            libc::EPIPE => EPIPE,
1248            libc::EDOM => EDOM,
1249            libc::ERANGE => ERANGE,
1250            libc::EAGAIN => EAGAIN,
1251            libc::EINPROGRESS => EINPROGRESS,
1252            libc::EALREADY => EALREADY,
1253            libc::ENOTSOCK => ENOTSOCK,
1254            libc::EDESTADDRREQ => EDESTADDRREQ,
1255            libc::EMSGSIZE => EMSGSIZE,
1256            libc::EPROTOTYPE => EPROTOTYPE,
1257            libc::ENOPROTOOPT => ENOPROTOOPT,
1258            libc::EPROTONOSUPPORT => EPROTONOSUPPORT,
1259            libc::ESOCKTNOSUPPORT => ESOCKTNOSUPPORT,
1260            libc::ENOTSUP => ENOTSUP,
1261            libc::EPFNOSUPPORT => EPFNOSUPPORT,
1262            libc::EAFNOSUPPORT => EAFNOSUPPORT,
1263            libc::EADDRINUSE => EADDRINUSE,
1264            libc::EADDRNOTAVAIL => EADDRNOTAVAIL,
1265            libc::ENETDOWN => ENETDOWN,
1266            libc::ENETUNREACH => ENETUNREACH,
1267            libc::ENETRESET => ENETRESET,
1268            libc::ECONNABORTED => ECONNABORTED,
1269            libc::ECONNRESET => ECONNRESET,
1270            libc::ENOBUFS => ENOBUFS,
1271            libc::EISCONN => EISCONN,
1272            libc::ENOTCONN => ENOTCONN,
1273            libc::ESHUTDOWN => ESHUTDOWN,
1274            libc::ETOOMANYREFS => ETOOMANYREFS,
1275            libc::ETIMEDOUT => ETIMEDOUT,
1276            libc::ECONNREFUSED => ECONNREFUSED,
1277            libc::ELOOP => ELOOP,
1278            libc::ENAMETOOLONG => ENAMETOOLONG,
1279            libc::EHOSTDOWN => EHOSTDOWN,
1280            libc::EHOSTUNREACH => EHOSTUNREACH,
1281            libc::ENOTEMPTY => ENOTEMPTY,
1282            libc::EPROCLIM => EPROCLIM,
1283            libc::EUSERS => EUSERS,
1284            libc::EDQUOT => EDQUOT,
1285            libc::ESTALE => ESTALE,
1286            libc::EREMOTE => EREMOTE,
1287            libc::EBADRPC => EBADRPC,
1288            libc::ERPCMISMATCH => ERPCMISMATCH,
1289            libc::EPROGUNAVAIL => EPROGUNAVAIL,
1290            libc::EPROGMISMATCH => EPROGMISMATCH,
1291            libc::EPROCUNAVAIL => EPROCUNAVAIL,
1292            libc::ENOLCK => ENOLCK,
1293            libc::ENOSYS => ENOSYS,
1294            libc::EFTYPE => EFTYPE,
1295            libc::EAUTH => EAUTH,
1296            libc::ENEEDAUTH => ENEEDAUTH,
1297            libc::EPWROFF => EPWROFF,
1298            libc::EDEVERR => EDEVERR,
1299            libc::EOVERFLOW => EOVERFLOW,
1300            libc::EBADEXEC => EBADEXEC,
1301            libc::EBADARCH => EBADARCH,
1302            libc::ESHLIBVERS => ESHLIBVERS,
1303            libc::EBADMACHO => EBADMACHO,
1304            libc::ECANCELED => ECANCELED,
1305            libc::EIDRM => EIDRM,
1306            libc::ENOMSG => ENOMSG,
1307            libc::EILSEQ => EILSEQ,
1308            libc::ENOATTR => ENOATTR,
1309            libc::EBADMSG => EBADMSG,
1310            libc::EMULTIHOP => EMULTIHOP,
1311            libc::ENODATA => ENODATA,
1312            libc::ENOLINK => ENOLINK,
1313            libc::ENOSR => ENOSR,
1314            libc::ENOSTR => ENOSTR,
1315            libc::EPROTO => EPROTO,
1316            libc::ETIME => ETIME,
1317            libc::EOPNOTSUPP => EOPNOTSUPP,
1318            libc::ENOPOLICY => ENOPOLICY,
1319            libc::ENOTRECOVERABLE => ENOTRECOVERABLE,
1320            libc::EOWNERDEAD => EOWNERDEAD,
1321            libc::EQFULL => EQFULL,
1322            _   => UnknownErrno,
1323        }
1324    }
1325}
1326
1327#[cfg(target_os = "freebsd")]
1328mod consts {
1329    #[derive(Clone, Copy, Debug, Eq, PartialEq)]
1330    #[repr(i32)]
1331    #[non_exhaustive]
1332    pub enum Errno {
1333        UnknownErrno    = 0,
1334        EPERM           = libc::EPERM,
1335        ENOENT          = libc::ENOENT,
1336        ESRCH           = libc::ESRCH,
1337        EINTR           = libc::EINTR,
1338        EIO             = libc::EIO,
1339        ENXIO           = libc::ENXIO,
1340        E2BIG           = libc::E2BIG,
1341        ENOEXEC         = libc::ENOEXEC,
1342        EBADF           = libc::EBADF,
1343        ECHILD          = libc::ECHILD,
1344        EDEADLK         = libc::EDEADLK,
1345        ENOMEM          = libc::ENOMEM,
1346        EACCES          = libc::EACCES,
1347        EFAULT          = libc::EFAULT,
1348        ENOTBLK         = libc::ENOTBLK,
1349        EBUSY           = libc::EBUSY,
1350        EEXIST          = libc::EEXIST,
1351        EXDEV           = libc::EXDEV,
1352        ENODEV          = libc::ENODEV,
1353        ENOTDIR         = libc::ENOTDIR,
1354        EISDIR          = libc::EISDIR,
1355        EINVAL          = libc::EINVAL,
1356        ENFILE          = libc::ENFILE,
1357        EMFILE          = libc::EMFILE,
1358        ENOTTY          = libc::ENOTTY,
1359        ETXTBSY         = libc::ETXTBSY,
1360        EFBIG           = libc::EFBIG,
1361        ENOSPC          = libc::ENOSPC,
1362        ESPIPE          = libc::ESPIPE,
1363        EROFS           = libc::EROFS,
1364        EMLINK          = libc::EMLINK,
1365        EPIPE           = libc::EPIPE,
1366        EDOM            = libc::EDOM,
1367        ERANGE          = libc::ERANGE,
1368        EAGAIN          = libc::EAGAIN,
1369        EINPROGRESS     = libc::EINPROGRESS,
1370        EALREADY        = libc::EALREADY,
1371        ENOTSOCK        = libc::ENOTSOCK,
1372        EDESTADDRREQ    = libc::EDESTADDRREQ,
1373        EMSGSIZE        = libc::EMSGSIZE,
1374        EPROTOTYPE      = libc::EPROTOTYPE,
1375        ENOPROTOOPT     = libc::ENOPROTOOPT,
1376        EPROTONOSUPPORT = libc::EPROTONOSUPPORT,
1377        ESOCKTNOSUPPORT = libc::ESOCKTNOSUPPORT,
1378        ENOTSUP         = libc::ENOTSUP,
1379        EPFNOSUPPORT    = libc::EPFNOSUPPORT,
1380        EAFNOSUPPORT    = libc::EAFNOSUPPORT,
1381        EADDRINUSE      = libc::EADDRINUSE,
1382        EADDRNOTAVAIL   = libc::EADDRNOTAVAIL,
1383        ENETDOWN        = libc::ENETDOWN,
1384        ENETUNREACH     = libc::ENETUNREACH,
1385        ENETRESET       = libc::ENETRESET,
1386        ECONNABORTED    = libc::ECONNABORTED,
1387        ECONNRESET      = libc::ECONNRESET,
1388        ENOBUFS         = libc::ENOBUFS,
1389        EISCONN         = libc::EISCONN,
1390        ENOTCONN        = libc::ENOTCONN,
1391        ESHUTDOWN       = libc::ESHUTDOWN,
1392        ETOOMANYREFS    = libc::ETOOMANYREFS,
1393        ETIMEDOUT       = libc::ETIMEDOUT,
1394        ECONNREFUSED    = libc::ECONNREFUSED,
1395        ELOOP           = libc::ELOOP,
1396        ENAMETOOLONG    = libc::ENAMETOOLONG,
1397        EHOSTDOWN       = libc::EHOSTDOWN,
1398        EHOSTUNREACH    = libc::EHOSTUNREACH,
1399        ENOTEMPTY       = libc::ENOTEMPTY,
1400        EPROCLIM        = libc::EPROCLIM,
1401        EUSERS          = libc::EUSERS,
1402        EDQUOT          = libc::EDQUOT,
1403        ESTALE          = libc::ESTALE,
1404        EREMOTE         = libc::EREMOTE,
1405        EBADRPC         = libc::EBADRPC,
1406        ERPCMISMATCH    = libc::ERPCMISMATCH,
1407        EPROGUNAVAIL    = libc::EPROGUNAVAIL,
1408        EPROGMISMATCH   = libc::EPROGMISMATCH,
1409        EPROCUNAVAIL    = libc::EPROCUNAVAIL,
1410        ENOLCK          = libc::ENOLCK,
1411        ENOSYS          = libc::ENOSYS,
1412        EFTYPE          = libc::EFTYPE,
1413        EAUTH           = libc::EAUTH,
1414        ENEEDAUTH       = libc::ENEEDAUTH,
1415        EIDRM           = libc::EIDRM,
1416        ENOMSG          = libc::ENOMSG,
1417        EOVERFLOW       = libc::EOVERFLOW,
1418        ECANCELED       = libc::ECANCELED,
1419        EILSEQ          = libc::EILSEQ,
1420        ENOATTR         = libc::ENOATTR,
1421        EDOOFUS         = libc::EDOOFUS,
1422        EBADMSG         = libc::EBADMSG,
1423        EMULTIHOP       = libc::EMULTIHOP,
1424        ENOLINK         = libc::ENOLINK,
1425        EPROTO          = libc::EPROTO,
1426        ENOTCAPABLE     = libc::ENOTCAPABLE,
1427        ECAPMODE        = libc::ECAPMODE,
1428        ENOTRECOVERABLE = libc::ENOTRECOVERABLE,
1429        EOWNERDEAD      = libc::EOWNERDEAD,
1430    }
1431
1432    #[deprecated(
1433        since = "0.22.1",
1434        note = "use nix::errno::Errno::ELAST instead"
1435    )]
1436    pub const ELAST: Errno       = Errno::EOWNERDEAD;
1437    #[deprecated(
1438        since = "0.22.1",
1439        note = "use nix::errno::Errno::EWOULDBLOCK instead"
1440    )]
1441    pub const EWOULDBLOCK: Errno = Errno::EAGAIN;
1442    #[deprecated(
1443        since = "0.22.1",
1444        note = "use nix::errno::Errno::EDEADLOCK instead"
1445    )]
1446    pub const EDEADLOCK:   Errno = Errno::EDEADLK;
1447    #[deprecated(
1448        since = "0.22.1",
1449        note = "use nix::errno::Errno::EOPNOTSUPP instead"
1450    )]
1451    pub const EOPNOTSUPP:  Errno = Errno::ENOTSUP;
1452
1453    impl Errno {
1454        pub const ELAST: Errno       = Errno::EOWNERDEAD;
1455        pub const EWOULDBLOCK: Errno = Errno::EAGAIN;
1456        pub const EDEADLOCK:   Errno = Errno::EDEADLK;
1457        pub const EOPNOTSUPP:  Errno = Errno::ENOTSUP;
1458    }
1459
1460    pub const fn from_i32(e: i32) -> Errno {
1461        use self::Errno::*;
1462
1463        match e {
1464            libc::EPERM => EPERM,
1465            libc::ENOENT => ENOENT,
1466            libc::ESRCH => ESRCH,
1467            libc::EINTR => EINTR,
1468            libc::EIO => EIO,
1469            libc::ENXIO => ENXIO,
1470            libc::E2BIG => E2BIG,
1471            libc::ENOEXEC => ENOEXEC,
1472            libc::EBADF => EBADF,
1473            libc::ECHILD => ECHILD,
1474            libc::EDEADLK => EDEADLK,
1475            libc::ENOMEM => ENOMEM,
1476            libc::EACCES => EACCES,
1477            libc::EFAULT => EFAULT,
1478            libc::ENOTBLK => ENOTBLK,
1479            libc::EBUSY => EBUSY,
1480            libc::EEXIST => EEXIST,
1481            libc::EXDEV => EXDEV,
1482            libc::ENODEV => ENODEV,
1483            libc::ENOTDIR => ENOTDIR,
1484            libc::EISDIR => EISDIR,
1485            libc::EINVAL => EINVAL,
1486            libc::ENFILE => ENFILE,
1487            libc::EMFILE => EMFILE,
1488            libc::ENOTTY => ENOTTY,
1489            libc::ETXTBSY => ETXTBSY,
1490            libc::EFBIG => EFBIG,
1491            libc::ENOSPC => ENOSPC,
1492            libc::ESPIPE => ESPIPE,
1493            libc::EROFS => EROFS,
1494            libc::EMLINK => EMLINK,
1495            libc::EPIPE => EPIPE,
1496            libc::EDOM => EDOM,
1497            libc::ERANGE => ERANGE,
1498            libc::EAGAIN => EAGAIN,
1499            libc::EINPROGRESS => EINPROGRESS,
1500            libc::EALREADY => EALREADY,
1501            libc::ENOTSOCK => ENOTSOCK,
1502            libc::EDESTADDRREQ => EDESTADDRREQ,
1503            libc::EMSGSIZE => EMSGSIZE,
1504            libc::EPROTOTYPE => EPROTOTYPE,
1505            libc::ENOPROTOOPT => ENOPROTOOPT,
1506            libc::EPROTONOSUPPORT => EPROTONOSUPPORT,
1507            libc::ESOCKTNOSUPPORT => ESOCKTNOSUPPORT,
1508            libc::ENOTSUP => ENOTSUP,
1509            libc::EPFNOSUPPORT => EPFNOSUPPORT,
1510            libc::EAFNOSUPPORT => EAFNOSUPPORT,
1511            libc::EADDRINUSE => EADDRINUSE,
1512            libc::EADDRNOTAVAIL => EADDRNOTAVAIL,
1513            libc::ENETDOWN => ENETDOWN,
1514            libc::ENETUNREACH => ENETUNREACH,
1515            libc::ENETRESET => ENETRESET,
1516            libc::ECONNABORTED => ECONNABORTED,
1517            libc::ECONNRESET => ECONNRESET,
1518            libc::ENOBUFS => ENOBUFS,
1519            libc::EISCONN => EISCONN,
1520            libc::ENOTCONN => ENOTCONN,
1521            libc::ESHUTDOWN => ESHUTDOWN,
1522            libc::ETOOMANYREFS => ETOOMANYREFS,
1523            libc::ETIMEDOUT => ETIMEDOUT,
1524            libc::ECONNREFUSED => ECONNREFUSED,
1525            libc::ELOOP => ELOOP,
1526            libc::ENAMETOOLONG => ENAMETOOLONG,
1527            libc::EHOSTDOWN => EHOSTDOWN,
1528            libc::EHOSTUNREACH => EHOSTUNREACH,
1529            libc::ENOTEMPTY => ENOTEMPTY,
1530            libc::EPROCLIM => EPROCLIM,
1531            libc::EUSERS => EUSERS,
1532            libc::EDQUOT => EDQUOT,
1533            libc::ESTALE => ESTALE,
1534            libc::EREMOTE => EREMOTE,
1535            libc::EBADRPC => EBADRPC,
1536            libc::ERPCMISMATCH => ERPCMISMATCH,
1537            libc::EPROGUNAVAIL => EPROGUNAVAIL,
1538            libc::EPROGMISMATCH => EPROGMISMATCH,
1539            libc::EPROCUNAVAIL => EPROCUNAVAIL,
1540            libc::ENOLCK => ENOLCK,
1541            libc::ENOSYS => ENOSYS,
1542            libc::EFTYPE => EFTYPE,
1543            libc::EAUTH => EAUTH,
1544            libc::ENEEDAUTH => ENEEDAUTH,
1545            libc::EIDRM => EIDRM,
1546            libc::ENOMSG => ENOMSG,
1547            libc::EOVERFLOW => EOVERFLOW,
1548            libc::ECANCELED => ECANCELED,
1549            libc::EILSEQ => EILSEQ,
1550            libc::ENOATTR => ENOATTR,
1551            libc::EDOOFUS => EDOOFUS,
1552            libc::EBADMSG => EBADMSG,
1553            libc::EMULTIHOP => EMULTIHOP,
1554            libc::ENOLINK => ENOLINK,
1555            libc::EPROTO => EPROTO,
1556            libc::ENOTCAPABLE => ENOTCAPABLE,
1557            libc::ECAPMODE => ECAPMODE,
1558            libc::ENOTRECOVERABLE => ENOTRECOVERABLE,
1559            libc::EOWNERDEAD => EOWNERDEAD,
1560            _   => UnknownErrno,
1561        }
1562    }
1563}
1564
1565
1566#[cfg(target_os = "dragonfly")]
1567mod consts {
1568    #[derive(Clone, Copy, Debug, Eq, PartialEq)]
1569    #[repr(i32)]
1570    #[non_exhaustive]
1571    pub enum Errno {
1572        UnknownErrno    = 0,
1573        EPERM           = libc::EPERM,
1574        ENOENT          = libc::ENOENT,
1575        ESRCH           = libc::ESRCH,
1576        EINTR           = libc::EINTR,
1577        EIO             = libc::EIO,
1578        ENXIO           = libc::ENXIO,
1579        E2BIG           = libc::E2BIG,
1580        ENOEXEC         = libc::ENOEXEC,
1581        EBADF           = libc::EBADF,
1582        ECHILD          = libc::ECHILD,
1583        EDEADLK         = libc::EDEADLK,
1584        ENOMEM          = libc::ENOMEM,
1585        EACCES          = libc::EACCES,
1586        EFAULT          = libc::EFAULT,
1587        ENOTBLK         = libc::ENOTBLK,
1588        EBUSY           = libc::EBUSY,
1589        EEXIST          = libc::EEXIST,
1590        EXDEV           = libc::EXDEV,
1591        ENODEV          = libc::ENODEV,
1592        ENOTDIR         = libc::ENOTDIR,
1593        EISDIR          = libc::EISDIR,
1594        EINVAL          = libc::EINVAL,
1595        ENFILE          = libc::ENFILE,
1596        EMFILE          = libc::EMFILE,
1597        ENOTTY          = libc::ENOTTY,
1598        ETXTBSY         = libc::ETXTBSY,
1599        EFBIG           = libc::EFBIG,
1600        ENOSPC          = libc::ENOSPC,
1601        ESPIPE          = libc::ESPIPE,
1602        EROFS           = libc::EROFS,
1603        EMLINK          = libc::EMLINK,
1604        EPIPE           = libc::EPIPE,
1605        EDOM            = libc::EDOM,
1606        ERANGE          = libc::ERANGE,
1607        EAGAIN          = libc::EAGAIN,
1608        EINPROGRESS     = libc::EINPROGRESS,
1609        EALREADY        = libc::EALREADY,
1610        ENOTSOCK        = libc::ENOTSOCK,
1611        EDESTADDRREQ    = libc::EDESTADDRREQ,
1612        EMSGSIZE        = libc::EMSGSIZE,
1613        EPROTOTYPE      = libc::EPROTOTYPE,
1614        ENOPROTOOPT     = libc::ENOPROTOOPT,
1615        EPROTONOSUPPORT = libc::EPROTONOSUPPORT,
1616        ESOCKTNOSUPPORT = libc::ESOCKTNOSUPPORT,
1617        ENOTSUP         = libc::ENOTSUP,
1618        EPFNOSUPPORT    = libc::EPFNOSUPPORT,
1619        EAFNOSUPPORT    = libc::EAFNOSUPPORT,
1620        EADDRINUSE      = libc::EADDRINUSE,
1621        EADDRNOTAVAIL   = libc::EADDRNOTAVAIL,
1622        ENETDOWN        = libc::ENETDOWN,
1623        ENETUNREACH     = libc::ENETUNREACH,
1624        ENETRESET       = libc::ENETRESET,
1625        ECONNABORTED    = libc::ECONNABORTED,
1626        ECONNRESET      = libc::ECONNRESET,
1627        ENOBUFS         = libc::ENOBUFS,
1628        EISCONN         = libc::EISCONN,
1629        ENOTCONN        = libc::ENOTCONN,
1630        ESHUTDOWN       = libc::ESHUTDOWN,
1631        ETOOMANYREFS    = libc::ETOOMANYREFS,
1632        ETIMEDOUT       = libc::ETIMEDOUT,
1633        ECONNREFUSED    = libc::ECONNREFUSED,
1634        ELOOP           = libc::ELOOP,
1635        ENAMETOOLONG    = libc::ENAMETOOLONG,
1636        EHOSTDOWN       = libc::EHOSTDOWN,
1637        EHOSTUNREACH    = libc::EHOSTUNREACH,
1638        ENOTEMPTY       = libc::ENOTEMPTY,
1639        EPROCLIM        = libc::EPROCLIM,
1640        EUSERS          = libc::EUSERS,
1641        EDQUOT          = libc::EDQUOT,
1642        ESTALE          = libc::ESTALE,
1643        EREMOTE         = libc::EREMOTE,
1644        EBADRPC         = libc::EBADRPC,
1645        ERPCMISMATCH    = libc::ERPCMISMATCH,
1646        EPROGUNAVAIL    = libc::EPROGUNAVAIL,
1647        EPROGMISMATCH   = libc::EPROGMISMATCH,
1648        EPROCUNAVAIL    = libc::EPROCUNAVAIL,
1649        ENOLCK          = libc::ENOLCK,
1650        ENOSYS          = libc::ENOSYS,
1651        EFTYPE          = libc::EFTYPE,
1652        EAUTH           = libc::EAUTH,
1653        ENEEDAUTH       = libc::ENEEDAUTH,
1654        EIDRM           = libc::EIDRM,
1655        ENOMSG          = libc::ENOMSG,
1656        EOVERFLOW       = libc::EOVERFLOW,
1657        ECANCELED       = libc::ECANCELED,
1658        EILSEQ          = libc::EILSEQ,
1659        ENOATTR         = libc::ENOATTR,
1660        EDOOFUS         = libc::EDOOFUS,
1661        EBADMSG         = libc::EBADMSG,
1662        EMULTIHOP       = libc::EMULTIHOP,
1663        ENOLINK         = libc::ENOLINK,
1664        EPROTO          = libc::EPROTO,
1665        ENOMEDIUM       = libc::ENOMEDIUM,
1666        ENOTRECOVERABLE = libc::ENOTRECOVERABLE,
1667        EOWNERDEAD      = libc::EOWNERDEAD,
1668        EASYNC          = libc::EASYNC,
1669    }
1670
1671    #[deprecated(
1672        since = "0.22.1",
1673        note = "use nix::errno::Errno::ELAST instead"
1674    )]
1675    pub const ELAST: Errno       = Errno::EASYNC;
1676    #[deprecated(
1677        since = "0.22.1",
1678        note = "use nix::errno::Errno::EWOULDBLOCK instead"
1679    )]
1680    pub const EWOULDBLOCK: Errno = Errno::EAGAIN;
1681    #[deprecated(
1682        since = "0.22.1",
1683        note = "use nix::errno::Errno::EDEADLOCK instead"
1684    )]
1685    pub const EDEADLOCK:   Errno = Errno::EDEADLK;
1686    #[deprecated(
1687        since = "0.22.1",
1688        note = "use nix::errno::Errno::EOPNOTSUPP instead"
1689    )]
1690    pub const EOPNOTSUPP:  Errno = Errno::ENOTSUP;
1691
1692    impl Errno {
1693        pub const ELAST: Errno       = Errno::EASYNC;
1694        pub const EWOULDBLOCK: Errno = Errno::EAGAIN;
1695        pub const EDEADLOCK:   Errno = Errno::EDEADLK;
1696        pub const EOPNOTSUPP:  Errno = Errno::ENOTSUP;
1697    }
1698
1699    pub const fn from_i32(e: i32) -> Errno {
1700        use self::Errno::*;
1701
1702        match e {
1703            libc::EPERM => EPERM,
1704            libc::ENOENT => ENOENT,
1705            libc::ESRCH => ESRCH,
1706            libc::EINTR => EINTR,
1707            libc::EIO => EIO,
1708            libc::ENXIO => ENXIO,
1709            libc::E2BIG => E2BIG,
1710            libc::ENOEXEC => ENOEXEC,
1711            libc::EBADF => EBADF,
1712            libc::ECHILD => ECHILD,
1713            libc::EDEADLK => EDEADLK,
1714            libc::ENOMEM => ENOMEM,
1715            libc::EACCES => EACCES,
1716            libc::EFAULT => EFAULT,
1717            libc::ENOTBLK => ENOTBLK,
1718            libc::EBUSY => EBUSY,
1719            libc::EEXIST => EEXIST,
1720            libc::EXDEV => EXDEV,
1721            libc::ENODEV => ENODEV,
1722            libc::ENOTDIR => ENOTDIR,
1723            libc::EISDIR=> EISDIR,
1724            libc::EINVAL => EINVAL,
1725            libc::ENFILE => ENFILE,
1726            libc::EMFILE => EMFILE,
1727            libc::ENOTTY => ENOTTY,
1728            libc::ETXTBSY => ETXTBSY,
1729            libc::EFBIG => EFBIG,
1730            libc::ENOSPC => ENOSPC,
1731            libc::ESPIPE => ESPIPE,
1732            libc::EROFS => EROFS,
1733            libc::EMLINK => EMLINK,
1734            libc::EPIPE => EPIPE,
1735            libc::EDOM => EDOM,
1736            libc::ERANGE => ERANGE,
1737            libc::EAGAIN => EAGAIN,
1738            libc::EINPROGRESS => EINPROGRESS,
1739            libc::EALREADY => EALREADY,
1740            libc::ENOTSOCK => ENOTSOCK,
1741            libc::EDESTADDRREQ => EDESTADDRREQ,
1742            libc::EMSGSIZE => EMSGSIZE,
1743            libc::EPROTOTYPE => EPROTOTYPE,
1744            libc::ENOPROTOOPT => ENOPROTOOPT,
1745            libc::EPROTONOSUPPORT => EPROTONOSUPPORT,
1746            libc::ESOCKTNOSUPPORT => ESOCKTNOSUPPORT,
1747            libc::ENOTSUP => ENOTSUP,
1748            libc::EPFNOSUPPORT => EPFNOSUPPORT,
1749            libc::EAFNOSUPPORT => EAFNOSUPPORT,
1750            libc::EADDRINUSE => EADDRINUSE,
1751            libc::EADDRNOTAVAIL => EADDRNOTAVAIL,
1752            libc::ENETDOWN => ENETDOWN,
1753            libc::ENETUNREACH => ENETUNREACH,
1754            libc::ENETRESET => ENETRESET,
1755            libc::ECONNABORTED => ECONNABORTED,
1756            libc::ECONNRESET => ECONNRESET,
1757            libc::ENOBUFS => ENOBUFS,
1758            libc::EISCONN => EISCONN,
1759            libc::ENOTCONN => ENOTCONN,
1760            libc::ESHUTDOWN => ESHUTDOWN,
1761            libc::ETOOMANYREFS => ETOOMANYREFS,
1762            libc::ETIMEDOUT => ETIMEDOUT,
1763            libc::ECONNREFUSED => ECONNREFUSED,
1764            libc::ELOOP => ELOOP,
1765            libc::ENAMETOOLONG => ENAMETOOLONG,
1766            libc::EHOSTDOWN => EHOSTDOWN,
1767            libc::EHOSTUNREACH => EHOSTUNREACH,
1768            libc::ENOTEMPTY => ENOTEMPTY,
1769            libc::EPROCLIM => EPROCLIM,
1770            libc::EUSERS => EUSERS,
1771            libc::EDQUOT => EDQUOT,
1772            libc::ESTALE => ESTALE,
1773            libc::EREMOTE => EREMOTE,
1774            libc::EBADRPC => EBADRPC,
1775            libc::ERPCMISMATCH => ERPCMISMATCH,
1776            libc::EPROGUNAVAIL => EPROGUNAVAIL,
1777            libc::EPROGMISMATCH => EPROGMISMATCH,
1778            libc::EPROCUNAVAIL => EPROCUNAVAIL,
1779            libc::ENOLCK => ENOLCK,
1780            libc::ENOSYS => ENOSYS,
1781            libc::EFTYPE => EFTYPE,
1782            libc::EAUTH => EAUTH,
1783            libc::ENEEDAUTH => ENEEDAUTH,
1784            libc::EIDRM => EIDRM,
1785            libc::ENOMSG => ENOMSG,
1786            libc::EOVERFLOW => EOVERFLOW,
1787            libc::ECANCELED => ECANCELED,
1788            libc::EILSEQ => EILSEQ,
1789            libc::ENOATTR => ENOATTR,
1790            libc::EDOOFUS => EDOOFUS,
1791            libc::EBADMSG => EBADMSG,
1792            libc::EMULTIHOP => EMULTIHOP,
1793            libc::ENOLINK => ENOLINK,
1794            libc::EPROTO => EPROTO,
1795            libc::ENOMEDIUM => ENOMEDIUM,
1796            libc::EASYNC => EASYNC,
1797            _   => UnknownErrno,
1798        }
1799    }
1800}
1801
1802
1803#[cfg(target_os = "openbsd")]
1804mod consts {
1805    #[derive(Clone, Copy, Debug, Eq, PartialEq)]
1806    #[repr(i32)]
1807    #[non_exhaustive]
1808    pub enum Errno {
1809        UnknownErrno    = 0,
1810        EPERM           = libc::EPERM,
1811        ENOENT          = libc::ENOENT,
1812        ESRCH           = libc::ESRCH,
1813        EINTR           = libc::EINTR,
1814        EIO             = libc::EIO,
1815        ENXIO           = libc::ENXIO,
1816        E2BIG           = libc::E2BIG,
1817        ENOEXEC         = libc::ENOEXEC,
1818        EBADF           = libc::EBADF,
1819        ECHILD          = libc::ECHILD,
1820        EDEADLK         = libc::EDEADLK,
1821        ENOMEM          = libc::ENOMEM,
1822        EACCES          = libc::EACCES,
1823        EFAULT          = libc::EFAULT,
1824        ENOTBLK         = libc::ENOTBLK,
1825        EBUSY           = libc::EBUSY,
1826        EEXIST          = libc::EEXIST,
1827        EXDEV           = libc::EXDEV,
1828        ENODEV          = libc::ENODEV,
1829        ENOTDIR         = libc::ENOTDIR,
1830        EISDIR          = libc::EISDIR,
1831        EINVAL          = libc::EINVAL,
1832        ENFILE          = libc::ENFILE,
1833        EMFILE          = libc::EMFILE,
1834        ENOTTY          = libc::ENOTTY,
1835        ETXTBSY         = libc::ETXTBSY,
1836        EFBIG           = libc::EFBIG,
1837        ENOSPC          = libc::ENOSPC,
1838        ESPIPE          = libc::ESPIPE,
1839        EROFS           = libc::EROFS,
1840        EMLINK          = libc::EMLINK,
1841        EPIPE           = libc::EPIPE,
1842        EDOM            = libc::EDOM,
1843        ERANGE          = libc::ERANGE,
1844        EAGAIN          = libc::EAGAIN,
1845        EINPROGRESS     = libc::EINPROGRESS,
1846        EALREADY        = libc::EALREADY,
1847        ENOTSOCK        = libc::ENOTSOCK,
1848        EDESTADDRREQ    = libc::EDESTADDRREQ,
1849        EMSGSIZE        = libc::EMSGSIZE,
1850        EPROTOTYPE      = libc::EPROTOTYPE,
1851        ENOPROTOOPT     = libc::ENOPROTOOPT,
1852        EPROTONOSUPPORT = libc::EPROTONOSUPPORT,
1853        ESOCKTNOSUPPORT = libc::ESOCKTNOSUPPORT,
1854        EOPNOTSUPP      = libc::EOPNOTSUPP,
1855        EPFNOSUPPORT    = libc::EPFNOSUPPORT,
1856        EAFNOSUPPORT    = libc::EAFNOSUPPORT,
1857        EADDRINUSE      = libc::EADDRINUSE,
1858        EADDRNOTAVAIL   = libc::EADDRNOTAVAIL,
1859        ENETDOWN        = libc::ENETDOWN,
1860        ENETUNREACH     = libc::ENETUNREACH,
1861        ENETRESET       = libc::ENETRESET,
1862        ECONNABORTED    = libc::ECONNABORTED,
1863        ECONNRESET      = libc::ECONNRESET,
1864        ENOBUFS         = libc::ENOBUFS,
1865        EISCONN         = libc::EISCONN,
1866        ENOTCONN        = libc::ENOTCONN,
1867        ESHUTDOWN       = libc::ESHUTDOWN,
1868        ETOOMANYREFS    = libc::ETOOMANYREFS,
1869        ETIMEDOUT       = libc::ETIMEDOUT,
1870        ECONNREFUSED    = libc::ECONNREFUSED,
1871        ELOOP           = libc::ELOOP,
1872        ENAMETOOLONG    = libc::ENAMETOOLONG,
1873        EHOSTDOWN       = libc::EHOSTDOWN,
1874        EHOSTUNREACH    = libc::EHOSTUNREACH,
1875        ENOTEMPTY       = libc::ENOTEMPTY,
1876        EPROCLIM        = libc::EPROCLIM,
1877        EUSERS          = libc::EUSERS,
1878        EDQUOT          = libc::EDQUOT,
1879        ESTALE          = libc::ESTALE,
1880        EREMOTE         = libc::EREMOTE,
1881        EBADRPC         = libc::EBADRPC,
1882        ERPCMISMATCH    = libc::ERPCMISMATCH,
1883        EPROGUNAVAIL    = libc::EPROGUNAVAIL,
1884        EPROGMISMATCH   = libc::EPROGMISMATCH,
1885        EPROCUNAVAIL    = libc::EPROCUNAVAIL,
1886        ENOLCK          = libc::ENOLCK,
1887        ENOSYS          = libc::ENOSYS,
1888        EFTYPE          = libc::EFTYPE,
1889        EAUTH           = libc::EAUTH,
1890        ENEEDAUTH       = libc::ENEEDAUTH,
1891        EIPSEC          = libc::EIPSEC,
1892        ENOATTR         = libc::ENOATTR,
1893        EILSEQ          = libc::EILSEQ,
1894        ENOMEDIUM       = libc::ENOMEDIUM,
1895        EMEDIUMTYPE     = libc::EMEDIUMTYPE,
1896        EOVERFLOW       = libc::EOVERFLOW,
1897        ECANCELED       = libc::ECANCELED,
1898        EIDRM           = libc::EIDRM,
1899        ENOMSG          = libc::ENOMSG,
1900        ENOTSUP         = libc::ENOTSUP,
1901        EBADMSG         = libc::EBADMSG,
1902        ENOTRECOVERABLE = libc::ENOTRECOVERABLE,
1903        EOWNERDEAD      = libc::EOWNERDEAD,
1904        EPROTO          = libc::EPROTO,
1905    }
1906
1907    #[deprecated(
1908        since = "0.22.1",
1909        note = "use nix::errno::Errno::ELAST instead"
1910    )]
1911    pub const ELAST: Errno       = Errno::ENOTSUP;
1912    #[deprecated(
1913        since = "0.22.1",
1914        note = "use nix::errno::Errno::EWOULDBLOCK instead"
1915    )]
1916    pub const EWOULDBLOCK: Errno = Errno::EAGAIN;
1917
1918    impl Errno {
1919        pub const ELAST: Errno       = Errno::ENOTSUP;
1920        pub const EWOULDBLOCK: Errno = Errno::EAGAIN;
1921    }
1922
1923    pub const fn from_i32(e: i32) -> Errno {
1924        use self::Errno::*;
1925
1926        match e {
1927            libc::EPERM => EPERM,
1928            libc::ENOENT => ENOENT,
1929            libc::ESRCH => ESRCH,
1930            libc::EINTR => EINTR,
1931            libc::EIO => EIO,
1932            libc::ENXIO => ENXIO,
1933            libc::E2BIG => E2BIG,
1934            libc::ENOEXEC => ENOEXEC,
1935            libc::EBADF => EBADF,
1936            libc::ECHILD => ECHILD,
1937            libc::EDEADLK => EDEADLK,
1938            libc::ENOMEM => ENOMEM,
1939            libc::EACCES => EACCES,
1940            libc::EFAULT => EFAULT,
1941            libc::ENOTBLK => ENOTBLK,
1942            libc::EBUSY => EBUSY,
1943            libc::EEXIST => EEXIST,
1944            libc::EXDEV => EXDEV,
1945            libc::ENODEV => ENODEV,
1946            libc::ENOTDIR => ENOTDIR,
1947            libc::EISDIR => EISDIR,
1948            libc::EINVAL => EINVAL,
1949            libc::ENFILE => ENFILE,
1950            libc::EMFILE => EMFILE,
1951            libc::ENOTTY => ENOTTY,
1952            libc::ETXTBSY => ETXTBSY,
1953            libc::EFBIG => EFBIG,
1954            libc::ENOSPC => ENOSPC,
1955            libc::ESPIPE => ESPIPE,
1956            libc::EROFS => EROFS,
1957            libc::EMLINK => EMLINK,
1958            libc::EPIPE => EPIPE,
1959            libc::EDOM => EDOM,
1960            libc::ERANGE => ERANGE,
1961            libc::EAGAIN => EAGAIN,
1962            libc::EINPROGRESS => EINPROGRESS,
1963            libc::EALREADY => EALREADY,
1964            libc::ENOTSOCK => ENOTSOCK,
1965            libc::EDESTADDRREQ => EDESTADDRREQ,
1966            libc::EMSGSIZE => EMSGSIZE,
1967            libc::EPROTOTYPE => EPROTOTYPE,
1968            libc::ENOPROTOOPT => ENOPROTOOPT,
1969            libc::EPROTONOSUPPORT => EPROTONOSUPPORT,
1970            libc::ESOCKTNOSUPPORT => ESOCKTNOSUPPORT,
1971            libc::EOPNOTSUPP => EOPNOTSUPP,
1972            libc::EPFNOSUPPORT => EPFNOSUPPORT,
1973            libc::EAFNOSUPPORT => EAFNOSUPPORT,
1974            libc::EADDRINUSE => EADDRINUSE,
1975            libc::EADDRNOTAVAIL => EADDRNOTAVAIL,
1976            libc::ENETDOWN => ENETDOWN,
1977            libc::ENETUNREACH => ENETUNREACH,
1978            libc::ENETRESET => ENETRESET,
1979            libc::ECONNABORTED => ECONNABORTED,
1980            libc::ECONNRESET => ECONNRESET,
1981            libc::ENOBUFS => ENOBUFS,
1982            libc::EISCONN => EISCONN,
1983            libc::ENOTCONN => ENOTCONN,
1984            libc::ESHUTDOWN => ESHUTDOWN,
1985            libc::ETOOMANYREFS => ETOOMANYREFS,
1986            libc::ETIMEDOUT => ETIMEDOUT,
1987            libc::ECONNREFUSED => ECONNREFUSED,
1988            libc::ELOOP => ELOOP,
1989            libc::ENAMETOOLONG => ENAMETOOLONG,
1990            libc::EHOSTDOWN => EHOSTDOWN,
1991            libc::EHOSTUNREACH => EHOSTUNREACH,
1992            libc::ENOTEMPTY => ENOTEMPTY,
1993            libc::EPROCLIM => EPROCLIM,
1994            libc::EUSERS => EUSERS,
1995            libc::EDQUOT => EDQUOT,
1996            libc::ESTALE => ESTALE,
1997            libc::EREMOTE => EREMOTE,
1998            libc::EBADRPC => EBADRPC,
1999            libc::ERPCMISMATCH => ERPCMISMATCH,
2000            libc::EPROGUNAVAIL => EPROGUNAVAIL,
2001            libc::EPROGMISMATCH => EPROGMISMATCH,
2002            libc::EPROCUNAVAIL => EPROCUNAVAIL,
2003            libc::ENOLCK => ENOLCK,
2004            libc::ENOSYS => ENOSYS,
2005            libc::EFTYPE => EFTYPE,
2006            libc::EAUTH => EAUTH,
2007            libc::ENEEDAUTH => ENEEDAUTH,
2008            libc::EIPSEC => EIPSEC,
2009            libc::ENOATTR => ENOATTR,
2010            libc::EILSEQ => EILSEQ,
2011            libc::ENOMEDIUM => ENOMEDIUM,
2012            libc::EMEDIUMTYPE => EMEDIUMTYPE,
2013            libc::EOVERFLOW => EOVERFLOW,
2014            libc::ECANCELED => ECANCELED,
2015            libc::EIDRM => EIDRM,
2016            libc::ENOMSG => ENOMSG,
2017            libc::ENOTSUP => ENOTSUP,
2018            libc::EBADMSG => EBADMSG,
2019            libc::ENOTRECOVERABLE => ENOTRECOVERABLE,
2020            libc::EOWNERDEAD => EOWNERDEAD,
2021            libc::EPROTO => EPROTO,
2022            _   => UnknownErrno,
2023        }
2024    }
2025}
2026
2027#[cfg(target_os = "netbsd")]
2028mod consts {
2029    #[derive(Clone, Copy, Debug, Eq, PartialEq)]
2030    #[repr(i32)]
2031    #[non_exhaustive]
2032    pub enum Errno {
2033        UnknownErrno    = 0,
2034        EPERM           = libc::EPERM,
2035        ENOENT          = libc::ENOENT,
2036        ESRCH           = libc::ESRCH,
2037        EINTR           = libc::EINTR,
2038        EIO             = libc::EIO,
2039        ENXIO           = libc::ENXIO,
2040        E2BIG           = libc::E2BIG,
2041        ENOEXEC         = libc::ENOEXEC,
2042        EBADF           = libc::EBADF,
2043        ECHILD          = libc::ECHILD,
2044        EDEADLK         = libc::EDEADLK,
2045        ENOMEM          = libc::ENOMEM,
2046        EACCES          = libc::EACCES,
2047        EFAULT          = libc::EFAULT,
2048        ENOTBLK         = libc::ENOTBLK,
2049        EBUSY           = libc::EBUSY,
2050        EEXIST          = libc::EEXIST,
2051        EXDEV           = libc::EXDEV,
2052        ENODEV          = libc::ENODEV,
2053        ENOTDIR         = libc::ENOTDIR,
2054        EISDIR          = libc::EISDIR,
2055        EINVAL          = libc::EINVAL,
2056        ENFILE          = libc::ENFILE,
2057        EMFILE          = libc::EMFILE,
2058        ENOTTY          = libc::ENOTTY,
2059        ETXTBSY         = libc::ETXTBSY,
2060        EFBIG           = libc::EFBIG,
2061        ENOSPC          = libc::ENOSPC,
2062        ESPIPE          = libc::ESPIPE,
2063        EROFS           = libc::EROFS,
2064        EMLINK          = libc::EMLINK,
2065        EPIPE           = libc::EPIPE,
2066        EDOM            = libc::EDOM,
2067        ERANGE          = libc::ERANGE,
2068        EAGAIN          = libc::EAGAIN,
2069        EINPROGRESS     = libc::EINPROGRESS,
2070        EALREADY        = libc::EALREADY,
2071        ENOTSOCK        = libc::ENOTSOCK,
2072        EDESTADDRREQ    = libc::EDESTADDRREQ,
2073        EMSGSIZE        = libc::EMSGSIZE,
2074        EPROTOTYPE      = libc::EPROTOTYPE,
2075        ENOPROTOOPT     = libc::ENOPROTOOPT,
2076        EPROTONOSUPPORT = libc::EPROTONOSUPPORT,
2077        ESOCKTNOSUPPORT = libc::ESOCKTNOSUPPORT,
2078        EOPNOTSUPP      = libc::EOPNOTSUPP,
2079        EPFNOSUPPORT    = libc::EPFNOSUPPORT,
2080        EAFNOSUPPORT    = libc::EAFNOSUPPORT,
2081        EADDRINUSE      = libc::EADDRINUSE,
2082        EADDRNOTAVAIL   = libc::EADDRNOTAVAIL,
2083        ENETDOWN        = libc::ENETDOWN,
2084        ENETUNREACH     = libc::ENETUNREACH,
2085        ENETRESET       = libc::ENETRESET,
2086        ECONNABORTED    = libc::ECONNABORTED,
2087        ECONNRESET      = libc::ECONNRESET,
2088        ENOBUFS         = libc::ENOBUFS,
2089        EISCONN         = libc::EISCONN,
2090        ENOTCONN        = libc::ENOTCONN,
2091        ESHUTDOWN       = libc::ESHUTDOWN,
2092        ETOOMANYREFS    = libc::ETOOMANYREFS,
2093        ETIMEDOUT       = libc::ETIMEDOUT,
2094        ECONNREFUSED    = libc::ECONNREFUSED,
2095        ELOOP           = libc::ELOOP,
2096        ENAMETOOLONG    = libc::ENAMETOOLONG,
2097        EHOSTDOWN       = libc::EHOSTDOWN,
2098        EHOSTUNREACH    = libc::EHOSTUNREACH,
2099        ENOTEMPTY       = libc::ENOTEMPTY,
2100        EPROCLIM        = libc::EPROCLIM,
2101        EUSERS          = libc::EUSERS,
2102        EDQUOT          = libc::EDQUOT,
2103        ESTALE          = libc::ESTALE,
2104        EREMOTE         = libc::EREMOTE,
2105        EBADRPC         = libc::EBADRPC,
2106        ERPCMISMATCH    = libc::ERPCMISMATCH,
2107        EPROGUNAVAIL    = libc::EPROGUNAVAIL,
2108        EPROGMISMATCH   = libc::EPROGMISMATCH,
2109        EPROCUNAVAIL    = libc::EPROCUNAVAIL,
2110        ENOLCK          = libc::ENOLCK,
2111        ENOSYS          = libc::ENOSYS,
2112        EFTYPE          = libc::EFTYPE,
2113        EAUTH           = libc::EAUTH,
2114        ENEEDAUTH       = libc::ENEEDAUTH,
2115        EIDRM           = libc::EIDRM,
2116        ENOMSG          = libc::ENOMSG,
2117        EOVERFLOW       = libc::EOVERFLOW,
2118        EILSEQ          = libc::EILSEQ,
2119        ENOTSUP         = libc::ENOTSUP,
2120        ECANCELED       = libc::ECANCELED,
2121        EBADMSG         = libc::EBADMSG,
2122        ENODATA         = libc::ENODATA,
2123        ENOSR           = libc::ENOSR,
2124        ENOSTR          = libc::ENOSTR,
2125        ETIME           = libc::ETIME,
2126        ENOATTR         = libc::ENOATTR,
2127        EMULTIHOP       = libc::EMULTIHOP,
2128        ENOLINK         = libc::ENOLINK,
2129        EPROTO          = libc::EPROTO,
2130    }
2131
2132    #[deprecated(
2133        since = "0.22.1",
2134        note = "use nix::errno::Errno::ELAST instead"
2135    )]
2136    pub const ELAST: Errno       = Errno::ENOTSUP;
2137    #[deprecated(
2138        since = "0.22.1",
2139        note = "use nix::errno::Errno::EWOULDBLOCK instead"
2140    )]
2141    pub const EWOULDBLOCK: Errno = Errno::EAGAIN;
2142
2143    impl Errno {
2144        pub const ELAST: Errno       = Errno::ENOTSUP;
2145        pub const EWOULDBLOCK: Errno = Errno::EAGAIN;
2146    }
2147
2148    pub const fn from_i32(e: i32) -> Errno {
2149        use self::Errno::*;
2150
2151        match e {
2152            libc::EPERM => EPERM,
2153            libc::ENOENT => ENOENT,
2154            libc::ESRCH => ESRCH,
2155            libc::EINTR => EINTR,
2156            libc::EIO => EIO,
2157            libc::ENXIO => ENXIO,
2158            libc::E2BIG => E2BIG,
2159            libc::ENOEXEC => ENOEXEC,
2160            libc::EBADF => EBADF,
2161            libc::ECHILD => ECHILD,
2162            libc::EDEADLK => EDEADLK,
2163            libc::ENOMEM => ENOMEM,
2164            libc::EACCES => EACCES,
2165            libc::EFAULT => EFAULT,
2166            libc::ENOTBLK => ENOTBLK,
2167            libc::EBUSY => EBUSY,
2168            libc::EEXIST => EEXIST,
2169            libc::EXDEV => EXDEV,
2170            libc::ENODEV => ENODEV,
2171            libc::ENOTDIR => ENOTDIR,
2172            libc::EISDIR => EISDIR,
2173            libc::EINVAL => EINVAL,
2174            libc::ENFILE => ENFILE,
2175            libc::EMFILE => EMFILE,
2176            libc::ENOTTY => ENOTTY,
2177            libc::ETXTBSY => ETXTBSY,
2178            libc::EFBIG => EFBIG,
2179            libc::ENOSPC => ENOSPC,
2180            libc::ESPIPE => ESPIPE,
2181            libc::EROFS => EROFS,
2182            libc::EMLINK => EMLINK,
2183            libc::EPIPE => EPIPE,
2184            libc::EDOM => EDOM,
2185            libc::ERANGE => ERANGE,
2186            libc::EAGAIN => EAGAIN,
2187            libc::EINPROGRESS => EINPROGRESS,
2188            libc::EALREADY => EALREADY,
2189            libc::ENOTSOCK => ENOTSOCK,
2190            libc::EDESTADDRREQ => EDESTADDRREQ,
2191            libc::EMSGSIZE => EMSGSIZE,
2192            libc::EPROTOTYPE => EPROTOTYPE,
2193            libc::ENOPROTOOPT => ENOPROTOOPT,
2194            libc::EPROTONOSUPPORT => EPROTONOSUPPORT,
2195            libc::ESOCKTNOSUPPORT => ESOCKTNOSUPPORT,
2196            libc::EOPNOTSUPP => EOPNOTSUPP,
2197            libc::EPFNOSUPPORT => EPFNOSUPPORT,
2198            libc::EAFNOSUPPORT => EAFNOSUPPORT,
2199            libc::EADDRINUSE => EADDRINUSE,
2200            libc::EADDRNOTAVAIL => EADDRNOTAVAIL,
2201            libc::ENETDOWN => ENETDOWN,
2202            libc::ENETUNREACH => ENETUNREACH,
2203            libc::ENETRESET => ENETRESET,
2204            libc::ECONNABORTED => ECONNABORTED,
2205            libc::ECONNRESET => ECONNRESET,
2206            libc::ENOBUFS => ENOBUFS,
2207            libc::EISCONN => EISCONN,
2208            libc::ENOTCONN => ENOTCONN,
2209            libc::ESHUTDOWN => ESHUTDOWN,
2210            libc::ETOOMANYREFS => ETOOMANYREFS,
2211            libc::ETIMEDOUT => ETIMEDOUT,
2212            libc::ECONNREFUSED => ECONNREFUSED,
2213            libc::ELOOP => ELOOP,
2214            libc::ENAMETOOLONG => ENAMETOOLONG,
2215            libc::EHOSTDOWN => EHOSTDOWN,
2216            libc::EHOSTUNREACH => EHOSTUNREACH,
2217            libc::ENOTEMPTY => ENOTEMPTY,
2218            libc::EPROCLIM => EPROCLIM,
2219            libc::EUSERS => EUSERS,
2220            libc::EDQUOT => EDQUOT,
2221            libc::ESTALE => ESTALE,
2222            libc::EREMOTE => EREMOTE,
2223            libc::EBADRPC => EBADRPC,
2224            libc::ERPCMISMATCH => ERPCMISMATCH,
2225            libc::EPROGUNAVAIL => EPROGUNAVAIL,
2226            libc::EPROGMISMATCH => EPROGMISMATCH,
2227            libc::EPROCUNAVAIL => EPROCUNAVAIL,
2228            libc::ENOLCK => ENOLCK,
2229            libc::ENOSYS => ENOSYS,
2230            libc::EFTYPE => EFTYPE,
2231            libc::EAUTH => EAUTH,
2232            libc::ENEEDAUTH => ENEEDAUTH,
2233            libc::EIDRM => EIDRM,
2234            libc::ENOMSG => ENOMSG,
2235            libc::EOVERFLOW => EOVERFLOW,
2236            libc::EILSEQ => EILSEQ,
2237            libc::ENOTSUP => ENOTSUP,
2238            libc::ECANCELED => ECANCELED,
2239            libc::EBADMSG => EBADMSG,
2240            libc::ENODATA => ENODATA,
2241            libc::ENOSR => ENOSR,
2242            libc::ENOSTR => ENOSTR,
2243            libc::ETIME => ETIME,
2244            libc::ENOATTR => ENOATTR,
2245            libc::EMULTIHOP => EMULTIHOP,
2246            libc::ENOLINK => ENOLINK,
2247            libc::EPROTO => EPROTO,
2248            _   => UnknownErrno,
2249        }
2250    }
2251}
2252
2253#[cfg(target_os = "redox")]
2254mod consts {
2255    #[derive(Clone, Copy, Debug, Eq, PartialEq)]
2256    #[repr(i32)]
2257    #[non_exhaustive]
2258    pub enum Errno {
2259        UnknownErrno = 0,
2260        EPERM = libc::EPERM,
2261        ENOENT = libc::ENOENT,
2262        ESRCH = libc::ESRCH,
2263        EINTR = libc::EINTR,
2264        EIO = libc::EIO,
2265        ENXIO = libc::ENXIO,
2266        E2BIG = libc::E2BIG,
2267        ENOEXEC = libc::ENOEXEC,
2268        EBADF = libc::EBADF,
2269        ECHILD = libc::ECHILD,
2270        EDEADLK = libc::EDEADLK,
2271        ENOMEM = libc::ENOMEM,
2272        EACCES = libc::EACCES,
2273        EFAULT = libc::EFAULT,
2274        ENOTBLK = libc::ENOTBLK,
2275        EBUSY = libc::EBUSY,
2276        EEXIST = libc::EEXIST,
2277        EXDEV = libc::EXDEV,
2278        ENODEV = libc::ENODEV,
2279        ENOTDIR = libc::ENOTDIR,
2280        EISDIR = libc::EISDIR,
2281        EINVAL = libc::EINVAL,
2282        ENFILE = libc::ENFILE,
2283        EMFILE = libc::EMFILE,
2284        ENOTTY = libc::ENOTTY,
2285        ETXTBSY = libc::ETXTBSY,
2286        EFBIG = libc::EFBIG,
2287        ENOSPC = libc::ENOSPC,
2288        ESPIPE = libc::ESPIPE,
2289        EROFS = libc::EROFS,
2290        EMLINK = libc::EMLINK,
2291        EPIPE = libc::EPIPE,
2292        EDOM = libc::EDOM,
2293        ERANGE = libc::ERANGE,
2294        EAGAIN = libc::EAGAIN,
2295        EINPROGRESS = libc::EINPROGRESS,
2296        EALREADY = libc::EALREADY,
2297        ENOTSOCK = libc::ENOTSOCK,
2298        EDESTADDRREQ = libc::EDESTADDRREQ,
2299        EMSGSIZE = libc::EMSGSIZE,
2300        EPROTOTYPE = libc::EPROTOTYPE,
2301        ENOPROTOOPT = libc::ENOPROTOOPT,
2302        EPROTONOSUPPORT = libc::EPROTONOSUPPORT,
2303        ESOCKTNOSUPPORT = libc::ESOCKTNOSUPPORT,
2304        EOPNOTSUPP = libc::EOPNOTSUPP,
2305        EPFNOSUPPORT = libc::EPFNOSUPPORT,
2306        EAFNOSUPPORT = libc::EAFNOSUPPORT,
2307        EADDRINUSE = libc::EADDRINUSE,
2308        EADDRNOTAVAIL = libc::EADDRNOTAVAIL,
2309        ENETDOWN = libc::ENETDOWN,
2310        ENETUNREACH = libc::ENETUNREACH,
2311        ENETRESET = libc::ENETRESET,
2312        ECONNABORTED = libc::ECONNABORTED,
2313        ECONNRESET = libc::ECONNRESET,
2314        ENOBUFS = libc::ENOBUFS,
2315        EISCONN = libc::EISCONN,
2316        ENOTCONN = libc::ENOTCONN,
2317        ESHUTDOWN = libc::ESHUTDOWN,
2318        ETOOMANYREFS = libc::ETOOMANYREFS,
2319        ETIMEDOUT = libc::ETIMEDOUT,
2320        ECONNREFUSED = libc::ECONNREFUSED,
2321        ELOOP = libc::ELOOP,
2322        ENAMETOOLONG = libc::ENAMETOOLONG,
2323        EHOSTDOWN = libc::EHOSTDOWN,
2324        EHOSTUNREACH = libc::EHOSTUNREACH,
2325        ENOTEMPTY = libc::ENOTEMPTY,
2326        EUSERS = libc::EUSERS,
2327        EDQUOT = libc::EDQUOT,
2328        ESTALE = libc::ESTALE,
2329        EREMOTE = libc::EREMOTE,
2330        ENOLCK = libc::ENOLCK,
2331        ENOSYS = libc::ENOSYS,
2332        EIDRM = libc::EIDRM,
2333        ENOMSG = libc::ENOMSG,
2334        EOVERFLOW = libc::EOVERFLOW,
2335        EILSEQ = libc::EILSEQ,
2336        ECANCELED = libc::ECANCELED,
2337        EBADMSG = libc::EBADMSG,
2338        ENODATA = libc::ENODATA,
2339        ENOSR = libc::ENOSR,
2340        ENOSTR = libc::ENOSTR,
2341        ETIME = libc::ETIME,
2342        EMULTIHOP = libc::EMULTIHOP,
2343        ENOLINK = libc::ENOLINK,
2344        EPROTO = libc::EPROTO,
2345    }
2346
2347    #[deprecated(
2348        since = "0.22.1",
2349        note = "use nix::errno::Errno::EWOULDBLOCK instead"
2350    )]
2351    pub const EWOULDBLOCK: Errno = Errno::EAGAIN;
2352
2353    impl Errno {
2354        pub const EWOULDBLOCK: Errno = Errno::EAGAIN;
2355    }
2356
2357    pub const fn from_i32(e: i32) -> Errno {
2358        use self::Errno::*;
2359
2360        match e {
2361            libc::EPERM => EPERM,
2362            libc::ENOENT => ENOENT,
2363            libc::ESRCH => ESRCH,
2364            libc::EINTR => EINTR,
2365            libc::EIO => EIO,
2366            libc::ENXIO => ENXIO,
2367            libc::E2BIG => E2BIG,
2368            libc::ENOEXEC => ENOEXEC,
2369            libc::EBADF => EBADF,
2370            libc::ECHILD => ECHILD,
2371            libc::EDEADLK => EDEADLK,
2372            libc::ENOMEM => ENOMEM,
2373            libc::EACCES => EACCES,
2374            libc::EFAULT => EFAULT,
2375            libc::ENOTBLK => ENOTBLK,
2376            libc::EBUSY => EBUSY,
2377            libc::EEXIST => EEXIST,
2378            libc::EXDEV => EXDEV,
2379            libc::ENODEV => ENODEV,
2380            libc::ENOTDIR => ENOTDIR,
2381            libc::EISDIR => EISDIR,
2382            libc::EINVAL => EINVAL,
2383            libc::ENFILE => ENFILE,
2384            libc::EMFILE => EMFILE,
2385            libc::ENOTTY => ENOTTY,
2386            libc::ETXTBSY => ETXTBSY,
2387            libc::EFBIG => EFBIG,
2388            libc::ENOSPC => ENOSPC,
2389            libc::ESPIPE => ESPIPE,
2390            libc::EROFS => EROFS,
2391            libc::EMLINK => EMLINK,
2392            libc::EPIPE => EPIPE,
2393            libc::EDOM => EDOM,
2394            libc::ERANGE => ERANGE,
2395            libc::EAGAIN => EAGAIN,
2396            libc::EINPROGRESS => EINPROGRESS,
2397            libc::EALREADY => EALREADY,
2398            libc::ENOTSOCK => ENOTSOCK,
2399            libc::EDESTADDRREQ => EDESTADDRREQ,
2400            libc::EMSGSIZE => EMSGSIZE,
2401            libc::EPROTOTYPE => EPROTOTYPE,
2402            libc::ENOPROTOOPT => ENOPROTOOPT,
2403            libc::EPROTONOSUPPORT => EPROTONOSUPPORT,
2404            libc::ESOCKTNOSUPPORT => ESOCKTNOSUPPORT,
2405            libc::EOPNOTSUPP => EOPNOTSUPP,
2406            libc::EPFNOSUPPORT => EPFNOSUPPORT,
2407            libc::EAFNOSUPPORT => EAFNOSUPPORT,
2408            libc::EADDRINUSE => EADDRINUSE,
2409            libc::EADDRNOTAVAIL => EADDRNOTAVAIL,
2410            libc::ENETDOWN => ENETDOWN,
2411            libc::ENETUNREACH => ENETUNREACH,
2412            libc::ENETRESET => ENETRESET,
2413            libc::ECONNABORTED => ECONNABORTED,
2414            libc::ECONNRESET => ECONNRESET,
2415            libc::ENOBUFS => ENOBUFS,
2416            libc::EISCONN => EISCONN,
2417            libc::ENOTCONN => ENOTCONN,
2418            libc::ESHUTDOWN => ESHUTDOWN,
2419            libc::ETOOMANYREFS => ETOOMANYREFS,
2420            libc::ETIMEDOUT => ETIMEDOUT,
2421            libc::ECONNREFUSED => ECONNREFUSED,
2422            libc::ELOOP => ELOOP,
2423            libc::ENAMETOOLONG => ENAMETOOLONG,
2424            libc::EHOSTDOWN => EHOSTDOWN,
2425            libc::EHOSTUNREACH => EHOSTUNREACH,
2426            libc::ENOTEMPTY => ENOTEMPTY,
2427            libc::EUSERS => EUSERS,
2428            libc::EDQUOT => EDQUOT,
2429            libc::ESTALE => ESTALE,
2430            libc::EREMOTE => EREMOTE,
2431            libc::ENOLCK => ENOLCK,
2432            libc::ENOSYS => ENOSYS,
2433            libc::EIDRM => EIDRM,
2434            libc::ENOMSG => ENOMSG,
2435            libc::EOVERFLOW => EOVERFLOW,
2436            libc::EILSEQ => EILSEQ,
2437            libc::ECANCELED => ECANCELED,
2438            libc::EBADMSG => EBADMSG,
2439            libc::ENODATA => ENODATA,
2440            libc::ENOSR => ENOSR,
2441            libc::ENOSTR => ENOSTR,
2442            libc::ETIME => ETIME,
2443            libc::EMULTIHOP => EMULTIHOP,
2444            libc::ENOLINK => ENOLINK,
2445            libc::EPROTO => EPROTO,
2446            _ => UnknownErrno,
2447        }
2448    }
2449}
2450
2451#[cfg(any(target_os = "illumos", target_os = "solaris"))]
2452mod consts {
2453    #[derive(Clone, Copy, Debug, Eq, PartialEq)]
2454    #[repr(i32)]
2455    #[non_exhaustive]
2456    pub enum Errno {
2457        UnknownErrno = 0,
2458        EPERM = libc::EPERM,
2459        ENOENT = libc::ENOENT,
2460        ESRCH = libc::ESRCH,
2461        EINTR = libc::EINTR,
2462        EIO = libc::EIO,
2463        ENXIO = libc::ENXIO,
2464        E2BIG = libc::E2BIG,
2465        ENOEXEC = libc::ENOEXEC,
2466        EBADF = libc::EBADF,
2467        ECHILD = libc::ECHILD,
2468        EAGAIN = libc::EAGAIN,
2469        ENOMEM = libc::ENOMEM,
2470        EACCES = libc::EACCES,
2471        EFAULT = libc::EFAULT,
2472        ENOTBLK = libc::ENOTBLK,
2473        EBUSY = libc::EBUSY,
2474        EEXIST = libc::EEXIST,
2475        EXDEV = libc::EXDEV,
2476        ENODEV = libc::ENODEV,
2477        ENOTDIR = libc::ENOTDIR,
2478        EISDIR = libc::EISDIR,
2479        EINVAL = libc::EINVAL,
2480        ENFILE = libc::ENFILE,
2481        EMFILE = libc::EMFILE,
2482        ENOTTY = libc::ENOTTY,
2483        ETXTBSY = libc::ETXTBSY,
2484        EFBIG = libc::EFBIG,
2485        ENOSPC = libc::ENOSPC,
2486        ESPIPE = libc::ESPIPE,
2487        EROFS = libc::EROFS,
2488        EMLINK = libc::EMLINK,
2489        EPIPE = libc::EPIPE,
2490        EDOM = libc::EDOM,
2491        ERANGE = libc::ERANGE,
2492        ENOMSG = libc::ENOMSG,
2493        EIDRM = libc::EIDRM,
2494        ECHRNG = libc::ECHRNG,
2495        EL2NSYNC = libc::EL2NSYNC,
2496        EL3HLT = libc::EL3HLT,
2497        EL3RST = libc::EL3RST,
2498        ELNRNG = libc::ELNRNG,
2499        EUNATCH = libc::EUNATCH,
2500        ENOCSI = libc::ENOCSI,
2501        EL2HLT = libc::EL2HLT,
2502        EDEADLK = libc::EDEADLK,
2503        ENOLCK = libc::ENOLCK,
2504        ECANCELED = libc::ECANCELED,
2505        ENOTSUP = libc::ENOTSUP,
2506        EDQUOT = libc::EDQUOT,
2507        EBADE = libc::EBADE,
2508        EBADR = libc::EBADR,
2509        EXFULL = libc::EXFULL,
2510        ENOANO = libc::ENOANO,
2511        EBADRQC = libc::EBADRQC,
2512        EBADSLT = libc::EBADSLT,
2513        EDEADLOCK = libc::EDEADLOCK,
2514        EBFONT = libc::EBFONT,
2515        EOWNERDEAD = libc::EOWNERDEAD,
2516        ENOTRECOVERABLE = libc::ENOTRECOVERABLE,
2517        ENOSTR = libc::ENOSTR,
2518        ENODATA = libc::ENODATA,
2519        ETIME = libc::ETIME,
2520        ENOSR = libc::ENOSR,
2521        ENONET = libc::ENONET,
2522        ENOPKG = libc::ENOPKG,
2523        EREMOTE = libc::EREMOTE,
2524        ENOLINK = libc::ENOLINK,
2525        EADV = libc::EADV,
2526        ESRMNT = libc::ESRMNT,
2527        ECOMM = libc::ECOMM,
2528        EPROTO = libc::EPROTO,
2529        ELOCKUNMAPPED = libc::ELOCKUNMAPPED,
2530        ENOTACTIVE = libc::ENOTACTIVE,
2531        EMULTIHOP = libc::EMULTIHOP,
2532        EBADMSG = libc::EBADMSG,
2533        ENAMETOOLONG = libc::ENAMETOOLONG,
2534        EOVERFLOW = libc::EOVERFLOW,
2535        ENOTUNIQ = libc::ENOTUNIQ,
2536        EBADFD = libc::EBADFD,
2537        EREMCHG = libc::EREMCHG,
2538        ELIBACC = libc::ELIBACC,
2539        ELIBBAD = libc::ELIBBAD,
2540        ELIBSCN = libc::ELIBSCN,
2541        ELIBMAX = libc::ELIBMAX,
2542        ELIBEXEC = libc::ELIBEXEC,
2543        EILSEQ = libc::EILSEQ,
2544        ENOSYS = libc::ENOSYS,
2545        ELOOP = libc::ELOOP,
2546        ERESTART = libc::ERESTART,
2547        ESTRPIPE = libc::ESTRPIPE,
2548        ENOTEMPTY = libc::ENOTEMPTY,
2549        EUSERS = libc::EUSERS,
2550        ENOTSOCK = libc::ENOTSOCK,
2551        EDESTADDRREQ = libc::EDESTADDRREQ,
2552        EMSGSIZE = libc::EMSGSIZE,
2553        EPROTOTYPE = libc::EPROTOTYPE,
2554        ENOPROTOOPT = libc::ENOPROTOOPT,
2555        EPROTONOSUPPORT = libc::EPROTONOSUPPORT,
2556        ESOCKTNOSUPPORT = libc::ESOCKTNOSUPPORT,
2557        EOPNOTSUPP = libc::EOPNOTSUPP,
2558        EPFNOSUPPORT = libc::EPFNOSUPPORT,
2559        EAFNOSUPPORT = libc::EAFNOSUPPORT,
2560        EADDRINUSE = libc::EADDRINUSE,
2561        EADDRNOTAVAIL = libc::EADDRNOTAVAIL,
2562        ENETDOWN = libc::ENETDOWN,
2563        ENETUNREACH = libc::ENETUNREACH,
2564        ENETRESET = libc::ENETRESET,
2565        ECONNABORTED = libc::ECONNABORTED,
2566        ECONNRESET = libc::ECONNRESET,
2567        ENOBUFS = libc::ENOBUFS,
2568        EISCONN = libc::EISCONN,
2569        ENOTCONN = libc::ENOTCONN,
2570        ESHUTDOWN = libc::ESHUTDOWN,
2571        ETOOMANYREFS = libc::ETOOMANYREFS,
2572        ETIMEDOUT = libc::ETIMEDOUT,
2573        ECONNREFUSED = libc::ECONNREFUSED,
2574        EHOSTDOWN = libc::EHOSTDOWN,
2575        EHOSTUNREACH = libc::EHOSTUNREACH,
2576        EALREADY = libc::EALREADY,
2577        EINPROGRESS = libc::EINPROGRESS,
2578        ESTALE = libc::ESTALE,
2579    }
2580
2581    #[deprecated(
2582        since = "0.22.1",
2583        note = "use nix::errno::Errno::ELAST instead"
2584    )]
2585    pub const ELAST: Errno = Errno::ELAST;
2586    #[deprecated(
2587        since = "0.22.1",
2588        note = "use nix::errno::Errno::EWOULDBLOCK instead"
2589    )]
2590    pub const EWOULDBLOCK: Errno = Errno::EAGAIN;
2591
2592    impl Errno {
2593        pub const ELAST: Errno       = Errno::ESTALE;
2594        pub const EWOULDBLOCK: Errno = Errno::EAGAIN;
2595    }
2596
2597    pub const fn from_i32(e: i32) -> Errno {
2598        use self::Errno::*;
2599
2600        match e {
2601            libc::EPERM => EPERM,
2602            libc::ENOENT => ENOENT,
2603            libc::ESRCH => ESRCH,
2604            libc::EINTR => EINTR,
2605            libc::EIO => EIO,
2606            libc::ENXIO => ENXIO,
2607            libc::E2BIG => E2BIG,
2608            libc::ENOEXEC => ENOEXEC,
2609            libc::EBADF => EBADF,
2610            libc::ECHILD => ECHILD,
2611            libc::EAGAIN => EAGAIN,
2612            libc::ENOMEM => ENOMEM,
2613            libc::EACCES => EACCES,
2614            libc::EFAULT => EFAULT,
2615            libc::ENOTBLK => ENOTBLK,
2616            libc::EBUSY => EBUSY,
2617            libc::EEXIST => EEXIST,
2618            libc::EXDEV => EXDEV,
2619            libc::ENODEV => ENODEV,
2620            libc::ENOTDIR => ENOTDIR,
2621            libc::EISDIR => EISDIR,
2622            libc::EINVAL => EINVAL,
2623            libc::ENFILE => ENFILE,
2624            libc::EMFILE => EMFILE,
2625            libc::ENOTTY => ENOTTY,
2626            libc::ETXTBSY => ETXTBSY,
2627            libc::EFBIG => EFBIG,
2628            libc::ENOSPC => ENOSPC,
2629            libc::ESPIPE => ESPIPE,
2630            libc::EROFS => EROFS,
2631            libc::EMLINK => EMLINK,
2632            libc::EPIPE => EPIPE,
2633            libc::EDOM => EDOM,
2634            libc::ERANGE => ERANGE,
2635            libc::ENOMSG => ENOMSG,
2636            libc::EIDRM => EIDRM,
2637            libc::ECHRNG => ECHRNG,
2638            libc::EL2NSYNC => EL2NSYNC,
2639            libc::EL3HLT => EL3HLT,
2640            libc::EL3RST => EL3RST,
2641            libc::ELNRNG => ELNRNG,
2642            libc::EUNATCH => EUNATCH,
2643            libc::ENOCSI => ENOCSI,
2644            libc::EL2HLT => EL2HLT,
2645            libc::EDEADLK => EDEADLK,
2646            libc::ENOLCK => ENOLCK,
2647            libc::ECANCELED => ECANCELED,
2648            libc::ENOTSUP => ENOTSUP,
2649            libc::EDQUOT => EDQUOT,
2650            libc::EBADE => EBADE,
2651            libc::EBADR => EBADR,
2652            libc::EXFULL => EXFULL,
2653            libc::ENOANO => ENOANO,
2654            libc::EBADRQC => EBADRQC,
2655            libc::EBADSLT => EBADSLT,
2656            libc::EDEADLOCK => EDEADLOCK,
2657            libc::EBFONT => EBFONT,
2658            libc::EOWNERDEAD => EOWNERDEAD,
2659            libc::ENOTRECOVERABLE => ENOTRECOVERABLE,
2660            libc::ENOSTR => ENOSTR,
2661            libc::ENODATA => ENODATA,
2662            libc::ETIME => ETIME,
2663            libc::ENOSR => ENOSR,
2664            libc::ENONET => ENONET,
2665            libc::ENOPKG => ENOPKG,
2666            libc::EREMOTE => EREMOTE,
2667            libc::ENOLINK => ENOLINK,
2668            libc::EADV => EADV,
2669            libc::ESRMNT => ESRMNT,
2670            libc::ECOMM => ECOMM,
2671            libc::EPROTO => EPROTO,
2672            libc::ELOCKUNMAPPED => ELOCKUNMAPPED,
2673            libc::ENOTACTIVE => ENOTACTIVE,
2674            libc::EMULTIHOP => EMULTIHOP,
2675            libc::EBADMSG => EBADMSG,
2676            libc::ENAMETOOLONG => ENAMETOOLONG,
2677            libc::EOVERFLOW => EOVERFLOW,
2678            libc::ENOTUNIQ => ENOTUNIQ,
2679            libc::EBADFD => EBADFD,
2680            libc::EREMCHG => EREMCHG,
2681            libc::ELIBACC => ELIBACC,
2682            libc::ELIBBAD => ELIBBAD,
2683            libc::ELIBSCN => ELIBSCN,
2684            libc::ELIBMAX => ELIBMAX,
2685            libc::ELIBEXEC => ELIBEXEC,
2686            libc::EILSEQ => EILSEQ,
2687            libc::ENOSYS => ENOSYS,
2688            libc::ELOOP => ELOOP,
2689            libc::ERESTART => ERESTART,
2690            libc::ESTRPIPE => ESTRPIPE,
2691            libc::ENOTEMPTY => ENOTEMPTY,
2692            libc::EUSERS => EUSERS,
2693            libc::ENOTSOCK => ENOTSOCK,
2694            libc::EDESTADDRREQ => EDESTADDRREQ,
2695            libc::EMSGSIZE => EMSGSIZE,
2696            libc::EPROTOTYPE => EPROTOTYPE,
2697            libc::ENOPROTOOPT => ENOPROTOOPT,
2698            libc::EPROTONOSUPPORT => EPROTONOSUPPORT,
2699            libc::ESOCKTNOSUPPORT => ESOCKTNOSUPPORT,
2700            libc::EOPNOTSUPP => EOPNOTSUPP,
2701            libc::EPFNOSUPPORT => EPFNOSUPPORT,
2702            libc::EAFNOSUPPORT => EAFNOSUPPORT,
2703            libc::EADDRINUSE => EADDRINUSE,
2704            libc::EADDRNOTAVAIL => EADDRNOTAVAIL,
2705            libc::ENETDOWN => ENETDOWN,
2706            libc::ENETUNREACH => ENETUNREACH,
2707            libc::ENETRESET => ENETRESET,
2708            libc::ECONNABORTED => ECONNABORTED,
2709            libc::ECONNRESET => ECONNRESET,
2710            libc::ENOBUFS => ENOBUFS,
2711            libc::EISCONN => EISCONN,
2712            libc::ENOTCONN => ENOTCONN,
2713            libc::ESHUTDOWN => ESHUTDOWN,
2714            libc::ETOOMANYREFS => ETOOMANYREFS,
2715            libc::ETIMEDOUT => ETIMEDOUT,
2716            libc::ECONNREFUSED => ECONNREFUSED,
2717            libc::EHOSTDOWN => EHOSTDOWN,
2718            libc::EHOSTUNREACH => EHOSTUNREACH,
2719            libc::EALREADY => EALREADY,
2720            libc::EINPROGRESS => EINPROGRESS,
2721            libc::ESTALE => ESTALE,
2722            _ => UnknownErrno,
2723        }
2724    }
2725}