xref: /freebsd/contrib/lib9p/pytest/lerrno.py (revision e0c4386e)
1#! /usr/bin/env python
2
3"""
4Error number definitions for Linux.
5"""
6
7EPERM =                 1
8ENOENT =                2
9ESRCH =                 3
10EINTR =                 4
11EIO =                   5
12ENXIO =                 6
13E2BIG =                 7
14ENOEXEC =               8
15EBADF =                 9
16ECHILD =                10
17EAGAIN =                11
18ENOMEM =                12
19EACCES =                13
20EFAULT =                14
21ENOTBLK =               15
22EBUSY =                 16
23EEXIST =                17
24EXDEV =                 18
25ENODEV =                19
26ENOTDIR =               20
27EISDIR =                21
28EINVAL =                22
29ENFILE =                23
30EMFILE =                24
31ENOTTY =                25
32ETXTBSY =               26
33EFBIG =                 27
34ENOSPC =                28
35ESPIPE =                29
36EROFS =                 30
37EMLINK =                31
38EPIPE =                 32
39EDOM =                  33
40ERANGE =                34
41EDEADLK =               35
42ENAMETOOLONG =          36
43ENOLCK =                37
44ENOSYS =                38
45ENOTEMPTY =             39
46ELOOP =                 40
47#                       41 unused
48ENOMSG =                42
49EIDRM =                 43
50ECHRNG =                44
51EL2NSYNC =              45
52EL3HLT =                46
53EL3RST =                47
54ELNRNG =                48
55EUNATCH =               49
56ENOCSI =                50
57EL2HLT =                51
58EBADE =                 52
59EBADR =                 53
60EXFULL =                54
61ENOANO =                55
62EBADRQC =               56
63EBADSLT =               57
64#                       58 unused
65EBFONT =                59
66ENOSTR =                60
67ENODATA =               61
68ETIME =                 62
69ENOSR =                 63
70ENONET =                64
71ENOPKG =                65
72EREMOTE =               66
73ENOLINK =               67
74EADV =                  68
75ESRMNT =                69
76ECOMM =                 70
77EPROTO =                71
78EMULTIHOP =             72
79EDOTDOT =               73
80EBADMSG =               74
81EOVERFLOW =             75
82ENOTUNIQ =              76
83EBADFD =                77
84EREMCHG =               78
85ELIBACC =               79
86ELIBBAD =               80
87ELIBSCN =               81
88ELIBMAX =               82
89ELIBEXEC =              83
90EILSEQ =                84
91ERESTART =              85
92ESTRPIPE =              86
93EUSERS =                87
94ENOTSOCK =              88
95EDESTADDRREQ =          89
96EMSGSIZE =              90
97EPROTOTYPE =            91
98ENOPROTOOPT =           92
99EPROTONOSUPPORT =       93
100ESOCKTNOSUPPORT =       94
101EOPNOTSUPP =            95
102EPFNOSUPPORT =          96
103EAFNOSUPPORT =          97
104EADDRINUSE =            98
105EADDRNOTAVAIL =         99
106ENETDOWN =              100
107ENETUNREACH =           101
108ENETRESET =             102
109ECONNABORTED =          103
110ECONNRESET =            104
111ENOBUFS =               105
112EISCONN =               106
113ENOTCONN =              107
114ESHUTDOWN =             108
115ETOOMANYREFS =          109
116ETIMEDOUT =             110
117ECONNREFUSED =          111
118EHOSTDOWN =             112
119EHOSTUNREACH =          113
120EALREADY =              114
121EINPROGRESS =           115
122ESTALE =                116
123EUCLEAN =               117
124ENOTNAM =               118
125ENAVAIL =               119
126EISNAM =                120
127EREMOTEIO =             121
128EDQUOT =                122
129ENOMEDIUM =             123
130EMEDIUMTYPE =           124
131ECANCELED =             125
132ENOKEY =                126
133EKEYEXPIRED =           127
134EKEYREVOKED =           128
135EKEYREJECTED =          129
136EOWNERDEAD =            130
137ENOTRECOVERABLE =       131
138ERFKILL =               132
139EHWPOISON =             133
140
141_strerror = {
142    EPERM:              'Permission denied',
143    ENOENT:             'No such file or directory',
144    ESRCH:              'No such process',
145    EINTR:              'Interrupted system call',
146    EIO:                'Input/output error',
147    ENXIO:              'Device not configured',
148    E2BIG:              'Argument list too long',
149    ENOEXEC:            'Exec format error',
150    EBADF:              'Bad file descriptor',
151    ECHILD:             'No child processes',
152    EAGAIN:             'Resource temporarily unavailable',
153    ENOMEM:             'Cannot allocate memory',
154    EACCES:             'Permission denied',
155    EFAULT:             'Bad address',
156    ENOTBLK:            'Block device required',
157    EBUSY:              'Device busy',
158    EEXIST:             'File exists',
159    EXDEV:              'Cross-device link',
160    ENODEV:             'Operation not supported by device',
161    ENOTDIR:            'Not a directory',
162    EISDIR:             'Is a directory',
163    EINVAL:             'Invalid argument',
164    ENFILE:             'Too many open files in system',
165    EMFILE:             'Too many open files',
166    ENOTTY:             'Inappropriate ioctl for device',
167    ETXTBSY:            'Text file busy',
168    EFBIG:              'File too large',
169    ENOSPC:             'No space left on device',
170    ESPIPE:             'Illegal seek',
171    EROFS:              'Read-only filesystem',
172    EMLINK:             'Too many links',
173    EPIPE:              'Broken pipe',
174    EDOM:               'Numerical argument out of domain',
175    ERANGE:             'Result too large',
176    EDEADLK:            'Resource deadlock avoided',
177    ENAMETOOLONG:       'File name too long',
178    ENOLCK:             'No locks available',
179    ENOSYS:             'Function not implemented',
180    ENOTEMPTY:          'Directory not empty',
181    ELOOP:              'Too many levels of symbolic links',
182    ENOMSG:             'No message of desired type',
183    EIDRM:              'Identifier removed',
184    ECHRNG:             'Channel number out of range',
185    EL2NSYNC:           'Level 2 not synchronized',
186    EL3HLT:             'Level 3 halted',
187    EL3RST:             'Level 3 reset',
188    ELNRNG:             'Link number out of range',
189    EUNATCH:            'Protocol driver not attached',
190    ENOCSI:             'No CSI structure available',
191    EL2HLT:             'Level 2 halted',
192    EBADE:              'Invalid exchange',
193    EBADR:              'Invalid request descriptor',
194    EXFULL:             'Exchange full',
195    ENOANO:             'No anode',
196    EBADRQC:            'Invalid request code',
197    EBADSLT:            'Invalid slot',
198    EBFONT:             'Bad font file format',
199    ENOSTR:             'Device not a stream',
200    ENODATA:            'No data available',
201    ETIME:              'Timer expired',
202    ENOSR:              'Out of streams resources',
203    ENONET:             'Machine is not on the network',
204    ENOPKG:             'Package not installed',
205    EREMOTE:            'Object is remote',
206    ENOLINK:            'Link has been severed',
207    EADV:               'Advertise error',
208    ESRMNT:             'Srmount error',
209    ECOMM:              'Communication error on send',
210    EPROTO:             'Protocol error',
211    EMULTIHOP:          'Multihop attempted',
212    EDOTDOT:            'RFS specific error',
213    EBADMSG:            'Bad message',
214    EOVERFLOW:          'Value too large for defined data type',
215    ENOTUNIQ:           'Name not unique on network',
216    EBADFD:             'File descriptor in bad state',
217    EREMCHG:            'Remote address changed',
218    ELIBACC:            'Can not access a needed shared library',
219    ELIBBAD:            'Accessing a corrupted shared library',
220    ELIBSCN:            '.lib section in a.out corrupted',
221    ELIBMAX:            'Attempting to link in too many shared libraries',
222    ELIBEXEC:           'Cannot exec a shared library directly',
223    EILSEQ:             'Invalid or incomplete multibyte or wide character',
224    ERESTART:           'Interrupted system call should be restarted',
225    ESTRPIPE:           'Streams pipe error',
226    EUSERS:             'Too many users',
227    ENOTSOCK:           'Socket operation on non-socket',
228    EDESTADDRREQ:       'Destination address required',
229    EMSGSIZE:           'Message too long',
230    EPROTOTYPE:         'Protocol wrong type for socket',
231    ENOPROTOOPT:        'Protocol not available',
232    EPROTONOSUPPORT:    'Protocol not supported',
233    ESOCKTNOSUPPORT:    'Socket type not supported',
234    EOPNOTSUPP:         'Operation not supported',
235    EPFNOSUPPORT:       'Protocol family not supported',
236    EAFNOSUPPORT:       'Address family not supported by protocol',
237    EADDRINUSE:         'Address already in use',
238    EADDRNOTAVAIL:      'Cannot assign requested address',
239    ENETDOWN:           'Network is down',
240    ENETUNREACH:        'Network is unreachable',
241    ENETRESET:          'Network dropped connection on reset',
242    ECONNABORTED:       'Software caused connection abort',
243    ECONNRESET:         'Connection reset by peer',
244    ENOBUFS:            'No buffer space available',
245    EISCONN:            'Transport endpoint is already connected',
246    ENOTCONN:           'Transport endpoint is not connected',
247    ESHUTDOWN:          'Cannot send after transport endpoint shutdown',
248    ETOOMANYREFS:       'Too many references: cannot splice',
249    ETIMEDOUT:          'Connection timed out',
250    ECONNREFUSED:       'Connection refused',
251    EHOSTDOWN:          'Host is down',
252    EHOSTUNREACH:       'No route to host',
253    EALREADY:           'Operation already in progress',
254    EINPROGRESS:        'Operation now in progress',
255    ESTALE:             'Stale file handle',
256    EUCLEAN:            'Structure needs cleaning',
257    ENOTNAM:            'Not a XENIX named type file',
258    ENAVAIL:            'No XENIX semaphores available',
259    EISNAM:             'Is a named type file',
260    EREMOTEIO:          'Remote I/O error',
261    EDQUOT:             'Quota exceeded',
262    ENOMEDIUM:          'No medium found',
263    EMEDIUMTYPE:        'Wrong medium type',
264    ECANCELED:          'Operation canceled',
265    ENOKEY:             'Required key not available',
266    EKEYEXPIRED:        'Key has expired',
267    EKEYREVOKED:        'Key has been revoked',
268    EKEYREJECTED:       'Key was rejected by service',
269    EOWNERDEAD:         'Owner died',
270    ENOTRECOVERABLE:    'State not recoverable',
271    ERFKILL:            'Operation not possible due to RF-kill',
272    EHWPOISON:          'Memory page has hardware error',
273}
274
275def strerror(errnum):
276    """
277    Translate Linux errno to string.
278
279    >>> strerror(ENOKEY)
280    'Required key not available'
281    >>> strerror(41)
282    'Unknown error 41'
283    """
284    ret = _strerror.get(errnum)
285    if ret:
286        return ret
287    return 'Unknown error {0}'.format(errnum)
288
289if __name__ == '__main__':
290    import doctest
291    doctest.testmod()
292