]> git.ipfire.org Git - thirdparty/glibc.git/blame - nis/nis_error.c
nss_compat: query NIS domain only when needed
[thirdparty/glibc.git] / nis / nis_error.c
CommitLineData
a51752b6 1/* Copyright (c) 1997,1998,1999,2004,2005,2006 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
AJ
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
e61abf83
UD
19
20#include <errno.h>
21#include <syslog.h>
76b87c03 22#include <string.h>
4360eafd 23#include <libintl.h>
e61abf83 24#include <rpcsvc/nis.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}
7440c23e 63libnsl_hidden_def (nis_sperrno)
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}
70
71void
72nis_lerror (const nis_error status, const char *label)
73{
74 syslog (LOG_ERR, "%s: %s", label, nis_sperrno (status));
75}
76
77char *
78nis_sperror_r (const nis_error status, const char *label,
79 char *buffer, size_t buflen)
80{
8e64faef
UD
81 if (snprintf (buffer, buflen, "%s: %s", label, nis_sperrno (status))
82 >= buflen)
e61abf83 83 {
a51752b6 84 __set_errno (ERANGE);
e61abf83
UD
85 return NULL;
86 }
87
8e64faef 88 return buffer;
e61abf83 89}
7440c23e 90libnsl_hidden_def (nis_sperror_r)
e61abf83
UD
91
92char *
93nis_sperror (const nis_error status, const char *label)
94{
8e64faef 95 static char buffer[NIS_MAXNAMELEN + 1];
e61abf83
UD
96
97 return nis_sperror_r (status, label, buffer, sizeof (buffer));
98}