| 1 | /* Copyright (C) 1991-2020 Free Software Foundation, Inc. |
| 2 | This file is part of the GNU C Library. |
| 3 | |
| 4 | The GNU C Library is free software; you can redistribute it and/or |
| 5 | modify it under the terms of the GNU Lesser General Public |
| 6 | License as published by the Free Software Foundation; either |
| 7 | version 2.1 of the License, or (at your option) any later version. |
| 8 | |
| 9 | The GNU C Library is distributed in the hope that it will be useful, |
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | Lesser General Public License for more details. |
| 13 | |
| 14 | You should have received a copy of the GNU Lesser General Public |
| 15 | License along with the GNU C Library; if not, see |
| 16 | <https://www.gnu.org/licenses/>. */ |
| 17 | |
| 18 | #include <stdio.h> |
| 19 | #include <errno.h> |
| 20 | #include <libintl.h> |
| 21 | #include <array_length.h> |
| 22 | |
| 23 | const char *const _sys_errlist_internal[] = |
| 24 | { |
| 25 | #define _S(n, str) [n] = str, |
| 26 | #include <errlist.h> |
| 27 | #undef _S |
| 28 | }; |
| 29 | |
| 30 | const char * |
| 31 | __get_errlist (int errnum) |
| 32 | { |
| 33 | if (errnum >= 0 && errnum < array_length (_sys_errlist_internal)) |
| 34 | return _sys_errlist_internal[errnum]; |
| 35 | return NULL; |
| 36 | } |
| 37 | |
| 38 | static const union sys_errname_t |
| 39 | { |
| 40 | struct |
| 41 | { |
| 42 | #define MSGSTRFIELD1(line) str##line |
| 43 | #define MSGSTRFIELD(line) MSGSTRFIELD1(line) |
| 44 | #define _S(n, str) char MSGSTRFIELD(__LINE__)[sizeof(str)]; |
| 45 | #include <errlist.h> |
| 46 | #undef _S |
| 47 | }; |
| 48 | char str[0]; |
| 49 | } _sys_errname = { { |
| 50 | #define _S(n, s) s, |
| 51 | #include <errlist.h> |
| 52 | #undef _S |
| 53 | } }; |
| 54 | |
| 55 | static const unsigned short _sys_errnameidx[] = |
| 56 | { |
| 57 | #define _S(n, s) [n] = offsetof(union sys_errname_t, MSGSTRFIELD(__LINE__)), |
| 58 | #include <errlist.h> |
| 59 | #undef _S |
| 60 | }; |
| 61 | |
| 62 | const char * |
| 63 | __get_errname (int errnum) |
| 64 | { |
| 65 | if (errnum < 0 || errnum >= array_length (_sys_errnameidx) |
| 66 | || (errnum > 0 && _sys_errnameidx[errnum] == 0)) |
| 67 | return NULL; |
| 68 | return _sys_errname.str + _sys_errnameidx[errnum]; |
| 69 | } |
| 70 | |
| 71 | #include <errlist-compat.c> |
| 72 | |