xref: /netbsd-src/external/bsd/ntp/dist/sntp/libopts/compat/compat.h (revision daf6c4152fcddc27c445489775ed1f66ab4ea9a9)
1 /*	$NetBSD: compat.h,v 1.1.1.1 2009/12/13 16:57:25 kardel Exp $	*/
2 
3 /*  -*- Mode: C -*-  */
4 
5 /* compat.h --- fake the preprocessor into handlng portability
6  *
7  *  Time-stamp:      "2009-10-18 11:14:14 bkorb"
8  *
9  * Id: 27c1eb45f171295ab6176280aeca742cfdbe9fed
10  *
11  *  compat.h is free software.
12  *  This file is part of AutoGen.
13  *
14  *  AutoGen copyright (c) 1992-2009 by Bruce Korb - all rights reserved
15  *
16  *  AutoGen is free software: you can redistribute it and/or modify it
17  *  under the terms of the GNU General Public License as published by the
18  *  Free Software Foundation, either version 3 of the License, or
19  *  (at your option) any later version.
20  *
21  *  AutoGen is distributed in the hope that it will be useful, but
22  *  WITHOUT ANY WARRANTY; without even the implied warranty of
23  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
24  *  See the GNU General Public License for more details.
25  *
26  *  You should have received a copy of the GNU General Public License along
27  *  with this program.  If not, see <http://www.gnu.org/licenses/>.
28  *
29  *  As a special exception, Bruce Korb gives permission for additional
30  *  uses of the text contained in the release of compat.h.
31  *
32  *  The exception is that, if you link the compat.h library with other
33  *  files to produce an executable, this does not by itself cause the
34  *  resulting executable to be covered by the GNU General Public License.
35  *  Your use of that executable is in no way restricted on account of
36  *  linking the compat.h library code into it.
37  *
38  *  This exception does not however invalidate any other reasons why
39  *  the executable file might be covered by the GNU General Public License.
40  *
41  *  This exception applies only to the code released by Bruce Korb under
42  *  the name compat.h.  If you copy code from other sources under the
43  *  General Public License into a copy of compat.h, as the General Public
44  *  License permits, the exception does not apply to the code that you add
45  *  in this way.  To avoid misleading anyone as to the status of such
46  *  modified files, you must delete this exception notice from them.
47  *
48  *  If you write modifications of your own for compat.h, it is your choice
49  *  whether to permit this exception to apply to your modifications.
50  *  If you do not wish that, delete this exception notice.
51  */
52 #ifndef COMPAT_H_GUARD
53 #define COMPAT_H_GUARD 1
54 
55 #if defined(HAVE_CONFIG_H)
56 #  include <config.h>
57 
58 #elif defined(_WIN32) && !defined(__CYGWIN__)
59 #  include "windows-config.h"
60 
61 #else
62 #  error "compat.h" requires "config.h"
63    choke me.
64 #endif
65 
66 
67 #ifndef HAVE_STRSIGNAL
68    char * strsignal( int signo );
69 #endif
70 
71 #define  _GNU_SOURCE    1 /* for strsignal in GNU's libc */
72 #define  __USE_GNU      1 /* exact same thing as above   */
73 #define  __EXTENSIONS__ 1 /* and another way to call for it */
74 
75 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
76  *
77  *  SYSTEM HEADERS:
78  */
79 #include <sys/types.h>
80 #ifdef HAVE_SYS_MMAN_H
81 #  include <sys/mman.h>
82 #endif
83 #include <sys/param.h>
84 #if HAVE_SYS_PROCSET_H
85 #  include <sys/procset.h>
86 #endif
87 #include <sys/stat.h>
88 #include <sys/wait.h>
89 
90 #if defined( HAVE_SOLARIS_SYSINFO )
91 #  include <sys/systeminfo.h>
92 #elif defined( HAVE_UNAME_SYSCALL )
93 #  include <sys/utsname.h>
94 #endif
95 
96 #ifdef DAEMON_ENABLED
97 #  if HAVE_SYS_STROPTS_H
98 #  include <sys/stropts.h>
99 #  endif
100 
101 #  if HAVE_SYS_SOCKET_H
102 #  include <sys/socket.h>
103 #  endif
104 
105 #  if ! defined(HAVE_SYS_POLL_H) && ! defined(HAVE_SYS_SELECT_H)
106 #    error This system cannot support daemon processing
107      Choke Me.
108 #  endif
109 
110 #  if HAVE_SYS_POLL_H
111 #  include <sys/poll.h>
112 #  endif
113 
114 #  if HAVE_SYS_SELECT_H
115 #  include <sys/select.h>
116 #  endif
117 
118 #  if HAVE_NETINET_IN_H
119 #  include <netinet/in.h>
120 #  endif
121 
122 #  if HAVE_SYS_UN_H
123 #  include <sys/un.h>
124 #  endif
125 #endif
126 
127 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
128  *
129  *  USER HEADERS:
130  */
131 #include <stdio.h>
132 #include <assert.h>
133 #include <ctype.h>
134 
135 /*
136  *  Directory opening stuff:
137  */
138 # if defined (_POSIX_SOURCE)
139 /* Posix does not require that the d_ino field be present, and some
140    systems do not provide it. */
141 #    define REAL_DIR_ENTRY(dp) 1
142 # else /* !_POSIX_SOURCE */
143 #    define REAL_DIR_ENTRY(dp) (dp->d_ino != 0)
144 # endif /* !_POSIX_SOURCE */
145 
146 # if defined (HAVE_DIRENT_H)
147 #   include <dirent.h>
148 #   define D_NAMLEN(dirent) strlen((dirent)->d_name)
149 # else /* !HAVE_DIRENT_H */
150 #   define dirent direct
151 #   define D_NAMLEN(dirent) (dirent)->d_namlen
152 #   if defined (HAVE_SYS_NDIR_H)
153 #     include <sys/ndir.h>
154 #   endif /* HAVE_SYS_NDIR_H */
155 #   if defined (HAVE_SYS_DIR_H)
156 #     include <sys/dir.h>
157 #   endif /* HAVE_SYS_DIR_H */
158 #   if defined (HAVE_NDIR_H)
159 #     include <ndir.h>
160 #   endif /* HAVE_NDIR_H */
161 # endif /* !HAVE_DIRENT_H */
162 
163 #include <errno.h>
164 #ifdef HAVE_FCNTL_H
165 # include <fcntl.h>
166 #endif
167 #ifndef O_NONBLOCK
168 # define O_NONBLOCK FNDELAY
169 #endif
170 
171 #if defined(HAVE_LIBGEN) && defined(HAVE_LIBGEN_H)
172 #  include <libgen.h>
173 #endif
174 
175 #if defined(HAVE_LIMITS_H)  /* this is also in options.h */
176 #  include <limits.h>
177 #elif defined(HAVE_SYS_LIMITS_H)
178 #  include <sys/limits.h>
179 #endif /* HAVE_LIMITS/SYS_LIMITS_H */
180 
181 #include <memory.h>
182 #include <setjmp.h>
183 #include <signal.h>
184 
185 #if defined( HAVE_STDINT_H )
186 #  include <stdint.h>
187 #elif defined( HAVE_INTTYPES_H )
188 #  include <inttypes.h>
189 #endif
190 
191 #include <stdlib.h>
192 #include <string.h>
193 
194 #include <time.h>
195 
196 #ifdef HAVE_UTIME_H
197 #  include <utime.h>
198 #endif
199 
200 #ifdef HAVE_UNISTD_H
201 #  include <unistd.h>
202 #endif
203 
204 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
205  *
206  *  FIXUPS and CONVIENCE STUFF:
207  */
208 #ifdef __cplusplus
209 #   define EXTERN extern "C"
210 #else
211 #   define EXTERN extern
212 #endif
213 
214 /* some systems #def errno! and others do not declare it!! */
215 #ifndef errno
216    extern int errno;
217 #endif
218 
219 /* Some machines forget this! */
220 
221 # ifndef EXIT_FAILURE
222 #   define EXIT_SUCCESS 0
223 #   define EXIT_FAILURE 1
224 # endif
225 
226 #ifndef NUL
227 #  define NUL '\0'
228 #endif
229 
230 #ifndef NULL
231 #  define NULL 0
232 #endif
233 
234 #if !defined (MAXPATHLEN) && defined (HAVE_SYS_PARAM_H)
235 #  include <sys/param.h>
236 #endif /* !MAXPATHLEN && HAVE_SYS_PARAM_H */
237 
238 #if !defined (MAXPATHLEN) && defined (PATH_MAX)
239 #  define MAXPATHLEN PATH_MAX
240 #endif /* !MAXPATHLEN && PATH_MAX */
241 
242 #if !defined (MAXPATHLEN) && defined(_MAX_PATH)
243 #  define PATH_MAX _MAX_PATH
244 #  define MAXPATHLEN _MAX_PATH
245 #endif
246 
247 #if !defined (MAXPATHLEN)
248 #  define MAXPATHLEN ((size_t)4096)
249 #endif /* MAXPATHLEN */
250 
251 #define AG_PATH_MAX  ((size_t)MAXPATHLEN)
252 
253 #ifndef LONG_MAX
254 #  define LONG_MAX      ~(1L << (8*sizeof(long) -1))
255 #  define INT_MAX       ~(1 << (8*sizeof(int) -1))
256 #endif
257 
258 #ifndef ULONG_MAX
259 #  define ULONG_MAX     ~(OUL)
260 #  define UINT_MAX      ~(OU)
261 #endif
262 
263 #ifndef SHORT_MAX
264 #  define SHORT_MAX     ~(1 << (8*sizeof(short) - 1))
265 #else
266 #  define USHORT_MAX    ~(OUS)
267 #endif
268 
269 #ifndef HAVE_INT8_T
270   typedef signed char           int8_t;
271 # define  HAVE_INT8_T           1
272 #endif
273 #ifndef HAVE_UINT8_T
274   typedef unsigned char         uint8_t;
275 # define  HAVE_UINT8_T          1
276 #endif
277 #ifndef HAVE_INT16_T
278   typedef signed short          int16_t;
279 # define  HAVE_INT16_T          1
280 #endif
281 #ifndef HAVE_UINT16_T
282   typedef unsigned short        uint16_t;
283 # define  HAVE_UINT16_T         1
284 #endif
285 
286 #ifndef HAVE_INT32_T
287 # if SIZEOF_INT ==              4
288     typedef signed int          int32_t;
289 # elif SIZEOF_LONG ==           4
290     typedef signed long         int32_t;
291 # endif
292 # define  HAVE_INT32_T          1
293 #endif
294 
295 #ifndef HAVE_UINT32_T
296 # if SIZEOF_INT ==              4
297     typedef unsigned int        uint32_t;
298 # elif SIZEOF_LONG ==           4
299     typedef unsigned long       uint32_t;
300 # else
301 #   error Cannot create a uint32_t type.
302     Choke Me.
303 # endif
304 # define  HAVE_UINT32_T         1
305 #endif
306 
307 #ifndef HAVE_INTPTR_T
308 # if SIZEOF_CHARP == SIZEOF_LONG
309     typedef signed long         intptr_t;
310 # else
311     typedef signed int          intptr_t;
312 # endif
313 # define  HAVE_INTPTR_T         1
314 #endif
315 
316 #ifndef HAVE_UINTPTR_T
317 # if SIZEOF_CHARP == SIZEOF_LONG
318     typedef unsigned long       intptr_t;
319 # else
320     typedef unsigned int        intptr_t;
321 # endif
322 # define  HAVE_INTPTR_T         1
323 #endif
324 
325 #ifndef HAVE_UINT_T
326   typedef unsigned int          uint_t;
327 # define  HAVE_UINT_T           1
328 #endif
329 
330 #ifndef HAVE_SIZE_T
331   typedef unsigned int          size_t;
332 # define  HAVE_SIZE_T           1
333 #endif
334 #ifndef HAVE_WINT_T
335   typedef unsigned int          wint_t;
336 # define  HAVE_WINT_T           1
337 #endif
338 #ifndef HAVE_PID_T
339   typedef signed int            pid_t;
340 # define  HAVE_PID_T            1
341 #endif
342 
343 /* redefine these for BSD style string libraries */
344 #ifndef HAVE_STRCHR
345 #  define strchr            index
346 #  define strrchr           rindex
347 #endif
348 
349 #ifdef USE_FOPEN_BINARY
350 #  ifndef FOPEN_BINARY_FLAG
351 #    define FOPEN_BINARY_FLAG   "b"
352 #  endif
353 #  ifndef FOPEN_TEXT_FLAG
354 #    define FOPEN_TEXT_FLAG     "t"
355 #  endif
356 #else
357 #  ifndef FOPEN_BINARY_FLAG
358 #    define FOPEN_BINARY_FLAG
359 #  endif
360 #  ifndef FOPEN_TEXT_FLAG
361 #    define FOPEN_TEXT_FLAG
362 #  endif
363 #endif
364 
365 #ifndef STR
366 #  define _STR(s) #s
367 #  define STR(s)  _STR(s)
368 #endif
369 
370 /* ##### Pointer sized word ##### */
371 
372 /* FIXME:  the MAX stuff in here is broken! */
373 #if SIZEOF_CHARP > SIZEOF_INT
374    typedef long t_word;
375    #define WORD_MAX  LONG_MAX
376    #define WORD_MIN  LONG_MIN
377 #else /* SIZEOF_CHARP <= SIZEOF_INT */
378    typedef int t_word;
379    #define WORD_MAX  INT_MAX
380    #define WORD_MIN  INT_MIN
381 #endif
382 
383 #endif /* COMPAT_H_GUARD */
384 
385 /*
386  * Local Variables:
387  * mode: C
388  * c-file-style: "stroustrup"
389  * indent-tabs-mode: nil
390  * End:
391  * end of compat/compat.h */
392