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