1
2 /* Errno module */
3
4 #include "Python.h"
5
6 /* Windows socket errors (WSA*) */
7 #ifdef MS_WINDOWS
8 #define WIN32_LEAN_AND_MEAN
9 #include <windows.h>
10 /* The following constants were added to errno.h in VS2010 but have
11 preferred WSA equivalents. */
12 #undef EADDRINUSE
13 #undef EADDRNOTAVAIL
14 #undef EAFNOSUPPORT
15 #undef EALREADY
16 #undef ECONNABORTED
17 #undef ECONNREFUSED
18 #undef ECONNRESET
19 #undef EDESTADDRREQ
20 #undef EHOSTUNREACH
21 #undef EINPROGRESS
22 #undef EISCONN
23 #undef ELOOP
24 #undef EMSGSIZE
25 #undef ENETDOWN
26 #undef ENETRESET
27 #undef ENETUNREACH
28 #undef ENOBUFS
29 #undef ENOPROTOOPT
30 #undef ENOTCONN
31 #undef ENOTSOCK
32 #undef EOPNOTSUPP
33 #undef EPROTONOSUPPORT
34 #undef EPROTOTYPE
35 #undef ETIMEDOUT
36 #undef EWOULDBLOCK
37 #endif
38
39 /*
40 * Pull in the system error definitions
41 */
42
43 static PyMethodDef errno_methods[] = {
44 {NULL, NULL}
45 };
46
47 /* Helper function doing the dictionary inserting */
48
49 static int
50 _add_errcode(PyObject *module_dict, PyObject *error_dict, const char *name_str, int code_int)
51 {
52 PyObject *name = PyUnicode_FromString(name_str);
53 if (!name) {
54 return -1;
55 }
56
57 PyObject *code = PyLong_FromLong(code_int);
58 if (!code) {
59 Py_DECREF(name);
60 return -1;
61 }
62
63 int ret = -1;
64 /* insert in modules dict */
65 if (PyDict_SetItem(module_dict, name, code) < 0) {
66 goto end;
67 }
68 /* insert in errorcode dict */
69 if (PyDict_SetItem(error_dict, code, name) < 0) {
70 goto end;
71 }
72 ret = 0;
73 end:
74 Py_DECREF(name);
75 Py_DECREF(code);
76 return ret;
77 }
78
79 static int
80 errno_exec(PyObject *module)
81 {
82 PyObject *module_dict = PyModule_GetDict(module); // Borrowed ref.
83 if (module_dict == NULL) {
84 return -1;
85 }
86 PyObject *error_dict = PyDict_New();
87 if (error_dict == NULL) {
88 return -1;
89 }
90 if (PyDict_SetItemString(module_dict, "errorcode", error_dict) < 0) {
91 Py_DECREF(error_dict);
92 return -1;
93 }
94
95 /* Macro so I don't have to edit each and every line below... */
96 #define add_errcode(name, code, comment) \
97 do { \
98 if (_add_errcode(module_dict, error_dict, name, code) < 0) { \
99 Py_DECREF(error_dict); \
100 return -1; \
101 } \
102 } while (0);
103
104 /*
105 * The names and comments are borrowed from linux/include/errno.h,
106 * which should be pretty all-inclusive. However, the Solaris specific
107 * names and comments are borrowed from sys/errno.h in Solaris.
108 * MacOSX specific names and comments are borrowed from sys/errno.h in
109 * MacOSX.
110 */
111
112 #ifdef ENODEV
113 add_errcode("ENODEV", ENODEV, "No such device");
114 #endif
115 #ifdef ENOCSI
116 add_errcode("ENOCSI", ENOCSI, "No CSI structure available");
117 #endif
118 #ifdef EHOSTUNREACH
119 add_errcode("EHOSTUNREACH", EHOSTUNREACH, "No route to host");
120 #else
121 #ifdef WSAEHOSTUNREACH
122 add_errcode("EHOSTUNREACH", WSAEHOSTUNREACH, "No route to host");
123 #endif
124 #endif
125 #ifdef ENOMSG
126 add_errcode("ENOMSG", ENOMSG, "No message of desired type");
127 #endif
128 #ifdef EUCLEAN
129 add_errcode("EUCLEAN", EUCLEAN, "Structure needs cleaning");
130 #endif
131 #ifdef EL2NSYNC
132 add_errcode("EL2NSYNC", EL2NSYNC, "Level 2 not synchronized");
133 #endif
134 #ifdef EL2HLT
135 add_errcode("EL2HLT", EL2HLT, "Level 2 halted");
136 #endif
137 #ifdef ENODATA
138 add_errcode("ENODATA", ENODATA, "No data available");
139 #endif
140 #ifdef ENOTBLK
141 add_errcode("ENOTBLK", ENOTBLK, "Block device required");
142 #endif
143 #ifdef ENOSYS
144 add_errcode("ENOSYS", ENOSYS, "Function not implemented");
145 #endif
146 #ifdef EPIPE
147 add_errcode("EPIPE", EPIPE, "Broken pipe");
148 #endif
149 #ifdef EINVAL
150 add_errcode("EINVAL", EINVAL, "Invalid argument");
151 #else
152 #ifdef WSAEINVAL
153 add_errcode("EINVAL", WSAEINVAL, "Invalid argument");
154 #endif
155 #endif
156 #ifdef EOVERFLOW
157 add_errcode("EOVERFLOW", EOVERFLOW, "Value too large for defined data type");
158 #endif
159 #ifdef EADV
160 add_errcode("EADV", EADV, "Advertise error");
161 #endif
162 #ifdef EINTR
163 add_errcode("EINTR", EINTR, "Interrupted system call");
164 #else
165 #ifdef WSAEINTR
166 add_errcode("EINTR", WSAEINTR, "Interrupted system call");
167 #endif
168 #endif
169 #ifdef EUSERS
170 add_errcode("EUSERS", EUSERS, "Too many users");
171 #else
172 #ifdef WSAEUSERS
173 add_errcode("EUSERS", WSAEUSERS, "Too many users");
174 #endif
175 #endif
176 #ifdef ENOTEMPTY
177 add_errcode("ENOTEMPTY", ENOTEMPTY, "Directory not empty");
178 #else
179 #ifdef WSAENOTEMPTY
180 add_errcode("ENOTEMPTY", WSAENOTEMPTY, "Directory not empty");
181 #endif
182 #endif
183 #ifdef ENOBUFS
184 add_errcode("ENOBUFS", ENOBUFS, "No buffer space available");
185 #else
186 #ifdef WSAENOBUFS
187 add_errcode("ENOBUFS", WSAENOBUFS, "No buffer space available");
188 #endif
189 #endif
190 #ifdef EPROTO
191 add_errcode("EPROTO", EPROTO, "Protocol error");
192 #endif
193 #ifdef EREMOTE
194 add_errcode("EREMOTE", EREMOTE, "Object is remote");
195 #else
196 #ifdef WSAEREMOTE
197 add_errcode("EREMOTE", WSAEREMOTE, "Object is remote");
198 #endif
199 #endif
200 #ifdef ENAVAIL
201 add_errcode("ENAVAIL", ENAVAIL, "No XENIX semaphores available");
202 #endif
203 #ifdef ECHILD
204 add_errcode("ECHILD", ECHILD, "No child processes");
205 #endif
206 #ifdef ELOOP
207 add_errcode("ELOOP", ELOOP, "Too many symbolic links encountered");
208 #else
209 #ifdef WSAELOOP
210 add_errcode("ELOOP", WSAELOOP, "Too many symbolic links encountered");
211 #endif
212 #endif
213 #ifdef EXDEV
214 add_errcode("EXDEV", EXDEV, "Cross-device link");
215 #endif
216 #ifdef E2BIG
217 add_errcode("E2BIG", E2BIG, "Arg list too long");
218 #endif
219 #ifdef ESRCH
220 add_errcode("ESRCH", ESRCH, "No such process");
221 #endif
222 #ifdef EMSGSIZE
223 add_errcode("EMSGSIZE", EMSGSIZE, "Message too long");
224 #else
225 #ifdef WSAEMSGSIZE
226 add_errcode("EMSGSIZE", WSAEMSGSIZE, "Message too long");
227 #endif
228 #endif
229 #ifdef EAFNOSUPPORT
230 add_errcode("EAFNOSUPPORT", EAFNOSUPPORT, "Address family not supported by protocol");
231 #else
232 #ifdef WSAEAFNOSUPPORT
233 add_errcode("EAFNOSUPPORT", WSAEAFNOSUPPORT, "Address family not supported by protocol");
234 #endif
235 #endif
236 #ifdef EBADR
237 add_errcode("EBADR", EBADR, "Invalid request descriptor");
238 #endif
239 #ifdef EHOSTDOWN
240 add_errcode("EHOSTDOWN", EHOSTDOWN, "Host is down");
241 #else
242 #ifdef WSAEHOSTDOWN
243 add_errcode("EHOSTDOWN", WSAEHOSTDOWN, "Host is down");
244 #endif
245 #endif
246 #ifdef EPFNOSUPPORT
247 add_errcode("EPFNOSUPPORT", EPFNOSUPPORT, "Protocol family not supported");
248 #else
249 #ifdef WSAEPFNOSUPPORT
250 add_errcode("EPFNOSUPPORT", WSAEPFNOSUPPORT, "Protocol family not supported");
251 #endif
252 #endif
253 #ifdef ENOPROTOOPT
254 add_errcode("ENOPROTOOPT", ENOPROTOOPT, "Protocol not available");
255 #else
256 #ifdef WSAENOPROTOOPT
257 add_errcode("ENOPROTOOPT", WSAENOPROTOOPT, "Protocol not available");
258 #endif
259 #endif
260 #ifdef EBUSY
261 add_errcode("EBUSY", EBUSY, "Device or resource busy");
262 #endif
263 #ifdef EWOULDBLOCK
264 add_errcode("EWOULDBLOCK", EWOULDBLOCK, "Operation would block");
265 #else
266 #ifdef WSAEWOULDBLOCK
267 add_errcode("EWOULDBLOCK", WSAEWOULDBLOCK, "Operation would block");
268 #endif
269 #endif
270 #ifdef EBADFD
271 add_errcode("EBADFD", EBADFD, "File descriptor in bad state");
272 #endif
273 #ifdef EDOTDOT
274 add_errcode("EDOTDOT", EDOTDOT, "RFS specific error");
275 #endif
276 #ifdef EISCONN
277 add_errcode("EISCONN", EISCONN, "Transport endpoint is already connected");
278 #else
279 #ifdef WSAEISCONN
280 add_errcode("EISCONN", WSAEISCONN, "Transport endpoint is already connected");
281 #endif
282 #endif
283 #ifdef ENOANO
284 add_errcode("ENOANO", ENOANO, "No anode");
285 #endif
286 #if defined(__wasi__) && !defined(ESHUTDOWN)
287 // WASI SDK 16 does not have ESHUTDOWN, shutdown results in EPIPE.
288 #define ESHUTDOWN EPIPE
289 #endif
290 #ifdef ESHUTDOWN
291 add_errcode("ESHUTDOWN", ESHUTDOWN, "Cannot send after transport endpoint shutdown");
292 #else
293 #ifdef WSAESHUTDOWN
294 add_errcode("ESHUTDOWN", WSAESHUTDOWN, "Cannot send after transport endpoint shutdown");
295 #endif
296 #endif
297 #ifdef ECHRNG
298 add_errcode("ECHRNG", ECHRNG, "Channel number out of range");
299 #endif
300 #ifdef ELIBBAD
301 add_errcode("ELIBBAD", ELIBBAD, "Accessing a corrupted shared library");
302 #endif
303 #ifdef ENONET
304 add_errcode("ENONET", ENONET, "Machine is not on the network");
305 #endif
306 #ifdef EBADE
307 add_errcode("EBADE", EBADE, "Invalid exchange");
308 #endif
309 #ifdef EBADF
310 add_errcode("EBADF", EBADF, "Bad file number");
311 #else
312 #ifdef WSAEBADF
313 add_errcode("EBADF", WSAEBADF, "Bad file number");
314 #endif
315 #endif
316 #ifdef EMULTIHOP
317 add_errcode("EMULTIHOP", EMULTIHOP, "Multihop attempted");
318 #endif
319 #ifdef EIO
320 add_errcode("EIO", EIO, "I/O error");
321 #endif
322 #ifdef EUNATCH
323 add_errcode("EUNATCH", EUNATCH, "Protocol driver not attached");
324 #endif
325 #ifdef EPROTOTYPE
326 add_errcode("EPROTOTYPE", EPROTOTYPE, "Protocol wrong type for socket");
327 #else
328 #ifdef WSAEPROTOTYPE
329 add_errcode("EPROTOTYPE", WSAEPROTOTYPE, "Protocol wrong type for socket");
330 #endif
331 #endif
332 #ifdef ENOSPC
333 add_errcode("ENOSPC", ENOSPC, "No space left on device");
334 #endif
335 #ifdef ENOEXEC
336 add_errcode("ENOEXEC", ENOEXEC, "Exec format error");
337 #endif
338 #ifdef EALREADY
339 add_errcode("EALREADY", EALREADY, "Operation already in progress");
340 #else
341 #ifdef WSAEALREADY
342 add_errcode("EALREADY", WSAEALREADY, "Operation already in progress");
343 #endif
344 #endif
345 #ifdef ENETDOWN
346 add_errcode("ENETDOWN", ENETDOWN, "Network is down");
347 #else
348 #ifdef WSAENETDOWN
349 add_errcode("ENETDOWN", WSAENETDOWN, "Network is down");
350 #endif
351 #endif
352 #ifdef ENOTNAM
353 add_errcode("ENOTNAM", ENOTNAM, "Not a XENIX named type file");
354 #endif
355 #ifdef EACCES
356 add_errcode("EACCES", EACCES, "Permission denied");
357 #else
358 #ifdef WSAEACCES
359 add_errcode("EACCES", WSAEACCES, "Permission denied");
360 #endif
361 #endif
362 #ifdef ELNRNG
363 add_errcode("ELNRNG", ELNRNG, "Link number out of range");
364 #endif
365 #ifdef EILSEQ
366 add_errcode("EILSEQ", EILSEQ, "Illegal byte sequence");
367 #endif
368 #ifdef ENOTDIR
369 add_errcode("ENOTDIR", ENOTDIR, "Not a directory");
370 #endif
371 #ifdef ENOTUNIQ
372 add_errcode("ENOTUNIQ", ENOTUNIQ, "Name not unique on network");
373 #endif
374 #ifdef EPERM
375 add_errcode("EPERM", EPERM, "Operation not permitted");
376 #endif
377 #ifdef EDOM
378 add_errcode("EDOM", EDOM, "Math argument out of domain of func");
379 #endif
380 #ifdef EXFULL
381 add_errcode("EXFULL", EXFULL, "Exchange full");
382 #endif
383 #ifdef ECONNREFUSED
384 add_errcode("ECONNREFUSED", ECONNREFUSED, "Connection refused");
385 #else
386 #ifdef WSAECONNREFUSED
387 add_errcode("ECONNREFUSED", WSAECONNREFUSED, "Connection refused");
388 #endif
389 #endif
390 #ifdef EISDIR
391 add_errcode("EISDIR", EISDIR, "Is a directory");
392 #endif
393 #ifdef EPROTONOSUPPORT
394 add_errcode("EPROTONOSUPPORT", EPROTONOSUPPORT, "Protocol not supported");
395 #else
396 #ifdef WSAEPROTONOSUPPORT
397 add_errcode("EPROTONOSUPPORT", WSAEPROTONOSUPPORT, "Protocol not supported");
398 #endif
399 #endif
400 #ifdef EROFS
401 add_errcode("EROFS", EROFS, "Read-only file system");
402 #endif
403 #ifdef EADDRNOTAVAIL
404 add_errcode("EADDRNOTAVAIL", EADDRNOTAVAIL, "Cannot assign requested address");
405 #else
406 #ifdef WSAEADDRNOTAVAIL
407 add_errcode("EADDRNOTAVAIL", WSAEADDRNOTAVAIL, "Cannot assign requested address");
408 #endif
409 #endif
410 #ifdef EIDRM
411 add_errcode("EIDRM", EIDRM, "Identifier removed");
412 #endif
413 #ifdef ECOMM
414 add_errcode("ECOMM", ECOMM, "Communication error on send");
415 #endif
416 #ifdef ESRMNT
417 add_errcode("ESRMNT", ESRMNT, "Srmount error");
418 #endif
419 #ifdef EREMOTEIO
420 add_errcode("EREMOTEIO", EREMOTEIO, "Remote I/O error");
421 #endif
422 #ifdef EL3RST
423 add_errcode("EL3RST", EL3RST, "Level 3 reset");
424 #endif
425 #ifdef EBADMSG
426 add_errcode("EBADMSG", EBADMSG, "Not a data message");
427 #endif
428 #ifdef ENFILE
429 add_errcode("ENFILE", ENFILE, "File table overflow");
430 #endif
431 #ifdef ELIBMAX
432 add_errcode("ELIBMAX", ELIBMAX, "Attempting to link in too many shared libraries");
433 #endif
434 #ifdef ESPIPE
435 add_errcode("ESPIPE", ESPIPE, "Illegal seek");
436 #endif
437 #ifdef ENOLINK
438 add_errcode("ENOLINK", ENOLINK, "Link has been severed");
439 #endif
440 #ifdef ENETRESET
441 add_errcode("ENETRESET", ENETRESET, "Network dropped connection because of reset");
442 #else
443 #ifdef WSAENETRESET
444 add_errcode("ENETRESET", WSAENETRESET, "Network dropped connection because of reset");
445 #endif
446 #endif
447 #ifdef ETIMEDOUT
448 add_errcode("ETIMEDOUT", ETIMEDOUT, "Connection timed out");
449 #else
450 #ifdef WSAETIMEDOUT
451 add_errcode("ETIMEDOUT", WSAETIMEDOUT, "Connection timed out");
452 #endif
453 #endif
454 #ifdef ENOENT
455 add_errcode("ENOENT", ENOENT, "No such file or directory");
456 #endif
457 #ifdef EEXIST
458 add_errcode("EEXIST", EEXIST, "File exists");
459 #endif
460 #ifdef EDQUOT
461 add_errcode("EDQUOT", EDQUOT, "Quota exceeded");
462 #else
463 #ifdef WSAEDQUOT
464 add_errcode("EDQUOT", WSAEDQUOT, "Quota exceeded");
465 #endif
466 #endif
467 #ifdef ENOSTR
468 add_errcode("ENOSTR", ENOSTR, "Device not a stream");
469 #endif
470 #ifdef EBADSLT
471 add_errcode("EBADSLT", EBADSLT, "Invalid slot");
472 #endif
473 #ifdef EBADRQC
474 add_errcode("EBADRQC", EBADRQC, "Invalid request code");
475 #endif
476 #ifdef ELIBACC
477 add_errcode("ELIBACC", ELIBACC, "Can not access a needed shared library");
478 #endif
479 #ifdef EFAULT
480 add_errcode("EFAULT", EFAULT, "Bad address");
481 #else
482 #ifdef WSAEFAULT
483 add_errcode("EFAULT", WSAEFAULT, "Bad address");
484 #endif
485 #endif
486 #ifdef EFBIG
487 add_errcode("EFBIG", EFBIG, "File too large");
488 #endif
489 #ifdef EDEADLK
490 add_errcode("EDEADLK", EDEADLK, "Resource deadlock would occur");
491 #endif
492 #ifdef ENOTCONN
493 add_errcode("ENOTCONN", ENOTCONN, "Transport endpoint is not connected");
494 #else
495 #ifdef WSAENOTCONN
496 add_errcode("ENOTCONN", WSAENOTCONN, "Transport endpoint is not connected");
497 #endif
498 #endif
499 #ifdef EDESTADDRREQ
500 add_errcode("EDESTADDRREQ", EDESTADDRREQ, "Destination address required");
501 #else
502 #ifdef WSAEDESTADDRREQ
503 add_errcode("EDESTADDRREQ", WSAEDESTADDRREQ, "Destination address required");
504 #endif
505 #endif
506 #ifdef ELIBSCN
507 add_errcode("ELIBSCN", ELIBSCN, ".lib section in a.out corrupted");
508 #endif
509 #ifdef ENOLCK
510 add_errcode("ENOLCK", ENOLCK, "No record locks available");
511 #endif
512 #ifdef EISNAM
513 add_errcode("EISNAM", EISNAM, "Is a named type file");
514 #endif
515 #ifdef ECONNABORTED
516 add_errcode("ECONNABORTED", ECONNABORTED, "Software caused connection abort");
517 #else
518 #ifdef WSAECONNABORTED
519 add_errcode("ECONNABORTED", WSAECONNABORTED, "Software caused connection abort");
520 #endif
521 #endif
522 #ifdef ENETUNREACH
523 add_errcode("ENETUNREACH", ENETUNREACH, "Network is unreachable");
524 #else
525 #ifdef WSAENETUNREACH
526 add_errcode("ENETUNREACH", WSAENETUNREACH, "Network is unreachable");
527 #endif
528 #endif
529 #ifdef ESTALE
530 add_errcode("ESTALE", ESTALE, "Stale NFS file handle");
531 #else
532 #ifdef WSAESTALE
533 add_errcode("ESTALE", WSAESTALE, "Stale NFS file handle");
534 #endif
535 #endif
536 #ifdef ENOSR
537 add_errcode("ENOSR", ENOSR, "Out of streams resources");
538 #endif
539 #ifdef ENOMEM
540 add_errcode("ENOMEM", ENOMEM, "Out of memory");
541 #endif
542 #ifdef ENOTSOCK
543 add_errcode("ENOTSOCK", ENOTSOCK, "Socket operation on non-socket");
544 #else
545 #ifdef WSAENOTSOCK
546 add_errcode("ENOTSOCK", WSAENOTSOCK, "Socket operation on non-socket");
547 #endif
548 #endif
549 #ifdef ESTRPIPE
550 add_errcode("ESTRPIPE", ESTRPIPE, "Streams pipe error");
551 #endif
552 #ifdef EMLINK
553 add_errcode("EMLINK", EMLINK, "Too many links");
554 #endif
555 #ifdef ERANGE
556 add_errcode("ERANGE", ERANGE, "Math result not representable");
557 #endif
558 #ifdef ELIBEXEC
559 add_errcode("ELIBEXEC", ELIBEXEC, "Cannot exec a shared library directly");
560 #endif
561 #ifdef EL3HLT
562 add_errcode("EL3HLT", EL3HLT, "Level 3 halted");
563 #endif
564 #ifdef ECONNRESET
565 add_errcode("ECONNRESET", ECONNRESET, "Connection reset by peer");
566 #else
567 #ifdef WSAECONNRESET
568 add_errcode("ECONNRESET", WSAECONNRESET, "Connection reset by peer");
569 #endif
570 #endif
571 #ifdef EADDRINUSE
572 add_errcode("EADDRINUSE", EADDRINUSE, "Address already in use");
573 #else
574 #ifdef WSAEADDRINUSE
575 add_errcode("EADDRINUSE", WSAEADDRINUSE, "Address already in use");
576 #endif
577 #endif
578 #ifdef EOPNOTSUPP
579 add_errcode("EOPNOTSUPP", EOPNOTSUPP, "Operation not supported on transport endpoint");
580 #else
581 #ifdef WSAEOPNOTSUPP
582 add_errcode("EOPNOTSUPP", WSAEOPNOTSUPP, "Operation not supported on transport endpoint");
583 #endif
584 #endif
585 #ifdef EREMCHG
586 add_errcode("EREMCHG", EREMCHG, "Remote address changed");
587 #endif
588 #ifdef EAGAIN
589 add_errcode("EAGAIN", EAGAIN, "Try again");
590 #endif
591 #ifdef ENAMETOOLONG
592 add_errcode("ENAMETOOLONG", ENAMETOOLONG, "File name too long");
593 #else
594 #ifdef WSAENAMETOOLONG
595 add_errcode("ENAMETOOLONG", WSAENAMETOOLONG, "File name too long");
596 #endif
597 #endif
598 #ifdef ENOTTY
599 add_errcode("ENOTTY", ENOTTY, "Not a typewriter");
600 #endif
601 #ifdef ERESTART
602 add_errcode("ERESTART", ERESTART, "Interrupted system call should be restarted");
603 #endif
604 #ifdef ESOCKTNOSUPPORT
605 add_errcode("ESOCKTNOSUPPORT", ESOCKTNOSUPPORT, "Socket type not supported");
606 #else
607 #ifdef WSAESOCKTNOSUPPORT
608 add_errcode("ESOCKTNOSUPPORT", WSAESOCKTNOSUPPORT, "Socket type not supported");
609 #endif
610 #endif
611 #ifdef ETIME
612 add_errcode("ETIME", ETIME, "Timer expired");
613 #endif
614 #ifdef EBFONT
615 add_errcode("EBFONT", EBFONT, "Bad font file format");
616 #endif
617 #ifdef EDEADLOCK
618 add_errcode("EDEADLOCK", EDEADLOCK, "Error EDEADLOCK");
619 #endif
620 #ifdef ETOOMANYREFS
621 add_errcode("ETOOMANYREFS", ETOOMANYREFS, "Too many references: cannot splice");
622 #else
623 #ifdef WSAETOOMANYREFS
624 add_errcode("ETOOMANYREFS", WSAETOOMANYREFS, "Too many references: cannot splice");
625 #endif
626 #endif
627 #ifdef EMFILE
628 add_errcode("EMFILE", EMFILE, "Too many open files");
629 #else
630 #ifdef WSAEMFILE
631 add_errcode("EMFILE", WSAEMFILE, "Too many open files");
632 #endif
633 #endif
634 #ifdef ETXTBSY
635 add_errcode("ETXTBSY", ETXTBSY, "Text file busy");
636 #endif
637 #ifdef EINPROGRESS
638 add_errcode("EINPROGRESS", EINPROGRESS, "Operation now in progress");
639 #else
640 #ifdef WSAEINPROGRESS
641 add_errcode("EINPROGRESS", WSAEINPROGRESS, "Operation now in progress");
642 #endif
643 #endif
644 #ifdef ENXIO
645 add_errcode("ENXIO", ENXIO, "No such device or address");
646 #endif
647 #ifdef ENOPKG
648 add_errcode("ENOPKG", ENOPKG, "Package not installed");
649 #endif
650 #ifdef WSASY
651 add_errcode("WSASY", WSASY, "Error WSASY");
652 #endif
653 #ifdef WSAEHOSTDOWN
654 add_errcode("WSAEHOSTDOWN", WSAEHOSTDOWN, "Host is down");
655 #endif
656 #ifdef WSAENETDOWN
657 add_errcode("WSAENETDOWN", WSAENETDOWN, "Network is down");
658 #endif
659 #ifdef WSAENOTSOCK
660 add_errcode("WSAENOTSOCK", WSAENOTSOCK, "Socket operation on non-socket");
661 #endif
662 #ifdef WSAEHOSTUNREACH
663 add_errcode("WSAEHOSTUNREACH", WSAEHOSTUNREACH, "No route to host");
664 #endif
665 #ifdef WSAELOOP
666 add_errcode("WSAELOOP", WSAELOOP, "Too many symbolic links encountered");
667 #endif
668 #ifdef WSAEMFILE
669 add_errcode("WSAEMFILE", WSAEMFILE, "Too many open files");
670 #endif
671 #ifdef WSAESTALE
672 add_errcode("WSAESTALE", WSAESTALE, "Stale NFS file handle");
673 #endif
674 #ifdef WSAVERNOTSUPPORTED
675 add_errcode("WSAVERNOTSUPPORTED", WSAVERNOTSUPPORTED, "Error WSAVERNOTSUPPORTED");
676 #endif
677 #ifdef WSAENETUNREACH
678 add_errcode("WSAENETUNREACH", WSAENETUNREACH, "Network is unreachable");
679 #endif
680 #ifdef WSAEPROCLIM
681 add_errcode("WSAEPROCLIM", WSAEPROCLIM, "Error WSAEPROCLIM");
682 #endif
683 #ifdef WSAEFAULT
684 add_errcode("WSAEFAULT", WSAEFAULT, "Bad address");
685 #endif
686 #ifdef WSANOTINITIALISED
687 add_errcode("WSANOTINITIALISED", WSANOTINITIALISED, "Error WSANOTINITIALISED");
688 #endif
689 #ifdef WSAEUSERS
690 add_errcode("WSAEUSERS", WSAEUSERS, "Too many users");
691 #endif
692 #ifdef WSAMAKEASYNCREPL
693 add_errcode("WSAMAKEASYNCREPL", WSAMAKEASYNCREPL, "Error WSAMAKEASYNCREPL");
694 #endif
695 #ifdef WSAENOPROTOOPT
696 add_errcode("WSAENOPROTOOPT", WSAENOPROTOOPT, "Protocol not available");
697 #endif
698 #ifdef WSAECONNABORTED
699 add_errcode("WSAECONNABORTED", WSAECONNABORTED, "Software caused connection abort");
700 #endif
701 #ifdef WSAENAMETOOLONG
702 add_errcode("WSAENAMETOOLONG", WSAENAMETOOLONG, "File name too long");
703 #endif
704 #ifdef WSAENOTEMPTY
705 add_errcode("WSAENOTEMPTY", WSAENOTEMPTY, "Directory not empty");
706 #endif
707 #ifdef WSAESHUTDOWN
708 add_errcode("WSAESHUTDOWN", WSAESHUTDOWN, "Cannot send after transport endpoint shutdown");
709 #endif
710 #ifdef WSAEAFNOSUPPORT
711 add_errcode("WSAEAFNOSUPPORT", WSAEAFNOSUPPORT, "Address family not supported by protocol");
712 #endif
713 #ifdef WSAETOOMANYREFS
714 add_errcode("WSAETOOMANYREFS", WSAETOOMANYREFS, "Too many references: cannot splice");
715 #endif
716 #ifdef WSAEACCES
717 add_errcode("WSAEACCES", WSAEACCES, "Permission denied");
718 #endif
719 #ifdef WSATR
720 add_errcode("WSATR", WSATR, "Error WSATR");
721 #endif
722 #ifdef WSABASEERR
723 add_errcode("WSABASEERR", WSABASEERR, "Error WSABASEERR");
724 #endif
725 #ifdef WSADESCRIPTIO
726 add_errcode("WSADESCRIPTIO", WSADESCRIPTIO, "Error WSADESCRIPTIO");
727 #endif
728 #ifdef WSAEMSGSIZE
729 add_errcode("WSAEMSGSIZE", WSAEMSGSIZE, "Message too long");
730 #endif
731 #ifdef WSAEBADF
732 add_errcode("WSAEBADF", WSAEBADF, "Bad file number");
733 #endif
734 #ifdef WSAECONNRESET
735 add_errcode("WSAECONNRESET", WSAECONNRESET, "Connection reset by peer");
736 #endif
737 #ifdef WSAGETSELECTERRO
738 add_errcode("WSAGETSELECTERRO", WSAGETSELECTERRO, "Error WSAGETSELECTERRO");
739 #endif
740 #ifdef WSAETIMEDOUT
741 add_errcode("WSAETIMEDOUT", WSAETIMEDOUT, "Connection timed out");
742 #endif
743 #ifdef WSAENOBUFS
744 add_errcode("WSAENOBUFS", WSAENOBUFS, "No buffer space available");
745 #endif
746 #ifdef WSAEDISCON
747 add_errcode("WSAEDISCON", WSAEDISCON, "Error WSAEDISCON");
748 #endif
749 #ifdef WSAEINTR
750 add_errcode("WSAEINTR", WSAEINTR, "Interrupted system call");
751 #endif
752 #ifdef WSAEPROTOTYPE
753 add_errcode("WSAEPROTOTYPE", WSAEPROTOTYPE, "Protocol wrong type for socket");
754 #endif
755 #ifdef WSAHOS
756 add_errcode("WSAHOS", WSAHOS, "Error WSAHOS");
757 #endif
758 #ifdef WSAEADDRINUSE
759 add_errcode("WSAEADDRINUSE", WSAEADDRINUSE, "Address already in use");
760 #endif
761 #ifdef WSAEADDRNOTAVAIL
762 add_errcode("WSAEADDRNOTAVAIL", WSAEADDRNOTAVAIL, "Cannot assign requested address");
763 #endif
764 #ifdef WSAEALREADY
765 add_errcode("WSAEALREADY", WSAEALREADY, "Operation already in progress");
766 #endif
767 #ifdef WSAEPROTONOSUPPORT
768 add_errcode("WSAEPROTONOSUPPORT", WSAEPROTONOSUPPORT, "Protocol not supported");
769 #endif
770 #ifdef WSASYSNOTREADY
771 add_errcode("WSASYSNOTREADY", WSASYSNOTREADY, "Error WSASYSNOTREADY");
772 #endif
773 #ifdef WSAEWOULDBLOCK
774 add_errcode("WSAEWOULDBLOCK", WSAEWOULDBLOCK, "Operation would block");
775 #endif
776 #ifdef WSAEPFNOSUPPORT
777 add_errcode("WSAEPFNOSUPPORT", WSAEPFNOSUPPORT, "Protocol family not supported");
778 #endif
779 #ifdef WSAEOPNOTSUPP
780 add_errcode("WSAEOPNOTSUPP", WSAEOPNOTSUPP, "Operation not supported on transport endpoint");
781 #endif
782 #ifdef WSAEISCONN
783 add_errcode("WSAEISCONN", WSAEISCONN, "Transport endpoint is already connected");
784 #endif
785 #ifdef WSAEDQUOT
786 add_errcode("WSAEDQUOT", WSAEDQUOT, "Quota exceeded");
787 #endif
788 #ifdef WSAENOTCONN
789 add_errcode("WSAENOTCONN", WSAENOTCONN, "Transport endpoint is not connected");
790 #endif
791 #ifdef WSAEREMOTE
792 add_errcode("WSAEREMOTE", WSAEREMOTE, "Object is remote");
793 #endif
794 #ifdef WSAEINVAL
795 add_errcode("WSAEINVAL", WSAEINVAL, "Invalid argument");
796 #endif
797 #ifdef WSAEINPROGRESS
798 add_errcode("WSAEINPROGRESS", WSAEINPROGRESS, "Operation now in progress");
799 #endif
800 #ifdef WSAGETSELECTEVEN
801 add_errcode("WSAGETSELECTEVEN", WSAGETSELECTEVEN, "Error WSAGETSELECTEVEN");
802 #endif
803 #ifdef WSAESOCKTNOSUPPORT
804 add_errcode("WSAESOCKTNOSUPPORT", WSAESOCKTNOSUPPORT, "Socket type not supported");
805 #endif
806 #ifdef WSAGETASYNCERRO
807 add_errcode("WSAGETASYNCERRO", WSAGETASYNCERRO, "Error WSAGETASYNCERRO");
808 #endif
809 #ifdef WSAMAKESELECTREPL
810 add_errcode("WSAMAKESELECTREPL", WSAMAKESELECTREPL, "Error WSAMAKESELECTREPL");
811 #endif
812 #ifdef WSAGETASYNCBUFLE
813 add_errcode("WSAGETASYNCBUFLE", WSAGETASYNCBUFLE, "Error WSAGETASYNCBUFLE");
814 #endif
815 #ifdef WSAEDESTADDRREQ
816 add_errcode("WSAEDESTADDRREQ", WSAEDESTADDRREQ, "Destination address required");
817 #endif
818 #ifdef WSAECONNREFUSED
819 add_errcode("WSAECONNREFUSED", WSAECONNREFUSED, "Connection refused");
820 #endif
821 #ifdef WSAENETRESET
822 add_errcode("WSAENETRESET", WSAENETRESET, "Network dropped connection because of reset");
823 #endif
824 #ifdef WSAN
825 add_errcode("WSAN", WSAN, "Error WSAN");
826 #endif
827 #ifdef ENOMEDIUM
828 add_errcode("ENOMEDIUM", ENOMEDIUM, "No medium found");
829 #endif
830 #ifdef EMEDIUMTYPE
831 add_errcode("EMEDIUMTYPE", EMEDIUMTYPE, "Wrong medium type");
832 #endif
833 #ifdef ECANCELED
834 add_errcode("ECANCELED", ECANCELED, "Operation Canceled");
835 #endif
836 #ifdef ENOKEY
837 add_errcode("ENOKEY", ENOKEY, "Required key not available");
838 #endif
839 #ifdef EKEYEXPIRED
840 add_errcode("EKEYEXPIRED", EKEYEXPIRED, "Key has expired");
841 #endif
842 #ifdef EKEYREVOKED
843 add_errcode("EKEYREVOKED", EKEYREVOKED, "Key has been revoked");
844 #endif
845 #ifdef EKEYREJECTED
846 add_errcode("EKEYREJECTED", EKEYREJECTED, "Key was rejected by service");
847 #endif
848 #ifdef EOWNERDEAD
849 add_errcode("EOWNERDEAD", EOWNERDEAD, "Owner died");
850 #endif
851 #ifdef ENOTRECOVERABLE
852 add_errcode("ENOTRECOVERABLE", ENOTRECOVERABLE, "State not recoverable");
853 #endif
854 #ifdef ERFKILL
855 add_errcode("ERFKILL", ERFKILL, "Operation not possible due to RF-kill");
856 #endif
857
858 /* Solaris-specific errnos */
859 #ifdef ECANCELED
860 add_errcode("ECANCELED", ECANCELED, "Operation canceled");
861 #endif
862 #ifdef ENOTSUP
863 add_errcode("ENOTSUP", ENOTSUP, "Operation not supported");
864 #endif
865 #ifdef EOWNERDEAD
866 add_errcode("EOWNERDEAD", EOWNERDEAD, "Process died with the lock");
867 #endif
868 #ifdef ENOTRECOVERABLE
869 add_errcode("ENOTRECOVERABLE", ENOTRECOVERABLE, "Lock is not recoverable");
870 #endif
871 #ifdef ELOCKUNMAPPED
872 add_errcode("ELOCKUNMAPPED", ELOCKUNMAPPED, "Locked lock was unmapped");
873 #endif
874 #ifdef ENOTACTIVE
875 add_errcode("ENOTACTIVE", ENOTACTIVE, "Facility is not active");
876 #endif
877
878 /* MacOSX specific errnos */
879 #ifdef EAUTH
880 add_errcode("EAUTH", EAUTH, "Authentication error");
881 #endif
882 #ifdef EBADARCH
883 add_errcode("EBADARCH", EBADARCH, "Bad CPU type in executable");
884 #endif
885 #ifdef EBADEXEC
886 add_errcode("EBADEXEC", EBADEXEC, "Bad executable (or shared library)");
887 #endif
888 #ifdef EBADMACHO
889 add_errcode("EBADMACHO", EBADMACHO, "Malformed Mach-o file");
890 #endif
891 #ifdef EBADRPC
892 add_errcode("EBADRPC", EBADRPC, "RPC struct is bad");
893 #endif
894 #ifdef EDEVERR
895 add_errcode("EDEVERR", EDEVERR, "Device error");
896 #endif
897 #ifdef EFTYPE
898 add_errcode("EFTYPE", EFTYPE, "Inappropriate file type or format");
899 #endif
900 #ifdef ENEEDAUTH
901 add_errcode("ENEEDAUTH", ENEEDAUTH, "Need authenticator");
902 #endif
903 #ifdef ENOATTR
904 add_errcode("ENOATTR", ENOATTR, "Attribute not found");
905 #endif
906 #ifdef ENOPOLICY
907 add_errcode("ENOPOLICY", ENOPOLICY, "Policy not found");
908 #endif
909 #ifdef EPROCLIM
910 add_errcode("EPROCLIM", EPROCLIM, "Too many processes");
911 #endif
912 #ifdef EPROCUNAVAIL
913 add_errcode("EPROCUNAVAIL", EPROCUNAVAIL, "Bad procedure for program");
914 #endif
915 #ifdef EPROGMISMATCH
916 add_errcode("EPROGMISMATCH", EPROGMISMATCH, "Program version wrong");
917 #endif
918 #ifdef EPROGUNAVAIL
919 add_errcode("EPROGUNAVAIL", EPROGUNAVAIL, "RPC prog. not avail");
920 #endif
921 #ifdef EPWROFF
922 add_errcode("EPWROFF", EPWROFF, "Device power is off");
923 #endif
924 #ifdef ERPCMISMATCH
925 add_errcode("ERPCMISMATCH", ERPCMISMATCH, "RPC version wrong");
926 #endif
927 #ifdef ESHLIBVERS
928 add_errcode("ESHLIBVERS", ESHLIBVERS, "Shared library version mismatch");
929 #endif
930 #ifdef EQFULL
931 add_errcode("EQFULL", EQFULL, "Interface output queue is full");
932 #endif
933 #ifdef ENOTCAPABLE
934 // WASI extension
935 add_errcode("ENOTCAPABLE", ENOTCAPABLE, "Capabilities insufficient");
936 #endif
937
938 Py_DECREF(error_dict);
939 return 0;
940 }
941
942 static PyModuleDef_Slot errno_slots[] = {
943 {Py_mod_exec, errno_exec},
944 {0, NULL}
945 };
946
947 PyDoc_STRVAR(errno__doc__,
948 "This module makes available standard errno system symbols.\n\
949 \n\
950 The value of each symbol is the corresponding integer value,\n\
951 e.g., on most systems, errno.ENOENT equals the integer 2.\n\
952 \n\
953 The dictionary errno.errorcode maps numeric codes to symbol names,\n\
954 e.g., errno.errorcode[2] could be the string 'ENOENT'.\n\
955 \n\
956 Symbols that are not relevant to the underlying system are not defined.\n\
957 \n\
958 To map error codes to error messages, use the function os.strerror(),\n\
959 e.g. os.strerror(2) could return 'No such file or directory'.");
960
961 static struct PyModuleDef errnomodule = {
962 PyModuleDef_HEAD_INIT,
963 .m_name = "errno",
964 .m_doc = errno__doc__,
965 .m_size = 0,
966 .m_methods = errno_methods,
967 .m_slots = errno_slots,
968 };
969
970 PyMODINIT_FUNC
971 PyInit_errno(void)
972 {
973 return PyModuleDef_Init(&errnomodule);
974 }