5 /* --- fake the preprocessor into handlng portability */
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)
20 #elif defined(_WIN32) && !defined(__CYGWIN__)
21 # include "windows-config.h"
24 # error "compat.h" requires "config.h"
29 #ifndef HAVE_STRSIGNAL
30 char * strsignal( int signo
);
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 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
41 #include <sys/types.h>
42 #ifdef HAVE_SYS_MMAN_H
43 # include <sys/mman.h>
45 #include <sys/param.h>
46 #if HAVE_SYS_PROCSET_H
47 # include <sys/procset.h>
52 #if defined( HAVE_SOLARIS_SYSINFO )
53 # include <sys/systeminfo.h>
54 #elif defined( HAVE_UNAME_SYSCALL )
55 # include <sys/utsname.h>
59 # if HAVE_SYS_STROPTS_H
60 # include <sys/stropts.h>
63 # if HAVE_SYS_SOCKET_H
64 # include <sys/socket.h>
67 # if ! defined(HAVE_SYS_POLL_H) && ! defined(HAVE_SYS_SELECT_H)
68 # error This system cannot support daemon processing
73 # include <sys/poll.h>
76 # if HAVE_SYS_SELECT_H
77 # include <sys/select.h>
80 # if HAVE_NETINET_IN_H
81 # include <netinet/in.h>
89 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
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)
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)
122 # endif /* HAVE_NDIR_H */
123 # endif /* !HAVE_DIRENT_H */
130 # define O_NONBLOCK FNDELAY
133 #if defined(HAVE_LIBGEN) && defined(HAVE_LIBGEN_H)
137 #if defined(HAVE_LIMITS_H) /* this is also in options.h */
139 #elif defined(HAVE_SYS_LIMITS_H)
140 # include <sys/limits.h>
141 #endif /* HAVE_LIMITS/SYS_LIMITS_H */
147 #if defined( HAVE_STDINT_H )
149 #elif defined( HAVE_INTTYPES_H )
150 # include <inttypes.h>
166 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
168 * FIXUPS and CONVIENCE STUFF:
171 # define EXTERN extern "C"
173 # define EXTERN extern
176 /* some systems #def errno! and others do not declare it!! */
181 /* Some machines forget this! */
183 # ifndef EXIT_FAILURE
184 # define EXIT_SUCCESS 0
185 # define EXIT_FAILURE 1
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
209 #if !defined (MAXPATHLEN)
210 # define MAXPATHLEN ((size_t)4096)
211 #endif /* MAXPATHLEN */
213 #define AG_PATH_MAX ((size_t)MAXPATHLEN)
216 # define LONG_MAX ~(1L << (8*sizeof(long) -1))
217 # define INT_MAX ~(1 << (8*sizeof(int) -1))
221 # define ULONG_MAX ~(OUL)
222 # define UINT_MAX ~(OU)
226 # define SHORT_MAX ~(1 << (8*sizeof(short) -1))
228 # define USHORT_MAX ~(OUS)
232 typedef signed char int8_t;
235 typedef unsigned char uint8_t;
238 typedef signed short int16_t;
240 #ifndef HAVE_UINT16_T
241 typedef unsigned short uint16_t;
244 typedef unsigned int uint_t
;
249 typedef signed int int32_t;
250 # elif SIZEOF_LONG == 4
251 typedef signed long int32_t;
255 #ifndef HAVE_UINT32_T
257 typedef unsigned int uint32_t;
258 # elif SIZEOF_LONG == 4
259 typedef unsigned long uint32_t;
261 # error Cannot create a uint32_t type.
266 #ifndef HAVE_INTPTR_T
267 typedef signed long intptr_t;
269 #ifndef HAVE_UINTPTR_T
270 typedef unsigned long uintptr_t;
273 /* redefine these for BSD style string libraries */
275 # define strchr index
276 # define strrchr rindex
279 #ifdef USE_FOPEN_BINARY
280 # ifndef FOPEN_BINARY_FLAG
281 # define FOPEN_BINARY_FLAG "b"
283 # ifndef FOPEN_TEXT_FLAG
284 # define FOPEN_TEXT_FLAG "t"
287 # ifndef FOPEN_BINARY_FLAG
288 # define FOPEN_BINARY_FLAG
290 # ifndef FOPEN_TEXT_FLAG
291 # define FOPEN_TEXT_FLAG
297 # define STR(s) _STR(s)
300 /* ##### Pointer sized word ##### */
302 /* FIXME: the MAX stuff in here is broken! */
303 #if SIZEOF_CHARP > SIZEOF_INT
305 #define WORD_MAX LONG_MAX
306 #define WORD_MIN LONG_MIN
307 #else /* SIZEOF_CHARP <= SIZEOF_INT */
309 #define WORD_MAX INT_MAX
310 #define WORD_MIN INT_MIN
313 #endif /* COMPAT_H_GUARD */
318 * c-file-style: "stroustrup"
319 * indent-tabs-mode: nil
321 * end of compat/compat.h */