Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / network / stacks / AROSTCP / netlib / err.c
blob55b42cf61fa3753c05354f4586967f65f3647fbb
1 /*-
2 * Copyright (c) 1993
3 * The Regents of the University of California. All rights reserved.
4 * Copyright (c) 2005
5 * Pavel Fedin
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the University of
18 * California, Berkeley and its contributors.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
36 #include <exec/types.h>
37 #include <clib/netlib_protos.h>
38 #include <sys/cdefs.h>
39 //#include "namespace.h"
40 #include <err.h>
41 #include <errno.h>
42 #include <stdarg.h>
43 #include <stdio.h>
44 #include <stdlib.h>
45 #include <string.h>
46 //#include "un-namespace.h"
48 //#include "libc_private.h"
50 extern STRPTR _ProgramName;
51 static FILE *err_file; /* file to use for error output */
52 static void (*err_exit)(int);
55 * This is declared to take a `void *' so that the caller is not required
56 * to include <stdio.h> first. However, it is really a `FILE *', and the
57 * manual page documents it as such.
59 void
60 err_set_file(void *fp)
62 if (fp)
63 err_file = fp;
64 else
65 err_file = stderr;
68 void
69 err_set_exit(void (*ef)(int))
71 err_exit = ef;
74 void
75 err(int eval, const char *fmt, ...)
77 va_list ap;
78 va_start(ap, fmt);
79 verrc(eval, errno, fmt, ap);
80 va_end(ap);
83 void
84 verr(eval, fmt, ap)
85 int eval;
86 const char *fmt;
87 va_list ap;
89 verrc(eval, errno, fmt, ap);
92 void
93 errc(int eval, int code, const char *fmt, ...)
95 va_list ap;
96 va_start(ap, fmt);
97 verrc(eval, code, fmt, ap);
98 va_end(ap);
101 void
102 verrc(eval, code, fmt, ap)
103 int eval;
104 int code;
105 const char *fmt;
106 va_list ap;
108 if (err_file == 0)
109 err_set_file((FILE *)0);
110 fprintf(err_file, "%s: ", _ProgramName);
111 if (fmt != NULL) {
112 vfprintf(err_file, fmt, ap);
113 fprintf(err_file, ": ");
115 fprintf(err_file, "%s\n", strerror(code));
116 if (err_exit)
117 err_exit(eval);
118 exit(eval);
121 void
122 errx(int eval, const char *fmt, ...)
124 va_list ap;
125 va_start(ap, fmt);
126 verrx(eval, fmt, ap);
127 va_end(ap);
130 void
131 verrx(eval, fmt, ap)
132 int eval;
133 const char *fmt;
134 va_list ap;
136 if (err_file == 0)
137 err_set_file((FILE *)0);
138 fprintf(err_file, "%s: ", _ProgramName);
139 if (fmt != NULL)
140 vfprintf(err_file, fmt, ap);
141 fprintf(err_file, "\n");
142 if (err_exit)
143 err_exit(eval);
144 exit(eval);
147 void
148 warn(const char *fmt, ...)
150 va_list ap;
151 va_start(ap, fmt);
152 vwarnc(errno, fmt, ap);
153 va_end(ap);
156 void
157 vwarn(fmt, ap)
158 const char *fmt;
159 va_list ap;
161 vwarnc(errno, fmt, ap);
164 void
165 warnc(int code, const char *fmt, ...)
167 va_list ap;
168 va_start(ap, fmt);
169 vwarnc(code, fmt, ap);
170 va_end(ap);
173 void
174 vwarnc(code, fmt, ap)
175 int code;
176 const char *fmt;
177 va_list ap;
179 if (err_file == 0)
180 err_set_file((FILE *)0);
181 fprintf(err_file, "%s: ", _ProgramName);
182 if (fmt != NULL) {
183 vfprintf(err_file, fmt, ap);
184 fprintf(err_file, ": ");
186 fprintf(err_file, "%s\n", strerror(code));
189 void
190 warnx(const char *fmt, ...)
192 va_list ap;
193 va_start(ap, fmt);
194 vwarnx(fmt, ap);
195 va_end(ap);
198 void
199 vwarnx(fmt, ap)
200 const char *fmt;
201 va_list ap;
203 if (err_file == 0)
204 err_set_file((FILE *)0);
205 fprintf(err_file, "%s: ", _ProgramName);
206 if (fmt != NULL)
207 vfprintf(err_file, fmt, ap);
208 fprintf(err_file, "\n");