]> git.ipfire.org Git - thirdparty/glibc.git/blame - nis/nis_error.c
Merge glibc-ports into ports/ directory.
[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 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>
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}
7440c23e 62libnsl_hidden_def (nis_sperrno)
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}
69
70void
71nis_lerror (const nis_error status, const char *label)
72{
73 syslog (LOG_ERR, "%s: %s", label, nis_sperrno (status));
74}
75
76char *
77nis_sperror_r (const nis_error status, const char *label,
78 char *buffer, size_t buflen)
79{
8e64faef
UD
80 if (snprintf (buffer, buflen, "%s: %s", label, nis_sperrno (status))
81 >= buflen)
e61abf83 82 {
a51752b6 83 __set_errno (ERANGE);
e61abf83
UD
84 return NULL;
85 }
86
8e64faef 87 return buffer;
e61abf83 88}
7440c23e 89libnsl_hidden_def (nis_sperror_r)
e61abf83
UD
90
91char *
92nis_sperror (const nis_error status, const char *label)
93{
8e64faef 94 static char buffer[NIS_MAXNAMELEN + 1];
e61abf83
UD
95
96 return nis_sperror_r (status, label, buffer, sizeof (buffer));
97}