xref: /freebsd/contrib/unifdef/FreeBSD/err.c (revision 069ac184)
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  * 4. 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  */
29 
30 #include "unifdef.h"
31 
32 void
33 err(int eval, const char *fmt, ...)
34 {
35 	va_list ap;
36 	va_start(ap, fmt);
37 	verrc(eval, errno, fmt, ap);
38 	va_end(ap);
39 }
40 
41 void
42 verr(int eval, const char *fmt, va_list ap)
43 {
44 	verrc(eval, errno, fmt, ap);
45 }
46 
47 void
48 errc(int eval, int code, const char *fmt, ...)
49 {
50 	va_list ap;
51 	va_start(ap, fmt);
52 	verrc(eval, code, fmt, ap);
53 	va_end(ap);
54 }
55 
56 void
57 verrc(int eval, int code, const char *fmt, va_list ap)
58 {
59 	fprintf(stderr, "%s: ", _getprogname());
60 	if (fmt != NULL) {
61 		vfprintf(stderr, fmt, ap);
62 		fprintf(stderr, ": ");
63 	}
64 	fprintf(stderr, "%s\n", strerror(code));
65 	exit(eval);
66 }
67 
68 void
69 errx(int eval, const char *fmt, ...)
70 {
71 	va_list ap;
72 	va_start(ap, fmt);
73 	verrx(eval, fmt, ap);
74 	va_end(ap);
75 }
76 
77 void
78 verrx(int eval, const char *fmt, va_list ap)
79 {
80 	fprintf(stderr, "%s: ", _getprogname());
81 	if (fmt != NULL)
82 		vfprintf(stderr, fmt, ap);
83 	fprintf(stderr, "\n");
84 	exit(eval);
85 }
86 
87 void
88 warn(const char *fmt, ...)
89 {
90 	va_list ap;
91 	va_start(ap, fmt);
92 	vwarnc(errno, fmt, ap);
93 	va_end(ap);
94 }
95 
96 void
97 vwarn(const char *fmt, va_list ap)
98 {
99 	vwarnc(errno, fmt, ap);
100 }
101 
102 void
103 warnc(int code, const char *fmt, ...)
104 {
105 	va_list ap;
106 	va_start(ap, fmt);
107 	vwarnc(code, fmt, ap);
108 	va_end(ap);
109 }
110 
111 void
112 vwarnc(int code, const char *fmt, va_list ap)
113 {
114 	fprintf(stderr, "%s: ", _getprogname());
115 	if (fmt != NULL) {
116 		vfprintf(stderr, fmt, ap);
117 		fprintf(stderr, ": ");
118 	}
119 	fprintf(stderr, "%s\n", strerror(code));
120 }
121 
122 void
123 warnx(const char *fmt, ...)
124 {
125 	va_list ap;
126 	va_start(ap, fmt);
127 	vwarnx(fmt, ap);
128 	va_end(ap);
129 }
130 
131 void
132 vwarnx(const char *fmt, va_list ap)
133 {
134 	fprintf(stderr, "%s: ", _getprogname());
135 	if (fmt != NULL)
136 		vfprintf(stderr, fmt, ap);
137 	fprintf(stderr, "\n");
138 }
139