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