1/* Copyright (c) 1997-2022 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 <errno.h>
19#include <syslog.h>
20#include <string.h>
21#include <libintl.h>
22#include <rpcsvc/nis.h>
23#include <shlib-compat.h>
24
25
26#define MF(line) MF1 (line)
27#define MF1(line) str##line
28static const union msgstr_t
29{
30 struct
31 {
32#define S(s) char MF(__LINE__)[sizeof (s)];
33#include "nis_error.h"
34#undef S
35 };
36 char str[0];
37} msgstr =
38 {
39 {
40#define S(s) s,
41#include "nis_error.h"
42#undef S
43 }
44 };
45
46static const unsigned short int msgidx[] =
47 {
48#define S(s) offsetof (union msgstr_t, MF (__LINE__)),
49#include "nis_error.h"
50#undef S
51 };
52
53
54const char *
55nis_sperrno (const nis_error status)
56{
57 if (status >= sizeof (msgidx) / sizeof (msgidx[0]))
58 return "???";
59 else
60 return gettext (msgstr.str + msgidx[status]);
61}
62libnsl_hidden_nolink_def (nis_sperrno, GLIBC_2_1)
63
64void
65nis_perror (const nis_error status, const char *label)
66{
67 fprintf (stderr, format: "%s: %s\n", label, nis_sperrno (status));
68}
69libnsl_hidden_nolink_def (nis_perror, GLIBC_2_1)
70
71void
72nis_lerror (const nis_error status, const char *label)
73{
74 syslog (LOG_ERR, fmt: "%s: %s", label, nis_sperrno (status));
75}
76libnsl_hidden_nolink_def (nis_lerror, GLIBC_2_1)
77
78char *
79nis_sperror_r (const nis_error status, const char *label,
80 char *buffer, size_t buflen)
81{
82 if (snprintf (s: buffer, maxlen: buflen, format: "%s: %s", label, nis_sperrno (status))
83 >= buflen)
84 {
85 __set_errno (ERANGE);
86 return NULL;
87 }
88
89 return buffer;
90}
91libnsl_hidden_nolink_def (nis_sperror_r, GLIBC_2_1)
92
93char *
94nis_sperror (const nis_error status, const char *label)
95{
96 static char buffer[NIS_MAXNAMELEN + 1];
97
98 return nis_sperror_r (status, label, buffer, buflen: sizeof (buffer));
99}
100libnsl_hidden_nolink_def (nis_sperror, GLIBC_2_1)
101

source code of glibc/nis/nis_error.c