corrected copyright notices
[gnutls.git] / src / libopts / compat / compat.h
blob9d1c02ac4a4fb8880a03b3c1b616ffae4050e97a
1 /* -*- Mode: C -*- */
3 /**
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)
53 # include <config.h>
55 #elif defined(_WIN32) && !defined(__CYGWIN__)
56 # include "windows-config.h"
58 #else
59 # error "compat.h" requires "config.h"
60 choke me.
61 #endif
64 #ifndef HAVE_STRSIGNAL
65 char * strsignal( int signo );
66 #endif
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 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
74 * SYSTEM HEADERS:
76 #include <sys/types.h>
77 #ifdef HAVE_SYS_MMAN_H
78 # include <sys/mman.h>
79 #endif
80 #include <sys/param.h>
81 #if HAVE_SYS_PROCSET_H
82 # include <sys/procset.h>
83 #endif
84 #include <sys/stat.h>
85 #ifdef HAVE_SYS_WAIT_H
86 # include <sys/wait.h>
87 #endif
89 #if defined( HAVE_SOLARIS_SYSINFO )
90 # include <sys/systeminfo.h>
91 #elif defined( HAVE_UNAME_SYSCALL )
92 # include <sys/utsname.h>
93 #endif
95 #ifdef DAEMON_ENABLED
96 # if HAVE_SYS_STROPTS_H
97 # include <sys/stropts.h>
98 # endif
100 # if HAVE_SYS_SOCKET_H
101 # include <sys/socket.h>
102 # endif
104 # if ! defined(HAVE_SYS_POLL_H) && ! defined(HAVE_SYS_SELECT_H)
105 # error This system cannot support daemon processing
106 Choke Me.
107 # endif
109 # if HAVE_SYS_POLL_H
110 # include <sys/poll.h>
111 # endif
113 # if HAVE_SYS_SELECT_H
114 # include <sys/select.h>
115 # endif
117 # if HAVE_NETINET_IN_H
118 # include <netinet/in.h>
119 # endif
121 # if HAVE_SYS_UN_H
122 # include <sys/un.h>
123 # endif
124 #endif
126 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
128 * USER HEADERS:
130 #include <stdio.h>
131 #include <assert.h>
132 #include <ctype.h>
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)
146 # include <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)
158 # include <ndir.h>
159 # endif /* HAVE_NDIR_H */
160 # endif /* !HAVE_DIRENT_H */
162 #include <errno.h>
163 #ifdef HAVE_FCNTL_H
164 # include <fcntl.h>
165 #endif
166 #ifndef O_NONBLOCK
167 # define O_NONBLOCK FNDELAY
168 #endif
170 #if defined(HAVE_LIBGEN) && defined(HAVE_LIBGEN_H)
171 # include <libgen.h>
172 #endif
174 #if defined(HAVE_LIMITS_H) /* this is also in options.h */
175 # include <limits.h>
176 #elif defined(HAVE_SYS_LIMITS_H)
177 # include <sys/limits.h>
178 #endif /* HAVE_LIMITS/SYS_LIMITS_H */
180 #include <memory.h>
181 #include <setjmp.h>
182 #include <signal.h>
184 #if defined(HAVE_STDINT_H)
185 # include <stdint.h>
187 #elif defined(HAVE_INTTYPES_H)
188 # include <inttypes.h>
189 #endif
191 #include <stdlib.h>
192 #include <string.h>
193 #include <time.h>
195 #ifdef HAVE_UTIME_H
196 # include <utime.h>
197 #endif
199 #ifdef HAVE_UNISTD_H
200 # include <unistd.h>
201 #endif
203 #ifdef HAVE_STDBOOL_H
204 # include <stdbool.h>
205 #else
206 typedef enum { false = 0, true = 1 } _Bool;
207 # define bool _Bool
209 /* The other macros must be usable in preprocessor directives. */
210 # define false 0
211 # define true 1
212 #endif
214 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
216 * FIXUPS and CONVIENCE STUFF:
218 #ifdef __cplusplus
219 # define EXTERN extern "C"
220 #else
221 # define EXTERN extern
222 #endif
224 /* some systems #def errno! and others do not declare it!! */
225 #ifndef errno
226 extern int errno;
227 #endif
229 /* Some machines forget this! */
231 # ifndef EXIT_FAILURE
232 # define EXIT_SUCCESS 0
233 # define EXIT_FAILURE 1
234 # endif
236 #ifndef NUL
237 # define NUL '\0'
238 #endif
240 #ifndef NULL
241 # define NULL 0
242 #endif
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
255 #endif
257 #if !defined (MAXPATHLEN)
258 # define MAXPATHLEN ((size_t)4096)
259 #endif /* MAXPATHLEN */
261 #define AG_PATH_MAX ((size_t)MAXPATHLEN)
263 #ifndef LONG_MAX
264 # define LONG_MAX ~(1L << (8*sizeof(long) -1))
265 # define INT_MAX ~(1 << (8*sizeof(int) -1))
266 #endif
268 #ifndef ULONG_MAX
269 # define ULONG_MAX ~(OUL)
270 # define UINT_MAX ~(OU)
271 #endif
273 #ifndef SHORT_MAX
274 # define SHORT_MAX ~(1 << (8*sizeof(short) - 1))
275 #else
276 # define USHORT_MAX ~(OUS)
277 #endif
279 #ifndef HAVE_INT8_T
280 typedef signed char int8_t;
281 # define HAVE_INT8_T 1
282 #endif
283 #ifndef HAVE_UINT8_T
284 typedef unsigned char uint8_t;
285 # define HAVE_UINT8_T 1
286 #endif
287 #ifndef HAVE_INT16_T
288 typedef signed short int16_t;
289 # define HAVE_INT16_T 1
290 #endif
291 #ifndef HAVE_UINT16_T
292 typedef unsigned short uint16_t;
293 # define HAVE_UINT16_T 1
294 #endif
296 #ifndef HAVE_INT32_T
297 # if SIZEOF_INT == 4
298 typedef signed int int32_t;
299 # elif SIZEOF_LONG == 4
300 typedef signed long int32_t;
301 # endif
302 # define HAVE_INT32_T 1
303 #endif
305 #ifndef HAVE_UINT32_T
306 # if SIZEOF_INT == 4
307 typedef unsigned int uint32_t;
308 # elif SIZEOF_LONG == 4
309 typedef unsigned long uint32_t;
310 # else
311 # error Cannot create a uint32_t type.
312 Choke Me.
313 # endif
314 # define HAVE_UINT32_T 1
315 #endif
317 #ifndef HAVE_INTPTR_T
318 # if SIZEOF_CHARP == SIZEOF_LONG
319 typedef signed long intptr_t;
320 # else
321 typedef signed int intptr_t;
322 # endif
323 # define HAVE_INTPTR_T 1
324 #endif
326 #ifndef HAVE_UINTPTR_T
327 # if SIZEOF_CHARP == SIZEOF_LONG
328 typedef unsigned long intptr_t;
329 # else
330 typedef unsigned int intptr_t;
331 # endif
332 # define HAVE_INTPTR_T 1
333 #endif
335 #ifndef HAVE_UINT_T
336 typedef unsigned int uint_t;
337 # define HAVE_UINT_T 1
338 #endif
340 #ifndef HAVE_SIZE_T
341 typedef unsigned int size_t;
342 # define HAVE_SIZE_T 1
343 #endif
344 #ifndef HAVE_WINT_T
345 typedef unsigned int wint_t;
346 # define HAVE_WINT_T 1
347 #endif
348 #ifndef HAVE_PID_T
349 typedef signed int pid_t;
350 # define HAVE_PID_T 1
351 #endif
353 /* redefine these for BSD style string libraries */
354 #ifndef HAVE_STRCHR
355 # define strchr index
356 # define strrchr rindex
357 #endif
359 #ifdef USE_FOPEN_BINARY
360 # ifndef FOPEN_BINARY_FLAG
361 # define FOPEN_BINARY_FLAG "b"
362 # endif
363 # ifndef FOPEN_TEXT_FLAG
364 # define FOPEN_TEXT_FLAG "t"
365 # endif
366 #else
367 # ifndef FOPEN_BINARY_FLAG
368 # define FOPEN_BINARY_FLAG
369 # endif
370 # ifndef FOPEN_TEXT_FLAG
371 # define FOPEN_TEXT_FLAG
372 # endif
373 #endif
375 #ifndef STR
376 # define _STR(s) #s
377 # define STR(s) _STR(s)
378 #endif
380 /* ##### Pointer sized word ##### */
382 /* FIXME: the MAX stuff in here is broken! */
383 #if SIZEOF_CHARP > SIZEOF_INT
384 typedef long t_word;
385 #define WORD_MAX LONG_MAX
386 #define WORD_MIN LONG_MIN
387 #else /* SIZEOF_CHARP <= SIZEOF_INT */
388 typedef int t_word;
389 #define WORD_MAX INT_MAX
390 #define WORD_MIN INT_MIN
391 #endif
393 #endif /* COMPAT_H_GUARD */
396 * Local Variables:
397 * mode: C
398 * c-file-style: "stroustrup"
399 * indent-tabs-mode: nil
400 * End:
401 * end of compat/compat.h */