AArch64: Improve strchrnul
[glibc.git] / nis / nis_error.c
blobf15321dd269bb22d15a96ada1275532c89974ffe
1 /* Copyright (c) 1997-2023 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
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.
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.
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/>. */
18 #include <errno.h>
19 #include <syslog.h>
20 #include <string.h>
21 #include <libintl.h>
22 #include <rpcsvc/nis.h>
23 #include <shlib-compat.h>
26 #define MF(line) MF1 (line)
27 #define MF1(line) str##line
28 static const union msgstr_t
30 struct
32 #define S(s) char MF(__LINE__)[sizeof (s)];
33 #include "nis_error.h"
34 #undef S
36 char str[0];
37 } msgstr =
40 #define S(s) s,
41 #include "nis_error.h"
42 #undef S
46 static const unsigned short int msgidx[] =
48 #define S(s) offsetof (union msgstr_t, MF (__LINE__)),
49 #include "nis_error.h"
50 #undef S
54 const char *
55 nis_sperrno (const nis_error status)
57 if (status >= sizeof (msgidx) / sizeof (msgidx[0]))
58 return "???";
59 else
60 return gettext (msgstr.str + msgidx[status]);
62 libnsl_hidden_nolink_def (nis_sperrno, GLIBC_2_1)
64 void
65 nis_perror (const nis_error status, const char *label)
67 fprintf (stderr, "%s: %s\n", label, nis_sperrno (status));
69 libnsl_hidden_nolink_def (nis_perror, GLIBC_2_1)
71 void
72 nis_lerror (const nis_error status, const char *label)
74 syslog (LOG_ERR, "%s: %s", label, nis_sperrno (status));
76 libnsl_hidden_nolink_def (nis_lerror, GLIBC_2_1)
78 char *
79 nis_sperror_r (const nis_error status, const char *label,
80 char *buffer, size_t buflen)
82 if (snprintf (buffer, buflen, "%s: %s", label, nis_sperrno (status))
83 >= buflen)
85 __set_errno (ERANGE);
86 return NULL;
89 return buffer;
91 libnsl_hidden_nolink_def (nis_sperror_r, GLIBC_2_1)
93 char *
94 nis_sperror (const nis_error status, const char *label)
96 static char buffer[NIS_MAXNAMELEN + 1];
98 return nis_sperror_r (status, label, buffer, sizeof (buffer));
100 libnsl_hidden_nolink_def (nis_sperror, GLIBC_2_1)