rustix/backend/libc/io/
errno.rs

1//! The `rustix` `Errno` type.
2//!
3//! This type holds an OS error code, which conceptually corresponds to an
4//! `errno` value.
5
6use crate::backend::c;
7use libc_errno::errno;
8
9/// `errno`—An error code.
10///
11/// The error type for `rustix` APIs. This is similar to [`std::io::Error`],
12/// but only holds an OS error code, and no extra error value.
13///
14/// # References
15///  - [POSIX]
16///  - [Linux]
17///  - [Winsock]
18///  - [FreeBSD]
19///  - [NetBSD]
20///  - [OpenBSD]
21///  - [DragonFly BSD]
22///  - [illumos]
23///  - [glibc]
24///
25/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9799919799/functions/errno.html
26/// [Linux]: https://man7.org/linux/man-pages/man3/errno.3.html
27/// [Winsock]: https://learn.microsoft.com/en-us/windows/win32/winsock/windows-sockets-error-codes-2
28/// [FreeBSD]: https://man.freebsd.org/cgi/man.cgi?errno
29/// [NetBSD]: https://man.netbsd.org/errno.2
30/// [OpenBSD]: https://man.openbsd.org/errno.2
31/// [DragonFly BSD]: https://man.dragonflybsd.org/?command=errno&section=2
32/// [illumos]: https://illumos.org/man/3C/errno
33/// [glibc]: https://sourceware.org/glibc/manual/latest/html_node/Error-Codes.html
34#[repr(transparent)]
35#[doc(alias = "errno")]
36#[derive(Eq, PartialEq, Hash, Copy, Clone)]
37pub struct Errno(pub(crate) c::c_int);
38
39impl Errno {
40    /// `EACCES`
41    #[doc(alias = "ACCES")]
42    pub const ACCESS: Self = Self(c::EACCES);
43    /// `EADDRINUSE`
44    pub const ADDRINUSE: Self = Self(c::EADDRINUSE);
45    /// `EADDRNOTAVAIL`
46    pub const ADDRNOTAVAIL: Self = Self(c::EADDRNOTAVAIL);
47    /// `EADV`
48    #[cfg(not(any(
49        bsd,
50        windows,
51        target_os = "aix",
52        target_os = "espidf",
53        target_os = "haiku",
54        target_os = "horizon",
55        target_os = "hurd",
56        target_os = "l4re",
57        target_os = "vita",
58        target_os = "wasi",
59    )))]
60    pub const ADV: Self = Self(c::EADV);
61    /// `EAFNOSUPPORT`
62    #[cfg(not(target_os = "l4re"))]
63    pub const AFNOSUPPORT: Self = Self(c::EAFNOSUPPORT);
64    /// `EAGAIN`
65    pub const AGAIN: Self = Self(c::EAGAIN);
66    /// `EALREADY`
67    #[cfg(not(target_os = "l4re"))]
68    pub const ALREADY: Self = Self(c::EALREADY);
69    /// `EAUTH`
70    #[cfg(bsd)]
71    pub const AUTH: Self = Self(c::EAUTH);
72    /// `EBADE`
73    #[cfg(not(any(
74        bsd,
75        windows,
76        target_os = "aix",
77        target_os = "espidf",
78        target_os = "haiku",
79        target_os = "horizon",
80        target_os = "hurd",
81        target_os = "l4re",
82        target_os = "vita",
83        target_os = "wasi",
84    )))]
85    pub const BADE: Self = Self(c::EBADE);
86    /// `EBADF`
87    pub const BADF: Self = Self(c::EBADF);
88    /// `EBADFD`
89    #[cfg(not(any(
90        bsd,
91        windows,
92        target_os = "aix",
93        target_os = "espidf",
94        target_os = "haiku",
95        target_os = "horizon",
96        target_os = "hurd",
97        target_os = "l4re",
98        target_os = "vita",
99        target_os = "wasi",
100    )))]
101    pub const BADFD: Self = Self(c::EBADFD);
102    /// `EBADMSG`
103    #[cfg(not(any(windows, target_os = "l4re")))]
104    pub const BADMSG: Self = Self(c::EBADMSG);
105    /// `EBADR`
106    #[cfg(not(any(
107        bsd,
108        windows,
109        target_os = "aix",
110        target_os = "espidf",
111        target_os = "haiku",
112        target_os = "horizon",
113        target_os = "hurd",
114        target_os = "l4re",
115        target_os = "vita",
116        target_os = "wasi",
117    )))]
118    pub const BADR: Self = Self(c::EBADR);
119    /// `EBADRPC`
120    #[cfg(bsd)]
121    pub const BADRPC: Self = Self(c::EBADRPC);
122    /// `EBADRQC`
123    #[cfg(not(any(
124        bsd,
125        windows,
126        target_os = "aix",
127        target_os = "espidf",
128        target_os = "haiku",
129        target_os = "horizon",
130        target_os = "hurd",
131        target_os = "l4re",
132        target_os = "vita",
133        target_os = "wasi",
134    )))]
135    pub const BADRQC: Self = Self(c::EBADRQC);
136    /// `EBADSLT`
137    #[cfg(not(any(
138        bsd,
139        windows,
140        target_os = "aix",
141        target_os = "espidf",
142        target_os = "haiku",
143        target_os = "horizon",
144        target_os = "hurd",
145        target_os = "l4re",
146        target_os = "vita",
147        target_os = "wasi",
148    )))]
149    pub const BADSLT: Self = Self(c::EBADSLT);
150    /// `EBFONT`
151    #[cfg(not(any(
152        bsd,
153        windows,
154        target_os = "aix",
155        target_os = "espidf",
156        target_os = "haiku",
157        target_os = "horizon",
158        target_os = "hurd",
159        target_os = "l4re",
160        target_os = "vita",
161        target_os = "wasi",
162    )))]
163    pub const BFONT: Self = Self(c::EBFONT);
164    /// `EBUSY`
165    #[cfg(not(windows))]
166    pub const BUSY: Self = Self(c::EBUSY);
167    /// `ECANCELED`
168    #[cfg(not(target_os = "l4re"))]
169    pub const CANCELED: Self = Self(c::ECANCELED);
170    /// `ECAPMODE`
171    #[cfg(target_os = "freebsd")]
172    pub const CAPMODE: Self = Self(c::ECAPMODE);
173    /// `ECHILD`
174    #[cfg(not(windows))]
175    pub const CHILD: Self = Self(c::ECHILD);
176    /// `ECHRNG`
177    #[cfg(not(any(
178        bsd,
179        windows,
180        target_os = "espidf",
181        target_os = "haiku",
182        target_os = "horizon",
183        target_os = "hurd",
184        target_os = "l4re",
185        target_os = "vita",
186        target_os = "wasi"
187    )))]
188    pub const CHRNG: Self = Self(c::ECHRNG);
189    /// `ECOMM`
190    #[cfg(not(any(
191        bsd,
192        windows,
193        target_os = "aix",
194        target_os = "espidf",
195        target_os = "haiku",
196        target_os = "horizon",
197        target_os = "hurd",
198        target_os = "l4re",
199        target_os = "vita",
200        target_os = "wasi",
201    )))]
202    pub const COMM: Self = Self(c::ECOMM);
203    /// `ECONNABORTED`
204    pub const CONNABORTED: Self = Self(c::ECONNABORTED);
205    /// `ECONNREFUSED`
206    pub const CONNREFUSED: Self = Self(c::ECONNREFUSED);
207    /// `ECONNRESET`
208    pub const CONNRESET: Self = Self(c::ECONNRESET);
209    /// `EDEADLK`
210    #[cfg(not(windows))]
211    pub const DEADLK: Self = Self(c::EDEADLK);
212    /// `EDEADLOCK`
213    #[cfg(not(any(
214        bsd,
215        windows,
216        target_os = "aix",
217        target_os = "android",
218        target_os = "espidf",
219        target_os = "haiku",
220        target_os = "horizon",
221        target_os = "hurd",
222        target_os = "vita",
223        target_os = "wasi",
224    )))]
225    pub const DEADLOCK: Self = Self(c::EDEADLOCK);
226    /// `EDESTADDRREQ`
227    #[cfg(not(target_os = "l4re"))]
228    pub const DESTADDRREQ: Self = Self(c::EDESTADDRREQ);
229    /// `EDISCON`
230    #[cfg(windows)]
231    pub const DISCON: Self = Self(c::EDISCON);
232    /// `EDOM`
233    #[cfg(not(windows))]
234    pub const DOM: Self = Self(c::EDOM);
235    /// `EDOOFUS`
236    #[cfg(freebsdlike)]
237    pub const DOOFUS: Self = Self(c::EDOOFUS);
238    /// `EDOTDOT`
239    #[cfg(not(any(
240        bsd,
241        solarish,
242        windows,
243        target_os = "aix",
244        target_os = "espidf",
245        target_os = "haiku",
246        target_os = "horizon",
247        target_os = "hurd",
248        target_os = "l4re",
249        target_os = "nto",
250        target_os = "vita",
251        target_os = "wasi",
252    )))]
253    pub const DOTDOT: Self = Self(c::EDOTDOT);
254    /// `EDQUOT`
255    pub const DQUOT: Self = Self(c::EDQUOT);
256    /// `EEXIST`
257    #[cfg(not(windows))]
258    pub const EXIST: Self = Self(c::EEXIST);
259    /// `EFAULT`
260    pub const FAULT: Self = Self(c::EFAULT);
261    /// `EFBIG`
262    #[cfg(not(windows))]
263    pub const FBIG: Self = Self(c::EFBIG);
264    /// `EFTYPE`
265    #[cfg(any(bsd, target_env = "newlib"))]
266    pub const FTYPE: Self = Self(c::EFTYPE);
267    /// `EHOSTDOWN`
268    #[cfg(not(any(target_os = "l4re", target_os = "wasi")))]
269    pub const HOSTDOWN: Self = Self(c::EHOSTDOWN);
270    /// `EHOSTUNREACH`
271    pub const HOSTUNREACH: Self = Self(c::EHOSTUNREACH);
272    /// `EHWPOISON`
273    #[cfg(not(any(
274        bsd,
275        solarish,
276        windows,
277        target_os = "aix",
278        target_os = "android",
279        target_os = "cygwin",
280        target_os = "espidf",
281        target_os = "haiku",
282        target_os = "horizon",
283        target_os = "hurd",
284        target_os = "l4re",
285        target_os = "nto",
286        target_os = "redox",
287        target_os = "vita",
288        target_os = "wasi",
289    )))]
290    pub const HWPOISON: Self = Self(c::EHWPOISON);
291    /// `EIDRM`
292    #[cfg(not(any(windows, target_os = "l4re")))]
293    pub const IDRM: Self = Self(c::EIDRM);
294    /// `EILSEQ`
295    #[cfg(not(any(windows, target_os = "l4re")))]
296    pub const ILSEQ: Self = Self(c::EILSEQ);
297    /// `EINPROGRESS`
298    #[cfg(not(target_os = "l4re"))]
299    pub const INPROGRESS: Self = Self(c::EINPROGRESS);
300    /// `EINTR`
301    ///
302    /// For a convenient way to retry system calls that exit with `INTR`, use
303    /// [`retry_on_intr`].
304    ///
305    /// [`retry_on_intr`]: crate::io::retry_on_intr
306    pub const INTR: Self = Self(c::EINTR);
307    /// `EINVAL`
308    pub const INVAL: Self = Self(c::EINVAL);
309    /// `EINVALIDPROCTABLE`
310    #[cfg(windows)]
311    pub const INVALIDPROCTABLE: Self = Self(c::EINVALIDPROCTABLE);
312    /// `EINVALIDPROVIDER`
313    #[cfg(windows)]
314    pub const INVALIDPROVIDER: Self = Self(c::EINVALIDPROVIDER);
315    /// `EIO`
316    #[cfg(not(windows))]
317    pub const IO: Self = Self(c::EIO);
318    /// `EISCONN`
319    #[cfg(not(target_os = "l4re"))]
320    pub const ISCONN: Self = Self(c::EISCONN);
321    /// `EISDIR`
322    #[cfg(not(windows))]
323    pub const ISDIR: Self = Self(c::EISDIR);
324    /// `EISNAM`
325    #[cfg(not(any(
326        bsd,
327        solarish,
328        windows,
329        target_os = "aix",
330        target_os = "cygwin",
331        target_os = "espidf",
332        target_os = "haiku",
333        target_os = "horizon",
334        target_os = "hurd",
335        target_os = "l4re",
336        target_os = "nto",
337        target_os = "vita",
338        target_os = "wasi",
339    )))]
340    pub const ISNAM: Self = Self(c::EISNAM);
341    /// `EKEYEXPIRED`
342    #[cfg(not(any(
343        bsd,
344        solarish,
345        windows,
346        target_os = "aix",
347        target_os = "cygwin",
348        target_os = "espidf",
349        target_os = "haiku",
350        target_os = "horizon",
351        target_os = "hurd",
352        target_os = "l4re",
353        target_os = "nto",
354        target_os = "vita",
355        target_os = "wasi",
356    )))]
357    pub const KEYEXPIRED: Self = Self(c::EKEYEXPIRED);
358    /// `EKEYREJECTED`
359    #[cfg(not(any(
360        bsd,
361        solarish,
362        windows,
363        target_os = "aix",
364        target_os = "cygwin",
365        target_os = "espidf",
366        target_os = "haiku",
367        target_os = "horizon",
368        target_os = "hurd",
369        target_os = "l4re",
370        target_os = "nto",
371        target_os = "vita",
372        target_os = "wasi",
373    )))]
374    pub const KEYREJECTED: Self = Self(c::EKEYREJECTED);
375    /// `EKEYREVOKED`
376    #[cfg(not(any(
377        bsd,
378        solarish,
379        windows,
380        target_os = "aix",
381        target_os = "cygwin",
382        target_os = "espidf",
383        target_os = "haiku",
384        target_os = "horizon",
385        target_os = "hurd",
386        target_os = "l4re",
387        target_os = "nto",
388        target_os = "vita",
389        target_os = "wasi",
390    )))]
391    pub const KEYREVOKED: Self = Self(c::EKEYREVOKED);
392    /// `EL2HLT`
393    #[cfg(not(any(
394        bsd,
395        windows,
396        target_os = "espidf",
397        target_os = "haiku",
398        target_os = "horizon",
399        target_os = "hurd",
400        target_os = "l4re",
401        target_os = "vita",
402        target_os = "wasi"
403    )))]
404    pub const L2HLT: Self = Self(c::EL2HLT);
405    /// `EL2NSYNC`
406    #[cfg(not(any(
407        bsd,
408        windows,
409        target_os = "espidf",
410        target_os = "haiku",
411        target_os = "horizon",
412        target_os = "hurd",
413        target_os = "l4re",
414        target_os = "vita",
415        target_os = "wasi"
416    )))]
417    pub const L2NSYNC: Self = Self(c::EL2NSYNC);
418    /// `EL3HLT`
419    #[cfg(not(any(
420        bsd,
421        windows,
422        target_os = "espidf",
423        target_os = "haiku",
424        target_os = "horizon",
425        target_os = "hurd",
426        target_os = "l4re",
427        target_os = "vita",
428        target_os = "wasi"
429    )))]
430    pub const L3HLT: Self = Self(c::EL3HLT);
431    /// `EL3RST`
432    #[cfg(not(any(
433        bsd,
434        windows,
435        target_os = "espidf",
436        target_os = "haiku",
437        target_os = "horizon",
438        target_os = "hurd",
439        target_os = "l4re",
440        target_os = "vita",
441        target_os = "wasi"
442    )))]
443    pub const L3RST: Self = Self(c::EL3RST);
444    /// `ELIBACC`
445    #[cfg(not(any(
446        bsd,
447        windows,
448        target_os = "aix",
449        target_os = "espidf",
450        target_os = "haiku",
451        target_os = "horizon",
452        target_os = "hurd",
453        target_os = "l4re",
454        target_os = "vita",
455        target_os = "wasi",
456    )))]
457    pub const LIBACC: Self = Self(c::ELIBACC);
458    /// `ELIBBAD`
459    #[cfg(not(any(
460        bsd,
461        windows,
462        target_os = "aix",
463        target_os = "espidf",
464        target_os = "haiku",
465        target_os = "horizon",
466        target_os = "hurd",
467        target_os = "l4re",
468        target_os = "vita",
469        target_os = "wasi",
470    )))]
471    pub const LIBBAD: Self = Self(c::ELIBBAD);
472    /// `ELIBEXEC`
473    #[cfg(not(any(
474        bsd,
475        windows,
476        target_os = "aix",
477        target_os = "espidf",
478        target_os = "haiku",
479        target_os = "horizon",
480        target_os = "l4re",
481        target_os = "vita",
482        target_os = "wasi",
483    )))]
484    pub const LIBEXEC: Self = Self(c::ELIBEXEC);
485    /// `ELIBMAX`
486    #[cfg(not(any(
487        bsd,
488        windows,
489        target_os = "aix",
490        target_os = "espidf",
491        target_os = "haiku",
492        target_os = "horizon",
493        target_os = "hurd",
494        target_os = "l4re",
495        target_os = "vita",
496        target_os = "wasi",
497    )))]
498    pub const LIBMAX: Self = Self(c::ELIBMAX);
499    /// `ELIBSCN`
500    #[cfg(not(any(
501        bsd,
502        windows,
503        target_os = "aix",
504        target_os = "espidf",
505        target_os = "haiku",
506        target_os = "horizon",
507        target_os = "hurd",
508        target_os = "l4re",
509        target_os = "vita",
510        target_os = "wasi",
511    )))]
512    pub const LIBSCN: Self = Self(c::ELIBSCN);
513    /// `ELNRNG`
514    #[cfg(not(any(
515        bsd,
516        windows,
517        target_os = "espidf",
518        target_os = "haiku",
519        target_os = "horizon",
520        target_os = "hurd",
521        target_os = "l4re",
522        target_os = "vita",
523        target_os = "wasi"
524    )))]
525    pub const LNRNG: Self = Self(c::ELNRNG);
526    /// `ELOOP`
527    pub const LOOP: Self = Self(c::ELOOP);
528    /// `EMEDIUMTYPE`
529    #[cfg(not(any(
530        bsd,
531        solarish,
532        windows,
533        target_os = "aix",
534        target_os = "cygwin",
535        target_os = "espidf",
536        target_os = "haiku",
537        target_os = "horizon",
538        target_os = "hurd",
539        target_os = "l4re",
540        target_os = "nto",
541        target_os = "vita",
542        target_os = "wasi",
543    )))]
544    pub const MEDIUMTYPE: Self = Self(c::EMEDIUMTYPE);
545    /// `EMFILE`
546    pub const MFILE: Self = Self(c::EMFILE);
547    /// `EMLINK`
548    #[cfg(not(windows))]
549    pub const MLINK: Self = Self(c::EMLINK);
550    /// `EMSGSIZE`
551    #[cfg(not(target_os = "l4re"))]
552    pub const MSGSIZE: Self = Self(c::EMSGSIZE);
553    /// `EMULTIHOP`
554    #[cfg(not(any(windows, target_os = "l4re", target_os = "openbsd")))]
555    pub const MULTIHOP: Self = Self(c::EMULTIHOP);
556    /// `ENAMETOOLONG`
557    pub const NAMETOOLONG: Self = Self(c::ENAMETOOLONG);
558    /// `ENAVAIL`
559    #[cfg(not(any(
560        bsd,
561        solarish,
562        windows,
563        target_os = "aix",
564        target_os = "cygwin",
565        target_os = "espidf",
566        target_os = "haiku",
567        target_os = "horizon",
568        target_os = "hurd",
569        target_os = "l4re",
570        target_os = "nto",
571        target_os = "vita",
572        target_os = "wasi",
573    )))]
574    pub const NAVAIL: Self = Self(c::ENAVAIL);
575    /// `ENEEDAUTH`
576    #[cfg(bsd)]
577    pub const NEEDAUTH: Self = Self(c::ENEEDAUTH);
578    /// `ENETDOWN`
579    pub const NETDOWN: Self = Self(c::ENETDOWN);
580    /// `ENETRESET`
581    #[cfg(not(target_os = "l4re"))]
582    pub const NETRESET: Self = Self(c::ENETRESET);
583    /// `ENETUNREACH`
584    pub const NETUNREACH: Self = Self(c::ENETUNREACH);
585    /// `ENFILE`
586    #[cfg(not(windows))]
587    pub const NFILE: Self = Self(c::ENFILE);
588    /// `ENOANO`
589    #[cfg(not(any(
590        bsd,
591        windows,
592        target_os = "aix",
593        target_os = "espidf",
594        target_os = "haiku",
595        target_os = "horizon",
596        target_os = "hurd",
597        target_os = "l4re",
598        target_os = "vita",
599        target_os = "wasi",
600    )))]
601    pub const NOANO: Self = Self(c::ENOANO);
602    /// `ENOATTR`
603    #[cfg(any(bsd, target_os = "haiku"))]
604    pub const NOATTR: Self = Self(c::ENOATTR);
605    /// `ENOBUFS`
606    #[cfg(not(target_os = "l4re"))]
607    pub const NOBUFS: Self = Self(c::ENOBUFS);
608    /// `ENOCSI`
609    #[cfg(not(any(
610        bsd,
611        windows,
612        target_os = "espidf",
613        target_os = "haiku",
614        target_os = "horizon",
615        target_os = "hurd",
616        target_os = "l4re",
617        target_os = "vita",
618        target_os = "wasi"
619    )))]
620    pub const NOCSI: Self = Self(c::ENOCSI);
621    /// `ENODATA`
622    #[cfg(not(any(
623        freebsdlike,
624        windows,
625        target_os = "haiku",
626        target_os = "openbsd",
627        target_os = "wasi",
628    )))]
629    pub const NODATA: Self = Self(c::ENODATA);
630    /// `ENODEV`
631    #[cfg(not(windows))]
632    pub const NODEV: Self = Self(c::ENODEV);
633    /// `ENOENT`
634    #[cfg(not(windows))]
635    pub const NOENT: Self = Self(c::ENOENT);
636    /// `ENOEXEC`
637    #[cfg(not(windows))]
638    pub const NOEXEC: Self = Self(c::ENOEXEC);
639    /// `ENOKEY`
640    #[cfg(not(any(
641        solarish,
642        bsd,
643        windows,
644        target_os = "aix",
645        target_os = "cygwin",
646        target_os = "espidf",
647        target_os = "haiku",
648        target_os = "horizon",
649        target_os = "hurd",
650        target_os = "l4re",
651        target_os = "nto",
652        target_os = "vita",
653        target_os = "wasi",
654    )))]
655    pub const NOKEY: Self = Self(c::ENOKEY);
656    /// `ENOLCK`
657    #[cfg(not(any(windows, target_os = "l4re")))]
658    pub const NOLCK: Self = Self(c::ENOLCK);
659    /// `ENOLINK`
660    #[cfg(not(any(windows, target_os = "l4re", target_os = "openbsd")))]
661    pub const NOLINK: Self = Self(c::ENOLINK);
662    /// `ENOMEDIUM`
663    #[cfg(not(any(
664        bsd,
665        solarish,
666        windows,
667        target_os = "aix",
668        target_os = "espidf",
669        target_os = "haiku",
670        target_os = "horizon",
671        target_os = "hurd",
672        target_os = "l4re",
673        target_os = "nto",
674        target_os = "vita",
675        target_os = "wasi",
676    )))]
677    pub const NOMEDIUM: Self = Self(c::ENOMEDIUM);
678    /// `ENOMEM`
679    #[cfg(not(windows))]
680    pub const NOMEM: Self = Self(c::ENOMEM);
681    /// `ENOMORE`
682    #[cfg(windows)]
683    pub const NOMORE: Self = Self(c::ENOMORE);
684    /// `ENOMSG`
685    #[cfg(not(any(windows, target_os = "l4re")))]
686    pub const NOMSG: Self = Self(c::ENOMSG);
687    /// `ENONET`
688    #[cfg(not(any(
689        bsd,
690        windows,
691        target_os = "aix",
692        target_os = "espidf",
693        target_os = "haiku",
694        target_os = "horizon",
695        target_os = "hurd",
696        target_os = "l4re",
697        target_os = "vita",
698        target_os = "wasi",
699    )))]
700    pub const NONET: Self = Self(c::ENONET);
701    /// `ENOPKG`
702    #[cfg(not(any(
703        bsd,
704        windows,
705        target_os = "aix",
706        target_os = "espidf",
707        target_os = "haiku",
708        target_os = "horizon",
709        target_os = "hurd",
710        target_os = "l4re",
711        target_os = "vita",
712        target_os = "wasi",
713    )))]
714    pub const NOPKG: Self = Self(c::ENOPKG);
715    /// `ENOPROTOOPT`
716    #[cfg(not(target_os = "l4re"))]
717    pub const NOPROTOOPT: Self = Self(c::ENOPROTOOPT);
718    /// `ENOSPC`
719    #[cfg(not(windows))]
720    pub const NOSPC: Self = Self(c::ENOSPC);
721    /// `ENOSR`
722    #[cfg(not(any(
723        freebsdlike,
724        windows,
725        target_os = "haiku",
726        target_os = "l4re",
727        target_os = "openbsd",
728        target_os = "wasi",
729    )))]
730    pub const NOSR: Self = Self(c::ENOSR);
731    /// `ENOSTR`
732    #[cfg(not(any(
733        freebsdlike,
734        windows,
735        target_os = "haiku",
736        target_os = "l4re",
737        target_os = "openbsd",
738        target_os = "wasi",
739    )))]
740    pub const NOSTR: Self = Self(c::ENOSTR);
741    /// `ENOSYS`
742    #[cfg(not(windows))]
743    pub const NOSYS: Self = Self(c::ENOSYS);
744    /// `ENOTBLK`
745    #[cfg(not(any(
746        windows,
747        target_os = "espidf",
748        target_os = "haiku",
749        target_os = "horizon",
750        target_os = "vita",
751        target_os = "wasi"
752    )))]
753    pub const NOTBLK: Self = Self(c::ENOTBLK);
754    /// `ENOTCAPABLE`
755    #[cfg(any(target_os = "freebsd", target_os = "wasi"))]
756    pub const NOTCAPABLE: Self = Self(c::ENOTCAPABLE);
757    /// `ENOTCONN`
758    pub const NOTCONN: Self = Self(c::ENOTCONN);
759    /// `ENOTDIR`
760    #[cfg(not(windows))]
761    pub const NOTDIR: Self = Self(c::ENOTDIR);
762    /// `ENOTEMPTY`
763    pub const NOTEMPTY: Self = Self(c::ENOTEMPTY);
764    /// `ENOTNAM`
765    #[cfg(not(any(
766        bsd,
767        solarish,
768        windows,
769        target_os = "aix",
770        target_os = "cygwin",
771        target_os = "espidf",
772        target_os = "haiku",
773        target_os = "horizon",
774        target_os = "hurd",
775        target_os = "l4re",
776        target_os = "nto",
777        target_os = "vita",
778        target_os = "wasi",
779    )))]
780    pub const NOTNAM: Self = Self(c::ENOTNAM);
781    /// `ENOTRECOVERABLE`
782    #[cfg(not(any(
783        freebsdlike,
784        netbsdlike,
785        windows,
786        target_os = "haiku",
787        target_os = "l4re"
788    )))]
789    pub const NOTRECOVERABLE: Self = Self(c::ENOTRECOVERABLE);
790    /// `ENOTSOCK`
791    #[cfg(not(target_os = "l4re"))]
792    pub const NOTSOCK: Self = Self(c::ENOTSOCK);
793    /// `ENOTSUP`
794    #[cfg(not(any(windows, target_os = "redox")))]
795    pub const NOTSUP: Self = Self(c::ENOTSUP);
796    /// `ENOTTY`
797    #[cfg(not(windows))]
798    pub const NOTTY: Self = Self(c::ENOTTY);
799    /// `ENOTUNIQ`
800    #[cfg(not(any(
801        bsd,
802        windows,
803        target_os = "aix",
804        target_os = "espidf",
805        target_os = "haiku",
806        target_os = "horizon",
807        target_os = "hurd",
808        target_os = "l4re",
809        target_os = "vita",
810        target_os = "wasi",
811    )))]
812    pub const NOTUNIQ: Self = Self(c::ENOTUNIQ);
813    /// `ENXIO`
814    #[cfg(not(windows))]
815    pub const NXIO: Self = Self(c::ENXIO);
816    /// `EOPNOTSUPP`
817    pub const OPNOTSUPP: Self = Self(c::EOPNOTSUPP);
818    /// `EOVERFLOW`
819    #[cfg(not(any(windows, target_os = "l4re")))]
820    pub const OVERFLOW: Self = Self(c::EOVERFLOW);
821    /// `EOWNERDEAD`
822    #[cfg(not(any(
823        freebsdlike,
824        netbsdlike,
825        windows,
826        target_os = "haiku",
827        target_os = "l4re"
828    )))]
829    pub const OWNERDEAD: Self = Self(c::EOWNERDEAD);
830    /// `EPERM`
831    #[cfg(not(windows))]
832    pub const PERM: Self = Self(c::EPERM);
833    /// `EPFNOSUPPORT`
834    #[cfg(not(any(target_os = "l4re", target_os = "wasi")))]
835    pub const PFNOSUPPORT: Self = Self(c::EPFNOSUPPORT);
836    /// `EPIPE`
837    #[cfg(not(windows))]
838    pub const PIPE: Self = Self(c::EPIPE);
839    /// `EPROCLIM`
840    #[cfg(bsd)]
841    pub const PROCLIM: Self = Self(c::EPROCLIM);
842    /// `EPROCUNAVAIL`
843    #[cfg(bsd)]
844    pub const PROCUNAVAIL: Self = Self(c::EPROCUNAVAIL);
845    /// `EPROGMISMATCH`
846    #[cfg(bsd)]
847    pub const PROGMISMATCH: Self = Self(c::EPROGMISMATCH);
848    /// `EPROGUNAVAIL`
849    #[cfg(bsd)]
850    pub const PROGUNAVAIL: Self = Self(c::EPROGUNAVAIL);
851    /// `EPROTO`
852    #[cfg(not(any(windows, target_os = "l4re")))]
853    pub const PROTO: Self = Self(c::EPROTO);
854    /// `EPROTONOSUPPORT`
855    #[cfg(not(target_os = "l4re"))]
856    pub const PROTONOSUPPORT: Self = Self(c::EPROTONOSUPPORT);
857    /// `EPROTOTYPE`
858    #[cfg(not(target_os = "l4re"))]
859    pub const PROTOTYPE: Self = Self(c::EPROTOTYPE);
860    /// `EPROVIDERFAILEDINIT`
861    #[cfg(windows)]
862    pub const PROVIDERFAILEDINIT: Self = Self(c::EPROVIDERFAILEDINIT);
863    /// `ERANGE`
864    #[cfg(not(windows))]
865    pub const RANGE: Self = Self(c::ERANGE);
866    /// `EREFUSED`
867    #[cfg(windows)]
868    pub const REFUSED: Self = Self(c::EREFUSED);
869    /// `EREMCHG`
870    #[cfg(not(any(
871        bsd,
872        windows,
873        target_os = "aix",
874        target_os = "espidf",
875        target_os = "haiku",
876        target_os = "horizon",
877        target_os = "hurd",
878        target_os = "l4re",
879        target_os = "vita",
880        target_os = "wasi",
881    )))]
882    pub const REMCHG: Self = Self(c::EREMCHG);
883    /// `EREMOTE`
884    #[cfg(not(any(
885        target_os = "espidf",
886        target_os = "haiku",
887        target_os = "horizon",
888        target_os = "l4re",
889        target_os = "vita",
890        target_os = "wasi"
891    )))]
892    pub const REMOTE: Self = Self(c::EREMOTE);
893    /// `EREMOTEIO`
894    #[cfg(not(any(
895        bsd,
896        solarish,
897        windows,
898        target_os = "aix",
899        target_os = "cygwin",
900        target_os = "espidf",
901        target_os = "haiku",
902        target_os = "horizon",
903        target_os = "hurd",
904        target_os = "l4re",
905        target_os = "nto",
906        target_os = "vita",
907        target_os = "wasi",
908    )))]
909    pub const REMOTEIO: Self = Self(c::EREMOTEIO);
910    /// `ERESTART`
911    #[cfg(not(any(
912        bsd,
913        windows,
914        target_os = "cygwin",
915        target_os = "espidf",
916        target_os = "haiku",
917        target_os = "horizon",
918        target_os = "hurd",
919        target_os = "l4re",
920        target_os = "vita",
921        target_os = "wasi",
922    )))]
923    pub const RESTART: Self = Self(c::ERESTART);
924    /// `ERFKILL`
925    #[cfg(not(any(
926        bsd,
927        solarish,
928        windows,
929        target_os = "aix",
930        target_os = "android",
931        target_os = "cygwin",
932        target_os = "espidf",
933        target_os = "haiku",
934        target_os = "horizon",
935        target_os = "hurd",
936        target_os = "l4re",
937        target_os = "nto",
938        target_os = "redox",
939        target_os = "vita",
940        target_os = "wasi",
941    )))]
942    pub const RFKILL: Self = Self(c::ERFKILL);
943    /// `EROFS`
944    #[cfg(not(windows))]
945    pub const ROFS: Self = Self(c::EROFS);
946    /// `ERPCMISMATCH`
947    #[cfg(bsd)]
948    pub const RPCMISMATCH: Self = Self(c::ERPCMISMATCH);
949    /// `ESHUTDOWN`
950    #[cfg(not(any(
951        target_os = "espidf",
952        target_os = "horizon",
953        target_os = "l4re",
954        target_os = "vita",
955        target_os = "wasi"
956    )))]
957    pub const SHUTDOWN: Self = Self(c::ESHUTDOWN);
958    /// `ESOCKTNOSUPPORT`
959    #[cfg(not(any(
960        target_os = "espidf",
961        target_os = "haiku",
962        target_os = "horizon",
963        target_os = "l4re",
964        target_os = "vita",
965        target_os = "wasi"
966    )))]
967    pub const SOCKTNOSUPPORT: Self = Self(c::ESOCKTNOSUPPORT);
968    /// `ESPIPE`
969    #[cfg(not(windows))]
970    pub const SPIPE: Self = Self(c::ESPIPE);
971    /// `ESRCH`
972    #[cfg(not(windows))]
973    pub const SRCH: Self = Self(c::ESRCH);
974    /// `ESRMNT`
975    #[cfg(not(any(
976        bsd,
977        windows,
978        target_os = "aix",
979        target_os = "espidf",
980        target_os = "haiku",
981        target_os = "horizon",
982        target_os = "hurd",
983        target_os = "l4re",
984        target_os = "vita",
985        target_os = "wasi",
986    )))]
987    pub const SRMNT: Self = Self(c::ESRMNT);
988    /// `ESTALE`
989    pub const STALE: Self = Self(c::ESTALE);
990    /// `ESTRPIPE`
991    #[cfg(not(any(
992        bsd,
993        windows,
994        target_os = "aix",
995        target_os = "espidf",
996        target_os = "haiku",
997        target_os = "horizon",
998        target_os = "hurd",
999        target_os = "l4re",
1000        target_os = "vita",
1001        target_os = "wasi",
1002    )))]
1003    pub const STRPIPE: Self = Self(c::ESTRPIPE);
1004    /// `ETIME`
1005    #[cfg(not(any(
1006        freebsdlike,
1007        windows,
1008        target_os = "l4re",
1009        target_os = "openbsd",
1010        target_os = "wasi"
1011    )))]
1012    pub const TIME: Self = Self(c::ETIME);
1013    /// `ETIMEDOUT`
1014    pub const TIMEDOUT: Self = Self(c::ETIMEDOUT);
1015    /// `E2BIG`
1016    #[cfg(not(windows))]
1017    #[doc(alias = "2BIG")]
1018    pub const TOOBIG: Self = Self(c::E2BIG);
1019    /// `ETOOMANYREFS`
1020    #[cfg(not(any(target_os = "haiku", target_os = "l4re", target_os = "wasi")))]
1021    pub const TOOMANYREFS: Self = Self(c::ETOOMANYREFS);
1022    /// `ETXTBSY`
1023    #[cfg(not(windows))]
1024    pub const TXTBSY: Self = Self(c::ETXTBSY);
1025    /// `EUCLEAN`
1026    #[cfg(not(any(
1027        bsd,
1028        solarish,
1029        windows,
1030        target_os = "aix",
1031        target_os = "cygwin",
1032        target_os = "espidf",
1033        target_os = "haiku",
1034        target_os = "horizon",
1035        target_os = "hurd",
1036        target_os = "l4re",
1037        target_os = "nto",
1038        target_os = "vita",
1039        target_os = "wasi",
1040    )))]
1041    pub const UCLEAN: Self = Self(c::EUCLEAN);
1042    /// `EUNATCH`
1043    #[cfg(not(any(
1044        bsd,
1045        windows,
1046        target_os = "espidf",
1047        target_os = "haiku",
1048        target_os = "horizon",
1049        target_os = "hurd",
1050        target_os = "l4re",
1051        target_os = "vita",
1052        target_os = "wasi"
1053    )))]
1054    pub const UNATCH: Self = Self(c::EUNATCH);
1055    /// `EUSERS`
1056    #[cfg(not(any(
1057        target_os = "espidf",
1058        target_os = "haiku",
1059        target_os = "horizon",
1060        target_os = "l4re",
1061        target_os = "vita",
1062        target_os = "wasi"
1063    )))]
1064    pub const USERS: Self = Self(c::EUSERS);
1065    /// `EWOULDBLOCK`
1066    pub const WOULDBLOCK: Self = Self(c::EWOULDBLOCK);
1067    /// `EXDEV`
1068    #[cfg(not(windows))]
1069    pub const XDEV: Self = Self(c::EXDEV);
1070    /// `EXFULL`
1071    #[cfg(not(any(
1072        bsd,
1073        windows,
1074        target_os = "aix",
1075        target_os = "espidf",
1076        target_os = "haiku",
1077        target_os = "horizon",
1078        target_os = "hurd",
1079        target_os = "l4re",
1080        target_os = "vita",
1081        target_os = "wasi",
1082    )))]
1083    pub const XFULL: Self = Self(c::EXFULL);
1084}
1085
1086impl Errno {
1087    /// Extract an `Errno` value from a `std::io::Error`.
1088    ///
1089    /// This isn't a `From` conversion because it's expected to be relatively
1090    /// uncommon.
1091    #[cfg(feature = "std")]
1092    #[inline]
1093    pub fn from_io_error(io_err: &std::io::Error) -> Option<Self> {
1094        io_err
1095            .raw_os_error()
1096            .and_then(|raw| if raw != 0 { Some(Self(raw)) } else { None })
1097    }
1098
1099    /// Extract the raw OS error number from this error.
1100    #[inline]
1101    pub const fn raw_os_error(self) -> i32 {
1102        self.0
1103    }
1104
1105    /// Construct an `Errno` from a raw OS error number.
1106    #[inline]
1107    pub const fn from_raw_os_error(raw: i32) -> Self {
1108        Self(raw)
1109    }
1110
1111    pub(crate) fn last_os_error() -> Self {
1112        Self(errno().0)
1113    }
1114}