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