1*c2c66affSColin Finck /*-
2*c2c66affSColin Finck * Copyright (c) 1993
3*c2c66affSColin Finck * The Regents of the University of California. All rights reserved.
4*c2c66affSColin Finck *
5*c2c66affSColin Finck * Redistribution and use in source and binary forms, with or without
6*c2c66affSColin Finck * modification, are permitted provided that the following conditions
7*c2c66affSColin Finck * are met:
8*c2c66affSColin Finck * 1. Redistributions of source code must retain the above copyright
9*c2c66affSColin Finck * notice, this list of conditions and the following disclaimer.
10*c2c66affSColin Finck * 2. Redistributions in binary form must reproduce the above copyright
11*c2c66affSColin Finck * notice, this list of conditions and the following disclaimer in the
12*c2c66affSColin Finck * documentation and/or other materials provided with the distribution.
13*c2c66affSColin Finck * 3. All advertising materials mentioning features or use of this software
14*c2c66affSColin Finck * must display the following acknowledgement:
15*c2c66affSColin Finck * This product includes software developed by the University of
16*c2c66affSColin Finck * California, Berkeley and its contributors.
17*c2c66affSColin Finck * 4. Neither the name of the University nor the names of its contributors
18*c2c66affSColin Finck * may be used to endorse or promote products derived from this software
19*c2c66affSColin Finck * without specific prior written permission.
20*c2c66affSColin Finck *
21*c2c66affSColin Finck * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22*c2c66affSColin Finck * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23*c2c66affSColin Finck * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24*c2c66affSColin Finck * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25*c2c66affSColin Finck * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26*c2c66affSColin Finck * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27*c2c66affSColin Finck * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28*c2c66affSColin Finck * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29*c2c66affSColin Finck * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30*c2c66affSColin Finck * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31*c2c66affSColin Finck * SUCH DAMAGE.
32*c2c66affSColin Finck */
33*c2c66affSColin Finck
34*c2c66affSColin Finck #include "precomp.h"
35*c2c66affSColin Finck
36*c2c66affSColin Finck #if defined(LIBC_SCCS) && !defined(lint)
37*c2c66affSColin Finck static char sccsid[] = "@(#)err.c 8.1 (Berkeley) 6/4/93";
38*c2c66affSColin Finck #endif /* LIBC_SCCS and not lint */
39*c2c66affSColin Finck
40*c2c66affSColin Finck extern char *__progname; /* Program name, from crt0. */
41*c2c66affSColin Finck
42*c2c66affSColin Finck void
err(int eval,const char * fmt,...)43*c2c66affSColin Finck err(int eval, const char *fmt, ...)
44*c2c66affSColin Finck {
45*c2c66affSColin Finck va_list ap;
46*c2c66affSColin Finck va_start(ap, fmt);
47*c2c66affSColin Finck verr(eval, fmt, ap);
48*c2c66affSColin Finck va_end(ap);
49*c2c66affSColin Finck }
50*c2c66affSColin Finck
51*c2c66affSColin Finck void
verr(int eval,const char * fmt,va_list ap)52*c2c66affSColin Finck verr(int eval, const char *fmt, va_list ap)
53*c2c66affSColin Finck {
54*c2c66affSColin Finck int sverrno;
55*c2c66affSColin Finck
56*c2c66affSColin Finck sverrno = errno;
57*c2c66affSColin Finck (void)fprintf(stderr, "%s: ", __progname);
58*c2c66affSColin Finck if (fmt != NULL) {
59*c2c66affSColin Finck (void)vfprintf(stderr, fmt, ap);
60*c2c66affSColin Finck (void)fprintf(stderr, ": ");
61*c2c66affSColin Finck }
62*c2c66affSColin Finck (void)fprintf(stderr, "%s\n", strerror(sverrno));
63*c2c66affSColin Finck exit(eval);
64*c2c66affSColin Finck }
65*c2c66affSColin Finck
66*c2c66affSColin Finck void
errx(int eval,const char * fmt,...)67*c2c66affSColin Finck errx(int eval, const char *fmt, ...)
68*c2c66affSColin Finck {
69*c2c66affSColin Finck va_list ap;
70*c2c66affSColin Finck va_start(ap, fmt);
71*c2c66affSColin Finck verrx(eval, fmt, ap);
72*c2c66affSColin Finck va_end(ap);
73*c2c66affSColin Finck }
74*c2c66affSColin Finck
75*c2c66affSColin Finck void
verrx(int eval,const char * fmt,va_list ap)76*c2c66affSColin Finck verrx(int eval, const char *fmt, va_list ap)
77*c2c66affSColin Finck {
78*c2c66affSColin Finck (void)fprintf(stderr, "%s: ", __progname);
79*c2c66affSColin Finck if (fmt != NULL)
80*c2c66affSColin Finck (void)vfprintf(stderr, fmt, ap);
81*c2c66affSColin Finck (void)fprintf(stderr, "\n");
82*c2c66affSColin Finck exit(eval);
83*c2c66affSColin Finck }
84*c2c66affSColin Finck
85*c2c66affSColin Finck void
warn(const char * fmt,...)86*c2c66affSColin Finck warn(const char *fmt, ...)
87*c2c66affSColin Finck {
88*c2c66affSColin Finck va_list ap;
89*c2c66affSColin Finck va_start(ap, fmt);
90*c2c66affSColin Finck vwarn(fmt, ap);
91*c2c66affSColin Finck va_end(ap);
92*c2c66affSColin Finck }
93*c2c66affSColin Finck
94*c2c66affSColin Finck void
vwarn(fmt,ap)95*c2c66affSColin Finck vwarn(fmt, ap)
96*c2c66affSColin Finck const char *fmt;
97*c2c66affSColin Finck va_list ap;
98*c2c66affSColin Finck {
99*c2c66affSColin Finck int sverrno;
100*c2c66affSColin Finck
101*c2c66affSColin Finck sverrno = errno;
102*c2c66affSColin Finck (void)fprintf(stderr, "%s: ", __progname);
103*c2c66affSColin Finck if (fmt != NULL) {
104*c2c66affSColin Finck (void)vfprintf(stderr, fmt, ap);
105*c2c66affSColin Finck (void)fprintf(stderr, ": ");
106*c2c66affSColin Finck }
107*c2c66affSColin Finck (void)fprintf(stderr, "%s\n", strerror(sverrno));
108*c2c66affSColin Finck }
109*c2c66affSColin Finck
110*c2c66affSColin Finck void
warnx(const char * fmt,...)111*c2c66affSColin Finck warnx(const char *fmt, ...)
112*c2c66affSColin Finck {
113*c2c66affSColin Finck va_list ap;
114*c2c66affSColin Finck va_start(ap, fmt);
115*c2c66affSColin Finck vwarnx(fmt, ap);
116*c2c66affSColin Finck va_end(ap);
117*c2c66affSColin Finck }
118*c2c66affSColin Finck
119*c2c66affSColin Finck void
vwarnx(fmt,ap)120*c2c66affSColin Finck vwarnx(fmt, ap)
121*c2c66affSColin Finck const char *fmt;
122*c2c66affSColin Finck va_list ap;
123*c2c66affSColin Finck {
124*c2c66affSColin Finck (void)fprintf(stderr, "%s: ", __progname);
125*c2c66affSColin Finck if (fmt != NULL)
126*c2c66affSColin Finck (void)vfprintf(stderr, fmt, ap);
127*c2c66affSColin Finck (void)fprintf(stderr, "\n");
128*c2c66affSColin Finck }
129