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