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