]> cygwin.com Git - cygwin-apps/cygutils.git/blob - src/col/err.c
Add col; regenerate autofiles
[cygwin-apps/cygutils.git] / src / col / err.c
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 */
29
30 /* 2002-05-22 David A. Willis: modified license to the 'BSD no advert'
31 * license, as required by the Director of the Office of
32 * Technology Licensing of the University of California on
33 * July 22, 1999.
34 * See http://www.opensource.org/licenses/bsd-license.html
35 * 2002-05-22 David A. Willis: "Ported" code for compilation under
36 * ix86-pc-cygwin (just added the #if HAVE_CONFIG_H block,
37 * really.)
38 */
39
40 #if defined(LIBC_SCCS) && !defined(lint)
41 static char sccsid[] = "@(#)err.c 8.1 (Berkeley) 6/4/93";
42 #endif /* LIBC_SCCS and not lint */
43
44 #if HAVE_CONFIG_H
45 #include "config.h"
46 #endif
47 #include "common.h"
48
49 #include "err.h"
50
51 /* These headers are included via common.h, except for <err.h> */
52 /* err.h is located in CWD, so include using " " instead of < > */
53 #if 0
54 #include <err.h>
55 #include <errno.h>
56 #include <stdio.h>
57 #include <stdlib.h>
58 #include <string.h>
59
60 #ifdef __STDC__
61 #include <stdarg.h>
62 #else
63 #include <varargs.h>
64 #endif
65
66 #endif
67
68 #ifdef HAVE___PROGNAME
69 extern char *__progname; /* Program name, from crt0. */
70 #else /* ! HAVE___PROGNAME */
71 /* Eugh! People shouldn't rely on crt0 defining things like this. For
72 example, linux doesn't define __progname. So each program has to call
73 err_setprogname() to register its name. */
74 /* don't define __progname, we're not allowed to use that namespace */
75 static const char *progname;
76 #define __progname progname
77 #endif /* ! HAVE___PROGNAME */
78
79
80 #ifndef HAVE___PROGNAME
81 /* sane C compiler, so none of this messy __STDC__ guff */
82
83 /* sets __progname to point into argv[0] at the right place. Takes
84 argv[0], and finds where 'the right place' is. */
85 void err_setprogname(const char *argv0)
86 {
87 __progname = strrchr(argv0, '/');
88 if (__progname==NULL || *__progname==0)
89 __progname = argv0;
90 else
91 __progname++;
92 }
93 #else /* HAVE___PROGNAME */
94 #define err_setprogname(x) (void *)0
95 #endif /* HAVE___PROGNAME */
96
97
98 __dead void
99 #ifdef __STDC__
100 err(int eval, const char *fmt, ...)
101 #else
102 err(eval, fmt, va_alist)
103 int eval;
104 const char *fmt;
105 va_dcl
106 #endif
107 {
108 va_list ap;
109 #if __STDC__
110 va_start(ap, fmt);
111 #else
112 va_start(ap);
113 #endif
114 verr(eval, fmt, ap);
115 va_end(ap);
116 }
117
118 __dead void
119 verr(eval, fmt, ap)
120 int eval;
121 const char *fmt;
122 va_list ap;
123 {
124 int sverrno;
125
126 sverrno = errno;
127 (void)fprintf(stderr, "%s: ", __progname);
128 if (fmt != NULL) {
129 (void)vfprintf(stderr, fmt, ap);
130 (void)fprintf(stderr, ": ");
131 }
132 (void)fprintf(stderr, "%s\n", strerror(sverrno));
133 exit(eval);
134 }
135
136 __dead void
137 #if __STDC__
138 errx(int eval, const char *fmt, ...)
139 #else
140 errx(eval, fmt, va_alist)
141 int eval;
142 const char *fmt;
143 va_dcl
144 #endif
145 {
146 va_list ap;
147 #if __STDC__
148 va_start(ap, fmt);
149 #else
150 va_start(ap);
151 #endif
152 verrx(eval, fmt, ap);
153 va_end(ap);
154 }
155
156 __dead void
157 verrx(eval, fmt, ap)
158 int eval;
159 const char *fmt;
160 va_list ap;
161 {
162 (void)fprintf(stderr, "%s: ", __progname);
163 if (fmt != NULL)
164 (void)vfprintf(stderr, fmt, ap);
165 (void)fprintf(stderr, "\n");
166 exit(eval);
167 }
168
169 void
170 #if __STDC__
171 warn(const char *fmt, ...)
172 #else
173 warn(fmt, va_alist)
174 const char *fmt;
175 va_dcl
176 #endif
177 {
178 va_list ap;
179 #if __STDC__
180 va_start(ap, fmt);
181 #else
182 va_start(ap);
183 #endif
184 vwarn(fmt, ap);
185 va_end(ap);
186 }
187
188 void
189 vwarn(fmt, ap)
190 const char *fmt;
191 va_list ap;
192 {
193 int sverrno;
194
195 sverrno = errno;
196 (void)fprintf(stderr, "%s: ", __progname);
197 if (fmt != NULL) {
198 (void)vfprintf(stderr, fmt, ap);
199 (void)fprintf(stderr, ": ");
200 }
201 (void)fprintf(stderr, "%s\n", strerror(sverrno));
202 }
203
204 void
205 #ifdef __STDC__
206 warnx(const char *fmt, ...)
207 #else
208 warnx(fmt, va_alist)
209 const char *fmt;
210 va_dcl
211 #endif
212 {
213 va_list ap;
214 #ifdef __STDC__
215 va_start(ap, fmt);
216 #else
217 va_start(ap);
218 #endif
219 vwarnx(fmt, ap);
220 va_end(ap);
221 }
222
223 void
224 vwarnx(fmt, ap)
225 const char *fmt;
226 va_list ap;
227 {
228 (void)fprintf(stderr, "%s: ", __progname);
229 if (fmt != NULL)
230 (void)vfprintf(stderr, fmt, ap);
231 (void)fprintf(stderr, "\n");
232 }
This page took 0.044818 seconds and 5 git commands to generate.