Add diclaimer of copyright to _osname() manual page.
[unix-history] / usr.bin / vi / clib / err.c
CommitLineData
1e64b3ba
JH
1#include <sys/cdefs.h>
2
3#include <err.h>
4#include <errno.h>
5#include <stdio.h>
6#include <stdlib.h>
7#include <string.h>
8
9#ifdef __STDC__
10#include <stdarg.h>
11#else
12#include <varargs.h>
13#endif
14
15char *__progname = "nvi"; /* Program name, from crt0. */
16
17void
18#ifdef __STDC__
19err(int eval, const char *fmt, ...)
20#else
21err(eval, fmt, va_alist)
22 int eval;
23 const char *fmt;
24 va_dcl
25#endif
26{
27 va_list ap;
28#ifdef __STDC__
29 va_start(ap, fmt);
30#else
31 va_start(ap);
32#endif
33 verr(eval, fmt, ap);
34 va_end(ap);
35}
36
37void
38verr(eval, fmt, ap)
39 int eval;
40 const char *fmt;
41 va_list ap;
42{
43 int sverrno;
44
45 sverrno = errno;
46 (void)fprintf(stderr, "%s: ", __progname);
47 if (fmt != NULL) {
48 (void)vfprintf(stderr, fmt, ap);
49 (void)fprintf(stderr, ": ");
50 }
51 (void)fprintf(stderr, "%s\n", strerror(sverrno));
52 exit(eval);
53}
54
55void
56#ifdef __STDC__
57errx(int eval, const char *fmt, ...)
58#else
59errx(eval, fmt, va_alist)
60 int eval;
61 const char *fmt;
62 va_dcl
63#endif
64{
65 va_list ap;
66#ifdef __STDC__
67 va_start(ap, fmt);
68#else
69 va_start(ap);
70#endif
71 verrx(eval, fmt, ap);
72 va_end(ap);
73}
74
75void
76verrx(eval, fmt, ap)
77 int eval;
78 const char *fmt;
79 va_list ap;
80{
81 (void)fprintf(stderr, "%s: ", __progname);
82 if (fmt != NULL)
83 (void)vfprintf(stderr, fmt, ap);
84 (void)fprintf(stderr, "\n");
85 exit(eval);
86}
87
88void
89#ifdef __STDC__
90warn(const char *fmt, ...)
91#else
92warn(fmt, va_alist)
93 const char *fmt;
94 va_dcl
95#endif
96{
97 va_list ap;
98#ifdef __STDC__
99 va_start(ap, fmt);
100#else
101 va_start(ap);
102#endif
103 vwarn(fmt, ap);
104 va_end(ap);
105}
106
107void
108vwarn(fmt, ap)
109 const char *fmt;
110 va_list ap;
111{
112 int sverrno;
113
114 sverrno = errno;
115 (void)fprintf(stderr, "%s: ", __progname);
116 if (fmt != NULL) {
117 (void)vfprintf(stderr, fmt, ap);
118 (void)fprintf(stderr, ": ");
119 }
120 (void)fprintf(stderr, "%s\n", strerror(sverrno));
121}
122
123void
124#ifdef __STDC__
125warnx(const char *fmt, ...)
126#else
127warnx(fmt, va_alist)
128 const char *fmt;
129 va_dcl
130#endif
131{
132 va_list ap;
133#ifdef __STDC__
134 va_start(ap, fmt);
135#else
136 va_start(ap);
137#endif
138 vwarnx(fmt, ap);
139 va_end(ap);
140}
141
142void
143vwarnx(fmt, ap)
144 const char *fmt;
145 va_list ap;
146{
147 (void)fprintf(stderr, "%s: ", __progname);
148 if (fmt != NULL)
149 (void)vfprintf(stderr, fmt, ap);
150 (void)fprintf(stderr, "\n");
151}