3 * compat.h is free software.
4 * This file is part of AutoGen and AutoOpts.
6 * AutoGen Copyright (C) 1992-2015 by Bruce Korb - all rights reserved
8 * AutoOpts is available under any one of two licenses. The license
9 * in use must be one of these two and the choice is under the control
10 * of the user of the license.
12 * The GNU Lesser General Public License, version 3 or later
13 * See the files "COPYING.lgplv3" and "COPYING.gplv3"
15 * The Modified Berkeley Software Distribution License
16 * See the file "COPYING.mbsd"
18 * These files have the following sha256 sums:
20 * 8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95 COPYING.gplv3
21 * 4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b COPYING.lgplv3
22 * 13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239 COPYING.mbsd
27 * fake the preprocessor into handlng stuff portability
29 #ifndef COMPAT_H_GUARD
30 #define COMPAT_H_GUARD 1
32 #if defined(HAVE_CONFIG_H)
35 #elif defined(_WIN32) && !defined(__CYGWIN__)
36 # include "windows-config.h"
39 # error "compat.h" requires "config.h"
44 #ifndef HAVE_STRSIGNAL
45 # ifndef HAVE_RAW_DECL_STRSIGNAL
46 char * strsignal(int signo);
50 #define _GNU_SOURCE 1 /* for strsignal in GNU's libc */
51 #define __USE_GNU 1 /* exact same thing as above */
52 #define __EXTENSIONS__ 1 /* and another way to call for it */
54 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
58 #include <sys/types.h>
59 #ifdef HAVE_SYS_MMAN_H
60 # include <sys/mman.h>
62 #include <sys/param.h>
63 #if HAVE_SYS_PROCSET_H
64 # include <sys/procset.h>
67 #ifdef HAVE_SYS_WAIT_H
68 # include <sys/wait.h>
71 #if defined( HAVE_SOLARIS_SYSINFO )
72 # include <sys/systeminfo.h>
73 #elif defined( HAVE_UNAME_SYSCALL )
74 # include <sys/utsname.h>
78 # if HAVE_SYS_STROPTS_H
79 # include <sys/stropts.h>
82 # if HAVE_SYS_SOCKET_H
83 # include <sys/socket.h>
86 # if ! defined(HAVE_SYS_POLL_H) && ! defined(HAVE_SYS_SELECT_H)
87 # error This system cannot support daemon processing
92 # include <sys/poll.h>
95 # if HAVE_SYS_SELECT_H
96 # include <sys/select.h>
99 # if HAVE_NETINET_IN_H
100 # include <netinet/in.h>
108 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
117 * Directory opening stuff:
119 # if defined (_POSIX_SOURCE)
120 /* Posix does not require that the d_ino field be present, and some
121 systems do not provide it. */
122 # define REAL_DIR_ENTRY(dp) 1
123 # else /* !_POSIX_SOURCE */
124 # define REAL_DIR_ENTRY(dp) (dp->d_ino != 0)
125 # endif /* !_POSIX_SOURCE */
127 # if defined (HAVE_DIRENT_H)
129 # define D_NAMLEN(dirent) strlen((dirent)->d_name)
130 # else /* !HAVE_DIRENT_H */
131 # define dirent direct
132 # define D_NAMLEN(dirent) (dirent)->d_namlen
133 # if defined (HAVE_SYS_NDIR_H)
134 # include <sys/ndir.h>
135 # endif /* HAVE_SYS_NDIR_H */
136 # if defined (HAVE_SYS_DIR_H)
137 # include <sys/dir.h>
138 # endif /* HAVE_SYS_DIR_H */
139 # if defined (HAVE_NDIR_H)
141 # endif /* HAVE_NDIR_H */
142 # endif /* !HAVE_DIRENT_H */
149 # define O_NONBLOCK FNDELAY
152 #if defined(HAVE_LIBGEN) && defined(HAVE_LIBGEN_H)
156 #if defined(HAVE_LIMITS_H) /* this is also in options.h */
158 #elif defined(HAVE_SYS_LIMITS_H)
159 # include <sys/limits.h>
160 #endif /* HAVE_LIMITS/SYS_LIMITS_H */
166 #if defined(HAVE_STDINT_H)
169 #elif defined(HAVE_INTTYPES_H)
170 # include <inttypes.h>
185 #ifdef HAVE_STDBOOL_H
186 # include <stdbool.h>
188 typedef enum { false = 0, true = 1 } _Bool;
191 /* The other macros must be usable in preprocessor directives. */
196 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
198 * FIXUPS and CONVIENCE STUFF:
201 # define EXTERN extern "C"
203 # define EXTERN extern
206 /* some systems #def errno! and others do not declare it!! */
211 /* Some machines forget this! */
213 # ifndef EXIT_FAILURE
214 # define EXIT_SUCCESS 0
215 # define EXIT_FAILURE 1
226 #if !defined (MAXPATHLEN) && defined (HAVE_SYS_PARAM_H)
227 # include <sys/param.h>
228 #endif /* !MAXPATHLEN && HAVE_SYS_PARAM_H */
230 #if !defined (MAXPATHLEN) && defined (PATH_MAX)
231 # define MAXPATHLEN PATH_MAX
232 #endif /* !MAXPATHLEN && PATH_MAX */
234 #if !defined (MAXPATHLEN) && defined(_MAX_PATH)
235 # define PATH_MAX _MAX_PATH
236 # define MAXPATHLEN _MAX_PATH
239 #if !defined (MAXPATHLEN)
240 # define MAXPATHLEN 4096
241 #endif /* MAXPATHLEN */
243 #define AG_PATH_MAX ((size_t)MAXPATHLEN)
246 # define LONG_MAX ~(1L << (8*sizeof(long) -1))
247 # define INT_MAX ~(1 << (8*sizeof(int) -1))
251 # define ULONG_MAX ~(OUL)
252 # define UINT_MAX ~(OU)
256 # define SHORT_MAX ~(1 << (8*sizeof(short) - 1))
258 # define USHORT_MAX ~(OUS)
262 typedef signed char int8_t;
263 # define HAVE_INT8_T 1
266 typedef unsigned char uint8_t;
267 # define HAVE_UINT8_T 1
270 typedef signed short int16_t;
271 # define HAVE_INT16_T 1
273 #ifndef HAVE_UINT16_T
274 typedef unsigned short uint16_t;
275 # define HAVE_UINT16_T 1
280 typedef signed int int32_t;
281 # elif SIZEOF_LONG == 4
282 typedef signed long int32_t;
284 # define HAVE_INT32_T 1
287 #ifndef HAVE_UINT32_T
289 typedef unsigned int uint32_t;
290 # elif SIZEOF_LONG == 4
291 typedef unsigned long uint32_t;
293 # error Cannot create a uint32_t type.
296 # define HAVE_UINT32_T 1
299 #ifndef HAVE_INTPTR_T
300 # if SIZEOF_CHARP == SIZEOF_LONG
301 typedef signed long intptr_t;
303 typedef signed int intptr_t;
305 # define HAVE_INTPTR_T 1
308 #ifndef HAVE_UINTPTR_T
309 # if SIZEOF_CHARP == SIZEOF_LONG
310 typedef unsigned long intptr_t;
312 typedef unsigned int intptr_t;
314 # define HAVE_INTPTR_T 1
318 typedef unsigned int uint_t;
319 # define HAVE_UINT_T 1
323 typedef unsigned int size_t;
324 # define HAVE_SIZE_T 1
327 typedef unsigned int wint_t;
328 # define HAVE_WINT_T 1
331 typedef signed int pid_t;
332 # define HAVE_PID_T 1
335 /* redefine these for BSD style string libraries */
337 # define strchr index
338 # define strrchr rindex
341 #ifdef USE_FOPEN_BINARY
342 # ifndef FOPEN_BINARY_FLAG
343 # define FOPEN_BINARY_FLAG "b"
345 # ifndef FOPEN_TEXT_FLAG
346 # define FOPEN_TEXT_FLAG "t"
349 # ifndef FOPEN_BINARY_FLAG
350 # define FOPEN_BINARY_FLAG
352 # ifndef FOPEN_TEXT_FLAG
353 # define FOPEN_TEXT_FLAG
359 # define STR(s) _STR(s)
362 /* ##### Pointer sized word ##### */
364 /* FIXME: the MAX stuff in here is broken! */
365 #if SIZEOF_CHARP > SIZEOF_INT
367 #define WORD_MAX LONG_MAX
368 #define WORD_MIN LONG_MIN
369 #else /* SIZEOF_CHARP <= SIZEOF_INT */
371 #define WORD_MAX INT_MAX
372 #define WORD_MIN INT_MIN
375 #endif /* COMPAT_H_GUARD */
380 * c-file-style: "stroustrup"
381 * indent-tabs-mode: nil
383 * end of compat/compat.h */