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