]> git.gag.com Git - fw/sdcc/blob - support/cpp2/system.h
ff0473d2204914a795365b95a616e846959032ba
[fw/sdcc] / support / cpp2 / system.h
1 /* Get common system includes and various definitions and declarations based
2    on autoconf macros.
3    Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
4
5 This file is part of GNU CC.
6
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING.  If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.  */
21
22
23 #ifndef GCC_SYSTEM_H
24 #define GCC_SYSTEM_H
25
26 /* This is the location of the online document giving information how
27    to report bugs. If you change this string, also check for strings
28    not under control of the preprocessor.  */
29 #define GCCBUGURL "<URL:http://www.gnu.org/software/gcc/bugs.html>"
30
31 #include "ansidecl.h"
32
33 /* We must include stdarg.h/varargs.h before stdio.h. */
34 #ifdef ANSI_PROTOTYPES
35 #include <stdarg.h>
36 #else
37 #include <varargs.h>
38 #endif
39
40 #ifndef va_copy
41 # ifdef __va_copy
42 #   define va_copy(d,s)  __va_copy((d),(s))
43 # else
44 #   define va_copy(d,s)  ((d) = (s))
45 # endif
46 #endif
47
48 #ifdef HAVE_STDDEF_H
49 # include <stddef.h>
50 #endif
51
52 #include <stdio.h>
53
54 #define CHAR_BIT 8
55
56 /* Define a generic NULL if one hasn't already been defined.  */
57 #ifndef NULL
58 #define NULL 0
59 #endif
60
61 /* There are an extraordinary number of issues with <ctype.h>.
62    The last straw is that it varies with the locale.  Use libiberty's
63    replacement instead.  */
64 #if defined(__APPLE__) && defined(__MACH__)
65 #include <libiberty/safe-ctype.h>
66 #else
67 #include <safe-ctype.h>
68 #endif
69
70 /* Define a default escape character; it's different for EBCDIC.  */
71 #ifndef TARGET_ESC
72 #define TARGET_ESC 033
73 #endif
74
75 #include <sys/types.h>
76
77 #include <errno.h>
78
79 #if !defined (errno) && defined (HAVE_DECL_ERRNO) && !HAVE_DECL_ERRNO
80 extern int errno;
81 #endif
82
83 #ifdef STRING_WITH_STRINGS
84 # include <string.h>
85 # include <strings.h>
86 #else
87 # ifdef HAVE_STRING_H
88 #  include <string.h>
89 # else
90 #  ifdef HAVE_STRINGS_H
91 #   include <strings.h>
92 #  endif
93 # endif
94 #endif
95
96 #ifdef HAVE_STDLIB_H
97 # include <stdlib.h>
98 #endif
99
100 /* If we don't have an overriding definition, set SUCCESS_EXIT_CODE and
101    FATAL_EXIT_CODE to EXIT_SUCCESS and EXIT_FAILURE respectively,
102    or 0 and 1 if those macros are not defined.  */
103 #ifndef SUCCESS_EXIT_CODE
104 # ifdef EXIT_SUCCESS
105 #  define SUCCESS_EXIT_CODE EXIT_SUCCESS
106 # else
107 #  define SUCCESS_EXIT_CODE 0
108 # endif
109 #endif
110
111 #ifndef FATAL_EXIT_CODE
112 # ifdef EXIT_FAILURE
113 #  define FATAL_EXIT_CODE EXIT_FAILURE
114 # else
115 #  define FATAL_EXIT_CODE 1
116 # endif
117 #endif
118
119 #ifdef HAVE_UNISTD_H
120 # include <unistd.h>
121 #endif
122
123 #ifdef HAVE_SYS_PARAM_H
124 # include <sys/param.h>
125 #endif
126
127 #if HAVE_LIMITS_H
128 # include <limits.h>
129 #endif
130
131 /* Get definitions of HOST_WIDE_INT and HOST_WIDEST_INT.  */
132 #include "hwint.h"
133
134 /* Infrastructure for defining missing _MAX and _MIN macros.  Note that
135    macros defined with these cannot be used in #if.  */
136
137 /* The extra casts work around common compiler bugs.  */
138 #define INTTYPE_SIGNED(t) (! ((t) 0 < (t) -1))
139 /* The outer cast is needed to work around a bug in Cray C 5.0.3.0.
140    It is necessary at least when t == time_t.  */
141 #define INTTYPE_MINIMUM(t) ((t) (INTTYPE_SIGNED (t) \
142                              ? ~ (t) 0 << (sizeof(t) * CHAR_BIT - 1) : (t) 0))
143 #define INTTYPE_MAXIMUM(t) ((t) (~ (t) 0 - INTTYPE_MINIMUM (t)))
144
145 /* Use that infrastructure to provide a few constants.  */
146 #ifndef UCHAR_MAX
147 # define UCHAR_MAX INTTYPE_MAXIMUM (unsigned char)
148 #endif
149
150 #ifdef TIME_WITH_SYS_TIME
151 # include <sys/time.h>
152 # include <time.h>
153 #else
154 # if HAVE_SYS_TIME_H
155 #  include <sys/time.h>
156 # else
157 #  ifdef HAVE_TIME_H
158 #   include <time.h>
159 #  endif
160 # endif
161 #endif
162
163 #ifdef HAVE_FCNTL_H
164 # include <fcntl.h>
165 #else
166 # ifdef HAVE_SYS_FILE_H
167 #  include <sys/file.h>
168 # endif
169 #endif
170
171 #ifndef SEEK_SET
172 # define SEEK_SET 0
173 # define SEEK_CUR 1
174 # define SEEK_END 2
175 #endif
176 #ifndef F_OK
177 # define F_OK 0
178 # define X_OK 1
179 # define W_OK 2
180 # define R_OK 4
181 #endif
182 #ifndef O_RDONLY
183 # define O_RDONLY 0
184 #endif
185 #ifndef O_WRONLY
186 # define O_WRONLY 1
187 #endif
188
189 /* Some systems define these in, e.g., param.h.  We undefine these names
190    here to avoid the warnings.  We prefer to use our definitions since we
191    know they are correct.  */
192
193 #undef MIN
194 #undef MAX
195 #define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
196 #define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
197
198 /* Returns the least number N such that N * Y >= X.  */
199 #define CEIL(x,y) (((x) + (y) - 1) / (y))
200
201 #ifdef HAVE_SYS_WAIT_H
202 #include <sys/wait.h>
203 #endif
204
205 #ifndef WIFSIGNALED
206 #define WIFSIGNALED(S) (((S) & 0xff) != 0 && ((S) & 0xff) != 0x7f)
207 #endif
208 #ifndef WTERMSIG
209 #define WTERMSIG(S) ((S) & 0x7f)
210 #endif
211 #ifndef WIFEXITED
212 #define WIFEXITED(S) (((S) & 0xff) == 0)
213 #endif
214 #ifndef WEXITSTATUS
215 #define WEXITSTATUS(S) (((S) & 0xff00) >> 8)
216 #endif
217 #ifndef WSTOPSIG
218 #define WSTOPSIG WEXITSTATUS
219 #endif
220
221 /* The HAVE_DECL_* macros are three-state, undefined, 0 or 1.  If they
222    are defined to 0 then we must provide the relevant declaration
223    here.  These checks will be in the undefined state while configure
224    is running so be careful to test "defined (HAVE_DECL_*)".  */
225
226 #if defined (HAVE_DECL_ATOF) && !HAVE_DECL_ATOF
227 extern double atof PARAMS ((const char *));
228 #endif
229
230 #if defined (HAVE_DECL_ATOL) && !HAVE_DECL_ATOL
231 extern long atol PARAMS ((const char *));
232 #endif
233
234 #if defined (HAVE_DECL_FREE) && !HAVE_DECL_FREE
235 extern void free PARAMS ((PTR));
236 #endif
237
238 #if defined (HAVE_DECL_GETCWD) && !HAVE_DECL_GETCWD
239 extern char *getcwd PARAMS ((char *, size_t));
240 #endif
241
242 #if defined (HAVE_DECL_GETENV) && !HAVE_DECL_GETENV
243 extern char *getenv PARAMS ((const char *));
244 #endif
245
246 #if defined (HAVE_DECL_GETOPT) && !HAVE_DECL_GETOPT
247 extern int getopt PARAMS ((int, char * const *, const char *));
248 #endif
249
250 #if defined (HAVE_DECL_GETWD) && !HAVE_DECL_GETWD
251 extern char *getwd PARAMS ((char *));
252 #endif
253
254 #if defined (HAVE_DECL_SBRK) && !HAVE_DECL_SBRK
255 extern PTR sbrk PARAMS ((int));
256 #endif
257
258 #if defined (HAVE_DECL_STRSTR) && !HAVE_DECL_STRSTR
259 extern char *strstr PARAMS ((const char *, const char *));
260 #endif
261
262 #ifdef HAVE_MALLOC_H
263 #include <malloc.h>
264 #endif
265
266 #if defined (HAVE_DECL_MALLOC) && !HAVE_DECL_MALLOC
267 extern PTR malloc PARAMS ((size_t));
268 #endif
269
270 #if defined (HAVE_DECL_CALLOC) && !HAVE_DECL_CALLOC
271 extern PTR calloc PARAMS ((size_t, size_t));
272 #endif
273
274 #if defined (HAVE_DECL_REALLOC) && !HAVE_DECL_REALLOC
275 extern PTR realloc PARAMS ((PTR, size_t));
276 #endif
277
278 #ifdef HAVE_GETRLIMIT
279 # if defined (HAVE_DECL_GETRLIMIT) && !HAVE_DECL_GETRLIMIT
280 #  ifndef getrlimit
281 #   ifdef ANSI_PROTOTYPES
282 struct rlimit;
283 #   endif
284 extern int getrlimit PARAMS ((int, struct rlimit *));
285 #  endif
286 # endif
287 #endif
288
289 #ifdef HAVE_SETRLIMIT
290 # if defined (HAVE_DECL_SETRLIMIT) && !HAVE_DECL_SETRLIMIT
291 #  ifndef setrlimit
292 #   ifdef ANSI_PROTOTYPES
293 struct rlimit;
294 #   endif
295 extern int setrlimit PARAMS ((int, const struct rlimit *));
296 #  endif
297 # endif
298 #endif
299
300 #if !defined(__STDC__) && !defined(volatile)
301 #define volatile
302 #endif
303
304 #if defined (HAVE_DECL_ABORT) && !HAVE_DECL_ABORT
305 extern void abort PARAMS ((void));
306 #endif
307
308 /* 1 if we have C99 designated initializers.  */
309 #if !defined(HAVE_DESIGNATED_INITIALIZERS)
310 #if defined(__APPLE__) && (__MACH__)
311 #define HAVE_DESIGNATED_INITIALIZERS 0
312 #else
313 #define HAVE_DESIGNATED_INITIALIZERS \
314   ((GCC_VERSION >= 2007) || (__STDC_VERSION__ >= 199901L))
315 #endif
316 #endif
317
318 #if HAVE_SYS_STAT_H
319 # include <sys/stat.h>
320 #endif
321
322 /* Test if something is a normal file.  */
323 #ifndef S_ISREG
324 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
325 #endif
326
327 /* Test if something is a directory.  */
328 #ifndef S_ISDIR
329 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
330 #endif
331
332 /* Test if something is a character special file.  */
333 #ifndef S_ISCHR
334 #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
335 #endif
336
337 /* Test if something is a block special file.  */
338 #ifndef S_ISBLK
339 #define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
340 #endif
341
342 /* Test if something is a socket.  */
343 #ifndef S_ISSOCK
344 # ifdef S_IFSOCK
345 #   define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
346 # else
347 #   define S_ISSOCK(m) 0
348 # endif
349 #endif
350
351 /* Test if something is a FIFO.  */
352 #ifndef S_ISFIFO
353 # ifdef S_IFIFO
354 #  define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
355 # else
356 #  define S_ISFIFO(m) 0
357 # endif
358 #endif
359
360 /* Approximate O_NONBLOCK.  */
361 #ifndef O_NONBLOCK
362 #define O_NONBLOCK O_NDELAY
363 #endif
364
365 /* Approximate O_NOCTTY.  */
366 #ifndef O_NOCTTY
367 #define O_NOCTTY 0
368 #endif
369
370 /* Define well known filenos if the system does not define them.  */
371 #ifndef STDIN_FILENO
372 # define STDIN_FILENO   0
373 #endif
374 #ifndef STDOUT_FILENO
375 # define STDOUT_FILENO  1
376 #endif
377 #ifndef STDERR_FILENO
378 # define STDERR_FILENO  2
379 #endif
380
381 /* Some systems have mkdir that takes a single argument. */
382 #ifdef MKDIR_TAKES_ONE_ARG
383 # define mkdir(a,b) mkdir(a)
384 #endif
385
386 /* Provide a way to print an address via printf.  */
387 #ifndef HOST_PTR_PRINTF
388 # ifdef HAVE_PRINTF_PTR
389 #  define HOST_PTR_PRINTF "%p"
390 # else
391 #  define HOST_PTR_PRINTF \
392     (sizeof (int) == sizeof (char *) ? "%x" \
393      : sizeof (long) == sizeof (char *) ? "%lx" : "%llx")
394 # endif
395 #endif /* ! HOST_PTR_PRINTF */
396
397 /* By default, colon separates directories in a path.  */
398 #ifndef PATH_SEPARATOR
399 #define PATH_SEPARATOR ':'
400 #endif
401
402 #ifndef DIR_SEPARATOR
403 #define DIR_SEPARATOR '/'
404 #endif
405
406 /* Define IS_DIR_SEPARATOR.  */
407 #ifndef DIR_SEPARATOR_2
408 # define IS_DIR_SEPARATOR(CH) ((CH) == DIR_SEPARATOR)
409 #else /* DIR_SEPARATOR_2 */
410 # define IS_DIR_SEPARATOR(CH) \
411         (((CH) == DIR_SEPARATOR) || ((CH) == DIR_SEPARATOR_2))
412 #endif /* DIR_SEPARATOR_2 */
413
414 /* Say how to test for an absolute pathname.  On Unix systems, this is if
415    it starts with a leading slash or a '$', the latter meaning the value of
416    an environment variable is to be used.  On machien with DOS-based
417    file systems, it is also absolute if it starts with a drive identifier.  */
418 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
419 #define IS_ABSOLUTE_PATHNAME(STR) \
420   (IS_DIR_SEPARATOR ((STR)[0]) || (STR)[0] == '$' \
421    || ((STR)[0] != '\0' && (STR)[1] == ':' && IS_DIR_SEPARATOR ((STR)[2])))
422 #else
423 #define IS_ABSOLUTE_PATHNAME(STR) \
424   (IS_DIR_SEPARATOR ((STR)[0]) || (STR)[0] == '$')
425 #endif
426
427 /* Get libiberty declarations. */
428 /* #include "libiberty.h" */
429 #include "sdcc.h"
430 #include "symcat.h"
431
432 /* Provide a default for the HOST_BIT_BUCKET.
433    This suffices for POSIX-like hosts.  */
434
435 #ifndef HOST_BIT_BUCKET
436 #define HOST_BIT_BUCKET "/dev/null"
437 #endif
438
439 /* Be conservative and only use enum bitfields with GCC.
440    FIXME: provide a complete autoconf test for buggy enum bitfields.  */
441
442 #if (GCC_VERSION > 2000)
443 #define ENUM_BITFIELD(TYPE) enum TYPE
444 #else
445 #define ENUM_BITFIELD(TYPE) unsigned int
446 #endif
447
448 #ifndef offsetof
449 #define offsetof(TYPE, MEMBER)  ((size_t) &((TYPE *)0)->MEMBER)
450 #endif
451
452 /* Traditional C cannot initialize union members of structs.  Provide
453    a macro which expands appropriately to handle it.  This only works
454    if you intend to initalize the union member to zero since it relies
455    on default initialization to zero in the traditional C case.  */
456 #ifdef __STDC__
457 #define UNION_INIT_ZERO , {0}
458 #else
459 #define UNION_INIT_ZERO
460 #endif
461
462 /* Various error reporting routines want to use __FUNCTION__.  */
463 #if (GCC_VERSION < 2007)
464 #ifndef __FUNCTION__
465 #define __FUNCTION__ "?"
466 #endif /* ! __FUNCTION__ */
467 #endif
468
469 /* As the last action in this file, we poison the identifiers that
470    shouldn't be used.  Note, luckily gcc-3.0's token-based integrated
471    preprocessor won't trip on poisoned identifiers that arrive from
472    the expansion of macros.  E.g. #define strrchr rindex, won't error
473    if rindex is poisoned after this directive is issued and later on
474    strrchr is called.
475
476    Note: We define bypass macros for the few cases where we really
477    want to use the libc memory allocation routines.  Otherwise we
478    insist you use the "x" versions from libiberty.  */
479
480 #define really_call_malloc malloc
481 #define really_call_calloc calloc
482 #define really_call_realloc realloc
483
484 #if (GCC_VERSION >= 3000)
485
486 /* Note autoconf checks for prototype declarations and includes
487    system.h while doing so.  Only poison these tokens if actually
488    compiling gcc, so that the autoconf declaration tests for malloc
489    etc don't spuriously fail.  */
490 #ifdef IN_GCC
491 #undef malloc
492 #undef realloc
493 #undef calloc
494 #undef strdup
495  #pragma GCC poison malloc realloc calloc strdup
496 #endif /* IN_GCC */
497
498 /* Note: not all uses of the `index' token (e.g. variable names and
499    structure members) have been eliminated.  */
500 #undef bcopy
501 #undef bzero
502 #undef bcmp
503 #undef rindex
504  #pragma GCC poison bcopy bzero bcmp rindex
505
506 #endif /* GCC >= 3.0 */
507
508 #endif /* ! GCC_SYSTEM_H */