Skip to main content

rustpython_vm/stdlib/
errno.rs

1// spell-checker:disable
2
3pub(crate) use errno_mod::module_def;
4
5#[pymodule(name = "errno")]
6mod errno_mod {
7    use crate::{Py, PyResult, VirtualMachine, builtins::PyModule};
8
9    pub(crate) fn module_exec(vm: &VirtualMachine, module: &Py<PyModule>) -> PyResult<()> {
10        __module_exec(vm, module);
11
12        let errorcode = vm.ctx.new_dict();
13        extend_module!(vm, module, {
14            "errorcode" => errorcode.clone(),
15        });
16        for (name, code) in super::ERROR_CODES {
17            let name = vm.ctx.intern_str(*name);
18            let code = vm.new_pyobj(*code);
19            errorcode.set_item(&*code, name.to_owned().into(), vm)?;
20            module.set_attr(name, code, vm)?;
21        }
22        Ok(())
23    }
24}
25
26pub use rustpython_host_env::errno::errors;
27
28#[cfg(any(unix, windows, target_os = "wasi"))]
29macro_rules! e {
30    ($name:ident) => {
31        (stringify!($name), errors::$name as _)
32    };
33    (cfg($($cfg:tt)*), $name:ident) => {
34        #[cfg($($cfg)*)]
35        (stringify!($name), errors::$name as _)
36    };
37}
38
39#[cfg(any(unix, windows, target_os = "wasi"))]
40const ERROR_CODES: &[(&str, i32)] = &[
41    e!(ENODEV),
42    e!(
43        cfg(any(
44            target_os = "android",
45            target_os = "fuchsia",
46            target_os = "linux",
47            target_os = "redox"
48        )),
49        ENOCSI
50    ),
51    e!(EHOSTUNREACH),
52    e!(cfg(not(windows)), ENOMSG),
53    e!(
54        cfg(any(
55            target_os = "android",
56            target_os = "fuchsia",
57            target_os = "linux",
58            target_os = "redox"
59        )),
60        EUCLEAN
61    ),
62    e!(
63        cfg(any(
64            target_os = "android",
65            target_os = "fuchsia",
66            target_os = "linux",
67            target_os = "redox"
68        )),
69        EL2NSYNC
70    ),
71    e!(
72        cfg(any(
73            target_os = "android",
74            target_os = "fuchsia",
75            target_os = "linux",
76            target_os = "redox"
77        )),
78        EL2HLT
79    ),
80    e!(
81        cfg(not(any(
82            target_os = "openbsd",
83            target_os = "freebsd",
84            target_os = "wasi",
85            windows
86        ))),
87        ENODATA
88    ),
89    e!(cfg(not(any(windows, target_os = "wasi"))), ENOTBLK),
90    e!(ENOSYS),
91    e!(EPIPE),
92    e!(EINVAL),
93    e!(cfg(not(windows)), EOVERFLOW),
94    e!(
95        cfg(any(
96            target_os = "android",
97            target_os = "fuchsia",
98            target_os = "linux",
99            target_os = "redox"
100        )),
101        EADV
102    ),
103    e!(EINTR),
104    e!(cfg(not(target_os = "wasi")), EUSERS),
105    e!(ENOTEMPTY),
106    e!(ENOBUFS),
107    e!(cfg(not(windows)), EPROTO),
108    e!(cfg(not(target_os = "wasi")), EREMOTE),
109    e!(
110        cfg(any(
111            target_os = "android",
112            target_os = "fuchsia",
113            target_os = "linux",
114            target_os = "redox"
115        )),
116        ENAVAIL
117    ),
118    e!(ECHILD),
119    e!(ELOOP),
120    e!(EXDEV),
121    e!(E2BIG),
122    e!(ESRCH),
123    e!(EMSGSIZE),
124    e!(EAFNOSUPPORT),
125    e!(
126        cfg(any(
127            target_os = "android",
128            target_os = "fuchsia",
129            target_os = "linux",
130            target_os = "redox"
131        )),
132        EBADR
133    ),
134    e!(cfg(not(target_os = "wasi")), EHOSTDOWN),
135    e!(cfg(not(target_os = "wasi")), EPFNOSUPPORT),
136    e!(ENOPROTOOPT),
137    e!(EBUSY),
138    e!(EWOULDBLOCK),
139    e!(
140        cfg(any(
141            target_os = "android",
142            target_os = "fuchsia",
143            target_os = "linux",
144            target_os = "redox"
145        )),
146        EBADFD
147    ),
148    e!(
149        cfg(any(
150            target_os = "android",
151            target_os = "fuchsia",
152            target_os = "linux",
153            target_os = "redox"
154        )),
155        EDOTDOT
156    ),
157    e!(EISCONN),
158    e!(
159        cfg(any(
160            target_os = "android",
161            target_os = "fuchsia",
162            target_os = "linux",
163            target_os = "redox"
164        )),
165        ENOANO
166    ),
167    e!(cfg(not(target_os = "wasi")), ESHUTDOWN),
168    e!(
169        cfg(any(
170            target_os = "android",
171            target_os = "fuchsia",
172            target_os = "linux",
173            target_os = "redox"
174        )),
175        ECHRNG
176    ),
177    e!(
178        cfg(any(
179            target_os = "android",
180            target_os = "fuchsia",
181            target_os = "linux",
182            target_os = "redox"
183        )),
184        ELIBBAD
185    ),
186    e!(
187        cfg(any(
188            target_os = "android",
189            target_os = "fuchsia",
190            target_os = "linux",
191            target_os = "redox"
192        )),
193        ENONET
194    ),
195    e!(
196        cfg(any(
197            target_os = "android",
198            target_os = "fuchsia",
199            target_os = "linux",
200            target_os = "redox"
201        )),
202        EBADE
203    ),
204    e!(EBADF),
205    e!(cfg(not(any(target_os = "openbsd", windows))), EMULTIHOP),
206    e!(EIO),
207    e!(
208        cfg(any(
209            target_os = "android",
210            target_os = "fuchsia",
211            target_os = "linux",
212            target_os = "redox"
213        )),
214        EUNATCH
215    ),
216    e!(EPROTOTYPE),
217    e!(ENOSPC),
218    e!(ENOEXEC),
219    e!(EALREADY),
220    e!(ENETDOWN),
221    e!(
222        cfg(any(
223            target_os = "android",
224            target_os = "fuchsia",
225            target_os = "linux",
226            target_os = "redox"
227        )),
228        ENOTNAM
229    ),
230    e!(EACCES),
231    e!(
232        cfg(any(
233            target_os = "android",
234            target_os = "fuchsia",
235            target_os = "linux",
236            target_os = "redox"
237        )),
238        ELNRNG
239    ),
240    e!(EILSEQ),
241    e!(ENOTDIR),
242    e!(
243        cfg(any(
244            target_os = "android",
245            target_os = "fuchsia",
246            target_os = "linux",
247            target_os = "redox"
248        )),
249        ENOTUNIQ
250    ),
251    e!(EPERM),
252    e!(EDOM),
253    e!(
254        cfg(any(
255            target_os = "android",
256            target_os = "fuchsia",
257            target_os = "linux",
258            target_os = "redox"
259        )),
260        EXFULL
261    ),
262    e!(ECONNREFUSED),
263    e!(EISDIR),
264    e!(EPROTONOSUPPORT),
265    e!(EROFS),
266    e!(EADDRNOTAVAIL),
267    e!(cfg(not(windows)), EIDRM),
268    e!(
269        cfg(any(
270            target_os = "android",
271            target_os = "fuchsia",
272            target_os = "linux",
273            target_os = "redox"
274        )),
275        ECOMM
276    ),
277    e!(
278        cfg(any(
279            target_os = "android",
280            target_os = "fuchsia",
281            target_os = "linux",
282            target_os = "redox"
283        )),
284        ESRMNT
285    ),
286    e!(
287        cfg(any(
288            target_os = "android",
289            target_os = "fuchsia",
290            target_os = "linux",
291            target_os = "redox"
292        )),
293        EREMOTEIO
294    ),
295    e!(
296        cfg(any(
297            target_os = "android",
298            target_os = "fuchsia",
299            target_os = "linux",
300            target_os = "redox"
301        )),
302        EL3RST
303    ),
304    e!(cfg(not(windows)), EBADMSG),
305    e!(ENFILE),
306    e!(
307        cfg(any(
308            target_os = "android",
309            target_os = "fuchsia",
310            target_os = "linux",
311            target_os = "redox"
312        )),
313        ELIBMAX
314    ),
315    e!(ESPIPE),
316    e!(cfg(not(any(target_os = "openbsd", windows))), ENOLINK),
317    e!(ENETRESET),
318    e!(ETIMEDOUT),
319    e!(ENOENT),
320    e!(EEXIST),
321    e!(EDQUOT),
322    e!(
323        cfg(not(any(
324            target_os = "openbsd",
325            target_os = "freebsd",
326            target_os = "wasi",
327            windows
328        ))),
329        ENOSTR
330    ),
331    e!(
332        cfg(any(
333            target_os = "android",
334            target_os = "fuchsia",
335            target_os = "linux",
336            target_os = "redox"
337        )),
338        EBADSLT
339    ),
340    e!(
341        cfg(any(
342            target_os = "android",
343            target_os = "fuchsia",
344            target_os = "linux",
345            target_os = "redox"
346        )),
347        EBADRQC
348    ),
349    e!(
350        cfg(any(
351            target_os = "android",
352            target_os = "fuchsia",
353            target_os = "linux",
354            target_os = "redox"
355        )),
356        ELIBACC
357    ),
358    e!(EFAULT),
359    e!(EFBIG),
360    e!(EDEADLK),
361    e!(ENOTCONN),
362    e!(EDESTADDRREQ),
363    e!(
364        cfg(any(
365            target_os = "android",
366            target_os = "fuchsia",
367            target_os = "linux",
368            target_os = "redox"
369        )),
370        ELIBSCN
371    ),
372    e!(ENOLCK),
373    e!(
374        cfg(any(
375            target_os = "android",
376            target_os = "fuchsia",
377            target_os = "linux",
378            target_os = "redox"
379        )),
380        EISNAM
381    ),
382    e!(ECONNABORTED),
383    e!(ENETUNREACH),
384    e!(ESTALE),
385    e!(
386        cfg(not(any(
387            target_os = "openbsd",
388            target_os = "freebsd",
389            target_os = "wasi",
390            windows
391        ))),
392        ENOSR
393    ),
394    e!(ENOMEM),
395    e!(ENOTSOCK),
396    e!(
397        cfg(any(
398            target_os = "android",
399            target_os = "fuchsia",
400            target_os = "linux",
401            target_os = "redox"
402        )),
403        ESTRPIPE
404    ),
405    e!(EMLINK),
406    e!(ERANGE),
407    e!(
408        cfg(any(
409            target_os = "android",
410            target_os = "fuchsia",
411            target_os = "linux",
412            target_os = "redox"
413        )),
414        ELIBEXEC
415    ),
416    e!(
417        cfg(any(
418            target_os = "android",
419            target_os = "fuchsia",
420            target_os = "linux",
421            target_os = "redox"
422        )),
423        EL3HLT
424    ),
425    e!(ECONNRESET),
426    e!(EADDRINUSE),
427    e!(EOPNOTSUPP),
428    e!(
429        cfg(any(
430            target_os = "android",
431            target_os = "fuchsia",
432            target_os = "linux",
433            target_os = "redox"
434        )),
435        EREMCHG
436    ),
437    e!(EAGAIN),
438    e!(ENAMETOOLONG),
439    e!(ENOTTY),
440    e!(
441        cfg(any(
442            target_os = "android",
443            target_os = "fuchsia",
444            target_os = "linux",
445            target_os = "redox"
446        )),
447        ERESTART
448    ),
449    e!(cfg(not(target_os = "wasi")), ESOCKTNOSUPPORT),
450    e!(
451        cfg(not(any(
452            target_os = "openbsd",
453            target_os = "freebsd",
454            target_os = "wasi",
455            windows
456        ))),
457        ETIME
458    ),
459    e!(
460        cfg(any(
461            target_os = "android",
462            target_os = "fuchsia",
463            target_os = "linux",
464            target_os = "redox"
465        )),
466        EBFONT
467    ),
468    e!(
469        cfg(any(
470            target_os = "fuchsia",
471            target_os = "linux",
472            target_os = "redox",
473            windows
474        )),
475        EDEADLOCK
476    ),
477    e!(cfg(not(target_os = "wasi")), ETOOMANYREFS),
478    e!(EMFILE),
479    e!(cfg(not(windows)), ETXTBSY),
480    e!(EINPROGRESS),
481    e!(ENXIO),
482    e!(
483        cfg(any(
484            target_os = "android",
485            target_os = "fuchsia",
486            target_os = "linux",
487            target_os = "redox"
488        )),
489        ENOPKG
490    ),
491    // TODO: e!(cfg(windows), WSASY),
492    e!(cfg(windows), WSAEHOSTDOWN),
493    e!(cfg(windows), WSAENETDOWN),
494    e!(cfg(windows), WSAENOTSOCK),
495    e!(cfg(windows), WSAEHOSTUNREACH),
496    e!(cfg(windows), WSAELOOP),
497    e!(cfg(windows), WSAEMFILE),
498    e!(cfg(windows), WSAESTALE),
499    e!(cfg(windows), WSAVERNOTSUPPORTED),
500    e!(cfg(windows), WSAENETUNREACH),
501    e!(cfg(windows), WSAEPROCLIM),
502    e!(cfg(windows), WSAEFAULT),
503    e!(cfg(windows), WSANOTINITIALISED),
504    e!(cfg(windows), WSAEUSERS),
505    // TODO: e!(cfg(windows), WSAMAKEASYNCREPL),
506    e!(cfg(windows), WSAENOPROTOOPT),
507    e!(cfg(windows), WSAECONNABORTED),
508    e!(cfg(windows), WSAENAMETOOLONG),
509    e!(cfg(windows), WSAENOTEMPTY),
510    e!(cfg(windows), WSAESHUTDOWN),
511    e!(cfg(windows), WSAEAFNOSUPPORT),
512    e!(cfg(windows), WSAETOOMANYREFS),
513    e!(cfg(windows), WSAEACCES),
514    // TODO: e!(cfg(windows), WSATR),
515    e!(cfg(windows), WSABASEERR),
516    // TODO: e!(cfg(windows), WSADESCRIPTIO),
517    e!(cfg(windows), WSAEMSGSIZE),
518    e!(cfg(windows), WSAEBADF),
519    e!(cfg(windows), WSAECONNRESET),
520    // TODO: e!(cfg(windows), WSAGETSELECTERRO),
521    e!(cfg(windows), WSAETIMEDOUT),
522    e!(cfg(windows), WSAENOBUFS),
523    e!(cfg(windows), WSAEDISCON),
524    e!(cfg(windows), WSAEINTR),
525    e!(cfg(windows), WSAEPROTOTYPE),
526    // TODO: e!(cfg(windows), WSAHOS),
527    e!(cfg(windows), WSAEADDRINUSE),
528    e!(cfg(windows), WSAEADDRNOTAVAIL),
529    e!(cfg(windows), WSAEALREADY),
530    e!(cfg(windows), WSAEPROTONOSUPPORT),
531    e!(cfg(windows), WSASYSNOTREADY),
532    e!(cfg(windows), WSAEWOULDBLOCK),
533    e!(cfg(windows), WSAEPFNOSUPPORT),
534    e!(cfg(windows), WSAEOPNOTSUPP),
535    e!(cfg(windows), WSAEISCONN),
536    e!(cfg(windows), WSAEDQUOT),
537    e!(cfg(windows), WSAENOTCONN),
538    e!(cfg(windows), WSAEREMOTE),
539    e!(cfg(windows), WSAEINVAL),
540    e!(cfg(windows), WSAEINPROGRESS),
541    // TODO: e!(cfg(windows), WSAGETSELECTEVEN),
542    e!(cfg(windows), WSAESOCKTNOSUPPORT),
543    // TODO: e!(cfg(windows), WSAGETASYNCERRO),
544    // TODO: e!(cfg(windows), WSAMAKESELECTREPL),
545    // TODO: e!(cfg(windows), WSAGETASYNCBUFLE),
546    e!(cfg(windows), WSAEDESTADDRREQ),
547    e!(cfg(windows), WSAECONNREFUSED),
548    e!(cfg(windows), WSAENETRESET),
549    // TODO: e!(cfg(windows), WSAN),
550    e!(
551        cfg(any(
552            target_os = "android",
553            target_os = "dragonfly",
554            target_os = "fuchsia",
555            target_os = "linux",
556            target_os = "openbsd",
557            target_os = "redox"
558        )),
559        ENOMEDIUM
560    ),
561    e!(
562        cfg(any(
563            target_os = "android",
564            target_os = "fuchsia",
565            target_os = "linux",
566            target_os = "openbsd",
567            target_os = "redox"
568        )),
569        EMEDIUMTYPE
570    ),
571    e!(ECANCELED),
572    e!(
573        cfg(any(
574            target_os = "android",
575            target_os = "fuchsia",
576            target_os = "linux",
577            target_os = "redox"
578        )),
579        ENOKEY
580    ),
581    e!(
582        cfg(any(
583            target_os = "android",
584            target_os = "fuchsia",
585            target_os = "linux",
586            target_os = "redox"
587        )),
588        EKEYEXPIRED
589    ),
590    e!(
591        cfg(any(
592            target_os = "android",
593            target_os = "fuchsia",
594            target_os = "linux",
595            target_os = "redox"
596        )),
597        EKEYREVOKED
598    ),
599    e!(
600        cfg(any(
601            target_os = "android",
602            target_os = "fuchsia",
603            target_os = "linux",
604            target_os = "redox"
605        )),
606        EKEYREJECTED
607    ),
608    e!(cfg(not(any(windows, target_os = "netbsd"))), EOWNERDEAD),
609    e!(
610        cfg(not(any(windows, target_os = "netbsd"))),
611        ENOTRECOVERABLE
612    ),
613    e!(
614        cfg(any(target_os = "fuchsia", target_os = "linux")),
615        ERFKILL
616    ),
617    // Solaris-specific errnos
618    e!(cfg(not(target_os = "redox")), ENOTSUP),
619    e!(
620        cfg(any(target_os = "illumos", target_os = "solaris")),
621        ELOCKUNMAPPED
622    ),
623    e!(
624        cfg(any(target_os = "illumos", target_os = "solaris")),
625        ENOTACTIVE
626    ),
627    // MacOSX specific errnos
628    e!(
629        cfg(any(
630            target_os = "dragonfly",
631            target_os = "freebsd",
632            target_os = "netbsd",
633            target_os = "openbsd",
634            target_vendor = "apple"
635        )),
636        EAUTH
637    ),
638    e!(cfg(target_vendor = "apple"), EBADARCH),
639    e!(cfg(target_vendor = "apple"), EBADEXEC),
640    e!(cfg(target_vendor = "apple"), EBADMACHO),
641    e!(
642        cfg(any(
643            target_os = "dragonfly",
644            target_os = "freebsd",
645            target_os = "netbsd",
646            target_os = "openbsd",
647            target_vendor = "apple"
648        )),
649        EBADRPC
650    ),
651    e!(cfg(target_vendor = "apple"), EDEVERR),
652    e!(
653        cfg(any(
654            target_os = "dragonfly",
655            target_os = "freebsd",
656            target_os = "netbsd",
657            target_os = "openbsd",
658            target_vendor = "apple"
659        )),
660        EFTYPE
661    ),
662    e!(
663        cfg(any(
664            target_os = "dragonfly",
665            target_os = "freebsd",
666            target_os = "netbsd",
667            target_os = "openbsd",
668            target_vendor = "apple"
669        )),
670        ENEEDAUTH
671    ),
672    e!(
673        cfg(any(
674            target_os = "dragonfly",
675            target_os = "freebsd",
676            target_os = "netbsd",
677            target_os = "openbsd",
678            target_vendor = "apple"
679        )),
680        ENOATTR
681    ),
682    e!(cfg(target_vendor = "apple"), ENOPOLICY),
683    e!(
684        cfg(any(
685            target_os = "dragonfly",
686            target_os = "freebsd",
687            target_os = "netbsd",
688            target_os = "openbsd",
689            target_vendor = "apple"
690        )),
691        EPROCLIM
692    ),
693    e!(
694        cfg(any(
695            target_os = "dragonfly",
696            target_os = "freebsd",
697            target_os = "netbsd",
698            target_os = "openbsd",
699            target_vendor = "apple"
700        )),
701        EPROCUNAVAIL
702    ),
703    e!(
704        cfg(any(
705            target_os = "dragonfly",
706            target_os = "freebsd",
707            target_os = "netbsd",
708            target_os = "openbsd",
709            target_vendor = "apple"
710        )),
711        EPROGMISMATCH
712    ),
713    e!(
714        cfg(any(
715            target_os = "dragonfly",
716            target_os = "freebsd",
717            target_os = "netbsd",
718            target_os = "openbsd",
719            target_vendor = "apple"
720        )),
721        EPROGUNAVAIL
722    ),
723    e!(cfg(target_vendor = "apple"), EPWROFF),
724    e!(cfg(target_vendor = "apple"), EQFULL),
725    e!(cfg(target_vendor = "apple"), ENOTCAPABLE),
726    e!(
727        cfg(any(
728            target_os = "dragonfly",
729            target_os = "freebsd",
730            target_os = "netbsd",
731            target_os = "openbsd",
732            target_vendor = "apple"
733        )),
734        ERPCMISMATCH
735    ),
736    e!(cfg(target_vendor = "apple"), ESHLIBVERS),
737    e!(
738        cfg(all(
739            unix,
740            any(target_os = "linux", target_os = "fuchsia"),
741            not(any(
742                target_os = "freebsd",
743                target_os = "android",
744                target_vendor = "apple",
745            ))
746        )),
747        EHWPOISON
748    ),
749];
750
751#[cfg(not(any(unix, windows, target_os = "wasi")))]
752const ERROR_CODES: &[(&str, i32)] = &[];