]> git.wh0rd.org - dump.git/blob - compat/lib/err.c
Version 0.4b5.
[dump.git] / compat / lib / err.c
1 /*
2 * Ported to Linux's Second Extended File System as part of the
3 * dump and restore backup suit
4 * Remy Card <card@Linux.EU.Org>, 1994-1997
5 * Stelian Pop <pop@cybercable.fr>, 1999
6 *
7 */
8
9 /*-
10 * Copyright (c) 1993
11 * The Regents of the University of California. All rights reserved.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. All advertising materials mentioning features or use of this software
22 * must display the following acknowledgement:
23 * This product includes software developed by the University of
24 * California, Berkeley and its contributors.
25 * 4. Neither the name of the University nor the names of its contributors
26 * may be used to endorse or promote products derived from this software
27 * without specific prior written permission.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
30 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
33 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 * SUCH DAMAGE.
40 * From: @(#)err.c 8.1 (Berkeley) 6/4/93
41 */
42
43 #if defined(LIBC_RCS) && !defined(lint)
44 static const char rcsid[] =
45 "$Id: err.c,v 1.2 1999/10/11 12:53:21 stelian Exp $";
46 #endif /* LIBC_RCS and not lint */
47
48 #include <err.h>
49 #include <errno.h>
50 #include <stdio.h>
51 #include <stdlib.h>
52 #include <string.h>
53
54 #include <stdarg.h>
55
56 #include <config.h>
57
58 extern char *__progname; /* Program name, from crt0. */
59
60 static FILE *err_file; /* file to use for error output */
61 static void (*err_exit)(int);
62
63 /*
64 * This is declared to take a `void *' so that the caller is not required
65 * to include <stdio.h> first. However, it is really a `FILE *', and the
66 * manual page documents it as such.
67 */
68 void
69 err_set_file(void *fp)
70 {
71 if (fp)
72 err_file = fp;
73 else
74 err_file = stderr;
75 }
76
77 void
78 err_set_exit(void (*ef)(int))
79 {
80 err_exit = ef;
81 }
82
83
84 #ifndef HAVE_ERR
85 __dead void
86 err(int eval, const char *fmt, ...)
87 {
88 va_list ap;
89 va_start(ap, fmt);
90 verrc(eval, errno, fmt, ap);
91 va_end(ap);
92 }
93 #endif
94
95 #ifndef HAVE_VERR
96 __dead void
97 verr(eval, fmt, ap)
98 int eval;
99 const char *fmt;
100 va_list ap;
101 {
102 verrc(eval, errno, fmt, ap);
103 }
104 #endif
105
106 #ifndef HAVE_ERRC
107 __dead void
108 errc(int eval, int code, const char *fmt, ...)
109 {
110 va_list ap;
111 va_start(ap, fmt);
112 verrc(eval, code, fmt, ap);
113 va_end(ap);
114 }
115 #endif
116
117 #ifndef HAVE_VERRC
118 __dead void
119 verrc(eval, code, fmt, ap)
120 int eval;
121 int code;
122 const char *fmt;
123 va_list ap;
124 {
125 if (err_file == 0)
126 err_set_file((FILE *)0);
127 fprintf(err_file, "%s: ", __progname);
128 if (fmt != NULL) {
129 vfprintf(err_file, fmt, ap);
130 fprintf(err_file, ": ");
131 }
132 fprintf(err_file, "%s\n", strerror(code));
133 if (err_exit)
134 err_exit(eval);
135 exit(eval);
136 }
137 #endif
138
139 #ifndef HAVE_ERRX
140 __dead void
141 errx(int eval, const char *fmt, ...)
142 {
143 va_list ap;
144 va_start(ap, fmt);
145 verrx(eval, fmt, ap);
146 va_end(ap);
147 }
148 #endif
149
150 #ifndef HAVE_VERRX
151 __dead void
152 verrx(eval, fmt, ap)
153 int eval;
154 const char *fmt;
155 va_list ap;
156 {
157 if (err_file == 0)
158 err_set_file((FILE *)0);
159 fprintf(err_file, "%s: ", __progname);
160 if (fmt != NULL)
161 vfprintf(err_file, fmt, ap);
162 fprintf(err_file, "\n");
163 if (err_exit)
164 err_exit(eval);
165 exit(eval);
166 }
167 #endif
168
169 #ifndef HAVE_WARN
170 void
171 warn(const char *fmt, ...)
172 {
173 va_list ap;
174 va_start(ap, fmt);
175 vwarnc(errno, fmt, ap);
176 va_end(ap);
177 }
178 #endif
179
180 #ifndef HAVE_VWARN
181 void
182 vwarn(fmt, ap)
183 const char *fmt;
184 va_list ap;
185 {
186 vwarnc(errno, fmt, ap);
187 }
188 #endif
189
190 #ifndef HAVE_WARNC
191 void
192 warnc(int code, const char *fmt, ...)
193 {
194 va_list ap;
195 va_start(ap, fmt);
196 vwarnc(code, fmt, ap);
197 va_end(ap);
198 }
199 #endif
200
201 #ifndef HAVE_VWARNC
202 void
203 vwarnc(code, fmt, ap)
204 int code;
205 const char *fmt;
206 va_list ap;
207 {
208 if (err_file == 0)
209 err_set_file((FILE *)0);
210 fprintf(err_file, "%s: ", __progname);
211 if (fmt != NULL) {
212 vfprintf(err_file, fmt, ap);
213 fprintf(err_file, ": ");
214 }
215 fprintf(err_file, "%s\n", strerror(code));
216 }
217 #endif
218
219 #ifndef HAVE_WARNX
220 void
221 warnx(const char *fmt, ...)
222 {
223 va_list ap;
224 va_start(ap, fmt);
225 vwarnx(fmt, ap);
226 va_end(ap);
227 }
228 #endif
229
230 #ifndef HAVE_VWARNX
231 void
232 vwarnx(fmt, ap)
233 const char *fmt;
234 va_list ap;
235 {
236 if (err_file == 0)
237 err_set_file((FILE *)0);
238 fprintf(err_file, "%s: ", __progname);
239 if (fmt != NULL)
240 vfprintf(err_file, fmt, ap);
241 fprintf(err_file, "\n");
242 }
243 #endif