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