Remove more obsolete $Id$ tags
[tftp-hpa.git] / config.h
blobed1e39ac7e9874cd30678d85ab0f613b687a0c67
1 /* -*- c -*- ------------------------------------------------------------- *
3 * Copyright 2001-2006 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 * ----------------------------------------------------------------------- */
12 * config.h
14 * Sets up a common baseline environment, based on "autoconf" findings...
17 #ifndef CONFIG_H
18 #define CONFIG_H 1
20 /* Must be included before we include any system headers! */
21 #include "aconfig.h" /* autogenerated configuration header */
23 /* Standard includes */
25 #include <stdio.h>
27 #ifdef HAVE_SYS_TYPES_H
28 #include <sys/types.h>
29 #endif
31 #ifdef HAVE_SYS_STAT_H
32 #include <sys/stat.h>
33 #endif
35 #ifdef STDC_HEADERS
36 #include <stdlib.h>
37 #include <stddef.h>
38 #else
39 #ifdef HAVE_STDLIB_H
40 #include <stdlib.h>
41 #endif
42 #endif
44 #ifdef HAVE_MEMORY_H
45 #ifndef STDC_HEADERS
46 #include <memory.h>
47 #endif
48 #endif
50 #ifdef HAVE_STRING_H
51 #include <string.h>
52 #endif
54 #ifdef HAVE_STRINGS_H
55 #include <strings.h>
56 #endif
58 #ifdef HAVE_INTTYPES_H
59 #ifdef INTTYPES_H_IS_SANE
60 #include <inttypes.h>
61 #endif
62 #else
63 #ifdef HAVE_STDINT_H
64 #include <stdint.h>
65 #endif
66 #endif
68 #ifdef HAVE_UNISTD_H
69 #include <unistd.h>
70 #endif
72 #ifdef HAVE_SETJMP_H
73 #include <setjmp.h>
74 #endif
76 #ifdef TIME_WITH_SYS_TIME
77 #include <sys/time.h>
78 #include <time.h>
79 #else
80 #if HAVE_SYS_TIME_H
81 #include <sys/time.h>
82 #else
83 #include <time.h>
84 #endif
85 #endif
87 #ifdef HAVE_GRP_H
88 #include <grp.h>
89 #endif
91 #ifdef HAVE_FCNTL_H
92 #include <fcntl.h>
93 #endif
95 #include <errno.h>
96 #include <signal.h>
98 #ifdef HAVE_SYS_SOCKET_H
99 #include <sys/socket.h>
100 #else
101 #ifdef HAVE_WINSOCK2_H
102 #include <winsock2.h>
103 #else
104 #ifdef HAVE_WINSOCK_H
105 #include <winsock.h>
106 #endif
107 #endif
108 #endif
110 #ifdef HAVE_GETOPT_H
111 #include <getopt.h>
112 #else
113 extern char *optarg;
114 extern int optind, opterr, optopt;
115 #endif
117 /* Test for EAGAIN/EWOULDBLOCK */
118 #ifdef EAGAIN
119 #if defined(EWOULDBLOCK) && (EWOULDBLOCK != EAGAIN)
120 #define E_WOULD_BLOCK(x) ((x) == EAGAIN || (x) == EWOULDBLOCK)
121 #else
122 #define E_WOULD_BLOCK(x) ((x) == EAGAIN)
123 #endif
124 #else
125 #define E_WOULD_BLOCK(x) ((x) == EWOULDBLOCK)
126 #endif
128 /* Some broken systems care about text versus binary, but
129 real Unix systems don't... */
130 #ifndef HAVE_O_TEXT_DEFINITION
131 #define O_TEXT 0
132 #endif
133 #ifndef HAVE_O_BINARY_DEFINITION
134 #define O_BINARY 0
135 #endif
137 /* If we don't have intmax_t, try creating it */
139 #ifndef HAVE_INTMAX_T
140 #ifdef HAVE_LONG_LONG
141 typedef long long intmax_t;
142 typedef unsigned long long uintmax_t;
143 #define PRIdMAX "lld"
144 #define PRIuMAX "llu"
145 #define PRIxMAX "llx"
146 #define INTMAX_C(x) (x##LL)
147 #define UINTMAX_C(x) (x##ULL)
148 #else
149 typedef long intmax_t;
150 typedef unsigned long uintmax_t;
151 #define PRIdMAX "ld"
152 #define PRIuMAX "lu"
153 #define PRIxMAX "lx"
154 #define INTMAX_C(x) (x##L)
155 #define UINTMAX_C(x) (x##UL)
156 #endif
157 #endif
159 /* On some version of AIX, <inttypes.h> is buggy to the point of
160 unusability. We have to use macros here, not typedefs, to override. */
161 #ifdef HAVE_INTTYPES_H
162 #ifndef INTTYPES_H_IS_SANE
163 #undef PRIdMAX
164 #undef PRIuMAX
165 #undef PRIxMAX
166 #undef INTMAX_C
167 #undef UINTMAX_C
168 #undef HAVE_STRTOUMAX
170 #ifdef HAVE_LONG_LONG
171 #define intmax_t long long
172 #define uintmax_t unsigned long long
173 #define PRIdMAX "Ld"
174 #define PRIuMAX "Lu"
175 #define PRIxMAX "Lx"
176 #define INTMAX_C(x) (x##LL)
177 #define UINTMAX_C(x) (x##ULL)
178 #else
179 #define intmax_t long
180 #define uintmax_t unsigned long
181 #define PRIdMAX "ld"
182 #define PRIuMAX "lu"
183 #define PRIxMAX "lx"
184 #define INTMAX_C(x) (x##L)
185 #define UINTMAX_C(x) (x##UL)
186 #endif
187 #endif
188 #endif
190 /* Even if intmax_t is defined, we may need this (Solaris 8 braindamage) */
191 #ifndef HAVE_STRTOUMAX
192 #if defined(HAVE_LONG_LONG) && defined(HAVE_STRTOULL)
193 #define strtoumax(p,e,b) ((uintmax_t)strtoull(p,e,b))
194 #else
195 #define strtoumax(p,e,b) ((uintmax_t)strtoul(p,e,b))
196 #endif
197 #endif
199 /* A lot of this is old BSD code. Some newer systems don't approve. */
201 /* The type used by htons(), ntohs() */
202 #ifndef HAVE_U_SHORT
203 #ifdef HAVE_UINT16_T
204 typedef uint16_t u_short;
205 #else
206 typedef unsigned short u_short;
207 #endif
208 #endif
210 /* The type used to htonl(), ntohl() */
211 #ifndef HAVE_U_LONG
212 #ifdef HAVE_UINT32_T
213 typedef uint32_t u_long;
214 #else
215 typedef unsigned long u_long;
216 #endif
217 #endif
219 /* socklen_t */
220 #ifndef HAVE_SOCKLEN_T
221 typedef int socklen_t;
222 #endif
224 /* sysexits.h */
226 #ifdef HAVE_SYSEXITS_H
227 #include <sysexits.h>
228 #else
229 #define EX_USAGE 64 /* command line usage error */
230 #define EX_DATAERR 65 /* data format error */
231 #define EX_NOINPUT 66 /* cannot open input */
232 #define EX_NOUSER 67 /* addressee unknown */
233 #define EX_NOHOST 68 /* host name unknown */
234 #define EX_UNAVAILABLE 69 /* service unavailable */
235 #define EX_SOFTWARE 70 /* internal software error */
236 #define EX_OSERR 71 /* system error (e.g., can't fork) */
237 #define EX_OSFILE 72 /* critical OS file missing */
238 #define EX_CANTCREAT 73 /* can't create (user) output file */
239 #define EX_IOERR 74 /* input/output error */
240 #define EX_TEMPFAIL 75 /* temp failure; user is invited to retry */
241 #define EX_PROTOCOL 76 /* remote error in protocol */
242 #define EX_NOPERM 77 /* permission denied */
243 #define EX_CONFIG 78 /* configuration error */
244 #endif
246 /* If we don't have sigsetjmp() et all, setjmp() will have to do */
248 #ifndef HAVE_SIGSETJMP
249 #define sigsetjmp(x,y) setjmp(x)
250 #define siglongjmp(x,y) longjmp(x,y)
251 #define sigjmp_buf jmp_buf
252 #endif
254 /* How do we annotate unused data items? */
256 #ifndef UNUSED
257 #ifdef __GNUC__
258 #define UNUSED __attribute__((unused))
259 #else
260 #define UNUSED
261 #endif
262 #endif
264 /* netinet/in.h, and possible missing pieces */
266 #include <netinet/in.h>
268 #ifndef HAVE_IPPORT_TFTP_DEFINITION
269 #ifndef IPPORT_TFTP
270 #define IPPORT_TFTP 69
271 #endif
272 #endif
274 /* arpa/{inet,tftp}.h, and possible missing pieces */
276 #ifdef HAVE_ARPA_INET_H
277 #include <arpa/inet.h>
278 #endif
279 /* If we don't have arpa/tftp.h we have problems... */
280 #include <arpa/tftp.h>
282 #ifndef OACK
283 #define OACK 6
284 #endif
285 #ifndef EOPTNEG
286 #define EOPTNEG 8
287 #endif
289 /* Prototypes for libxtra functions */
291 void *xmalloc(size_t);
292 char *xstrdup(const char *);
294 #ifndef HAVE_BSD_SIGNAL
295 void (*bsd_signal(int, void (*)(int))) (int);
296 #endif
297 #ifndef HAVE_DUP2
298 int dup2(int, int);
299 #endif
300 #ifndef HAVE_DAEMON
301 int daemon(int, int);
302 #endif
304 /* tftp-hpa version and configuration strings */
306 #include "version.h"
308 #ifdef WITH_READLINE
309 #define WITH_READLINE_STR ", with readline"
310 #else
311 #define WITH_READLINE_STR ", without readline"
312 #endif
314 #ifdef WITH_REGEX
315 #define WITH_REGEX_STR ", with remap"
316 #else
317 #define WITH_REGEX_STR ", without remap"
318 #endif
320 #ifdef HAVE_LIBWRAP
321 #define HAVE_LIBWRAP_STR ", with tcpwrappers"
322 #else
323 #define HAVE_LIBWRAP_STR ", without tcpwrappers"
324 #endif
326 #define TFTP_CONFIG_STR VERSION WITH_READLINE_STR
327 #define TFTPD_CONFIG_STR VERSION WITH_REGEX_STR HAVE_LIBWRAP_STR
329 #endif