Apply some code cleanups that apparently fix Solaris 7 gcc problems.
[tftp-hpa.git] / config.h
blobef0d408afbe70b0e770d82622d25e0604b42870a
1 /* -*- c -*- ------------------------------------------------------------- *
2 *
3 * Copyright 2001 H. Peter Anvin - All Rights Reserved
5 * This program is free software available under the same license
6 * as the "OpenBSD" operating system, distributed at
7 * http://www.openbsd.org/.
9 * ----------------------------------------------------------------------- */
10 /* $Id$ */
13 * config.h
15 * Sets up a common baseline environment, based on "autoconf" findings...
18 #ifndef CONFIG_H
19 #define CONFIG_H 1
21 /* Must be included before we include any system headers! */
22 #include "acconfig.h"
24 /* Standard includes */
26 #include <stdio.h>
28 #ifdef HAVE_SYS_TYPES_H
29 #include <sys/types.h>
30 #endif
32 #ifdef HAVE_SYS_STAT_H
33 #include <sys/stat.h>
34 #endif
36 #ifdef STDC_HEADERS
37 #include <stdlib.h>
38 #include <stddef.h>
39 #else
40 #ifdef HAVE_STDLIB_H
41 #include <stdlib.h>
42 #endif
43 #endif
45 #ifdef HAVE_MEMORY_H
46 #ifndef STDC_HEADERS
47 #include <memory.h>
48 #endif
49 #endif
51 #ifdef HAVE_STRING_H
52 #include <string.h>
53 #endif
55 #ifdef HAVE_STRINGS_H
56 #include <strings.h>
57 #endif
59 #ifdef HAVE_INTTYPES_H
60 #ifdef INTTYPES_H_IS_SANE
61 #include <inttypes.h>
62 #endif
63 #else
64 #ifdef HAVE_STDINT_H
65 #include <stdint.h>
66 #endif
67 #endif
69 #ifdef HAVE_UNISTD_H
70 #include <unistd.h>
71 #endif
73 #ifdef HAVE_SETJMP_H
74 #include <setjmp.h>
75 #endif
77 #ifdef TIME_WITH_SYS_TIME
78 #include <sys/time.h>
79 #include <time.h>
80 #else
81 #if HAVE_SYS_TIME_H
82 #include <sys/time.h>
83 #else
84 #include <time.h>
85 #endif
86 #endif
88 #ifdef HAVE_GRP_H
89 #include <grp.h>
90 #endif
92 #ifdef HAVE_FCNTL_H
93 #include <fcntl.h>
94 #endif
96 #include <errno.h>
97 #include <signal.h>
99 #include <sys/socket.h>
101 /* Test for EAGAIN/EWOULDBLOCK */
102 #ifdef EAGAIN
103 #if defined(EWOULDBLOCK) && (EWOULDBLOCK != EAGAIN)
104 #define E_WOULD_BLOCK(x) ((x) == EAGAIN || (x) == EWOULDBLOCK)
105 #else
106 #define E_WOULD_BLOCK(x) ((x) == EAGAIN)
107 #endif
108 #else
109 #define E_WOULD_BLOCK(x) ((x) == EWOULDBLOCK)
110 #endif
112 /* Some broken systems care about text versus binary, but
113 real Unix systems don't... */
114 #ifndef HAVE_O_TEXT_DEFINITION
115 #define O_TEXT 0
116 #endif
117 #ifndef HAVE_O_BINARY_DEFINITION
118 #define O_BINARY 0
119 #endif
121 /* If we don't have intmax_t, try creating it */
123 #ifndef HAVE_INTMAX_T
124 #ifdef HAVE_LONG_LONG
125 typedef long long intmax_t;
126 typedef unsigned long long uintmax_t;
127 #define PRIdMAX "Ld"
128 #define PRIuMAX "Lu"
129 #define PRIxMAX "Lx"
130 #define INTMAX_C(x) (x##LL)
131 #define UINTMAX_C(x) (x##ULL)
132 #else
133 typedef long intmax_t;
134 typedef unsigned long uintmax_t;
135 #define PRIdMAX "ld"
136 #define PRIuMAX "lu"
137 #define PRIxMAX "lx"
138 #define INTMAX_C(x) (x##L)
139 #define UINTMAX_C(x) (x##UL)
140 #endif
141 #endif
143 /* On some version of AIX, <inttypes.h> is buggy to the point of
144 unusability. We have to use macros here, not typedefs, to override. */
145 #ifdef HAVE_INTTYPES_H
146 #ifndef INTTYPES_H_IS_SANE
147 #undef PRIdMAX
148 #undef PRIuMAX
149 #undef PRIxMAX
150 #undef INTMAX_C
151 #undef UINTMAX_C
152 #undef HAVE_STRTOUMAX
154 #ifdef HAVE_LONG_LONG
155 #define intmax_t long long
156 #define uintmax_t unsigned long long
157 #define PRIdMAX "Ld"
158 #define PRIuMAX "Lu"
159 #define PRIxMAX "Lx"
160 #define INTMAX_C(x) (x##LL)
161 #define UINTMAX_C(x) (x##ULL)
162 #else
163 #define intmax_t long
164 #define uintmax_t unsigned long
165 #define PRIdMAX "ld"
166 #define PRIuMAX "lu"
167 #define PRIxMAX "lx"
168 #define INTMAX_C(x) (x##L)
169 #define UINTMAX_C(x) (x##UL)
170 #endif
171 #endif
172 #endif
174 /* Even if intmax_t is defined, we may need this (Solaris 8 braindamage) */
175 #ifndef HAVE_STRTOUMAX
176 #if defined(HAVE_LONG_LONG) && defined(HAVE_STRTOULL)
177 #define strtoumax(p,e,b) ((uintmax_t)strtoull(p,e,b))
178 #else
179 #define strtoumax(p,e,b) ((uintmax_t)strtoul(p,e,b))
180 #endif
181 #endif
183 /* A lot of this is old BSD code. Some newer systems don't approve. */
185 /* The type used by htons(), ntohs() */
186 #ifndef HAVE_U_SHORT
187 #ifdef HAVE_UINT16_T
188 typedef uint16_t u_short;
189 #else
190 typedef unsigned short u_short;
191 #endif
192 #endif
194 /* The type used to htonl(), ntohl() */
195 #ifndef HAVE_U_LONG
196 #ifdef HAVE_UINT32_T
197 typedef uint32_t u_long;
198 #else
199 typedef unsigned long u_long;
200 #endif
201 #endif
203 /* sysexits.h */
205 #ifdef HAVE_SYSEXITS_H
206 #include <sysexits.h>
207 #else
208 #define EX_USAGE 64 /* command line usage error */
209 #define EX_DATAERR 65 /* data format error */
210 #define EX_NOINPUT 66 /* cannot open input */
211 #define EX_NOUSER 67 /* addressee unknown */
212 #define EX_NOHOST 68 /* host name unknown */
213 #define EX_UNAVAILABLE 69 /* service unavailable */
214 #define EX_SOFTWARE 70 /* internal software error */
215 #define EX_OSERR 71 /* system error (e.g., can't fork) */
216 #define EX_OSFILE 72 /* critical OS file missing */
217 #define EX_CANTCREAT 73 /* can't create (user) output file */
218 #define EX_IOERR 74 /* input/output error */
219 #define EX_TEMPFAIL 75 /* temp failure; user is invited to retry */
220 #define EX_PROTOCOL 76 /* remote error in protocol */
221 #define EX_NOPERM 77 /* permission denied */
222 #define EX_CONFIG 78 /* configuration error */
223 #endif
225 /* If we don't have sigsetjmp() et all, setjmp() will have to do */
227 #ifndef HAVE_SIGSETJMP
228 #define sigsetjmp(x,y) setjmp(x)
229 #define siglongjmp(x,y) longjmp(x,y)
230 #define sigjmp_buf jmp_buf
231 #endif
233 /* How do we annotate unused data items? */
235 #ifndef UNUSED
236 #ifdef __GNUC__
237 #define UNUSED __attribute__((unused))
238 #else
239 #define UNUSED
240 #endif
241 #endif
243 /* netinet/in.h, and possible missing pieces */
245 #include <netinet/in.h>
247 #ifndef HAVE_IPPORT_TFTP_DEFINITION
248 #ifndef IPPORT_TFTP
249 #define IPPORT_TFTP 69
250 #endif
251 #endif
253 /* arpa/{inet,tftp}.h, and possible missing pieces */
255 #ifdef HAVE_ARPA_INET_H
256 #include <arpa/inet.h>
257 #endif
258 /* If we don't have arpa/tftp.h we have problems... */
259 #include <arpa/tftp.h>
261 #ifndef OACK
262 #define OACK 6
263 #endif
264 #ifndef EOPTNEG
265 #define EOPTNEG 8
266 #endif
268 /* tftp-hpa version and configuration strings */
270 #include "version.h"
272 #ifdef WITH_READLINE
273 #define WITH_READLINE_STR ", with readline"
274 #else
275 #define WITH_READLINE_STR ", without readline"
276 #endif
278 #ifdef WITH_REGEX
279 #define WITH_REGEX_STR ", with remap"
280 #else
281 #define WITH_REGEX_STR ", without remap"
282 #endif
284 #ifdef HAVE_LIBWRAP
285 #define HAVE_LIBWRAP_STR ", with tcpwrappers"
286 #else
287 #define HAVE_LIBWRAP_STR ", without tcpwrappers"
288 #endif
290 #define TFTP_CONFIG_STR VERSION WITH_READLINE_STR
291 #define TFTPD_CONFIG_STR VERSION WITH_REGEX_STR HAVE_LIBWRAP_STR
293 #endif