1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20: #include <errno.h>
21: #include <syslog.h>
22: #include <string.h>
23: #include <libintl.h>
24: #include <rpcsvc/nis.h>
25:
26:
27: #define MF(line) MF1 (line)
28: #define MF1(line) str##line
29: static const union msgstr_t
30: {
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:
47: static 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:
54:
55: const char *
56: nis_sperrno (const nis_error status)
57: {
58: if (status >= sizeof (msgidx) / sizeof (msgidx[0]))
59: return "???";
60: else
61: return gettext (msgstr.str + msgidx[status]);
62: }
63: libnsl_hidden_def (nis_sperrno)
64:
65: void
66: nis_perror (const nis_error status, const char *label)
67: {
68: fprintf (stderr, "%s: %s\n", label, nis_sperrno (status));
69: }
70:
71: void
72: nis_lerror (const nis_error status, const char *label)
73: {
74: syslog (LOG_ERR, "%s: %s", label, nis_sperrno (status));
75: }
76:
77: char *
78: nis_sperror_r (const nis_error status, const char *label,
79: char *buffer, size_t buflen)
80: {
81: if (snprintf (buffer, buflen, "%s: %s", label, nis_sperrno (status))
82: >= buflen)
83: {
84: __set_errno (ERANGE);
85: return NULL;
86: }
87:
88: return buffer;
89: }
90: libnsl_hidden_def (nis_sperror_r)
91:
92: char *
93: nis_sperror (const nis_error status, const char *label)
94: {
95: static char buffer[NIS_MAXNAMELEN + 1];
96:
97: return nis_sperror_r (status, label, buffer, sizeof (buffer));
98: }