1 /*
2 * Copyright (c) 2016 Dmitry V. Levin <ldv@altlinux.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 #include "tests.h"
29 #include <errno.h>
30
31 #define CASE(x) case x: return #x
32
33 const char *
errno2name(void)34 errno2name(void)
35 {
36 switch (errno) {
37 /* names taken from linux/errnoent.h */
38 #ifdef E2BIG
39 CASE(E2BIG);
40 #endif
41 #ifdef EACCES
42 CASE(EACCES);
43 #endif
44 #ifdef EADDRINUSE
45 CASE(EADDRINUSE);
46 #endif
47 #ifdef EADDRNOTAVAIL
48 CASE(EADDRNOTAVAIL);
49 #endif
50 #ifdef EADV
51 CASE(EADV);
52 #endif
53 #ifdef EAFNOSUPPORT
54 CASE(EAFNOSUPPORT);
55 #endif
56 #ifdef EAGAIN
57 CASE(EAGAIN);
58 #endif
59 #ifdef EALREADY
60 CASE(EALREADY);
61 #endif
62 #ifdef EBADCOOKIE
63 CASE(EBADCOOKIE);
64 #endif
65 #ifdef EBADE
66 CASE(EBADE);
67 #endif
68 #ifdef EBADF
69 CASE(EBADF);
70 #endif
71 #ifdef EBADFD
72 CASE(EBADFD);
73 #endif
74 #ifdef EBADHANDLE
75 CASE(EBADHANDLE);
76 #endif
77 #ifdef EBADMSG
78 CASE(EBADMSG);
79 #endif
80 #ifdef EBADR
81 CASE(EBADR);
82 #endif
83 #ifdef EBADRQC
84 CASE(EBADRQC);
85 #endif
86 #ifdef EBADSLT
87 CASE(EBADSLT);
88 #endif
89 #ifdef EBADTYPE
90 CASE(EBADTYPE);
91 #endif
92 #ifdef EBFONT
93 CASE(EBFONT);
94 #endif
95 #ifdef EBUSY
96 CASE(EBUSY);
97 #endif
98 #ifdef ECANCELED
99 CASE(ECANCELED);
100 #endif
101 #ifdef ECHILD
102 CASE(ECHILD);
103 #endif
104 #ifdef ECHRNG
105 CASE(ECHRNG);
106 #endif
107 #ifdef ECOMM
108 CASE(ECOMM);
109 #endif
110 #ifdef ECONNABORTED
111 CASE(ECONNABORTED);
112 #endif
113 #ifdef ECONNREFUSED
114 CASE(ECONNREFUSED);
115 #endif
116 #ifdef ECONNRESET
117 CASE(ECONNRESET);
118 #endif
119 #ifdef EDEADLK
120 CASE(EDEADLK);
121 #endif
122 #ifdef EDESTADDRREQ
123 CASE(EDESTADDRREQ);
124 #endif
125 #ifdef EDOM
126 CASE(EDOM);
127 #endif
128 #ifdef EDOTDOT
129 CASE(EDOTDOT);
130 #endif
131 #ifdef EDQUOT
132 CASE(EDQUOT);
133 #endif
134 #ifdef EEXIST
135 CASE(EEXIST);
136 #endif
137 #ifdef EFAULT
138 CASE(EFAULT);
139 #endif
140 #ifdef EFBIG
141 CASE(EFBIG);
142 #endif
143 #ifdef EHOSTDOWN
144 CASE(EHOSTDOWN);
145 #endif
146 #ifdef EHOSTUNREACH
147 CASE(EHOSTUNREACH);
148 #endif
149 #ifdef EHWPOISON
150 CASE(EHWPOISON);
151 #endif
152 #ifdef EIDRM
153 CASE(EIDRM);
154 #endif
155 #ifdef EILSEQ
156 CASE(EILSEQ);
157 #endif
158 #ifdef EINPROGRESS
159 CASE(EINPROGRESS);
160 #endif
161 #ifdef EINTR
162 CASE(EINTR);
163 #endif
164 #ifdef EINVAL
165 CASE(EINVAL);
166 #endif
167 #ifdef EIO
168 CASE(EIO);
169 #endif
170 #ifdef EIOCBQUEUED
171 CASE(EIOCBQUEUED);
172 #endif
173 #ifdef EISCONN
174 CASE(EISCONN);
175 #endif
176 #ifdef EISDIR
177 CASE(EISDIR);
178 #endif
179 #ifdef EISNAM
180 CASE(EISNAM);
181 #endif
182 #ifdef EJUKEBOX
183 CASE(EJUKEBOX);
184 #endif
185 #ifdef EKEYEXPIRED
186 CASE(EKEYEXPIRED);
187 #endif
188 #ifdef EKEYREJECTED
189 CASE(EKEYREJECTED);
190 #endif
191 #ifdef EKEYREVOKED
192 CASE(EKEYREVOKED);
193 #endif
194 #ifdef EL2HLT
195 CASE(EL2HLT);
196 #endif
197 #ifdef EL2NSYNC
198 CASE(EL2NSYNC);
199 #endif
200 #ifdef EL3HLT
201 CASE(EL3HLT);
202 #endif
203 #ifdef EL3RST
204 CASE(EL3RST);
205 #endif
206 #ifdef ELIBACC
207 CASE(ELIBACC);
208 #endif
209 #ifdef ELIBBAD
210 CASE(ELIBBAD);
211 #endif
212 #ifdef ELIBEXEC
213 CASE(ELIBEXEC);
214 #endif
215 #ifdef ELIBMAX
216 CASE(ELIBMAX);
217 #endif
218 #ifdef ELIBSCN
219 CASE(ELIBSCN);
220 #endif
221 #ifdef ELNRNG
222 CASE(ELNRNG);
223 #endif
224 #ifdef ELOOP
225 CASE(ELOOP);
226 #endif
227 #ifdef EMEDIUMTYPE
228 CASE(EMEDIUMTYPE);
229 #endif
230 #ifdef EMFILE
231 CASE(EMFILE);
232 #endif
233 #ifdef EMLINK
234 CASE(EMLINK);
235 #endif
236 #ifdef EMSGSIZE
237 CASE(EMSGSIZE);
238 #endif
239 #ifdef EMULTIHOP
240 CASE(EMULTIHOP);
241 #endif
242 #ifdef ENAMETOOLONG
243 CASE(ENAMETOOLONG);
244 #endif
245 #ifdef ENAVAIL
246 CASE(ENAVAIL);
247 #endif
248 #ifdef ENETDOWN
249 CASE(ENETDOWN);
250 #endif
251 #ifdef ENETRESET
252 CASE(ENETRESET);
253 #endif
254 #ifdef ENETUNREACH
255 CASE(ENETUNREACH);
256 #endif
257 #ifdef ENFILE
258 CASE(ENFILE);
259 #endif
260 #ifdef ENOANO
261 CASE(ENOANO);
262 #endif
263 #ifdef ENOBUFS
264 CASE(ENOBUFS);
265 #endif
266 #ifdef ENOCSI
267 CASE(ENOCSI);
268 #endif
269 #ifdef ENODATA
270 CASE(ENODATA);
271 #endif
272 #ifdef ENODEV
273 CASE(ENODEV);
274 #endif
275 #ifdef ENOENT
276 CASE(ENOENT);
277 #endif
278 #ifdef ENOEXEC
279 CASE(ENOEXEC);
280 #endif
281 #ifdef ENOIOCTLCMD
282 CASE(ENOIOCTLCMD);
283 #endif
284 #ifdef ENOKEY
285 CASE(ENOKEY);
286 #endif
287 #ifdef ENOLCK
288 CASE(ENOLCK);
289 #endif
290 #ifdef ENOLINK
291 CASE(ENOLINK);
292 #endif
293 #ifdef ENOMEDIUM
294 CASE(ENOMEDIUM);
295 #endif
296 #ifdef ENOMEM
297 CASE(ENOMEM);
298 #endif
299 #ifdef ENOMSG
300 CASE(ENOMSG);
301 #endif
302 #ifdef ENONET
303 CASE(ENONET);
304 #endif
305 #ifdef ENOPKG
306 CASE(ENOPKG);
307 #endif
308 #ifdef ENOPROTOOPT
309 CASE(ENOPROTOOPT);
310 #endif
311 #ifdef ENOSPC
312 CASE(ENOSPC);
313 #endif
314 #ifdef ENOSR
315 CASE(ENOSR);
316 #endif
317 #ifdef ENOSTR
318 CASE(ENOSTR);
319 #endif
320 #ifdef ENOSYS
321 CASE(ENOSYS);
322 #endif
323 #ifdef ENOTBLK
324 CASE(ENOTBLK);
325 #endif
326 #ifdef ENOTCONN
327 CASE(ENOTCONN);
328 #endif
329 #ifdef ENOTDIR
330 CASE(ENOTDIR);
331 #endif
332 #ifdef ENOTEMPTY
333 CASE(ENOTEMPTY);
334 #endif
335 #ifdef ENOTNAM
336 CASE(ENOTNAM);
337 #endif
338 #ifdef ENOTRECOVERABLE
339 CASE(ENOTRECOVERABLE);
340 #endif
341 #ifdef ENOTSOCK
342 CASE(ENOTSOCK);
343 #endif
344 #ifdef ENOTSUPP
345 CASE(ENOTSUPP);
346 #endif
347 #ifdef ENOTSYNC
348 CASE(ENOTSYNC);
349 #endif
350 #ifdef ENOTTY
351 CASE(ENOTTY);
352 #endif
353 #ifdef ENOTUNIQ
354 CASE(ENOTUNIQ);
355 #endif
356 #ifdef ENXIO
357 CASE(ENXIO);
358 #endif
359 #ifdef EOPENSTALE
360 CASE(EOPENSTALE);
361 #endif
362 #ifdef EOPNOTSUPP
363 CASE(EOPNOTSUPP);
364 #endif
365 #ifdef EOVERFLOW
366 CASE(EOVERFLOW);
367 #endif
368 #ifdef EOWNERDEAD
369 CASE(EOWNERDEAD);
370 #endif
371 #ifdef EPERM
372 CASE(EPERM);
373 #endif
374 #ifdef EPFNOSUPPORT
375 CASE(EPFNOSUPPORT);
376 #endif
377 #ifdef EPIPE
378 CASE(EPIPE);
379 #endif
380 #ifdef EPROBE_DEFER
381 CASE(EPROBE_DEFER);
382 #endif
383 #ifdef EPROTO
384 CASE(EPROTO);
385 #endif
386 #ifdef EPROTONOSUPPORT
387 CASE(EPROTONOSUPPORT);
388 #endif
389 #ifdef EPROTOTYPE
390 CASE(EPROTOTYPE);
391 #endif
392 #ifdef ERANGE
393 CASE(ERANGE);
394 #endif
395 #ifdef EREMCHG
396 CASE(EREMCHG);
397 #endif
398 #ifdef EREMOTE
399 CASE(EREMOTE);
400 #endif
401 #ifdef EREMOTEIO
402 CASE(EREMOTEIO);
403 #endif
404 #ifdef ERESTART
405 CASE(ERESTART);
406 #endif
407 #ifdef ERESTARTNOHAND
408 CASE(ERESTARTNOHAND);
409 #endif
410 #ifdef ERESTARTNOINTR
411 CASE(ERESTARTNOINTR);
412 #endif
413 #ifdef ERESTARTSYS
414 CASE(ERESTARTSYS);
415 #endif
416 #ifdef ERESTART_RESTARTBLOCK
417 CASE(ERESTART_RESTARTBLOCK);
418 #endif
419 #ifdef ERFKILL
420 CASE(ERFKILL);
421 #endif
422 #ifdef EROFS
423 CASE(EROFS);
424 #endif
425 #ifdef ESERVERFAULT
426 CASE(ESERVERFAULT);
427 #endif
428 #ifdef ESHUTDOWN
429 CASE(ESHUTDOWN);
430 #endif
431 #ifdef ESOCKTNOSUPPORT
432 CASE(ESOCKTNOSUPPORT);
433 #endif
434 #ifdef ESPIPE
435 CASE(ESPIPE);
436 #endif
437 #ifdef ESRCH
438 CASE(ESRCH);
439 #endif
440 #ifdef ESRMNT
441 CASE(ESRMNT);
442 #endif
443 #ifdef ESTALE
444 CASE(ESTALE);
445 #endif
446 #ifdef ESTRPIPE
447 CASE(ESTRPIPE);
448 #endif
449 #ifdef ETIME
450 CASE(ETIME);
451 #endif
452 #ifdef ETIMEDOUT
453 CASE(ETIMEDOUT);
454 #endif
455 #ifdef ETOOMANYREFS
456 CASE(ETOOMANYREFS);
457 #endif
458 #ifdef ETOOSMALL
459 CASE(ETOOSMALL);
460 #endif
461 #ifdef ETXTBSY
462 CASE(ETXTBSY);
463 #endif
464 #ifdef EUCLEAN
465 CASE(EUCLEAN);
466 #endif
467 #ifdef EUNATCH
468 CASE(EUNATCH);
469 #endif
470 #ifdef EUSERS
471 CASE(EUSERS);
472 #endif
473 #ifdef EXDEV
474 CASE(EXDEV);
475 #endif
476 #ifdef EXFULL
477 CASE(EXFULL);
478 #endif
479 default:
480 perror_msg_and_fail("unknown errno %d", errno);
481 }
482 }
483