blob: a3a3fd0827d260eedc789725ac3c7284cf9098ad [file] [log] [blame]
Guido van Rossum4dc66221996-07-24 00:51:51 +00001/***********************************************************
2Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
3The Netherlands.
4
5 All Rights Reserved
6
7Permission to use, copy, modify, and distribute this software and its
8documentation for any purpose and without fee is hereby granted,
9provided that the above copyright notice appear in all copies and that
10both that copyright notice and this permission notice appear in
11supporting documentation, and that the names of Stichting Mathematisch
12Centrum or CWI not be used in advertising or publicity pertaining to
13distribution of the software without specific, written prior permission.
14
15STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
16THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
18FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
21OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22
23******************************************************************/
24
25/* Errno module */
26
27#include "Python.h"
28
29/*
30 * Pull in the system error definitions
31 */
32
33#include <errno.h>
34
35static PyMethodDef errno_methods[] = {
36 {NULL, NULL}
37};
38
39/*
40 * Convenience routine to export an integer value.
41 * For simplicity, errors (which are unlikely anyway) are ignored.
42 */
43
44static void
45insint(d, name, value)
46 PyObject * d;
47 char * name;
48 int value;
49{
50 PyObject *v = PyInt_FromLong((long) value);
51 if (v == NULL) {
52 /* Don't bother reporting this error */
53 PyErr_Clear();
54 }
55 else {
56 PyDict_SetItemString(d, name, v);
57 Py_DECREF(v);
58 }
59}
60
61void
62initerrno()
63{
64 PyObject *m, *d;
65 m = Py_InitModule("errno", errno_methods);
66 d = PyModule_GetDict(m);
67
68 /*
69 * The names and comments are borrowed from linux/include/errno.h,
70 * which should be pretty all-inclusive
71 */
72
73#ifdef EPERM
74 /* Operation not permitted */
75 insint(d, "EPERM", EPERM);
76#endif
77#ifdef ENOENT
78 /* No such file or directory */
79 insint(d, "ENOENT", ENOENT);
80#endif
81#ifdef ESRCH
82 /* No such process */
83 insint(d, "ESRCH", ESRCH);
84#endif
85#ifdef EINTR
86 /* Interrupted system call */
87 insint(d, "EINTR", EINTR);
88#endif
89#ifdef EIO
90 /* I/O error */
91 insint(d, "EIO", EIO);
92#endif
93#ifdef ENXIO
94 /* No such device or address */
95 insint(d, "ENXIO", ENXIO);
96#endif
97#ifdef E2BIG
98 /* Arg list too long */
99 insint(d, "E2BIG", E2BIG);
100#endif
101#ifdef ENOEXEC
102 /* Exec format error */
103 insint(d, "ENOEXEC", ENOEXEC);
104#endif
105#ifdef EBADF
106 /* Bad file number */
107 insint(d, "EBADF", EBADF);
108#endif
109#ifdef ECHILD
110 /* No child processes */
111 insint(d, "ECHILD", ECHILD);
112#endif
113#ifdef EAGAIN
114 /* Try again */
115 insint(d, "EAGAIN", EAGAIN);
116#endif
117#ifdef ENOMEM
118 /* Out of memory */
119 insint(d, "ENOMEM", ENOMEM);
120#endif
121#ifdef EACCES
122 /* Permission denied */
123 insint(d, "EACCES", EACCES);
124#endif
125#ifdef EFAULT
126 /* Bad address */
127 insint(d, "EFAULT", EFAULT);
128#endif
129#ifdef ENOTBLK
130 /* Block device required */
131 insint(d, "ENOTBLK", ENOTBLK);
132#endif
133#ifdef EBUSY
134 /* Device or resource busy */
135 insint(d, "EBUSY", EBUSY);
136#endif
137#ifdef EEXIST
138 /* File exists */
139 insint(d, "EEXIST", EEXIST);
140#endif
141#ifdef EXDEV
142 /* Cross-device link */
143 insint(d, "EXDEV", EXDEV);
144#endif
145#ifdef ENODEV
146 /* No such device */
147 insint(d, "ENODEV", ENODEV);
148#endif
149#ifdef ENOTDIR
150 /* Not a directory */
151 insint(d, "ENOTDIR", ENOTDIR);
152#endif
153#ifdef EISDIR
154 /* Is a directory */
155 insint(d, "EISDIR", EISDIR);
156#endif
157#ifdef EINVAL
158 /* Invalid argument */
159 insint(d, "EINVAL", EINVAL);
160#endif
161#ifdef ENFILE
162 /* File table overflow */
163 insint(d, "ENFILE", ENFILE);
164#endif
165#ifdef EMFILE
166 /* Too many open files */
167 insint(d, "EMFILE", EMFILE);
168#endif
169#ifdef ENOTTY
170 /* Not a typewriter */
171 insint(d, "ENOTTY", ENOTTY);
172#endif
173#ifdef ETXTBSY
174 /* Text file busy */
175 insint(d, "ETXTBSY", ETXTBSY);
176#endif
177#ifdef EFBIG
178 /* File too large */
179 insint(d, "EFBIG", EFBIG);
180#endif
181#ifdef ENOSPC
182 /* No space left on device */
183 insint(d, "ENOSPC", ENOSPC);
184#endif
185#ifdef ESPIPE
186 /* Illegal seek */
187 insint(d, "ESPIPE", ESPIPE);
188#endif
189#ifdef EROFS
190 /* Read-only file system */
191 insint(d, "EROFS", EROFS);
192#endif
193#ifdef EMLINK
194 /* Too many links */
195 insint(d, "EMLINK", EMLINK);
196#endif
197#ifdef EPIPE
198 /* Broken pipe */
199 insint(d, "EPIPE", EPIPE);
200#endif
201#ifdef EDOM
202 /* Math argument out of domain of func */
203 insint(d, "EDOM", EDOM);
204#endif
205#ifdef ERANGE
206 /* Math result not representable */
207 insint(d, "ERANGE", ERANGE);
208#endif
209#ifdef EDEADLK
210 /* Resource deadlock would occur */
211 insint(d, "EDEADLK", EDEADLK);
212#endif
213#ifdef ENAMETOOLONG
214 /* File name too long */
215 insint(d, "ENAMETOOLONG", ENAMETOOLONG);
216#endif
217#ifdef ENOLCK
218 /* No record locks available */
219 insint(d, "ENOLCK", ENOLCK);
220#endif
221#ifdef ENOSYS
222 /* Function not implemented */
223 insint(d, "ENOSYS", ENOSYS);
224#endif
225#ifdef ENOTEMPTY
226 /* Directory not empty */
227 insint(d, "ENOTEMPTY", ENOTEMPTY);
228#endif
229#ifdef ELOOP
230 /* Too many symbolic links encountered */
231 insint(d, "ELOOP", ELOOP);
232#endif
233#ifdef EWOULDBLOCK
234 /* Operation would block */
235 insint(d, "EWOULDBLOCK", EWOULDBLOCK);
236#endif
237#ifdef ENOMSG
238 /* No message of desired type */
239 insint(d, "ENOMSG", ENOMSG);
240#endif
241#ifdef EIDRM
242 /* Identifier removed */
243 insint(d, "EIDRM", EIDRM);
244#endif
245#ifdef ECHRNG
246 /* Channel number out of range */
247 insint(d, "ECHRNG", ECHRNG);
248#endif
249#ifdef EL2NSYNC
250 /* Level 2 not synchronized */
251 insint(d, "EL2NSYNC", EL2NSYNC);
252#endif
253#ifdef EL3HLT
254 /* Level 3 halted */
255 insint(d, "EL3HLT", EL3HLT);
256#endif
257#ifdef EL3RST
258 /* Level 3 reset */
259 insint(d, "EL3RST", EL3RST);
260#endif
261#ifdef ELNRNG
262 /* Link number out of range */
263 insint(d, "ELNRNG", ELNRNG);
264#endif
265#ifdef EUNATCH
266 /* Protocol driver not attached */
267 insint(d, "EUNATCH", EUNATCH);
268#endif
269#ifdef ENOCSI
270 /* No CSI structure available */
271 insint(d, "ENOCSI", ENOCSI);
272#endif
273#ifdef EL2HLT
274 /* Level 2 halted */
275 insint(d, "EL2HLT", EL2HLT);
276#endif
277#ifdef EBADE
278 /* Invalid exchange */
279 insint(d, "EBADE", EBADE);
280#endif
281#ifdef EBADR
282 /* Invalid request descriptor */
283 insint(d, "EBADR", EBADR);
284#endif
285#ifdef EXFULL
286 /* Exchange full */
287 insint(d, "EXFULL", EXFULL);
288#endif
289#ifdef ENOANO
290 /* No anode */
291 insint(d, "ENOANO", ENOANO);
292#endif
293#ifdef EBADRQC
294 /* Invalid request code */
295 insint(d, "EBADRQC", EBADRQC);
296#endif
297#ifdef EBADSLT
298 /* Invalid slot */
299 insint(d, "EBADSLT", EBADSLT);
300#endif
301#ifdef EDEADLOCK
302 /* File locking deadlock error */
303 insint(d, "EDEADLOCK", EDEADLOCK);
304#endif
305#ifdef EBFONT
306 /* Bad font file format */
307 insint(d, "EBFONT", EBFONT);
308#endif
309#ifdef ENOSTR
310 /* Device not a stream */
311 insint(d, "ENOSTR", ENOSTR);
312#endif
313#ifdef ENODATA
314 /* No data available */
315 insint(d, "ENODATA", ENODATA);
316#endif
317#ifdef ETIME
318 /* Timer expired */
319 insint(d, "ETIME", ETIME);
320#endif
321#ifdef ENOSR
322 /* Out of streams resources */
323 insint(d, "ENOSR", ENOSR);
324#endif
325#ifdef ENONET
326 /* Machine is not on the network */
327 insint(d, "ENONET", ENONET);
328#endif
329#ifdef ENOPKG
330 /* Package not installed */
331 insint(d, "ENOPKG", ENOPKG);
332#endif
333#ifdef EREMOTE
334 /* Object is remote */
335 insint(d, "EREMOTE", EREMOTE);
336#endif
337#ifdef ENOLINK
338 /* Link has been severed */
339 insint(d, "ENOLINK", ENOLINK);
340#endif
341#ifdef EADV
342 /* Advertise error */
343 insint(d, "EADV", EADV);
344#endif
345#ifdef ESRMNT
346 /* Srmount error */
347 insint(d, "ESRMNT", ESRMNT);
348#endif
349#ifdef ECOMM
350 /* Communication error on send */
351 insint(d, "ECOMM", ECOMM);
352#endif
353#ifdef EPROTO
354 /* Protocol error */
355 insint(d, "EPROTO", EPROTO);
356#endif
357#ifdef EMULTIHOP
358 /* Multihop attempted */
359 insint(d, "EMULTIHOP", EMULTIHOP);
360#endif
361#ifdef EDOTDOT
362 /* RFS specific error */
363 insint(d, "EDOTDOT", EDOTDOT);
364#endif
365#ifdef EBADMSG
366 /* Not a data message */
367 insint(d, "EBADMSG", EBADMSG);
368#endif
369#ifdef EOVERFLOW
370 /* Value too large for defined data type */
371 insint(d, "EOVERFLOW", EOVERFLOW);
372#endif
373#ifdef ENOTUNIQ
374 /* Name not unique on network */
375 insint(d, "ENOTUNIQ", ENOTUNIQ);
376#endif
377#ifdef EBADFD
378 /* File descriptor in bad state */
379 insint(d, "EBADFD", EBADFD);
380#endif
381#ifdef EREMCHG
382 /* Remote address changed */
383 insint(d, "EREMCHG", EREMCHG);
384#endif
385#ifdef ELIBACC
386 /* Can not access a needed shared library */
387 insint(d, "ELIBACC", ELIBACC);
388#endif
389#ifdef ELIBBAD
390 /* Accessing a corrupted shared library */
391 insint(d, "ELIBBAD", ELIBBAD);
392#endif
393#ifdef ELIBSCN
394 /* .lib section in a.out corrupted */
395 insint(d, "ELIBSCN", ELIBSCN);
396#endif
397#ifdef ELIBMAX
398 /* Attempting to link in too many shared libraries */
399 insint(d, "ELIBMAX", ELIBMAX);
400#endif
401#ifdef ELIBEXEC
402 /* Cannot exec a shared library directly */
403 insint(d, "ELIBEXEC", ELIBEXEC);
404#endif
405#ifdef EILSEQ
406 /* Illegal byte sequence */
407 insint(d, "EILSEQ", EILSEQ);
408#endif
409#ifdef ERESTART
410 /* Interrupted system call should be restarted */
411 insint(d, "ERESTART", ERESTART);
412#endif
413#ifdef ESTRPIPE
414 /* Streams pipe error */
415 insint(d, "ESTRPIPE", ESTRPIPE);
416#endif
417#ifdef EUSERS
418 /* Too many users */
419 insint(d, "EUSERS", EUSERS);
420#endif
421#ifdef ENOTSOCK
422 /* Socket operation on non-socket */
423 insint(d, "ENOTSOCK", ENOTSOCK);
424#endif
425#ifdef EDESTADDRREQ
426 /* Destination address required */
427 insint(d, "EDESTADDRREQ", EDESTADDRREQ);
428#endif
429#ifdef EMSGSIZE
430 /* Message too long */
431 insint(d, "EMSGSIZE", EMSGSIZE);
432#endif
433#ifdef EPROTOTYPE
434 /* Protocol wrong type for socket */
435 insint(d, "EPROTOTYPE", EPROTOTYPE);
436#endif
437#ifdef ENOPROTOOPT
438 /* Protocol not available */
439 insint(d, "ENOPROTOOPT", ENOPROTOOPT);
440#endif
441#ifdef EPROTONOSUPPORT
442 /* Protocol not supported */
443 insint(d, "EPROTONOSUPPORT", EPROTONOSUPPORT);
444#endif
445#ifdef ESOCKTNOSUPPORT
446 /* Socket type not supported */
447 insint(d, "ESOCKTNOSUPPORT", ESOCKTNOSUPPORT);
448#endif
449#ifdef EOPNOTSUPP
450 /* Operation not supported on transport endpoint */
451 insint(d, "EOPNOTSUPP", EOPNOTSUPP);
452#endif
453#ifdef EPFNOSUPPORT
454 /* Protocol family not supported */
455 insint(d, "EPFNOSUPPORT", EPFNOSUPPORT);
456#endif
457#ifdef EAFNOSUPPORT
458 /* Address family not supported by protocol */
459 insint(d, "EAFNOSUPPORT", EAFNOSUPPORT);
460#endif
461#ifdef EADDRINUSE
462 /* Address already in use */
463 insint(d, "EADDRINUSE", EADDRINUSE);
464#endif
465#ifdef EADDRNOTAVAIL
466 /* Cannot assign requested address */
467 insint(d, "EADDRNOTAVAIL", EADDRNOTAVAIL);
468#endif
469#ifdef ENETDOWN
470 /* Network is down */
471 insint(d, "ENETDOWN", ENETDOWN);
472#endif
473#ifdef ENETUNREACH
474 /* Network is unreachable */
475 insint(d, "ENETUNREACH", ENETUNREACH);
476#endif
477#ifdef ENETRESET
478 /* Network dropped connection because of reset */
479 insint(d, "ENETRESET", ENETRESET);
480#endif
481#ifdef ECONNABORTED
482 /* Software caused connection abort */
483 insint(d, "ECONNABORTED", ECONNABORTED);
484#endif
485#ifdef ECONNRESET
486 /* Connection reset by peer */
487 insint(d, "ECONNRESET", ECONNRESET);
488#endif
489#ifdef ENOBUFS
490 /* No buffer space available */
491 insint(d, "ENOBUFS", ENOBUFS);
492#endif
493#ifdef EISCONN
494 /* Transport endpoint is already connected */
495 insint(d, "EISCONN", EISCONN);
496#endif
497#ifdef ENOTCONN
498 /* Transport endpoint is not connected */
499 insint(d, "ENOTCONN", ENOTCONN);
500#endif
501#ifdef ESHUTDOWN
502 /* Cannot send after transport endpoint shutdown */
503 insint(d, "ESHUTDOWN", ESHUTDOWN);
504#endif
505#ifdef ETOOMANYREFS
506 /* Too many references: cannot splice */
507 insint(d, "ETOOMANYREFS", ETOOMANYREFS);
508#endif
509#ifdef ETIMEDOUT
510 /* Connection timed out */
511 insint(d, "ETIMEDOUT", ETIMEDOUT);
512#endif
513#ifdef ECONNREFUSED
514 /* Connection refused */
515 insint(d, "ECONNREFUSED", ECONNREFUSED);
516#endif
517#ifdef EHOSTDOWN
518 /* Host is down */
519 insint(d, "EHOSTDOWN", EHOSTDOWN);
520#endif
521#ifdef EHOSTUNREACH
522 /* No route to host */
523 insint(d, "EHOSTUNREACH", EHOSTUNREACH);
524#endif
525#ifdef EALREADY
526 /* Operation already in progress */
527 insint(d, "EALREADY", EALREADY);
528#endif
529#ifdef EINPROGRESS
530 /* Operation now in progress */
531 insint(d, "EINPROGRESS", EINPROGRESS);
532#endif
533#ifdef ESTALE
534 /* Stale NFS file handle */
535 insint(d, "ESTALE", ESTALE);
536#endif
537#ifdef EUCLEAN
538 /* Structure needs cleaning */
539 insint(d, "EUCLEAN", EUCLEAN);
540#endif
541#ifdef ENOTNAM
542 /* Not a XENIX named type file */
543 insint(d, "ENOTNAM", ENOTNAM);
544#endif
545#ifdef ENAVAIL
546 /* No XENIX semaphores available */
547 insint(d, "ENAVAIL", ENAVAIL);
548#endif
549#ifdef EISNAM
550 /* Is a named type file */
551 insint(d, "EISNAM", EISNAM);
552#endif
553#ifdef EREMOTEIO
554 /* Remote I/O error */
555 insint(d, "EREMOTEIO", EREMOTEIO);
556#endif
557#ifdef EDQUOT
558 /* Quota exceeded */
559 insint(d, "EDQUOT", EDQUOT);
560#endif
561}