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