Blob


1 /*
2 * Copyright (c) 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
30 #include <errno.h>
31 #include <stdarg.h>
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <string.h>
36 void
37 vwarnx(const char *fmt, va_list ap)
38 {
39 fprintf(stderr, "%s: ", getprogname());
40 if (fmt != NULL)
41 vfprintf(stderr, fmt, ap);
42 fprintf(stderr, "\n");
43 }
45 void
46 vwarnc(int code, const char *fmt, va_list ap)
47 {
48 fprintf(stderr, "%s: ", getprogname());
49 if (fmt != NULL) {
50 vfprintf(stderr, fmt, ap);
51 fprintf(stderr, ": ");
52 }
53 fprintf(stderr, "%s\n", strerror(code));
54 }
56 void
57 vwarn(const char *fmt, va_list ap)
58 {
59 int sverrno;
61 sverrno = errno;
62 fprintf(stderr, "%s: ", getprogname());
63 if (fmt != NULL) {
64 vfprintf(stderr, fmt, ap);
65 fprintf(stderr, ": ");
66 }
67 fprintf(stderr, "%s\n", strerror(sverrno));
68 }
70 void
71 verrc(int eval, int code, const char *fmt, va_list ap)
72 {
73 fprintf(stderr, "%s: ", getprogname());
74 if (fmt != NULL) {
75 vfprintf(stderr, fmt, ap);
76 fprintf(stderr, ": ");
77 }
78 fprintf(stderr, "%s\n", strerror(code));
79 exit(eval);
80 }
82 void
83 verrx(int eval, const char *fmt, va_list ap)
84 {
85 fprintf(stderr, "%s: ", getprogname());
86 if (fmt != NULL)
87 vfprintf(stderr, fmt, ap);
88 fprintf(stderr, "\n");
89 exit(eval);
90 }
92 void
93 verr(int eval, const char *fmt, va_list ap)
94 {
95 int sverrno;
97 sverrno = errno;
98 fprintf(stderr, "%s: ", getprogname());
99 if (fmt != NULL) {
100 vfprintf(stderr, fmt, ap);
101 fprintf(stderr, ": ");
103 fprintf(stderr, "%s\n", strerror(sverrno));
104 exit(eval);
107 void
108 err(int eval, const char *fmt, ...)
110 va_list ap;
112 va_start(ap, fmt);
113 verr(eval, fmt, ap);
114 va_end(ap);
117 void
118 errc(int eval, int code, const char *fmt, ...)
120 va_list ap;
122 va_start(ap, fmt);
123 verrc(eval, code, fmt, ap);
124 va_end(ap);
127 void
128 errx(int eval, const char *fmt, ...)
130 va_list ap;
132 va_start(ap, fmt);
133 verrx(eval, fmt, ap);
134 va_end(ap);
137 void
138 warn(const char *fmt, ...)
140 va_list ap;
142 va_start(ap, fmt);
143 vwarn(fmt, ap);
144 va_end(ap);
147 void
148 warnc(int code, const char *fmt, ...)
150 va_list ap;
152 va_start(ap, fmt);
153 vwarnc(code, fmt, ap);
154 va_end(ap);
157 void
158 warnx(const char *fmt, ...)
160 va_list ap;
162 va_start(ap, fmt);
163 vwarnx(fmt, ap);
164 va_end(ap);