Debian Codegraph @

third_party/rust/rustix/src/backend/libc/io/errno.rs

raw
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/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)]
37 pub struct Errno(pub(crate) c::c_int);
38
39 impl 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 = "espidf",
280 target_os = "haiku",
281 target_os = "horizon",
282 target_os = "hurd",
283 target_os = "l4re",
284 target_os = "nto",
285 target_os = "redox",
286 target_os = "vita",
287 target_os = "wasi",
288 )))]
289 pub const HWPOISON: Self = Self(c::EHWPOISON);
290 /// `EIDRM`
291 #[cfg(not(any(windows, target_os = "l4re")))]
292 pub const IDRM: Self = Self(c::EIDRM);
293 /// `EILSEQ`
294 #[cfg(not(any(windows, target_os = "l4re")))]
295 pub const ILSEQ: Self = Self(c::EILSEQ);
296 /// `EINPROGRESS`
297 #[cfg(not(target_os = "l4re"))]
298 pub const INPROGRESS: Self = Self(c::EINPROGRESS);
299 /// `EINTR`
300 ///
301 /// For a convenient way to retry system calls that exit with `INTR`, use
302 /// [`retry_on_intr`].
303 ///
304 /// [`retry_on_intr`]: crate::io::retry_on_intr
305 pub const INTR: Self = Self(c::EINTR);
306 /// `EINVAL`
307 pub const INVAL: Self = Self(c::EINVAL);
308 /// `EINVALIDPROCTABLE`
309 #[cfg(windows)]
310 pub const INVALIDPROCTABLE: Self = Self(c::EINVALIDPROCTABLE);
311 /// `EINVALIDPROVIDER`
312 #[cfg(windows)]
313 pub const INVALIDPROVIDER: Self = Self(c::EINVALIDPROVIDER);
314 /// `EIO`
315 #[cfg(not(windows))]
316 pub const IO: Self = Self(c::EIO);
317 /// `EISCONN`
318 #[cfg(not(target_os = "l4re"))]
319 pub const ISCONN: Self = Self(c::EISCONN);
320 /// `EISDIR`
321 #[cfg(not(windows))]
322 pub const ISDIR: Self = Self(c::EISDIR);
323 /// `EISNAM`
324 #[cfg(not(any(
325 bsd,
326 solarish,
327 windows,
328 target_os = "aix",
329 target_os = "espidf",
330 target_os = "haiku",
331 target_os = "horizon",
332 target_os = "hurd",
333 target_os = "l4re",
334 target_os = "nto",
335 target_os = "vita",
336 target_os = "wasi",
337 )))]
338 pub const ISNAM: Self = Self(c::EISNAM);
339 /// `EKEYEXPIRED`
340 #[cfg(not(any(
341 bsd,
342 solarish,
343 windows,
344 target_os = "aix",
345 target_os = "espidf",
346 target_os = "haiku",
347 target_os = "horizon",
348 target_os = "hurd",
349 target_os = "l4re",
350 target_os = "nto",
351 target_os = "vita",
352 target_os = "wasi",
353 )))]
354 pub const KEYEXPIRED: Self = Self(c::EKEYEXPIRED);
355 /// `EKEYREJECTED`
356 #[cfg(not(any(
357 bsd,
358 solarish,
359 windows,
360 target_os = "aix",
361 target_os = "espidf",
362 target_os = "haiku",
363 target_os = "horizon",
364 target_os = "hurd",
365 target_os = "l4re",
366 target_os = "nto",
367 target_os = "vita",
368 target_os = "wasi",
369 )))]
370 pub const KEYREJECTED: Self = Self(c::EKEYREJECTED);
371 /// `EKEYREVOKED`
372 #[cfg(not(any(
373 bsd,
374 solarish,
375 windows,
376 target_os = "aix",
377 target_os = "espidf",
378 target_os = "haiku",
379 target_os = "horizon",
380 target_os = "hurd",
381 target_os = "l4re",
382 target_os = "nto",
383 target_os = "vita",
384 target_os = "wasi",
385 )))]
386 pub const KEYREVOKED: Self = Self(c::EKEYREVOKED);
387 /// `EL2HLT`
388 #[cfg(not(any(
389 bsd,
390 windows,
391 target_os = "espidf",
392 target_os = "haiku",
393 target_os = "horizon",
394 target_os = "hurd",
395 target_os = "l4re",
396 target_os = "vita",
397 target_os = "wasi"
398 )))]
399 pub const L2HLT: Self = Self(c::EL2HLT);
400 /// `EL2NSYNC`
401 #[cfg(not(any(
402 bsd,
403 windows,
404 target_os = "espidf",
405 target_os = "haiku",
406 target_os = "horizon",
407 target_os = "hurd",
408 target_os = "l4re",
409 target_os = "vita",
410 target_os = "wasi"
411 )))]
412 pub const L2NSYNC: Self = Self(c::EL2NSYNC);
413 /// `EL3HLT`
414 #[cfg(not(any(
415 bsd,
416 windows,
417 target_os = "espidf",
418 target_os = "haiku",
419 target_os = "horizon",
420 target_os = "hurd",
421 target_os = "l4re",
422 target_os = "vita",
423 target_os = "wasi"
424 )))]
425 pub const L3HLT: Self = Self(c::EL3HLT);
426 /// `EL3RST`
427 #[cfg(not(any(
428 bsd,
429 windows,
430 target_os = "espidf",
431 target_os = "haiku",
432 target_os = "horizon",
433 target_os = "hurd",
434 target_os = "l4re",
435 target_os = "vita",
436 target_os = "wasi"
437 )))]
438 pub const L3RST: Self = Self(c::EL3RST);
439 /// `ELIBACC`
440 #[cfg(not(any(
441 bsd,
442 windows,
443 target_os = "aix",
444 target_os = "espidf",
445 target_os = "haiku",
446 target_os = "horizon",
447 target_os = "hurd",
448 target_os = "l4re",
449 target_os = "vita",
450 target_os = "wasi",
451 )))]
452 pub const LIBACC: Self = Self(c::ELIBACC);
453 /// `ELIBBAD`
454 #[cfg(not(any(
455 bsd,
456 windows,
457 target_os = "aix",
458 target_os = "espidf",
459 target_os = "haiku",
460 target_os = "horizon",
461 target_os = "hurd",
462 target_os = "l4re",
463 target_os = "vita",
464 target_os = "wasi",
465 )))]
466 pub const LIBBAD: Self = Self(c::ELIBBAD);
467 /// `ELIBEXEC`
468 #[cfg(not(any(
469 bsd,
470 windows,
471 target_os = "aix",
472 target_os = "espidf",
473 target_os = "haiku",
474 target_os = "horizon",
475 target_os = "l4re",
476 target_os = "vita",
477 target_os = "wasi",
478 )))]
479 pub const LIBEXEC: Self = Self(c::ELIBEXEC);
480 /// `ELIBMAX`
481 #[cfg(not(any(
482 bsd,
483 windows,
484 target_os = "aix",
485 target_os = "espidf",
486 target_os = "haiku",
487 target_os = "horizon",
488 target_os = "hurd",
489 target_os = "l4re",
490 target_os = "vita",
491 target_os = "wasi",
492 )))]
493 pub const LIBMAX: Self = Self(c::ELIBMAX);
494 /// `ELIBSCN`
495 #[cfg(not(any(
496 bsd,
497 windows,
498 target_os = "aix",
499 target_os = "espidf",
500 target_os = "haiku",
501 target_os = "horizon",
502 target_os = "hurd",
503 target_os = "l4re",
504 target_os = "vita",
505 target_os = "wasi",
506 )))]
507 pub const LIBSCN: Self = Self(c::ELIBSCN);
508 /// `ELNRNG`
509 #[cfg(not(any(
510 bsd,
511 windows,
512 target_os = "espidf",
513 target_os = "haiku",
514 target_os = "horizon",
515 target_os = "hurd",
516 target_os = "l4re",
517 target_os = "vita",
518 target_os = "wasi"
519 )))]
520 pub const LNRNG: Self = Self(c::ELNRNG);
521 /// `ELOOP`
522 pub const LOOP: Self = Self(c::ELOOP);
523 /// `EMEDIUMTYPE`
524 #[cfg(not(any(
525 bsd,
526 solarish,
527 windows,
528 target_os = "aix",
529 target_os = "espidf",
530 target_os = "haiku",
531 target_os = "horizon",
532 target_os = "hurd",
533 target_os = "l4re",
534 target_os = "nto",
535 target_os = "vita",
536 target_os = "wasi",
537 )))]
538 pub const MEDIUMTYPE: Self = Self(c::EMEDIUMTYPE);
539 /// `EMFILE`
540 pub const MFILE: Self = Self(c::EMFILE);
541 /// `EMLINK`
542 #[cfg(not(windows))]
543 pub const MLINK: Self = Self(c::EMLINK);
544 /// `EMSGSIZE`
545 #[cfg(not(target_os = "l4re"))]
546 pub const MSGSIZE: Self = Self(c::EMSGSIZE);
547 /// `EMULTIHOP`
548 #[cfg(not(any(windows, target_os = "l4re", target_os = "openbsd")))]
549 pub const MULTIHOP: Self = Self(c::EMULTIHOP);
550 /// `ENAMETOOLONG`
551 pub const NAMETOOLONG: Self = Self(c::ENAMETOOLONG);
552 /// `ENAVAIL`
553 #[cfg(not(any(
554 bsd,
555 solarish,
556 windows,
557 target_os = "aix",
558 target_os = "espidf",
559 target_os = "haiku",
560 target_os = "horizon",
561 target_os = "hurd",
562 target_os = "l4re",
563 target_os = "nto",
564 target_os = "vita",
565 target_os = "wasi",
566 )))]
567 pub const NAVAIL: Self = Self(c::ENAVAIL);
568 /// `ENEEDAUTH`
569 #[cfg(bsd)]
570 pub const NEEDAUTH: Self = Self(c::ENEEDAUTH);
571 /// `ENETDOWN`
572 pub const NETDOWN: Self = Self(c::ENETDOWN);
573 /// `ENETRESET`
574 #[cfg(not(target_os = "l4re"))]
575 pub const NETRESET: Self = Self(c::ENETRESET);
576 /// `ENETUNREACH`
577 pub const NETUNREACH: Self = Self(c::ENETUNREACH);
578 /// `ENFILE`
579 #[cfg(not(windows))]
580 pub const NFILE: Self = Self(c::ENFILE);
581 /// `ENOANO`
582 #[cfg(not(any(
583 bsd,
584 windows,
585 target_os = "aix",
586 target_os = "espidf",
587 target_os = "haiku",
588 target_os = "horizon",
589 target_os = "hurd",
590 target_os = "l4re",
591 target_os = "vita",
592 target_os = "wasi",
593 )))]
594 pub const NOANO: Self = Self(c::ENOANO);
595 /// `ENOATTR`
596 #[cfg(any(bsd, target_os = "haiku"))]
597 pub const NOATTR: Self = Self(c::ENOATTR);
598 /// `ENOBUFS`
599 #[cfg(not(target_os = "l4re"))]
600 pub const NOBUFS: Self = Self(c::ENOBUFS);
601 /// `ENOCSI`
602 #[cfg(not(any(
603 bsd,
604 windows,
605 target_os = "espidf",
606 target_os = "haiku",
607 target_os = "horizon",
608 target_os = "hurd",
609 target_os = "l4re",
610 target_os = "vita",
611 target_os = "wasi"
612 )))]
613 pub const NOCSI: Self = Self(c::ENOCSI);
614 /// `ENODATA`
615 #[cfg(not(any(
616 freebsdlike,
617 windows,
618 target_os = "haiku",
619 target_os = "openbsd",
620 target_os = "wasi",
621 )))]
622 pub const NODATA: Self = Self(c::ENODATA);
623 /// `ENODEV`
624 #[cfg(not(windows))]
625 pub const NODEV: Self = Self(c::ENODEV);
626 /// `ENOENT`
627 #[cfg(not(windows))]
628 pub const NOENT: Self = Self(c::ENOENT);
629 /// `ENOEXEC`
630 #[cfg(not(windows))]
631 pub const NOEXEC: Self = Self(c::ENOEXEC);
632 /// `ENOKEY`
633 #[cfg(not(any(
634 solarish,
635 bsd,
636 windows,
637 target_os = "aix",
638 target_os = "espidf",
639 target_os = "haiku",
640 target_os = "horizon",
641 target_os = "hurd",
642 target_os = "l4re",
643 target_os = "nto",
644 target_os = "vita",
645 target_os = "wasi",
646 )))]
647 pub const NOKEY: Self = Self(c::ENOKEY);
648 /// `ENOLCK`
649 #[cfg(not(any(windows, target_os = "l4re")))]
650 pub const NOLCK: Self = Self(c::ENOLCK);
651 /// `ENOLINK`
652 #[cfg(not(any(windows, target_os = "l4re", target_os = "openbsd")))]
653 pub const NOLINK: Self = Self(c::ENOLINK);
654 /// `ENOMEDIUM`
655 #[cfg(not(any(
656 bsd,
657 solarish,
658 windows,
659 target_os = "aix",
660 target_os = "espidf",
661 target_os = "haiku",
662 target_os = "horizon",
663 target_os = "hurd",
664 target_os = "l4re",
665 target_os = "nto",
666 target_os = "vita",
667 target_os = "wasi",
668 )))]
669 pub const NOMEDIUM: Self = Self(c::ENOMEDIUM);
670 /// `ENOMEM`
671 #[cfg(not(windows))]
672 pub const NOMEM: Self = Self(c::ENOMEM);
673 /// `ENOMORE`
674 #[cfg(windows)]
675 pub const NOMORE: Self = Self(c::ENOMORE);
676 /// `ENOMSG`
677 #[cfg(not(any(windows, target_os = "l4re")))]
678 pub const NOMSG: Self = Self(c::ENOMSG);
679 /// `ENONET`
680 #[cfg(not(any(
681 bsd,
682 windows,
683 target_os = "aix",
684 target_os = "espidf",
685 target_os = "haiku",
686 target_os = "horizon",
687 target_os = "hurd",
688 target_os = "l4re",
689 target_os = "vita",
690 target_os = "wasi",
691 )))]
692 pub const NONET: Self = Self(c::ENONET);
693 /// `ENOPKG`
694 #[cfg(not(any(
695 bsd,
696 windows,
697 target_os = "aix",
698 target_os = "espidf",
699 target_os = "haiku",
700 target_os = "horizon",
701 target_os = "hurd",
702 target_os = "l4re",
703 target_os = "vita",
704 target_os = "wasi",
705 )))]
706 pub const NOPKG: Self = Self(c::ENOPKG);
707 /// `ENOPROTOOPT`
708 #[cfg(not(target_os = "l4re"))]
709 pub const NOPROTOOPT: Self = Self(c::ENOPROTOOPT);
710 /// `ENOSPC`
711 #[cfg(not(windows))]
712 pub const NOSPC: Self = Self(c::ENOSPC);
713 /// `ENOSR`
714 #[cfg(not(any(
715 freebsdlike,
716 windows,
717 target_os = "haiku",
718 target_os = "l4re",
719 target_os = "openbsd",
720 target_os = "wasi",
721 )))]
722 pub const NOSR: Self = Self(c::ENOSR);
723 /// `ENOSTR`
724 #[cfg(not(any(
725 freebsdlike,
726 windows,
727 target_os = "haiku",
728 target_os = "l4re",
729 target_os = "openbsd",
730 target_os = "wasi",
731 )))]
732 pub const NOSTR: Self = Self(c::ENOSTR);
733 /// `ENOSYS`
734 #[cfg(not(windows))]
735 pub const NOSYS: Self = Self(c::ENOSYS);
736 /// `ENOTBLK`
737 #[cfg(not(any(
738 windows,
739 target_os = "espidf",
740 target_os = "haiku",
741 target_os = "horizon",
742 target_os = "vita",
743 target_os = "wasi"
744 )))]
745 pub const NOTBLK: Self = Self(c::ENOTBLK);
746 /// `ENOTCAPABLE`
747 #[cfg(any(target_os = "freebsd", target_os = "wasi"))]
748 pub const NOTCAPABLE: Self = Self(c::ENOTCAPABLE);
749 /// `ENOTCONN`
750 pub const NOTCONN: Self = Self(c::ENOTCONN);
751 /// `ENOTDIR`
752 #[cfg(not(windows))]
753 pub const NOTDIR: Self = Self(c::ENOTDIR);
754 /// `ENOTEMPTY`
755 pub const NOTEMPTY: Self = Self(c::ENOTEMPTY);
756 /// `ENOTNAM`
757 #[cfg(not(any(
758 bsd,
759 solarish,
760 windows,
761 target_os = "aix",
762 target_os = "espidf",
763 target_os = "haiku",
764 target_os = "horizon",
765 target_os = "hurd",
766 target_os = "l4re",
767 target_os = "nto",
768 target_os = "vita",
769 target_os = "wasi",
770 )))]
771 pub const NOTNAM: Self = Self(c::ENOTNAM);
772 /// `ENOTRECOVERABLE`
773 #[cfg(not(any(
774 freebsdlike,
775 netbsdlike,
776 windows,
777 target_os = "haiku",
778 target_os = "l4re"
779 )))]
780 pub const NOTRECOVERABLE: Self = Self(c::ENOTRECOVERABLE);
781 /// `ENOTSOCK`
782 #[cfg(not(target_os = "l4re"))]
783 pub const NOTSOCK: Self = Self(c::ENOTSOCK);
784 /// `ENOTSUP`
785 #[cfg(not(any(windows, target_os = "haiku", target_os = "redox")))]
786 pub const NOTSUP: Self = Self(c::ENOTSUP);
787 /// `ENOTTY`
788 #[cfg(not(windows))]
789 pub const NOTTY: Self = Self(c::ENOTTY);
790 /// `ENOTUNIQ`
791 #[cfg(not(any(
792 bsd,
793 windows,
794 target_os = "aix",
795 target_os = "espidf",
796 target_os = "haiku",
797 target_os = "horizon",
798 target_os = "hurd",
799 target_os = "l4re",
800 target_os = "vita",
801 target_os = "wasi",
802 )))]
803 pub const NOTUNIQ: Self = Self(c::ENOTUNIQ);
804 /// `ENXIO`
805 #[cfg(not(windows))]
806 pub const NXIO: Self = Self(c::ENXIO);
807 /// `EOPNOTSUPP`
808 pub const OPNOTSUPP: Self = Self(c::EOPNOTSUPP);
809 /// `EOVERFLOW`
810 #[cfg(not(any(windows, target_os = "l4re")))]
811 pub const OVERFLOW: Self = Self(c::EOVERFLOW);
812 /// `EOWNERDEAD`
813 #[cfg(not(any(
814 freebsdlike,
815 netbsdlike,
816 windows,
817 target_os = "haiku",
818 target_os = "l4re"
819 )))]
820 pub const OWNERDEAD: Self = Self(c::EOWNERDEAD);
821 /// `EPERM`
822 #[cfg(not(windows))]
823 pub const PERM: Self = Self(c::EPERM);
824 /// `EPFNOSUPPORT`
825 #[cfg(not(any(target_os = "l4re", target_os = "wasi")))]
826 pub const PFNOSUPPORT: Self = Self(c::EPFNOSUPPORT);
827 /// `EPIPE`
828 #[cfg(not(windows))]
829 pub const PIPE: Self = Self(c::EPIPE);
830 /// `EPROCLIM`
831 #[cfg(bsd)]
832 pub const PROCLIM: Self = Self(c::EPROCLIM);
833 /// `EPROCUNAVAIL`
834 #[cfg(bsd)]
835 pub const PROCUNAVAIL: Self = Self(c::EPROCUNAVAIL);
836 /// `EPROGMISMATCH`
837 #[cfg(bsd)]
838 pub const PROGMISMATCH: Self = Self(c::EPROGMISMATCH);
839 /// `EPROGUNAVAIL`
840 #[cfg(bsd)]
841 pub const PROGUNAVAIL: Self = Self(c::EPROGUNAVAIL);
842 /// `EPROTO`
843 #[cfg(not(any(windows, target_os = "l4re")))]
844 pub const PROTO: Self = Self(c::EPROTO);
845 /// `EPROTONOSUPPORT`
846 #[cfg(not(target_os = "l4re"))]
847 pub const PROTONOSUPPORT: Self = Self(c::EPROTONOSUPPORT);
848 /// `EPROTOTYPE`
849 #[cfg(not(target_os = "l4re"))]
850 pub const PROTOTYPE: Self = Self(c::EPROTOTYPE);
851 /// `EPROVIDERFAILEDINIT`
852 #[cfg(windows)]
853 pub const PROVIDERFAILEDINIT: Self = Self(c::EPROVIDERFAILEDINIT);
854 /// `ERANGE`
855 #[cfg(not(windows))]
856 pub const RANGE: Self = Self(c::ERANGE);
857 /// `EREFUSED`
858 #[cfg(windows)]
859 pub const REFUSED: Self = Self(c::EREFUSED);
860 /// `EREMCHG`
861 #[cfg(not(any(
862 bsd,
863 windows,
864 target_os = "aix",
865 target_os = "espidf",
866 target_os = "haiku",
867 target_os = "horizon",
868 target_os = "hurd",
869 target_os = "l4re",
870 target_os = "vita",
871 target_os = "wasi",
872 )))]
873 pub const REMCHG: Self = Self(c::EREMCHG);
874 /// `EREMOTE`
875 #[cfg(not(any(
876 target_os = "espidf",
877 target_os = "haiku",
878 target_os = "horizon",
879 target_os = "l4re",
880 target_os = "vita",
881 target_os = "wasi"
882 )))]
883 pub const REMOTE: Self = Self(c::EREMOTE);
884 /// `EREMOTEIO`
885 #[cfg(not(any(
886 bsd,
887 solarish,
888 windows,
889 target_os = "aix",
890 target_os = "espidf",
891 target_os = "haiku",
892 target_os = "horizon",
893 target_os = "hurd",
894 target_os = "l4re",
895 target_os = "nto",
896 target_os = "vita",
897 target_os = "wasi",
898 )))]
899 pub const REMOTEIO: Self = Self(c::EREMOTEIO);
900 /// `ERESTART`
901 #[cfg(not(any(
902 bsd,
903 windows,
904 target_os = "espidf",
905 target_os = "haiku",
906 target_os = "horizon",
907 target_os = "hurd",
908 target_os = "l4re",
909 target_os = "vita",
910 target_os = "wasi"
911 )))]
912 pub const RESTART: Self = Self(c::ERESTART);
913 /// `ERFKILL`
914 #[cfg(not(any(
915 bsd,
916 solarish,
917 windows,
918 target_os = "aix",
919 target_os = "android",
920 target_os = "espidf",
921 target_os = "haiku",
922 target_os = "horizon",
923 target_os = "hurd",
924 target_os = "l4re",
925 target_os = "nto",
926 target_os = "redox",
927 target_os = "vita",
928 target_os = "wasi",
929 )))]
930 pub const RFKILL: Self = Self(c::ERFKILL);
931 /// `EROFS`
932 #[cfg(not(windows))]
933 pub const ROFS: Self = Self(c::EROFS);
934 /// `ERPCMISMATCH`
935 #[cfg(bsd)]
936 pub const RPCMISMATCH: Self = Self(c::ERPCMISMATCH);
937 /// `ESHUTDOWN`
938 #[cfg(not(any(
939 target_os = "espidf",
940 target_os = "horizon",
941 target_os = "l4re",
942 target_os = "vita",
943 target_os = "wasi"
944 )))]
945 pub const SHUTDOWN: Self = Self(c::ESHUTDOWN);
946 /// `ESOCKTNOSUPPORT`
947 #[cfg(not(any(
948 target_os = "espidf",
949 target_os = "haiku",
950 target_os = "horizon",
951 target_os = "l4re",
952 target_os = "vita",
953 target_os = "wasi"
954 )))]
955 pub const SOCKTNOSUPPORT: Self = Self(c::ESOCKTNOSUPPORT);
956 /// `ESPIPE`
957 #[cfg(not(windows))]
958 pub const SPIPE: Self = Self(c::ESPIPE);
959 /// `ESRCH`
960 #[cfg(not(windows))]
961 pub const SRCH: Self = Self(c::ESRCH);
962 /// `ESRMNT`
963 #[cfg(not(any(
964 bsd,
965 windows,
966 target_os = "aix",
967 target_os = "espidf",
968 target_os = "haiku",
969 target_os = "horizon",
970 target_os = "hurd",
971 target_os = "l4re",
972 target_os = "vita",
973 target_os = "wasi",
974 )))]
975 pub const SRMNT: Self = Self(c::ESRMNT);
976 /// `ESTALE`
977 pub const STALE: Self = Self(c::ESTALE);
978 /// `ESTRPIPE`
979 #[cfg(not(any(
980 bsd,
981 windows,
982 target_os = "aix",
983 target_os = "espidf",
984 target_os = "haiku",
985 target_os = "horizon",
986 target_os = "hurd",
987 target_os = "l4re",
988 target_os = "vita",
989 target_os = "wasi",
990 )))]
991 pub const STRPIPE: Self = Self(c::ESTRPIPE);
992 /// `ETIME`
993 #[cfg(not(any(
994 freebsdlike,
995 windows,
996 target_os = "l4re",
997 target_os = "openbsd",
998 target_os = "wasi"
999 )))]
1000 pub const TIME: Self = Self(c::ETIME);
1001 /// `ETIMEDOUT`
1002 pub const TIMEDOUT: Self = Self(c::ETIMEDOUT);
1003 /// `E2BIG`
1004 #[cfg(not(windows))]
1005 #[doc(alias = "2BIG")]
1006 pub const TOOBIG: Self = Self(c::E2BIG);
1007 /// `ETOOMANYREFS`
1008 #[cfg(not(any(target_os = "haiku", target_os = "l4re", target_os = "wasi")))]
1009 pub const TOOMANYREFS: Self = Self(c::ETOOMANYREFS);
1010 /// `ETXTBSY`
1011 #[cfg(not(windows))]
1012 pub const TXTBSY: Self = Self(c::ETXTBSY);
1013 /// `EUCLEAN`
1014 #[cfg(not(any(
1015 bsd,
1016 solarish,
1017 windows,
1018 target_os = "aix",
1019 target_os = "espidf",
1020 target_os = "haiku",
1021 target_os = "horizon",
1022 target_os = "hurd",
1023 target_os = "l4re",
1024 target_os = "nto",
1025 target_os = "vita",
1026 target_os = "wasi",
1027 )))]
1028 pub const UCLEAN: Self = Self(c::EUCLEAN);
1029 /// `EUNATCH`
1030 #[cfg(not(any(
1031 bsd,
1032 windows,
1033 target_os = "espidf",
1034 target_os = "haiku",
1035 target_os = "horizon",
1036 target_os = "hurd",
1037 target_os = "l4re",
1038 target_os = "vita",
1039 target_os = "wasi"
1040 )))]
1041 pub const UNATCH: Self = Self(c::EUNATCH);
1042 /// `EUSERS`
1043 #[cfg(not(any(
1044 target_os = "espidf",
1045 target_os = "haiku",
1046 target_os = "horizon",
1047 target_os = "l4re",
1048 target_os = "vita",
1049 target_os = "wasi"
1050 )))]
1051 pub const USERS: Self = Self(c::EUSERS);
1052 /// `EWOULDBLOCK`
1053 pub const WOULDBLOCK: Self = Self(c::EWOULDBLOCK);
1054 /// `EXDEV`
1055 #[cfg(not(windows))]
1056 pub const XDEV: Self = Self(c::EXDEV);
1057 /// `EXFULL`
1058 #[cfg(not(any(
1059 bsd,
1060 windows,
1061 target_os = "aix",
1062 target_os = "espidf",
1063 target_os = "haiku",
1064 target_os = "horizon",
1065 target_os = "hurd",
1066 target_os = "l4re",
1067 target_os = "vita",
1068 target_os = "wasi",
1069 )))]
1070 pub const XFULL: Self = Self(c::EXFULL);
1071 }
1072
1073 impl Errno {
1074 /// Extract an `Errno` value from a `std::io::Error`.
1075 ///
1076 /// This isn't a `From` conversion because it's expected to be relatively
1077 /// uncommon.
1078 #[cfg(feature = "std")]
1079 #[inline]
1080 pub fn from_io_error(io_err: &std::io::Error) -> Option<Self> {
1081 io_err
1082 .raw_os_error()
1083 .and_then(|raw| if raw != 0 { Some(Self(raw)) } else { None })
1084 }
1085
1086 /// Extract the raw OS error number from this error.
1087 #[inline]
1088 pub const fn raw_os_error(self) -> i32 {
1089 self.0
1090 }
1091
1092 /// Construct an `Errno` from a raw OS error number.
1093 #[inline]
1094 pub const fn from_raw_os_error(raw: i32) -> Self {
1095 Self(raw)
1096 }
1097
1098 pub(crate) fn last_os_error() -> Self {
1099 Self(errno().0)
1100 }
1101 }