4 * \file compat.h --- fake the preprocessor into handlng portability
6 * Time-stamp: "2012-02-28 19:40:44 bkorb"
8 * compat.h is free software.
9 * This file is part of AutoGen.
11 * AutoGen Copyright (c) 1992-2012 by Bruce Korb - all rights reserved
13 * AutoGen is free software: you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation, either version 3 of the License, or
16 * (at your option) any later version.
18 * AutoGen is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21 * See the GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License along
24 * with this program. If not, see <http://www.gnu.org/licenses/>.
26 * As a special exception, Bruce Korb gives permission for additional
27 * uses of the text contained in the release of compat.h.
29 * The exception is that, if you link the compat.h library with other
30 * files to produce an executable, this does not by itself cause the
31 * resulting executable to be covered by the GNU General Public License.
32 * Your use of that executable is in no way restricted on account of
33 * linking the compat.h library code into it.
35 * This exception does not however invalidate any other reasons why
36 * the executable file might be covered by the GNU General Public License.
38 * This exception applies only to the code released by Bruce Korb under
39 * the name compat.h. If you copy code from other sources under the
40 * General Public License into a copy of compat.h, as the General Public
41 * License permits, the exception does not apply to the code that you add
42 * in this way. To avoid misleading anyone as to the status of such
43 * modified files, you must delete this exception notice from them.
45 * If you write modifications of your own for compat.h, it is your choice
46 * whether to permit this exception to apply to your modifications.
47 * If you do not wish that, delete this exception notice.
49 #ifndef COMPAT_H_GUARD
50 #define COMPAT_H_GUARD 1
52 #if defined(HAVE_CONFIG_H)
55 #elif defined(_WIN32) && !defined(__CYGWIN__)
56 # include "windows-config.h"
59 # error "compat.h" requires "config.h"
64 #ifndef HAVE_STRSIGNAL
65 char * strsignal( int signo
);
68 #define _GNU_SOURCE 1 /* for strsignal in GNU's libc */
69 #define __USE_GNU 1 /* exact same thing as above */
70 #define __EXTENSIONS__ 1 /* and another way to call for it */
72 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
76 #include <sys/types.h>
77 #ifdef HAVE_SYS_MMAN_H
78 # include <sys/mman.h>
80 #include <sys/param.h>
81 #if HAVE_SYS_PROCSET_H
82 # include <sys/procset.h>
85 #ifdef HAVE_SYS_WAIT_H
86 # include <sys/wait.h>
89 #if defined( HAVE_SOLARIS_SYSINFO )
90 # include <sys/systeminfo.h>
91 #elif defined( HAVE_UNAME_SYSCALL )
92 # include <sys/utsname.h>
96 # if HAVE_SYS_STROPTS_H
97 # include <sys/stropts.h>
100 # if HAVE_SYS_SOCKET_H
101 # include <sys/socket.h>
104 # if ! defined(HAVE_SYS_POLL_H) && ! defined(HAVE_SYS_SELECT_H)
105 # error This system cannot support daemon processing
110 # include <sys/poll.h>
113 # if HAVE_SYS_SELECT_H
114 # include <sys/select.h>
117 # if HAVE_NETINET_IN_H
118 # include <netinet/in.h>
126 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
135 * Directory opening stuff:
137 # if defined (_POSIX_SOURCE)
138 /* Posix does not require that the d_ino field be present, and some
139 systems do not provide it. */
140 # define REAL_DIR_ENTRY(dp) 1
141 # else /* !_POSIX_SOURCE */
142 # define REAL_DIR_ENTRY(dp) (dp->d_ino != 0)
143 # endif /* !_POSIX_SOURCE */
145 # if defined (HAVE_DIRENT_H)
147 # define D_NAMLEN(dirent) strlen((dirent)->d_name)
148 # else /* !HAVE_DIRENT_H */
149 # define dirent direct
150 # define D_NAMLEN(dirent) (dirent)->d_namlen
151 # if defined (HAVE_SYS_NDIR_H)
152 # include <sys/ndir.h>
153 # endif /* HAVE_SYS_NDIR_H */
154 # if defined (HAVE_SYS_DIR_H)
155 # include <sys/dir.h>
156 # endif /* HAVE_SYS_DIR_H */
157 # if defined (HAVE_NDIR_H)
159 # endif /* HAVE_NDIR_H */
160 # endif /* !HAVE_DIRENT_H */
167 # define O_NONBLOCK FNDELAY
170 #if defined(HAVE_LIBGEN) && defined(HAVE_LIBGEN_H)
174 #if defined(HAVE_LIMITS_H) /* this is also in options.h */
176 #elif defined(HAVE_SYS_LIMITS_H)
177 # include <sys/limits.h>
178 #endif /* HAVE_LIMITS/SYS_LIMITS_H */
184 #if defined(HAVE_STDINT_H)
187 #elif defined(HAVE_INTTYPES_H)
188 # include <inttypes.h>
203 #ifdef HAVE_STDBOOL_H
204 # include <stdbool.h>
206 typedef enum { false = 0, true = 1 } _Bool
;
209 /* The other macros must be usable in preprocessor directives. */
214 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
216 * FIXUPS and CONVIENCE STUFF:
219 # define EXTERN extern "C"
221 # define EXTERN extern
224 /* some systems #def errno! and others do not declare it!! */
229 /* Some machines forget this! */
231 # ifndef EXIT_FAILURE
232 # define EXIT_SUCCESS 0
233 # define EXIT_FAILURE 1
244 #if !defined (MAXPATHLEN) && defined (HAVE_SYS_PARAM_H)
245 # include <sys/param.h>
246 #endif /* !MAXPATHLEN && HAVE_SYS_PARAM_H */
248 #if !defined (MAXPATHLEN) && defined (PATH_MAX)
249 # define MAXPATHLEN PATH_MAX
250 #endif /* !MAXPATHLEN && PATH_MAX */
252 #if !defined (MAXPATHLEN) && defined(_MAX_PATH)
253 # define PATH_MAX _MAX_PATH
254 # define MAXPATHLEN _MAX_PATH
257 #if !defined (MAXPATHLEN)
258 # define MAXPATHLEN ((size_t)4096)
259 #endif /* MAXPATHLEN */
261 #define AG_PATH_MAX ((size_t)MAXPATHLEN)
264 # define LONG_MAX ~(1L << (8*sizeof(long) -1))
265 # define INT_MAX ~(1 << (8*sizeof(int) -1))
269 # define ULONG_MAX ~(OUL)
270 # define UINT_MAX ~(OU)
274 # define SHORT_MAX ~(1 << (8*sizeof(short) - 1))
276 # define USHORT_MAX ~(OUS)
280 typedef signed char int8_t;
281 # define HAVE_INT8_T 1
284 typedef unsigned char uint8_t;
285 # define HAVE_UINT8_T 1
288 typedef signed short int16_t;
289 # define HAVE_INT16_T 1
291 #ifndef HAVE_UINT16_T
292 typedef unsigned short uint16_t;
293 # define HAVE_UINT16_T 1
298 typedef signed int int32_t;
299 # elif SIZEOF_LONG == 4
300 typedef signed long int32_t;
302 # define HAVE_INT32_T 1
305 #ifndef HAVE_UINT32_T
307 typedef unsigned int uint32_t;
308 # elif SIZEOF_LONG == 4
309 typedef unsigned long uint32_t;
311 # error Cannot create a uint32_t type.
314 # define HAVE_UINT32_T 1
317 #ifndef HAVE_INTPTR_T
318 # if SIZEOF_CHARP == SIZEOF_LONG
319 typedef signed long intptr_t;
321 typedef signed int intptr_t;
323 # define HAVE_INTPTR_T 1
326 #ifndef HAVE_UINTPTR_T
327 # if SIZEOF_CHARP == SIZEOF_LONG
328 typedef unsigned long intptr_t;
330 typedef unsigned int intptr_t;
332 # define HAVE_INTPTR_T 1
336 typedef unsigned int uint_t
;
337 # define HAVE_UINT_T 1
341 typedef unsigned int size_t;
342 # define HAVE_SIZE_T 1
345 typedef unsigned int wint_t;
346 # define HAVE_WINT_T 1
349 typedef signed int pid_t
;
350 # define HAVE_PID_T 1
353 /* redefine these for BSD style string libraries */
355 # define strchr index
356 # define strrchr rindex
359 #ifdef USE_FOPEN_BINARY
360 # ifndef FOPEN_BINARY_FLAG
361 # define FOPEN_BINARY_FLAG "b"
363 # ifndef FOPEN_TEXT_FLAG
364 # define FOPEN_TEXT_FLAG "t"
367 # ifndef FOPEN_BINARY_FLAG
368 # define FOPEN_BINARY_FLAG
370 # ifndef FOPEN_TEXT_FLAG
371 # define FOPEN_TEXT_FLAG
377 # define STR(s) _STR(s)
380 /* ##### Pointer sized word ##### */
382 /* FIXME: the MAX stuff in here is broken! */
383 #if SIZEOF_CHARP > SIZEOF_INT
385 #define WORD_MAX LONG_MAX
386 #define WORD_MIN LONG_MIN
387 #else /* SIZEOF_CHARP <= SIZEOF_INT */
389 #define WORD_MAX INT_MAX
390 #define WORD_MIN INT_MIN
393 #endif /* COMPAT_H_GUARD */
398 * c-file-style: "stroustrup"
399 * indent-tabs-mode: nil
401 * end of compat/compat.h */