Coverage Report

Created: 2025-11-24 06:11

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