xref: /original-bsd/lib/libc/gen/err.c (revision 4670e840)
1 /*-
2  * Copyright (c) 1993 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #if defined(LIBC_SCCS) && !defined(lint)
9 static char sccsid[] = "@(#)err.c	5.1 (Berkeley) 03/04/93";
10 #endif /* LIBC_SCCS and not lint */
11 
12 #include <err.h>
13 #include <errno.h>
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <string.h>
17 
18 #ifdef __STDC__
19 #include <stdarg.h>
20 #else
21 #include <varargs.h>
22 #endif
23 
24 extern char *__progname;		/* Program name, from crt0. */
25 
26 __dead void
27 #ifdef __STDC__
28 err(int eval, const char *fmt, ...)
29 #else
30 err(eval, fmt, va_alist)
31 	int eval;
32 	const char *fmt;
33 	va_dcl
34 #endif
35 {
36 	va_list ap;
37 #if __STDC__
38 	va_start(ap, fmt);
39 #else
40 	va_start(ap);
41 #endif
42 	verr(eval, fmt, ap);
43 	va_end(ap);
44 }
45 
46 __dead void
47 verr(eval, fmt, ap)
48 	int eval;
49 	const char *fmt;
50 	va_list ap;
51 {
52 	int sverrno;
53 
54 	sverrno = errno;
55 	(void)fprintf(stderr, "%s: ", __progname);
56 	(void)vfprintf(stderr, fmt, ap);
57 	(void)fprintf(stderr, ": %s\n", strerror(sverrno));
58 	exit(eval);
59 }
60 
61 __dead void
62 #if __STDC__
63 errx(int eval, const char *fmt, ...)
64 #else
65 errx(eval, fmt, va_alist)
66 	int eval;
67 	const char *fmt;
68 	va_dcl
69 #endif
70 {
71 	va_list ap;
72 #if __STDC__
73 	va_start(ap, fmt);
74 #else
75 	va_start(ap);
76 #endif
77 	verrx(eval, fmt, ap);
78 	va_end(ap);
79 }
80 
81 __dead void
82 verrx(eval, fmt, ap)
83 	int eval;
84 	const char *fmt;
85 	va_list ap;
86 {
87 	(void)fprintf(stderr, "%s: ", __progname);
88 	(void)vfprintf(stderr, fmt, ap);
89 	(void)fprintf(stderr, "\n");
90 	exit(eval);
91 }
92 
93 void
94 #if __STDC__
95 warn(const char *fmt, ...)
96 #else
97 warn(fmt, va_alist)
98 	int eval;
99 	const char *fmt;
100 	va_dcl
101 #endif
102 {
103 	va_list ap;
104 #if __STDC__
105 	va_start(ap, fmt);
106 #else
107 	va_start(ap);
108 #endif
109 	vwarn(fmt, ap);
110 	va_end(ap);
111 }
112 
113 void
114 vwarn(fmt, ap)
115 	const char *fmt;
116 	va_list ap;
117 {
118 	int sverrno;
119 
120 	sverrno = errno;
121 	(void)fprintf(stderr, "%s: ", __progname);
122 	(void)vfprintf(stderr, fmt, ap);
123 	(void)fprintf(stderr, ": %s\n", strerror(sverrno));
124 }
125 
126 void
127 #ifdef __STDC__
128 warnx(const char *fmt, ...)
129 #else
130 warnx(fmt, va_alist)
131 	int eval;
132 	const char *fmt;
133 	va_dcl
134 #endif
135 {
136 	va_list ap;
137 #ifdef __STDC__
138 	va_start(ap, fmt);
139 #else
140 	va_start(ap);
141 #endif
142 	vwarnx(fmt, ap);
143 	va_end(ap);
144 }
145 
146 void
147 vwarnx(fmt, ap)
148 	const char *fmt;
149 	va_list ap;
150 {
151 	(void)fprintf(stderr, "%s: ", __progname);
152 	(void)vfprintf(stderr, fmt, ap);
153 	(void)fprintf(stderr, "\n");
154 }
155