errnomodule.c 28.1 KB
Newer Older
1 2 3 4 5

/* Errno module */

#include "Python.h"

6
/* Windows socket errors (WSA*)  */
7
#ifdef MS_WINDOWS
8
#define WIN32_LEAN_AND_MEAN
9
#include <windows.h>
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
/* The following constants were added to errno.h in VS2010 but have
   preferred WSA equivalents. */
#undef EADDRINUSE
#undef EADDRNOTAVAIL
#undef EAFNOSUPPORT
#undef EALREADY
#undef ECONNABORTED
#undef ECONNREFUSED
#undef ECONNRESET
#undef EDESTADDRREQ
#undef EHOSTUNREACH
#undef EINPROGRESS
#undef EISCONN
#undef ELOOP
#undef EMSGSIZE
#undef ENETDOWN
#undef ENETRESET
#undef ENETUNREACH
#undef ENOBUFS
#undef ENOPROTOOPT
#undef ENOTCONN
#undef ENOTSOCK
#undef EOPNOTSUPP
#undef EPROTONOSUPPORT
#undef EPROTOTYPE
#undef ETIMEDOUT
#undef EWOULDBLOCK
37 38
#endif

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
50
_inscode(PyObject *d, PyObject *de, const char *name, int code)
51
{
52 53
    PyObject *u = PyUnicode_FromString(name);
    PyObject *v = PyLong_FromLong((long) code);
54

55 56 57 58 59 60 61 62 63 64 65 66
    /* Don't bother checking for errors; they'll be caught at the end
     * of the module initialization function by the caller of
     * initerrno().
     */
    if (u && v) {
        /* insert in modules dict */
        PyDict_SetItem(d, u, v);
        /* insert in errorcode dict */
        PyDict_SetItem(de, v, u);
    }
    Py_XDECREF(u);
    Py_XDECREF(v);
67 68
}

69
PyDoc_STRVAR(errno__doc__,
70 71 72 73 74 75 76 77 78 79 80
"This module makes available standard errno system symbols.\n\
\n\
The value of each symbol is the corresponding integer value,\n\
e.g., on most systems, errno.ENOENT equals the integer 2.\n\
\n\
The dictionary errno.errorcode maps numeric codes to symbol names,\n\
e.g., errno.errorcode[2] could be the string 'ENOENT'.\n\
\n\
Symbols that are not relevant to the underlying system are not defined.\n\
\n\
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 85 86 87 88 89 90 91 92
    PyModuleDef_HEAD_INIT,
    "errno",
    errno__doc__,
    -1,
    errno_methods,
    NULL,
    NULL,
    NULL,
    NULL
93 94
};

95
PyMODINIT_FUNC
96
PyInit_errno(void)
97
{
98 99 100 101 102 103 104 105
    PyObject *m, *d, *de;
    m = PyModule_Create(&errnomodule);
    if (m == NULL)
        return NULL;
    d = PyModule_GetDict(m);
    de = PyDict_New();
    if (!d || !de || PyDict_SetItemString(d, "errorcode", de) < 0)
        return NULL;
106

107 108 109
/* Macro so I don't have to edit each and every line below... */
#define inscode(d, ds, de, name, code, comment) _inscode(d, de, name, code)

110 111
    /*
     * The names and comments are borrowed from linux/include/errno.h,
112 113
     * which should be pretty all-inclusive.  However, the Solaris specific
     * names and comments are borrowed from sys/errno.h in Solaris.
114 115
     * MacOSX specific names and comments are borrowed from sys/errno.h in
     * 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 127
#else
#ifdef WSAEHOSTUNREACH
128
    inscode(d, ds, de, "EHOSTUNREACH", WSAEHOSTUNREACH, "No route to host");
129 130 131
#endif
#endif
#ifdef ENOMSG
132
    inscode(d, ds, de, "ENOMSG", ENOMSG, "No message of desired type");
133 134
#endif
#ifdef EUCLEAN
135
    inscode(d, ds, de, "EUCLEAN", EUCLEAN, "Structure needs cleaning");
136 137
#endif
#ifdef EL2NSYNC
138
    inscode(d, ds, de, "EL2NSYNC", EL2NSYNC, "Level 2 not synchronized");
139 140
#endif
#ifdef EL2HLT
141
    inscode(d, ds, de, "EL2HLT", EL2HLT, "Level 2 halted");
142 143
#endif
#ifdef ENODATA
144
    inscode(d, ds, de, "ENODATA", ENODATA, "No data available");
145 146
#endif
#ifdef ENOTBLK
147
    inscode(d, ds, de, "ENOTBLK", ENOTBLK, "Block device required");
148 149
#endif
#ifdef ENOSYS
150
    inscode(d, ds, de, "ENOSYS", ENOSYS, "Function not implemented");
151 152
#endif
#ifdef EPIPE
153
    inscode(d, ds, de, "EPIPE", EPIPE, "Broken pipe");
154 155
#endif
#ifdef EINVAL
156
    inscode(d, ds, de, "EINVAL", EINVAL, "Invalid argument");
157 158
#else
#ifdef WSAEINVAL
159
    inscode(d, ds, de, "EINVAL", WSAEINVAL, "Invalid argument");
160 161 162
#endif
#endif
#ifdef EOVERFLOW
163
    inscode(d, ds, de, "EOVERFLOW", EOVERFLOW, "Value too large for defined data type");
164 165
#endif
#ifdef EADV
166
    inscode(d, ds, de, "EADV", EADV, "Advertise error");
167 168
#endif
#ifdef EINTR
169
    inscode(d, ds, de, "EINTR", EINTR, "Interrupted system call");
170 171
#else
#ifdef WSAEINTR
172
    inscode(d, ds, de, "EINTR", WSAEINTR, "Interrupted system call");
173 174
#endif
#endif
175
#ifdef EUSERS
176
    inscode(d, ds, de, "EUSERS", EUSERS, "Too many users");
177 178
#else
#ifdef WSAEUSERS
179
    inscode(d, ds, de, "EUSERS", WSAEUSERS, "Too many users");
180 181
#endif
#endif
182
#ifdef ENOTEMPTY
183
    inscode(d, ds, de, "ENOTEMPTY", ENOTEMPTY, "Directory not empty");
184 185
#else
#ifdef WSAENOTEMPTY
186
    inscode(d, ds, de, "ENOTEMPTY", WSAENOTEMPTY, "Directory not empty");
187 188 189
#endif
#endif
#ifdef ENOBUFS
190
    inscode(d, ds, de, "ENOBUFS", ENOBUFS, "No buffer space available");
191 192
#else
#ifdef WSAENOBUFS
193
    inscode(d, ds, de, "ENOBUFS", WSAENOBUFS, "No buffer space available");
194
#endif
195 196
#endif
#ifdef EPROTO
197
    inscode(d, ds, de, "EPROTO", EPROTO, "Protocol error");
198 199
#endif
#ifdef EREMOTE
200
    inscode(d, ds, de, "EREMOTE", EREMOTE, "Object is remote");
201 202
#else
#ifdef WSAEREMOTE
203
    inscode(d, ds, de, "EREMOTE", WSAEREMOTE, "Object is remote");
204 205 206
#endif
#endif
#ifdef ENAVAIL
207
    inscode(d, ds, de, "ENAVAIL", ENAVAIL, "No XENIX semaphores available");
208 209
#endif
#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 215
#else
#ifdef WSAELOOP
216
    inscode(d, ds, de, "ELOOP", WSAELOOP, "Too many symbolic links encountered");
217 218
#endif
#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 225
#endif
#ifdef ESRCH
226
    inscode(d, ds, de, "ESRCH", ESRCH, "No such process");
227 228
#endif
#ifdef EMSGSIZE
229
    inscode(d, ds, de, "EMSGSIZE", EMSGSIZE, "Message too long");
230 231
#else
#ifdef WSAEMSGSIZE
232
    inscode(d, ds, de, "EMSGSIZE", WSAEMSGSIZE, "Message too long");
233 234 235
#endif
#endif
#ifdef EAFNOSUPPORT
236
    inscode(d, ds, de, "EAFNOSUPPORT", EAFNOSUPPORT, "Address family not supported by protocol");
237 238
#else
#ifdef WSAEAFNOSUPPORT
239
    inscode(d, ds, de, "EAFNOSUPPORT", WSAEAFNOSUPPORT, "Address family not supported by protocol");
240 241 242
#endif
#endif
#ifdef EBADR
243
    inscode(d, ds, de, "EBADR", EBADR, "Invalid request descriptor");
244 245
#endif
#ifdef EHOSTDOWN
246
    inscode(d, ds, de, "EHOSTDOWN", EHOSTDOWN, "Host is down");
247 248
#else
#ifdef WSAEHOSTDOWN
249
    inscode(d, ds, de, "EHOSTDOWN", WSAEHOSTDOWN, "Host is down");
250 251 252
#endif
#endif
#ifdef EPFNOSUPPORT
253
    inscode(d, ds, de, "EPFNOSUPPORT", EPFNOSUPPORT, "Protocol family not supported");
254 255
#else
#ifdef WSAEPFNOSUPPORT
256
    inscode(d, ds, de, "EPFNOSUPPORT", WSAEPFNOSUPPORT, "Protocol family not supported");
257 258 259
#endif
#endif
#ifdef ENOPROTOOPT
260
    inscode(d, ds, de, "ENOPROTOOPT", ENOPROTOOPT, "Protocol not available");
261 262
#else
#ifdef WSAENOPROTOOPT
263
    inscode(d, ds, de, "ENOPROTOOPT", WSAENOPROTOOPT, "Protocol not available");
264 265 266
#endif
#endif
#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 272
#else
#ifdef WSAEWOULDBLOCK
273
    inscode(d, ds, de, "EWOULDBLOCK", WSAEWOULDBLOCK, "Operation would block");
274 275
#endif
#endif
276
#ifdef EBADFD
277
    inscode(d, ds, de, "EBADFD", EBADFD, "File descriptor in bad state");
278 279
#endif
#ifdef EDOTDOT
280
    inscode(d, ds, de, "EDOTDOT", EDOTDOT, "RFS specific error");
281 282
#endif
#ifdef EISCONN
283
    inscode(d, ds, de, "EISCONN", EISCONN, "Transport endpoint is already connected");
284 285
#else
#ifdef WSAEISCONN
286
    inscode(d, ds, de, "EISCONN", WSAEISCONN, "Transport endpoint is already connected");
287 288 289
#endif
#endif
#ifdef ENOANO
290
    inscode(d, ds, de, "ENOANO", ENOANO, "No anode");
291 292
#endif
#ifdef ESHUTDOWN
293
    inscode(d, ds, de, "ESHUTDOWN", ESHUTDOWN, "Cannot send after transport endpoint shutdown");
294 295
#else
#ifdef WSAESHUTDOWN
296
    inscode(d, ds, de, "ESHUTDOWN", WSAESHUTDOWN, "Cannot send after transport endpoint shutdown");
297 298 299
#endif
#endif
#ifdef ECHRNG
300
    inscode(d, ds, de, "ECHRNG", ECHRNG, "Channel number out of range");
301 302
#endif
#ifdef ELIBBAD
303
    inscode(d, ds, de, "ELIBBAD", ELIBBAD, "Accessing a corrupted shared library");
304 305
#endif
#ifdef ENONET
306
    inscode(d, ds, de, "ENONET", ENONET, "Machine is not on the network");
307 308
#endif
#ifdef EBADE
309
    inscode(d, ds, de, "EBADE", EBADE, "Invalid exchange");
310 311
#endif
#ifdef EBADF
312
    inscode(d, ds, de, "EBADF", EBADF, "Bad file number");
313 314
#else
#ifdef WSAEBADF
315
    inscode(d, ds, de, "EBADF", WSAEBADF, "Bad file number");
316 317 318
#endif
#endif
#ifdef EMULTIHOP
319
    inscode(d, ds, de, "EMULTIHOP", EMULTIHOP, "Multihop attempted");
320 321
#endif
#ifdef EIO
322
    inscode(d, ds, de, "EIO", EIO, "I/O error");
323 324
#endif
#ifdef EUNATCH
325
    inscode(d, ds, de, "EUNATCH", EUNATCH, "Protocol driver not attached");
326 327
#endif
#ifdef EPROTOTYPE
328
    inscode(d, ds, de, "EPROTOTYPE", EPROTOTYPE, "Protocol wrong type for socket");
329 330
#else
#ifdef WSAEPROTOTYPE
331
    inscode(d, ds, de, "EPROTOTYPE", WSAEPROTOTYPE, "Protocol wrong type for socket");
332 333 334
#endif
#endif
#ifdef ENOSPC
335
    inscode(d, ds, de, "ENOSPC", ENOSPC, "No space left on device");
336 337
#endif
#ifdef ENOEXEC
338
    inscode(d, ds, de, "ENOEXEC", ENOEXEC, "Exec format error");
339 340
#endif
#ifdef EALREADY
341
    inscode(d, ds, de, "EALREADY", EALREADY, "Operation already in progress");
342 343
#else
#ifdef WSAEALREADY
344
    inscode(d, ds, de, "EALREADY", WSAEALREADY, "Operation already in progress");
345 346 347
#endif
#endif
#ifdef ENETDOWN
348
    inscode(d, ds, de, "ENETDOWN", ENETDOWN, "Network is down");
349 350
#else
#ifdef WSAENETDOWN
351
    inscode(d, ds, de, "ENETDOWN", WSAENETDOWN, "Network is down");
352 353 354
#endif
#endif
#ifdef ENOTNAM
355
    inscode(d, ds, de, "ENOTNAM", ENOTNAM, "Not a XENIX named type file");
356 357
#endif
#ifdef EACCES
358
    inscode(d, ds, de, "EACCES", EACCES, "Permission denied");
359 360
#else
#ifdef WSAEACCES
361
    inscode(d, ds, de, "EACCES", WSAEACCES, "Permission denied");
362 363 364
#endif
#endif
#ifdef ELNRNG
365
    inscode(d, ds, de, "ELNRNG", ELNRNG, "Link number out of range");
366 367
#endif
#ifdef EILSEQ
368
    inscode(d, ds, de, "EILSEQ", EILSEQ, "Illegal byte sequence");
369 370
#endif
#ifdef ENOTDIR
371
    inscode(d, ds, de, "ENOTDIR", ENOTDIR, "Not a directory");
372 373
#endif
#ifdef ENOTUNIQ
374
    inscode(d, ds, de, "ENOTUNIQ", ENOTUNIQ, "Name not unique on network");
375 376
#endif
#ifdef EPERM
377
    inscode(d, ds, de, "EPERM", EPERM, "Operation not permitted");
378 379
#endif
#ifdef EDOM
380
    inscode(d, ds, de, "EDOM", EDOM, "Math argument out of domain of func");
381 382
#endif
#ifdef EXFULL
383
    inscode(d, ds, de, "EXFULL", EXFULL, "Exchange full");
384 385
#endif
#ifdef ECONNREFUSED
386
    inscode(d, ds, de, "ECONNREFUSED", ECONNREFUSED, "Connection refused");
387 388
#else
#ifdef WSAECONNREFUSED
389
    inscode(d, ds, de, "ECONNREFUSED", WSAECONNREFUSED, "Connection refused");
390
#endif
391 392
#endif
#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 398
#else
#ifdef WSAEPROTONOSUPPORT
399
    inscode(d, ds, de, "EPROTONOSUPPORT", WSAEPROTONOSUPPORT, "Protocol not supported");
400 401
#endif
#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 408
#else
#ifdef WSAEADDRNOTAVAIL
409
    inscode(d, ds, de, "EADDRNOTAVAIL", WSAEADDRNOTAVAIL, "Cannot assign requested address");
410 411
#endif
#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 418
#endif
#ifdef ESRMNT
419
    inscode(d, ds, de, "ESRMNT", ESRMNT, "Srmount error");
420 421
#endif
#ifdef EREMOTEIO
422
    inscode(d, ds, de, "EREMOTEIO", EREMOTEIO, "Remote I/O error");
423 424
#endif
#ifdef EL3RST
425
    inscode(d, ds, de, "EL3RST", EL3RST, "Level 3 reset");
426 427
#endif
#ifdef EBADMSG
428
    inscode(d, ds, de, "EBADMSG", EBADMSG, "Not a data message");
429 430
#endif
#ifdef ENFILE
431
    inscode(d, ds, de, "ENFILE", ENFILE, "File table overflow");
432 433
#endif
#ifdef ELIBMAX
434
    inscode(d, ds, de, "ELIBMAX", ELIBMAX, "Attempting to link in too many shared libraries");
435 436
#endif
#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 445
#else
#ifdef WSAENETRESET
446
    inscode(d, ds, de, "ENETRESET", WSAENETRESET, "Network dropped connection because of reset");
447 448
#endif
#endif
449
#ifdef ETIMEDOUT
450
    inscode(d, ds, de, "ETIMEDOUT", ETIMEDOUT, "Connection timed out");
451 452
#else
#ifdef WSAETIMEDOUT
453
    inscode(d, ds, de, "ETIMEDOUT", WSAETIMEDOUT, "Connection timed out");
454
#endif
455 456
#endif
#ifdef ENOENT
457
    inscode(d, ds, de, "ENOENT", ENOENT, "No such file or directory");
458 459
#endif
#ifdef EEXIST
460
    inscode(d, ds, de, "EEXIST", EEXIST, "File exists");
461 462
#endif
#ifdef EDQUOT
463
    inscode(d, ds, de, "EDQUOT", EDQUOT, "Quota exceeded");
464 465
#else
#ifdef WSAEDQUOT
466
    inscode(d, ds, de, "EDQUOT", WSAEDQUOT, "Quota exceeded");
467 468 469
#endif
#endif
#ifdef ENOSTR
470
    inscode(d, ds, de, "ENOSTR", ENOSTR, "Device not a stream");
471 472
#endif
#ifdef EBADSLT
473
    inscode(d, ds, de, "EBADSLT", EBADSLT, "Invalid slot");
474 475
#endif
#ifdef EBADRQC
476
    inscode(d, ds, de, "EBADRQC", EBADRQC, "Invalid request code");
477 478
#endif
#ifdef ELIBACC
479
    inscode(d, ds, de, "ELIBACC", ELIBACC, "Can not access a needed shared library");
480 481
#endif
#ifdef EFAULT
482
    inscode(d, ds, de, "EFAULT", EFAULT, "Bad address");
483 484
#else
#ifdef WSAEFAULT
485
    inscode(d, ds, de, "EFAULT", WSAEFAULT, "Bad address");
486 487 488
#endif
#endif
#ifdef EFBIG
489
    inscode(d, ds, de, "EFBIG", EFBIG, "File too large");
490 491
#endif
#ifdef EDEADLK
492
    inscode(d, ds, de, "EDEADLK", EDEADLK, "Resource deadlock would occur");
493 494
#endif
#ifdef ENOTCONN
495
    inscode(d, ds, de, "ENOTCONN", ENOTCONN, "Transport endpoint is not connected");
496 497
#else
#ifdef WSAENOTCONN
498
    inscode(d, ds, de, "ENOTCONN", WSAENOTCONN, "Transport endpoint is not connected");
499 500 501
#endif
#endif
#ifdef EDESTADDRREQ
502
    inscode(d, ds, de, "EDESTADDRREQ", EDESTADDRREQ, "Destination address required");
503 504
#else
#ifdef WSAEDESTADDRREQ
505
    inscode(d, ds, de, "EDESTADDRREQ", WSAEDESTADDRREQ, "Destination address required");
506
#endif
507 508
#endif
#ifdef ELIBSCN
509
    inscode(d, ds, de, "ELIBSCN", ELIBSCN, ".lib section in a.out corrupted");
510 511
#endif
#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 520
#else
#ifdef WSAECONNABORTED
521
    inscode(d, ds, de, "ECONNABORTED", WSAECONNABORTED, "Software caused connection abort");
522 523
#endif
#endif
524
#ifdef ENETUNREACH
525
    inscode(d, ds, de, "ENETUNREACH", ENETUNREACH, "Network is unreachable");
526 527
#else
#ifdef WSAENETUNREACH
528
    inscode(d, ds, de, "ENETUNREACH", WSAENETUNREACH, "Network is unreachable");
529 530
#endif
#endif
531
#ifdef ESTALE
532
    inscode(d, ds, de, "ESTALE", ESTALE, "Stale NFS file handle");
533 534
#else
#ifdef WSAESTALE
535
    inscode(d, ds, de, "ESTALE", WSAESTALE, "Stale NFS file handle");
536 537
#endif
#endif
538
#ifdef ENOSR
539
    inscode(d, ds, de, "ENOSR", ENOSR, "Out of streams resources");
540 541
#endif
#ifdef ENOMEM
542
    inscode(d, ds, de, "ENOMEM", ENOMEM, "Out of memory");
543 544
#endif
#ifdef ENOTSOCK
545
    inscode(d, ds, de, "ENOTSOCK", ENOTSOCK, "Socket operation on non-socket");
546 547
#else
#ifdef WSAENOTSOCK
548
    inscode(d, ds, de, "ENOTSOCK", WSAENOTSOCK, "Socket operation on non-socket");
549 550 551
#endif
#endif
#ifdef ESTRPIPE
552
    inscode(d, ds, de, "ESTRPIPE", ESTRPIPE, "Streams pipe error");
553 554
#endif
#ifdef EMLINK
555
    inscode(d, ds, de, "EMLINK", EMLINK, "Too many links");
556 557
#endif
#ifdef ERANGE
558
    inscode(d, ds, de, "ERANGE", ERANGE, "Math result not representable");
559 560
#endif
#ifdef ELIBEXEC
561
    inscode(d, ds, de, "ELIBEXEC", ELIBEXEC, "Cannot exec a shared library directly");
562 563
#endif
#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 569
#else
#ifdef WSAECONNRESET
570
    inscode(d, ds, de, "ECONNRESET", WSAECONNRESET, "Connection reset by peer");
571 572
#endif
#endif
573
#ifdef EADDRINUSE
574
    inscode(d, ds, de, "EADDRINUSE", EADDRINUSE, "Address already in use");
575 576
#else
#ifdef WSAEADDRINUSE
577
    inscode(d, ds, de, "EADDRINUSE", WSAEADDRINUSE, "Address already in use");
578 579
#endif
#endif
580
#ifdef EOPNOTSUPP
581
    inscode(d, ds, de, "EOPNOTSUPP", EOPNOTSUPP, "Operation not supported on transport endpoint");
582 583
#else
#ifdef WSAEOPNOTSUPP
584
    inscode(d, ds, de, "EOPNOTSUPP", WSAEOPNOTSUPP, "Operation not supported on transport endpoint");
585 586
#endif
#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 596
#else
#ifdef WSAENAMETOOLONG
597
    inscode(d, ds, de, "ENAMETOOLONG", WSAENAMETOOLONG, "File name too long");
598 599
#endif
#endif
600
#ifdef ENOTTY
601
    inscode(d, ds, de, "ENOTTY", ENOTTY, "Not a typewriter");
602 603
#endif
#ifdef ERESTART
604
    inscode(d, ds, de, "ERESTART", ERESTART, "Interrupted system call should be restarted");
605 606
#endif
#ifdef ESOCKTNOSUPPORT
607
    inscode(d, ds, de, "ESOCKTNOSUPPORT", ESOCKTNOSUPPORT, "Socket type not supported");
608 609
#else
#ifdef WSAESOCKTNOSUPPORT
610
    inscode(d, ds, de, "ESOCKTNOSUPPORT", WSAESOCKTNOSUPPORT, "Socket type not supported");
611
#endif
612 613
#endif
#ifdef ETIME
614
    inscode(d, ds, de, "ETIME", ETIME, "Timer expired");
615 616
#endif
#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 625
#else
#ifdef WSAETOOMANYREFS
626
    inscode(d, ds, de, "ETOOMANYREFS", WSAETOOMANYREFS, "Too many references: cannot splice");
627 628
#endif
#endif
629
#ifdef EMFILE
630
    inscode(d, ds, de, "EMFILE", EMFILE, "Too many open files");
631 632
#else
#ifdef WSAEMFILE
633
    inscode(d, ds, de, "EMFILE", WSAEMFILE, "Too many open files");
634
#endif
635 636
#endif
#ifdef ETXTBSY
637
    inscode(d, ds, de, "ETXTBSY", ETXTBSY, "Text file busy");
638 639
#endif
#ifdef EINPROGRESS
640
    inscode(d, ds, de, "EINPROGRESS", EINPROGRESS, "Operation now in progress");
641 642
#else
#ifdef WSAEINPROGRESS
643
    inscode(d, ds, de, "EINPROGRESS", WSAEINPROGRESS, "Operation now in progress");
644 645 646
#endif
#endif
#ifdef ENXIO
647
    inscode(d, ds, de, "ENXIO", ENXIO, "No such device or address");
648 649
#endif
#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 823
#endif
#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 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858
#ifdef ENOMEDIUM
    inscode(d, ds, de, "ENOMEDIUM", ENOMEDIUM, "No medium found");
#endif
#ifdef EMEDIUMTYPE
    inscode(d, ds, de, "EMEDIUMTYPE", EMEDIUMTYPE, "Wrong medium type");
#endif
#ifdef ECANCELED
    inscode(d, ds, de, "ECANCELED", ECANCELED, "Operation Canceled");
#endif
#ifdef ENOKEY
    inscode(d, ds, de, "ENOKEY", ENOKEY, "Required key not available");
#endif
#ifdef EKEYEXPIRED
    inscode(d, ds, de, "EKEYEXPIRED", EKEYEXPIRED, "Key has expired");
#endif
#ifdef EKEYREVOKED
    inscode(d, ds, de, "EKEYREVOKED", EKEYREVOKED, "Key has been revoked");
#endif
#ifdef EKEYREJECTED
    inscode(d, ds, de, "EKEYREJECTED", EKEYREJECTED, "Key was rejected by service");
#endif
#ifdef EOWNERDEAD
    inscode(d, ds, de, "EOWNERDEAD", EOWNERDEAD, "Owner died");
#endif
#ifdef ENOTRECOVERABLE
    inscode(d, ds, de, "ENOTRECOVERABLE", ENOTRECOVERABLE, "State not recoverable");
#endif
#ifdef ERFKILL
    inscode(d, ds, de, "ERFKILL", ERFKILL, "Operation not possible due to RF-kill");
#endif
859

860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879
    /* Solaris-specific errnos */
#ifdef ECANCELED
    inscode(d, ds, de, "ECANCELED", ECANCELED, "Operation canceled");
#endif
#ifdef ENOTSUP
    inscode(d, ds, de, "ENOTSUP", ENOTSUP, "Operation not supported");
#endif
#ifdef EOWNERDEAD
    inscode(d, ds, de, "EOWNERDEAD", EOWNERDEAD, "Process died with the lock");
#endif
#ifdef ENOTRECOVERABLE
    inscode(d, ds, de, "ENOTRECOVERABLE", ENOTRECOVERABLE, "Lock is not recoverable");
#endif
#ifdef ELOCKUNMAPPED
    inscode(d, ds, de, "ELOCKUNMAPPED", ELOCKUNMAPPED, "Locked lock was unmapped");
#endif
#ifdef ENOTACTIVE
    inscode(d, ds, de, "ENOTACTIVE", ENOTACTIVE, "Facility is not active");
#endif

880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932
    /* MacOSX specific errnos */
#ifdef EAUTH
    inscode(d, ds, de, "EAUTH", EAUTH, "Authentication error");
#endif
#ifdef EBADARCH
    inscode(d, ds, de, "EBADARCH", EBADARCH, "Bad CPU type in executable");
#endif
#ifdef EBADEXEC
    inscode(d, ds, de, "EBADEXEC", EBADEXEC, "Bad executable (or shared library)");
#endif
#ifdef EBADMACHO
    inscode(d, ds, de, "EBADMACHO", EBADMACHO, "Malformed Mach-o file");
#endif
#ifdef EBADRPC
    inscode(d, ds, de, "EBADRPC", EBADRPC, "RPC struct is bad");
#endif
#ifdef EDEVERR
    inscode(d, ds, de, "EDEVERR", EDEVERR, "Device error");
#endif
#ifdef EFTYPE
    inscode(d, ds, de, "EFTYPE", EFTYPE, "Inappropriate file type or format");
#endif
#ifdef ENEEDAUTH
    inscode(d, ds, de, "ENEEDAUTH", ENEEDAUTH, "Need authenticator");
#endif
#ifdef ENOATTR
    inscode(d, ds, de, "ENOATTR", ENOATTR, "Attribute not found");
#endif
#ifdef ENOPOLICY
    inscode(d, ds, de, "ENOPOLICY", ENOPOLICY, "Policy not found");
#endif
#ifdef EPROCLIM
    inscode(d, ds, de, "EPROCLIM", EPROCLIM, "Too many processes");
#endif
#ifdef EPROCUNAVAIL
    inscode(d, ds, de, "EPROCUNAVAIL", EPROCUNAVAIL, "Bad procedure for program");
#endif
#ifdef EPROGMISMATCH
    inscode(d, ds, de, "EPROGMISMATCH", EPROGMISMATCH, "Program version wrong");
#endif
#ifdef EPROGUNAVAIL
    inscode(d, ds, de, "EPROGUNAVAIL", EPROGUNAVAIL, "RPC prog. not avail");
#endif
#ifdef EPWROFF
    inscode(d, ds, de, "EPWROFF", EPWROFF, "Device power is off");
#endif
#ifdef ERPCMISMATCH
    inscode(d, ds, de, "ERPCMISMATCH", ERPCMISMATCH, "RPC version wrong");
#endif
#ifdef ESHLIBVERS
    inscode(d, ds, de, "ESHLIBVERS", ESHLIBVERS, "Shared library version mismatch");
#endif

933 934
    Py_DECREF(de);
    return m;
935
}