| 1 | /* Copyright (c) 1997-2021 Free Software Foundation, Inc. |
| 2 | This file is part of the GNU C Library. |
| 3 | Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997. |
| 4 | |
| 5 | The GNU C Library is free software; you can redistribute it and/or |
| 6 | modify it under the terms of the GNU Lesser General Public |
| 7 | License as published by the Free Software Foundation; either |
| 8 | version 2.1 of the License, or (at your option) any later version. |
| 9 | |
| 10 | The GNU C Library is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | Lesser General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU Lesser General Public |
| 16 | License along with the GNU C Library; if not, see |
| 17 | <https://www.gnu.org/licenses/>. */ |
| 18 | |
| 19 | #include <errno.h> |
| 20 | #include <syslog.h> |
| 21 | #include <string.h> |
| 22 | #include <libintl.h> |
| 23 | #include <rpcsvc/nis.h> |
| 24 | #include <shlib-compat.h> |
| 25 | |
| 26 | |
| 27 | #define MF(line) MF1 (line) |
| 28 | #define MF1(line) str##line |
| 29 | static const union msgstr_t |
| 30 | { |
| 31 | struct |
| 32 | { |
| 33 | #define S(s) char MF(__LINE__)[sizeof (s)]; |
| 34 | #include "nis_error.h" |
| 35 | #undef S |
| 36 | }; |
| 37 | char str[0]; |
| 38 | } msgstr = |
| 39 | { |
| 40 | { |
| 41 | #define S(s) s, |
| 42 | #include "nis_error.h" |
| 43 | #undef S |
| 44 | } |
| 45 | }; |
| 46 | |
| 47 | static const unsigned short int msgidx[] = |
| 48 | { |
| 49 | #define S(s) offsetof (union msgstr_t, MF (__LINE__)), |
| 50 | #include "nis_error.h" |
| 51 | #undef S |
| 52 | }; |
| 53 | |
| 54 | |
| 55 | const char * |
| 56 | nis_sperrno (const nis_error status) |
| 57 | { |
| 58 | if (status >= sizeof (msgidx) / sizeof (msgidx[0])) |
| 59 | return "???" ; |
| 60 | else |
| 61 | return gettext (msgstr.str + msgidx[status]); |
| 62 | } |
| 63 | libnsl_hidden_nolink_def (nis_sperrno, GLIBC_2_1) |
| 64 | |
| 65 | void |
| 66 | nis_perror (const nis_error status, const char *label) |
| 67 | { |
| 68 | fprintf (stderr, "%s: %s\n" , label, nis_sperrno (status)); |
| 69 | } |
| 70 | libnsl_hidden_nolink_def (nis_perror, GLIBC_2_1) |
| 71 | |
| 72 | void |
| 73 | nis_lerror (const nis_error status, const char *label) |
| 74 | { |
| 75 | syslog (LOG_ERR, "%s: %s" , label, nis_sperrno (status)); |
| 76 | } |
| 77 | libnsl_hidden_nolink_def (nis_lerror, GLIBC_2_1) |
| 78 | |
| 79 | char * |
| 80 | nis_sperror_r (const nis_error status, const char *label, |
| 81 | char *buffer, size_t buflen) |
| 82 | { |
| 83 | if (snprintf (buffer, buflen, "%s: %s" , label, nis_sperrno (status)) |
| 84 | >= buflen) |
| 85 | { |
| 86 | __set_errno (ERANGE); |
| 87 | return NULL; |
| 88 | } |
| 89 | |
| 90 | return buffer; |
| 91 | } |
| 92 | libnsl_hidden_nolink_def (nis_sperror_r, GLIBC_2_1) |
| 93 | |
| 94 | char * |
| 95 | nis_sperror (const nis_error status, const char *label) |
| 96 | { |
| 97 | static char buffer[NIS_MAXNAMELEN + 1]; |
| 98 | |
| 99 | return nis_sperror_r (status, label, buffer, sizeof (buffer)); |
| 100 | } |
| 101 | libnsl_hidden_nolink_def (nis_sperror, GLIBC_2_1) |
| 102 | |