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 * ----------------------------------------------------------------------- */
14 * Sets up a common baseline environment, based on "autoconf" findings...
20 /* Must be included before we include any system headers! */
21 #include "aconfig.h" /* autogenerated configuration header */
23 /* Standard includes */
27 #ifdef HAVE_SYS_TYPES_H
28 #include <sys/types.h>
31 #ifdef HAVE_SYS_STAT_H
58 #ifdef HAVE_INTTYPES_H
59 #ifdef INTTYPES_H_IS_SANE
76 #ifdef TIME_WITH_SYS_TIME
98 #ifdef HAVE_SYS_SOCKET_H
99 #include <sys/socket.h>
101 #ifdef HAVE_WINSOCK2_H
102 #include <winsock2.h>
104 #ifdef HAVE_WINSOCK_H
114 extern int optind
, opterr
, optopt
;
117 /* Test for EAGAIN/EWOULDBLOCK */
119 #if defined(EWOULDBLOCK) && (EWOULDBLOCK != EAGAIN)
120 #define E_WOULD_BLOCK(x) ((x) == EAGAIN || (x) == EWOULDBLOCK)
122 #define E_WOULD_BLOCK(x) ((x) == EAGAIN)
125 #define E_WOULD_BLOCK(x) ((x) == EWOULDBLOCK)
128 /* Some broken systems care about text versus binary, but
129 real Unix systems don't... */
130 #ifndef HAVE_O_TEXT_DEFINITION
133 #ifndef HAVE_O_BINARY_DEFINITION
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)
149 typedef long intmax_t;
150 typedef unsigned long uintmax_t;
154 #define INTMAX_C(x) (x##L)
155 #define UINTMAX_C(x) (x##UL)
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
168 #undef HAVE_STRTOUMAX
170 #ifdef HAVE_LONG_LONG
171 #define intmax_t long long
172 #define uintmax_t unsigned long long
176 #define INTMAX_C(x) (x##LL)
177 #define UINTMAX_C(x) (x##ULL)
179 #define intmax_t long
180 #define uintmax_t unsigned long
184 #define INTMAX_C(x) (x##L)
185 #define UINTMAX_C(x) (x##UL)
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))
195 #define strtoumax(p,e,b) ((uintmax_t)strtoul(p,e,b))
199 /* A lot of this is old BSD code. Some newer systems don't approve. */
201 /* The type used by htons(), ntohs() */
204 typedef uint16_t u_short
;
206 typedef unsigned short u_short
;
210 /* The type used to htonl(), ntohl() */
213 typedef uint32_t u_long
;
215 typedef unsigned long u_long
;
220 #ifndef HAVE_SOCKLEN_T
221 typedef int socklen_t
;
226 #ifdef HAVE_SYSEXITS_H
227 #include <sysexits.h>
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 */
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
254 /* How do we annotate unused data items? */
258 #define UNUSED __attribute__((unused))
264 /* netinet/in.h, and possible missing pieces */
266 #include <netinet/in.h>
268 #ifndef HAVE_IPPORT_TFTP_DEFINITION
270 #define IPPORT_TFTP 69
274 /* arpa/{inet,tftp}.h, and possible missing pieces */
276 #ifdef HAVE_ARPA_INET_H
277 #include <arpa/inet.h>
279 /* If we don't have arpa/tftp.h we have problems... */
280 #include <arpa/tftp.h>
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);
301 int daemon(int, int);
304 /* tftp-hpa version and configuration strings */
309 #define WITH_READLINE_STR ", with readline"
311 #define WITH_READLINE_STR ", without readline"
315 #define WITH_REGEX_STR ", with remap"
317 #define WITH_REGEX_STR ", without remap"
321 #define HAVE_LIBWRAP_STR ", with tcpwrappers"
323 #define HAVE_LIBWRAP_STR ", without tcpwrappers"
326 #define TFTP_CONFIG_STR VERSION WITH_READLINE_STR
327 #define TFTPD_CONFIG_STR VERSION WITH_REGEX_STR HAVE_LIBWRAP_STR