]> git.ipfire.org Git - thirdparty/glibc.git/blame - nis/nis_error.c
Remove "Contributed by" lines
[thirdparty/glibc.git] / nis / nis_error.c
CommitLineData
2b778ceb 1/* Copyright (c) 1997-2021 Free Software Foundation, Inc.
e61abf83 2 This file is part of the GNU C Library.
e61abf83
UD
3
4 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
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.
e61abf83
UD
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
41bdb6e2 12 Lesser General Public License for more details.
e61abf83 13
41bdb6e2 14 You should have received a copy of the GNU Lesser General Public
59ba27a6 15 License along with the GNU C Library; if not, see
5a82c748 16 <https://www.gnu.org/licenses/>. */
e61abf83
UD
17
18#include <errno.h>
19#include <syslog.h>
76b87c03 20#include <string.h>
4360eafd 21#include <libintl.h>
e61abf83 22#include <rpcsvc/nis.h>
82f43dd2 23#include <shlib-compat.h>
e61abf83
UD
24
25
a51752b6
UD
26#define MF(line) MF1 (line)
27#define MF1(line) str##line
28static const union msgstr_t
e61abf83 29{
a51752b6
UD
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
e61abf83
UD
53
54const char *
55nis_sperrno (const nis_error status)
56{
a51752b6 57 if (status >= sizeof (msgidx) / sizeof (msgidx[0]))
e61abf83
UD
58 return "???";
59 else
a51752b6 60 return gettext (msgstr.str + msgidx[status]);
e61abf83 61}
1e4d83f6 62libnsl_hidden_nolink_def (nis_sperrno, GLIBC_2_1)
e61abf83
UD
63
64void
65nis_perror (const nis_error status, const char *label)
66{
67 fprintf (stderr, "%s: %s\n", label, nis_sperrno (status));
68}
1e4d83f6 69libnsl_hidden_nolink_def (nis_perror, GLIBC_2_1)
e61abf83
UD
70
71void
72nis_lerror (const nis_error status, const char *label)
73{
74 syslog (LOG_ERR, "%s: %s", label, nis_sperrno (status));
75}
1e4d83f6 76libnsl_hidden_nolink_def (nis_lerror, GLIBC_2_1)
e61abf83
UD
77
78char *
79nis_sperror_r (const nis_error status, const char *label,
80 char *buffer, size_t buflen)
81{
8e64faef
UD
82 if (snprintf (buffer, buflen, "%s: %s", label, nis_sperrno (status))
83 >= buflen)
e61abf83 84 {
a51752b6 85 __set_errno (ERANGE);
e61abf83
UD
86 return NULL;
87 }
88
8e64faef 89 return buffer;
e61abf83 90}
1e4d83f6 91libnsl_hidden_nolink_def (nis_sperror_r, GLIBC_2_1)
e61abf83
UD
92
93char *
94nis_sperror (const nis_error status, const char *label)
95{
8e64faef 96 static char buffer[NIS_MAXNAMELEN + 1];
e61abf83
UD
97
98 return nis_sperror_r (status, label, buffer, sizeof (buffer));
99}
1e4d83f6 100libnsl_hidden_nolink_def (nis_sperror, GLIBC_2_1)