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