errnomodule.c 28 KB

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