turns printfs back on
[freebsd-src/fkvm-freebsd.git] / contrib / ntp / libopts / compat / compat.h
blobb3bd58ff425397c332c2ecbdcbaf8abd421f3ab9
1 /* -*- Mode: C -*- */
3 /* --- fake the preprocessor into handlng portability */
4 /*
5 * Time-stamp: "2007-02-03 17:41:06 bkorb"
7 * Author: Gary V Vaughan <gvaughan@oranda.demon.co.uk>
8 * Created: Mon Jun 30 15:54:46 1997
10 * $Id: compat.h,v 4.16 2007/04/27 01:10:47 bkorb Exp $
12 #ifndef COMPAT_H_GUARD
13 #define COMPAT_H_GUARD 1
15 #if defined(HAVE_CONFIG_H)
16 # include <config.h>
18 #elif defined(_WIN32) && !defined(__CYGWIN__)
19 # include "windows-config.h"
21 #else
22 # error "compat.h" requires "config.h"
23 choke me.
24 #endif
27 #ifndef HAVE_STRSIGNAL
28 char * strsignal( int signo );
29 #endif
31 #define _GNU_SOURCE 1 /* for strsignal in GNU's libc */
32 #define __USE_GNU 1 /* exact same thing as above */
33 #define __EXTENSIONS__ 1 /* and another way to call for it */
35 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
37 * SYSTEM HEADERS:
39 #include <sys/types.h>
40 #ifdef HAVE_SYS_MMAN_H
41 # include <sys/mman.h>
42 #endif
43 #include <sys/param.h>
44 #if HAVE_SYS_PROCSET_H
45 # include <sys/procset.h>
46 #endif
47 #include <sys/stat.h>
48 #include <sys/wait.h>
50 #if defined( HAVE_SOLARIS_SYSINFO )
51 # include <sys/systeminfo.h>
52 #elif defined( HAVE_UNAME_SYSCALL )
53 # include <sys/utsname.h>
54 #endif
56 #ifdef DAEMON_ENABLED
57 # if HAVE_SYS_STROPTS_H
58 # include <sys/stropts.h>
59 # endif
61 # if HAVE_SYS_SOCKET_H
62 # include <sys/socket.h>
63 # endif
65 # if ! defined(HAVE_SYS_POLL_H) && ! defined(HAVE_SYS_SELECT_H)
66 # error This system cannot support daemon processing
67 Choke Me.
68 # endif
70 # if HAVE_SYS_POLL_H
71 # include <sys/poll.h>
72 # endif
74 # if HAVE_SYS_SELECT_H
75 # include <sys/select.h>
76 # endif
78 # if HAVE_NETINET_IN_H
79 # include <netinet/in.h>
80 # endif
82 # if HAVE_SYS_UN_H
83 # include <sys/un.h>
84 # endif
85 #endif
87 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
89 * USER HEADERS:
91 #include <stdio.h>
92 #include <assert.h>
93 #include <ctype.h>
96 * Directory opening stuff:
98 # if defined (_POSIX_SOURCE)
99 /* Posix does not require that the d_ino field be present, and some
100 systems do not provide it. */
101 # define REAL_DIR_ENTRY(dp) 1
102 # else /* !_POSIX_SOURCE */
103 # define REAL_DIR_ENTRY(dp) (dp->d_ino != 0)
104 # endif /* !_POSIX_SOURCE */
106 # if defined (HAVE_DIRENT_H)
107 # include <dirent.h>
108 # define D_NAMLEN(dirent) strlen((dirent)->d_name)
109 # else /* !HAVE_DIRENT_H */
110 # define dirent direct
111 # define D_NAMLEN(dirent) (dirent)->d_namlen
112 # if defined (HAVE_SYS_NDIR_H)
113 # include <sys/ndir.h>
114 # endif /* HAVE_SYS_NDIR_H */
115 # if defined (HAVE_SYS_DIR_H)
116 # include <sys/dir.h>
117 # endif /* HAVE_SYS_DIR_H */
118 # if defined (HAVE_NDIR_H)
119 # include <ndir.h>
120 # endif /* HAVE_NDIR_H */
121 # endif /* !HAVE_DIRENT_H */
123 #include <errno.h>
124 #ifdef HAVE_FCNTL_H
125 # include <fcntl.h>
126 #endif
127 #ifndef O_NONBLOCK
128 # define O_NONBLOCK FNDELAY
129 #endif
131 #if defined(HAVE_LIBGEN) && defined(HAVE_LIBGEN_H)
132 # include <libgen.h>
133 #endif
135 #if defined(HAVE_LIMITS_H) /* this is also in options.h */
136 # include <limits.h>
137 #elif defined(HAVE_SYS_LIMITS_H)
138 # include <sys/limits.h>
139 #endif /* HAVE_LIMITS/SYS_LIMITS_H */
141 #include <memory.h>
142 #include <setjmp.h>
143 #include <signal.h>
145 #if defined( HAVE_STDINT_H )
146 # include <stdint.h>
147 #elif defined( HAVE_INTTYPES_H )
148 # include <inttypes.h>
149 #endif
151 #include <stdlib.h>
152 #include <string.h>
154 #include <time.h>
156 #ifdef HAVE_UTIME_H
157 # include <utime.h>
158 #endif
160 #ifdef HAVE_UNISTD_H
161 # include <unistd.h>
162 #endif
164 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
166 * FIXUPS and CONVIENCE STUFF:
168 #ifdef __cplusplus
169 # define EXTERN extern "C"
170 #else
171 # define EXTERN extern
172 #endif
174 /* some systems #def errno! and others do not declare it!! */
175 #ifndef errno
176 extern int errno;
177 #endif
179 /* Some machines forget this! */
181 # ifndef EXIT_FAILURE
182 # define EXIT_SUCCESS 0
183 # define EXIT_FAILURE 1
184 # endif
186 #ifndef NUL
187 # define NUL '\0'
188 #endif
190 #ifndef NULL
191 # define NULL 0
192 #endif
194 #if !defined (MAXPATHLEN) && defined (HAVE_SYS_PARAM_H)
195 # include <sys/param.h>
196 #endif /* !MAXPATHLEN && HAVE_SYS_PARAM_H */
198 #if !defined (MAXPATHLEN) && defined (PATH_MAX)
199 # define MAXPATHLEN PATH_MAX
200 #endif /* !MAXPATHLEN && PATH_MAX */
202 #if !defined (MAXPATHLEN) && defined(_MAX_PATH)
203 # define PATH_MAX _MAX_PATH
204 # define MAXPATHLEN _MAX_PATH
205 #endif
207 #if !defined (MAXPATHLEN)
208 # define MAXPATHLEN ((size_t)4096)
209 #endif /* MAXPATHLEN */
211 #define AG_PATH_MAX ((size_t)MAXPATHLEN)
213 #ifndef LONG_MAX
214 # define LONG_MAX ~(1L << (8*sizeof(long) -1))
215 # define INT_MAX ~(1 << (8*sizeof(int) -1))
216 #endif
218 #ifndef ULONG_MAX
219 # define ULONG_MAX ~(OUL)
220 # define UINT_MAX ~(OU)
221 #endif
223 #ifndef SHORT_MAX
224 # define SHORT_MAX ~(1 << (8*sizeof(short) -1))
225 #else
226 # define USHORT_MAX ~(OUS)
227 #endif
229 #ifndef HAVE_INT8_T
230 typedef signed char int8_t;
231 #endif
232 #ifndef HAVE_UINT8_T
233 typedef unsigned char uint8_t;
234 #endif
235 #ifndef HAVE_INT16_T
236 typedef signed short int16_t;
237 #endif
238 #ifndef HAVE_UINT16_T
239 typedef unsigned short uint16_t;
240 #endif
241 #ifndef HAVE_UINT_T
242 typedef unsigned int uint_t;
243 #endif
245 #ifndef HAVE_INT32_T
246 # if SIZEOF_INT == 4
247 typedef signed int int32_t;
248 # elif SIZEOF_LONG == 4
249 typedef signed long int32_t;
250 # endif
251 #endif
253 #ifndef HAVE_UINT32_T
254 # if SIZEOF_INT == 4
255 typedef unsigned int uint32_t;
256 # elif SIZEOF_LONG == 4
257 typedef unsigned long uint32_t;
258 # else
259 # error Cannot create a uint32_t type.
260 Choke Me.
261 # endif
262 #endif
264 #ifndef HAVE_INTPTR_T
265 typedef signed long intptr_t;
266 #endif
267 #ifndef HAVE_UINTPTR_T
268 typedef unsigned long uintptr_t;
269 #endif
271 /* redefine these for BSD style string libraries */
272 #ifndef HAVE_STRCHR
273 # define strchr index
274 # define strrchr rindex
275 #endif
277 #ifdef USE_FOPEN_BINARY
278 # ifndef FOPEN_BINARY_FLAG
279 # define FOPEN_BINARY_FLAG "b"
280 # endif
281 # ifndef FOPEN_TEXT_FLAG
282 # define FOPEN_TEXT_FLAG "t"
283 # endif
284 #else
285 # ifndef FOPEN_BINARY_FLAG
286 # define FOPEN_BINARY_FLAG
287 # endif
288 # ifndef FOPEN_TEXT_FLAG
289 # define FOPEN_TEXT_FLAG
290 # endif
291 #endif
293 #ifndef STR
294 # define _STR(s) #s
295 # define STR(s) _STR(s)
296 #endif
298 /* ##### Pointer sized word ##### */
300 /* FIXME: the MAX stuff in here is broken! */
301 #if SIZEOF_CHARP > SIZEOF_INT
302 typedef long t_word;
303 #define WORD_MAX LONG_MAX
304 #define WORD_MIN LONG_MIN
305 #else /* SIZEOF_CHARP <= SIZEOF_INT */
306 typedef int t_word;
307 #define WORD_MAX INT_MAX
308 #define WORD_MIN INT_MIN
309 #endif
311 #endif /* COMPAT_H_GUARD */
314 * Local Variables:
315 * mode: C
316 * c-file-style: "stroustrup"
317 * indent-tabs-mode: nil
318 * End:
319 * end of compat/compat.h */