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