4.4BSD snapshot (revision 8.1)
[unix-history] / usr / src / lib / libc / gen / err.c
CommitLineData
c886b408 1/*-
74155b62
KB
2 * Copyright (c) 1993
3 * The Regents of the University of California. All rights reserved.
c886b408
KB
4 *
5 * %sccs.include.redist.c%
6 */
7
8#if defined(LIBC_SCCS) && !defined(lint)
74155b62 9static char sccsid[] = "@(#)err.c 8.1 (Berkeley) %G%";
c886b408
KB
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
24extern char *__progname; /* Program name, from crt0. */
25
26__dead void
27#ifdef __STDC__
28err(int eval, const char *fmt, ...)
29#else
30err(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
47verr(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);
5d4306e6
KB
56 if (fmt != NULL) {
57 (void)vfprintf(stderr, fmt, ap);
58 (void)fprintf(stderr, ": ");
59 }
60 (void)fprintf(stderr, "%s\n", strerror(sverrno));
c886b408
KB
61 exit(eval);
62}
63
64__dead void
65#if __STDC__
66errx(int eval, const char *fmt, ...)
67#else
68errx(eval, fmt, va_alist)
69 int eval;
70 const char *fmt;
71 va_dcl
72#endif
73{
74 va_list ap;
75#if __STDC__
76 va_start(ap, fmt);
77#else
78 va_start(ap);
79#endif
80 verrx(eval, fmt, ap);
81 va_end(ap);
82}
83
84__dead void
85verrx(eval, fmt, ap)
86 int eval;
87 const char *fmt;
88 va_list ap;
89{
90 (void)fprintf(stderr, "%s: ", __progname);
5d4306e6
KB
91 if (fmt != NULL)
92 (void)vfprintf(stderr, fmt, ap);
c886b408
KB
93 (void)fprintf(stderr, "\n");
94 exit(eval);
95}
96
97void
98#if __STDC__
99warn(const char *fmt, ...)
100#else
101warn(fmt, va_alist)
c886b408
KB
102 const char *fmt;
103 va_dcl
104#endif
105{
106 va_list ap;
107#if __STDC__
108 va_start(ap, fmt);
109#else
110 va_start(ap);
111#endif
112 vwarn(fmt, ap);
113 va_end(ap);
114}
115
116void
117vwarn(fmt, ap)
118 const char *fmt;
119 va_list ap;
120{
121 int sverrno;
122
123 sverrno = errno;
124 (void)fprintf(stderr, "%s: ", __progname);
5d4306e6
KB
125 if (fmt != NULL) {
126 (void)vfprintf(stderr, fmt, ap);
127 (void)fprintf(stderr, ": ");
128 }
129 (void)fprintf(stderr, "%s\n", strerror(sverrno));
c886b408
KB
130}
131
132void
133#ifdef __STDC__
134warnx(const char *fmt, ...)
135#else
136warnx(fmt, va_alist)
c886b408
KB
137 const char *fmt;
138 va_dcl
139#endif
140{
141 va_list ap;
142#ifdef __STDC__
143 va_start(ap, fmt);
144#else
145 va_start(ap);
146#endif
147 vwarnx(fmt, ap);
148 va_end(ap);
149}
150
151void
152vwarnx(fmt, ap)
153 const char *fmt;
154 va_list ap;
155{
156 (void)fprintf(stderr, "%s: ", __progname);
5d4306e6
KB
157 if (fmt != NULL)
158 (void)vfprintf(stderr, fmt, ap);
c886b408
KB
159 (void)fprintf(stderr, "\n");
160}