3 /* --- fake the preprocessor into handlng portability */
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)
18 #elif defined(_WIN32) && !defined(__CYGWIN__)
19 # include "windows-config.h"
22 # error "compat.h" requires "config.h"
27 #ifndef HAVE_STRSIGNAL
28 char * strsignal( int signo
);
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 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
39 #include <sys/types.h>
40 #ifdef HAVE_SYS_MMAN_H
41 # include <sys/mman.h>
43 #include <sys/param.h>
44 #if HAVE_SYS_PROCSET_H
45 # include <sys/procset.h>
50 #if defined( HAVE_SOLARIS_SYSINFO )
51 # include <sys/systeminfo.h>
52 #elif defined( HAVE_UNAME_SYSCALL )
53 # include <sys/utsname.h>
57 # if HAVE_SYS_STROPTS_H
58 # include <sys/stropts.h>
61 # if HAVE_SYS_SOCKET_H
62 # include <sys/socket.h>
65 # if ! defined(HAVE_SYS_POLL_H) && ! defined(HAVE_SYS_SELECT_H)
66 # error This system cannot support daemon processing
71 # include <sys/poll.h>
74 # if HAVE_SYS_SELECT_H
75 # include <sys/select.h>
78 # if HAVE_NETINET_IN_H
79 # include <netinet/in.h>
87 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
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)
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)
120 # endif /* HAVE_NDIR_H */
121 # endif /* !HAVE_DIRENT_H */
128 # define O_NONBLOCK FNDELAY
131 #if defined(HAVE_LIBGEN) && defined(HAVE_LIBGEN_H)
135 #if defined(HAVE_LIMITS_H) /* this is also in options.h */
137 #elif defined(HAVE_SYS_LIMITS_H)
138 # include <sys/limits.h>
139 #endif /* HAVE_LIMITS/SYS_LIMITS_H */
145 #if defined( HAVE_STDINT_H )
147 #elif defined( HAVE_INTTYPES_H )
148 # include <inttypes.h>
164 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
166 * FIXUPS and CONVIENCE STUFF:
169 # define EXTERN extern "C"
171 # define EXTERN extern
174 /* some systems #def errno! and others do not declare it!! */
179 /* Some machines forget this! */
181 # ifndef EXIT_FAILURE
182 # define EXIT_SUCCESS 0
183 # define EXIT_FAILURE 1
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
207 #if !defined (MAXPATHLEN)
208 # define MAXPATHLEN ((size_t)4096)
209 #endif /* MAXPATHLEN */
211 #define AG_PATH_MAX ((size_t)MAXPATHLEN)
214 # define LONG_MAX ~(1L << (8*sizeof(long) -1))
215 # define INT_MAX ~(1 << (8*sizeof(int) -1))
219 # define ULONG_MAX ~(OUL)
220 # define UINT_MAX ~(OU)
224 # define SHORT_MAX ~(1 << (8*sizeof(short) -1))
226 # define USHORT_MAX ~(OUS)
230 typedef signed char int8_t;
233 typedef unsigned char uint8_t;
236 typedef signed short int16_t;
238 #ifndef HAVE_UINT16_T
239 typedef unsigned short uint16_t;
242 typedef unsigned int uint_t
;
247 typedef signed int int32_t;
248 # elif SIZEOF_LONG == 4
249 typedef signed long int32_t;
253 #ifndef HAVE_UINT32_T
255 typedef unsigned int uint32_t;
256 # elif SIZEOF_LONG == 4
257 typedef unsigned long uint32_t;
259 # error Cannot create a uint32_t type.
264 #ifndef HAVE_INTPTR_T
265 typedef signed long intptr_t;
267 #ifndef HAVE_UINTPTR_T
268 typedef unsigned long uintptr_t;
271 /* redefine these for BSD style string libraries */
273 # define strchr index
274 # define strrchr rindex
277 #ifdef USE_FOPEN_BINARY
278 # ifndef FOPEN_BINARY_FLAG
279 # define FOPEN_BINARY_FLAG "b"
281 # ifndef FOPEN_TEXT_FLAG
282 # define FOPEN_TEXT_FLAG "t"
285 # ifndef FOPEN_BINARY_FLAG
286 # define FOPEN_BINARY_FLAG
288 # ifndef FOPEN_TEXT_FLAG
289 # define FOPEN_TEXT_FLAG
295 # define STR(s) _STR(s)
298 /* ##### Pointer sized word ##### */
300 /* FIXME: the MAX stuff in here is broken! */
301 #if SIZEOF_CHARP > SIZEOF_INT
303 #define WORD_MAX LONG_MAX
304 #define WORD_MIN LONG_MIN
305 #else /* SIZEOF_CHARP <= SIZEOF_INT */
307 #define WORD_MAX INT_MAX
308 #define WORD_MIN INT_MIN
311 #endif /* COMPAT_H_GUARD */
316 * c-file-style: "stroustrup"
317 * indent-tabs-mode: nil
319 * end of compat/compat.h */