err.c revision 1.9 1 1.9 jtc /*-
2 1.9 jtc * Copyright (c) 1993
3 1.9 jtc * The Regents of the University of California. All rights reserved.
4 1.1 glass *
5 1.1 glass * Redistribution and use in source and binary forms, with or without
6 1.1 glass * modification, are permitted provided that the following conditions
7 1.1 glass * are met:
8 1.1 glass * 1. Redistributions of source code must retain the above copyright
9 1.1 glass * notice, this list of conditions and the following disclaimer.
10 1.1 glass * 2. Redistributions in binary form must reproduce the above copyright
11 1.1 glass * notice, this list of conditions and the following disclaimer in the
12 1.1 glass * documentation and/or other materials provided with the distribution.
13 1.1 glass * 3. All advertising materials mentioning features or use of this software
14 1.1 glass * must display the following acknowledgement:
15 1.9 jtc * This product includes software developed by the University of
16 1.9 jtc * California, Berkeley and its contributors.
17 1.9 jtc * 4. Neither the name of the University nor the names of its contributors
18 1.9 jtc * may be used to endorse or promote products derived from this software
19 1.9 jtc * without specific prior written permission.
20 1.1 glass *
21 1.9 jtc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 1.9 jtc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 1.9 jtc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 1.9 jtc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 1.9 jtc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 1.1 glass * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 1.1 glass * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 1.1 glass * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 1.1 glass * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 1.1 glass * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 1.1 glass * SUCH DAMAGE.
32 1.1 glass */
33 1.1 glass
34 1.9 jtc #if defined(LIBC_SCCS) && !defined(lint)
35 1.9 jtc /* from: static char sccsid[] = "@(#)err.c 8.1 (Berkeley) 6/4/93"; */
36 1.9 jtc static char *rcsid = "$Id: err.c,v 1.9 1994/12/12 22:42:06 jtc Exp $";
37 1.9 jtc #endif /* LIBC_SCCS and not lint */
38 1.9 jtc
39 1.9 jtc #include <err.h>
40 1.9 jtc #include <errno.h>
41 1.9 jtc #include <stdio.h>
42 1.9 jtc #include <stdlib.h>
43 1.9 jtc #include <string.h>
44 1.1 glass
45 1.9 jtc #ifdef __STDC__
46 1.9 jtc #include <stdarg.h>
47 1.9 jtc #else
48 1.9 jtc #include <varargs.h>
49 1.9 jtc #endif
50 1.9 jtc
51 1.9 jtc extern char *__progname; /* Program name, from crt0. */
52 1.9 jtc
53 1.9 jtc __dead void
54 1.9 jtc _verr(eval, fmt, ap)
55 1.9 jtc int eval;
56 1.9 jtc const char *fmt;
57 1.9 jtc va_list ap;
58 1.9 jtc {
59 1.9 jtc int sverrno;
60 1.9 jtc
61 1.9 jtc sverrno = errno;
62 1.9 jtc (void)fprintf(stderr, "%s: ", __progname);
63 1.9 jtc if (fmt != NULL) {
64 1.9 jtc (void)vfprintf(stderr, fmt, ap);
65 1.9 jtc (void)fprintf(stderr, ": ");
66 1.9 jtc }
67 1.9 jtc (void)fprintf(stderr, "%s\n", strerror(sverrno));
68 1.9 jtc exit(eval);
69 1.9 jtc }
70 1.9 jtc
71 1.9 jtc
72 1.9 jtc __dead void
73 1.9 jtc #ifdef __STDC__
74 1.9 jtc _err(int eval, const char *fmt, ...)
75 1.9 jtc #else
76 1.9 jtc _err(va_alist)
77 1.9 jtc va_dcl
78 1.9 jtc #endif
79 1.9 jtc {
80 1.9 jtc va_list ap;
81 1.9 jtc #if __STDC__
82 1.9 jtc va_start(ap, fmt);
83 1.9 jtc #else
84 1.9 jtc int eval;
85 1.9 jtc const char *fmt;
86 1.9 jtc
87 1.9 jtc va_start(ap);
88 1.9 jtc eval = va_arg(ap, int);
89 1.9 jtc fmt = va_arg(ap, const char *);
90 1.9 jtc #endif
91 1.9 jtc __verr(eval, fmt, ap);
92 1.9 jtc va_end(ap);
93 1.9 jtc }
94 1.9 jtc
95 1.9 jtc
96 1.9 jtc __dead void
97 1.9 jtc _verrx(eval, fmt, ap)
98 1.9 jtc int eval;
99 1.9 jtc const char *fmt;
100 1.9 jtc va_list ap;
101 1.9 jtc {
102 1.9 jtc (void)fprintf(stderr, "%s: ", __progname);
103 1.9 jtc if (fmt != NULL)
104 1.9 jtc (void)vfprintf(stderr, fmt, ap);
105 1.9 jtc (void)fprintf(stderr, "\n");
106 1.9 jtc exit(eval);
107 1.9 jtc }
108 1.9 jtc
109 1.9 jtc
110 1.9 jtc __dead void
111 1.9 jtc #if __STDC__
112 1.9 jtc _errx(int eval, const char *fmt, ...)
113 1.9 jtc #else
114 1.9 jtc _errx(va_alist)
115 1.9 jtc va_dcl
116 1.9 jtc #endif
117 1.9 jtc {
118 1.9 jtc va_list ap;
119 1.9 jtc #if __STDC__
120 1.9 jtc va_start(ap, fmt);
121 1.9 jtc #else
122 1.9 jtc int eval;
123 1.9 jtc const char *fmt;
124 1.8 christos
125 1.9 jtc va_start(ap);
126 1.9 jtc eval = va_arg(ap, int);
127 1.9 jtc fmt = va_arg(ap, const char *);
128 1.9 jtc #endif
129 1.9 jtc __verrx(eval, fmt, ap);
130 1.9 jtc va_end(ap);
131 1.9 jtc }
132 1.9 jtc
133 1.9 jtc
134 1.9 jtc void
135 1.9 jtc _vwarn(fmt, ap)
136 1.9 jtc const char *fmt;
137 1.9 jtc va_list ap;
138 1.9 jtc {
139 1.9 jtc int sverrno;
140 1.9 jtc
141 1.9 jtc sverrno = errno;
142 1.9 jtc (void)fprintf(stderr, "%s: ", __progname);
143 1.9 jtc if (fmt != NULL) {
144 1.9 jtc (void)vfprintf(stderr, fmt, ap);
145 1.9 jtc (void)fprintf(stderr, ": ");
146 1.9 jtc }
147 1.9 jtc (void)fprintf(stderr, "%s\n", strerror(sverrno));
148 1.9 jtc }
149 1.9 jtc
150 1.9 jtc
151 1.9 jtc void
152 1.9 jtc #if __STDC__
153 1.9 jtc _warn(const char *fmt, ...)
154 1.9 jtc #else
155 1.9 jtc _warn(va_alist)
156 1.9 jtc va_dcl
157 1.9 jtc #endif
158 1.9 jtc {
159 1.9 jtc va_list ap;
160 1.9 jtc #if __STDC__
161 1.9 jtc va_start(ap, fmt);
162 1.9 jtc #else
163 1.9 jtc const char *fmt;
164 1.1 glass
165 1.9 jtc va_start(ap);
166 1.9 jtc fmt = va_arg(ap, const char *);
167 1.9 jtc #endif
168 1.9 jtc __vwarn(fmt, ap);
169 1.9 jtc va_end(ap);
170 1.9 jtc }
171 1.9 jtc
172 1.9 jtc
173 1.9 jtc void
174 1.9 jtc _vwarnx(fmt, ap)
175 1.9 jtc const char *fmt;
176 1.9 jtc va_list ap;
177 1.9 jtc {
178 1.9 jtc (void)fprintf(stderr, "%s: ", __progname);
179 1.9 jtc if (fmt != NULL)
180 1.9 jtc (void)vfprintf(stderr, fmt, ap);
181 1.9 jtc (void)fprintf(stderr, "\n");
182 1.9 jtc }
183 1.9 jtc
184 1.9 jtc
185 1.9 jtc void
186 1.9 jtc #ifdef __STDC__
187 1.9 jtc _warnx(const char *fmt, ...)
188 1.9 jtc #else
189 1.9 jtc _warnx(va_alist)
190 1.9 jtc va_dcl
191 1.9 jtc #endif
192 1.9 jtc {
193 1.9 jtc va_list ap;
194 1.9 jtc #ifdef __STDC__
195 1.9 jtc va_start(ap, fmt);
196 1.9 jtc #else
197 1.9 jtc const char *fmt;
198 1.1 glass
199 1.9 jtc va_start(ap);
200 1.9 jtc fmt = va_arg(ap, const char *);
201 1.1 glass #endif
202 1.9 jtc __vwarnx(fmt, ap);
203 1.9 jtc va_end(ap);
204 1.9 jtc }
205