]> git.wh0rd.org - dump.git/blame - compat/lib/err.c
Version 0.4b5.
[dump.git] / compat / lib / err.c
CommitLineData
1227625a
SP
1/*
2 * Ported to Linux's Second Extended File System as part of the
3 * dump and restore backup suit
b45f51d6
SP
4 * Remy Card <card@Linux.EU.Org>, 1994-1997
5 * Stelian Pop <pop@cybercable.fr>, 1999
1227625a
SP
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.
b45f51d6 40 * From: @(#)err.c 8.1 (Berkeley) 6/4/93
1227625a
SP
41 */
42
b45f51d6
SP
43#if defined(LIBC_RCS) && !defined(lint)
44static 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 */
1227625a
SP
47
48#include <err.h>
49#include <errno.h>
50#include <stdio.h>
51#include <stdlib.h>
52#include <string.h>
53
1227625a 54#include <stdarg.h>
1227625a
SP
55
56#include <config.h>
57
58extern char *__progname; /* Program name, from crt0. */
59
b45f51d6
SP
60static FILE *err_file; /* file to use for error output */
61static 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 */
68void
69err_set_file(void *fp)
70{
71 if (fp)
72 err_file = fp;
73 else
74 err_file = stderr;
75}
76
77void
78err_set_exit(void (*ef)(int))
79{
80 err_exit = ef;
81}
82
83
1227625a
SP
84#ifndef HAVE_ERR
85__dead void
1227625a 86err(int eval, const char *fmt, ...)
1227625a
SP
87{
88 va_list ap;
1227625a 89 va_start(ap, fmt);
b45f51d6 90 verrc(eval, errno, fmt, ap);
1227625a
SP
91 va_end(ap);
92}
93#endif
94
95#ifndef HAVE_VERR
96__dead void
97verr(eval, fmt, ap)
98 int eval;
99 const char *fmt;
100 va_list ap;
101{
b45f51d6
SP
102 verrc(eval, errno, fmt, ap);
103}
104#endif
105
106#ifndef HAVE_ERRC
107__dead void
108errc(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
1227625a 116
b45f51d6
SP
117#ifndef HAVE_VERRC
118__dead void
119verrc(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);
1227625a 128 if (fmt != NULL) {
b45f51d6
SP
129 vfprintf(err_file, fmt, ap);
130 fprintf(err_file, ": ");
1227625a 131 }
b45f51d6
SP
132 fprintf(err_file, "%s\n", strerror(code));
133 if (err_exit)
134 err_exit(eval);
1227625a
SP
135 exit(eval);
136}
137#endif
138
139#ifndef HAVE_ERRX
140__dead void
1227625a 141errx(int eval, const char *fmt, ...)
1227625a
SP
142{
143 va_list ap;
1227625a 144 va_start(ap, fmt);
1227625a
SP
145 verrx(eval, fmt, ap);
146 va_end(ap);
147}
148#endif
149
150#ifndef HAVE_VERRX
151__dead void
152verrx(eval, fmt, ap)
153 int eval;
154 const char *fmt;
155 va_list ap;
156{
b45f51d6
SP
157 if (err_file == 0)
158 err_set_file((FILE *)0);
159 fprintf(err_file, "%s: ", __progname);
1227625a 160 if (fmt != NULL)
b45f51d6
SP
161 vfprintf(err_file, fmt, ap);
162 fprintf(err_file, "\n");
163 if (err_exit)
164 err_exit(eval);
1227625a
SP
165 exit(eval);
166}
167#endif
168
169#ifndef HAVE_WARN
170void
1227625a 171warn(const char *fmt, ...)
1227625a
SP
172{
173 va_list ap;
1227625a 174 va_start(ap, fmt);
b45f51d6 175 vwarnc(errno, fmt, ap);
1227625a
SP
176 va_end(ap);
177}
178#endif
179
180#ifndef HAVE_VWARN
181void
182vwarn(fmt, ap)
183 const char *fmt;
184 va_list ap;
185{
b45f51d6
SP
186 vwarnc(errno, fmt, ap);
187}
188#endif
189
190#ifndef HAVE_WARNC
191void
192warnc(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
1227625a 200
b45f51d6
SP
201#ifndef HAVE_VWARNC
202void
203vwarnc(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);
1227625a 211 if (fmt != NULL) {
b45f51d6
SP
212 vfprintf(err_file, fmt, ap);
213 fprintf(err_file, ": ");
1227625a 214 }
b45f51d6 215 fprintf(err_file, "%s\n", strerror(code));
1227625a
SP
216}
217#endif
218
219#ifndef HAVE_WARNX
220void
1227625a 221warnx(const char *fmt, ...)
1227625a
SP
222{
223 va_list ap;
1227625a 224 va_start(ap, fmt);
1227625a
SP
225 vwarnx(fmt, ap);
226 va_end(ap);
227}
228#endif
229
230#ifndef HAVE_VWARNX
231void
232vwarnx(fmt, ap)
233 const char *fmt;
234 va_list ap;
235{
b45f51d6
SP
236 if (err_file == 0)
237 err_set_file((FILE *)0);
238 fprintf(err_file, "%s: ", __progname);
1227625a 239 if (fmt != NULL)
b45f51d6
SP
240 vfprintf(err_file, fmt, ap);
241 fprintf(err_file, "\n");
1227625a
SP
242}
243#endif