1 /* Get common system includes and various definitions and declarations based
3 Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
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>"
31 /* We must include stdarg.h/varargs.h before stdio.h. */
32 #ifdef ANSI_PROTOTYPES
40 # define va_copy(d,s) __va_copy((d),(s))
42 # define va_copy(d,s) ((d) = (s))
52 /* Define a generic NULL if one hasn't already been defined. */
57 /* The compiler is not a multi-threaded application and therefore we
58 do not have to use the locking functions.
60 HAVE_DECL_PUTC_UNLOCKED actually indicates whether or not the IO
61 code is multi-thread safe by default. If it is set to 0, then do
62 not worry about using the _unlocked functions.
64 fputs_unlocked is an extension and needs to be prototyped specially. */
66 #if defined HAVE_PUTC_UNLOCKED && (defined (HAVE_DECL_PUTC_UNLOCKED) && HAVE_DECL_PUTC_UNLOCKED)
68 # define putc(C, Stream) putc_unlocked (C, Stream)
70 #if defined HAVE_FPUTC_UNLOCKED && (defined (HAVE_DECL_PUTC_UNLOCKED) && HAVE_DECL_PUTC_UNLOCKED)
72 # define fputc(C, Stream) fputc_unlocked (C, Stream)
74 #if defined HAVE_FPUTS_UNLOCKED && (defined (HAVE_DECL_PUTC_UNLOCKED) && HAVE_DECL_PUTC_UNLOCKED)
76 # define fputs(String, Stream) fputs_unlocked (String, Stream)
77 # if defined (HAVE_DECL_FPUTS_UNLOCKED) && !HAVE_DECL_FPUTS_UNLOCKED
78 extern int fputs_unlocked
PARAMS ((const char *, FILE *));
82 /* There are an extraordinary number of issues with <ctype.h>.
83 The last straw is that it varies with the locale. Use libiberty's
84 replacement instead. */
85 #include <safe-ctype.h>
87 #include <sys/types.h>
91 #if !defined (errno) && defined (HAVE_DECL_ERRNO) && !HAVE_DECL_ERRNO
95 #ifdef STRING_WITH_STRINGS
102 # ifdef HAVE_STRINGS_H
103 # include <strings.h>
112 /* If we don't have an overriding definition, set SUCCESS_EXIT_CODE and
113 FATAL_EXIT_CODE to EXIT_SUCCESS and EXIT_FAILURE respectively,
114 or 0 and 1 if those macros are not defined. */
115 #ifndef SUCCESS_EXIT_CODE
117 # define SUCCESS_EXIT_CODE EXIT_SUCCESS
119 # define SUCCESS_EXIT_CODE 0
123 #ifndef FATAL_EXIT_CODE
125 # define FATAL_EXIT_CODE EXIT_FAILURE
127 # define FATAL_EXIT_CODE 1
135 #ifdef HAVE_SYS_PARAM_H
136 # include <sys/param.h>
143 /* Get definitions of HOST_WIDE_INT and HOST_WIDEST_INT. */
146 /* Infrastructure for defining missing _MAX and _MIN macros. Note that
147 macros defined with these cannot be used in #if. */
149 /* The extra casts work around common compiler bugs. */
150 #define INTTYPE_SIGNED(t) (! ((t) 0 < (t) -1))
151 /* The outer cast is needed to work around a bug in Cray C 5.0.3.0.
152 It is necessary at least when t == time_t. */
153 #define INTTYPE_MINIMUM(t) ((t) (INTTYPE_SIGNED (t) \
154 ? ~ (t) 0 << (sizeof(t) * CHAR_BIT - 1) : (t) 0))
155 #define INTTYPE_MAXIMUM(t) ((t) (~ (t) 0 - INTTYPE_MINIMUM (t)))
157 /* Use that infrastructure to provide a few constants. */
159 # define UCHAR_MAX INTTYPE_MAXIMUM (unsigned char)
162 #ifdef TIME_WITH_SYS_TIME
163 # include <sys/time.h>
167 # include <sys/time.h>
178 # ifdef HAVE_SYS_FILE_H
179 # include <sys/file.h>
201 /* Some systems define these in, e.g., param.h. We undefine these names
202 here to avoid the warnings. We prefer to use our definitions since we
203 know they are correct. */
207 #define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
208 #define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
210 /* Returns the least number N such that N * Y >= X. */
211 #define CEIL(x,y) (((x) + (y) - 1) / (y))
213 #ifdef HAVE_SYS_WAIT_H
214 #include <sys/wait.h>
218 #define WIFSIGNALED(S) (((S) & 0xff) != 0 && ((S) & 0xff) != 0x7f)
221 #define WTERMSIG(S) ((S) & 0x7f)
224 #define WIFEXITED(S) (((S) & 0xff) == 0)
227 #define WEXITSTATUS(S) (((S) & 0xff00) >> 8)
230 #define WSTOPSIG WEXITSTATUS
233 /* The HAVE_DECL_* macros are three-state, undefined, 0 or 1. If they
234 are defined to 0 then we must provide the relevant declaration
235 here. These checks will be in the undefined state while configure
236 is running so be careful to test "defined (HAVE_DECL_*)". */
238 #if defined (HAVE_DECL_ATOF) && !HAVE_DECL_ATOF
239 extern double atof
PARAMS ((const char *));
242 #if defined (HAVE_DECL_ATOL) && !HAVE_DECL_ATOL
243 extern long atol
PARAMS ((const char *));
246 #if defined (HAVE_DECL_FREE) && !HAVE_DECL_FREE
247 extern void free
PARAMS ((PTR
));
250 #if defined (HAVE_DECL_GETCWD) && !HAVE_DECL_GETCWD
251 extern char *getcwd
PARAMS ((char *, size_t));
254 #if defined (HAVE_DECL_GETENV) && !HAVE_DECL_GETENV
255 extern char *getenv
PARAMS ((const char *));
258 #if defined (HAVE_DECL_GETOPT) && !HAVE_DECL_GETOPT
259 extern int getopt
PARAMS ((int, char * const *, const char *));
262 #if defined (HAVE_DECL_GETWD) && !HAVE_DECL_GETWD
263 extern char *getwd
PARAMS ((char *));
266 #if defined (HAVE_DECL_SBRK) && !HAVE_DECL_SBRK
267 extern PTR sbrk
PARAMS ((int));
270 #if defined (HAVE_DECL_STRSTR) && !HAVE_DECL_STRSTR
271 extern char *strstr
PARAMS ((const char *, const char *));
278 #if defined (HAVE_DECL_MALLOC) && !HAVE_DECL_MALLOC
279 extern PTR malloc
PARAMS ((size_t));
282 #if defined (HAVE_DECL_CALLOC) && !HAVE_DECL_CALLOC
283 extern PTR calloc
PARAMS ((size_t, size_t));
286 #if defined (HAVE_DECL_REALLOC) && !HAVE_DECL_REALLOC
287 extern PTR realloc
PARAMS ((PTR
, size_t));
290 /* If the system doesn't provide strsignal, we get it defined in
291 libiberty but no declaration is supplied. */
292 #ifndef HAVE_STRSIGNAL
294 extern const char *strsignal
PARAMS ((int));
298 #ifdef HAVE_GETRLIMIT
299 # if defined (HAVE_DECL_GETRLIMIT) && !HAVE_DECL_GETRLIMIT
301 # ifdef ANSI_PROTOTYPES
304 extern int getrlimit
PARAMS ((int, struct rlimit
*));
309 #ifdef HAVE_SETRLIMIT
310 # if defined (HAVE_DECL_SETRLIMIT) && !HAVE_DECL_SETRLIMIT
312 # ifdef ANSI_PROTOTYPES
315 extern int setrlimit
PARAMS ((int, const struct rlimit
*));
320 /* HAVE_VOLATILE only refers to the stage1 compiler. We also check
321 __STDC__ and assume gcc sets it and has volatile in stage >=2. */
322 #if !defined(HAVE_VOLATILE) && !defined(__STDC__) && !defined(volatile)
326 #if defined (HAVE_DECL_ABORT) && !HAVE_DECL_ABORT
327 extern void abort
PARAMS ((void));
330 /* 1 if we have C99 designated initializers. */
331 #if !defined(HAVE_DESIGNATED_INITIALIZERS)
332 #define HAVE_DESIGNATED_INITIALIZERS \
333 ((GCC_VERSION >= 2007) || (__STDC_VERSION__ >= 199901L))
336 /* 1 if we have _Bool. */
338 # define HAVE__BOOL \
339 ((GCC_VERSION >= 3000) || (__STDC_VERSION__ >= 199901L))
344 # include <sys/stat.h>
347 /* Test if something is a normal file. */
349 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
352 /* Test if something is a directory. */
354 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
357 /* Test if something is a character special file. */
359 #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
362 /* Test if something is a block special file. */
364 #define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
367 /* Test if something is a socket. */
370 # define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
372 # define S_ISSOCK(m) 0
376 /* Test if something is a FIFO. */
379 # define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
381 # define S_ISFIFO(m) 0
385 /* Approximate O_NONBLOCK. */
387 #define O_NONBLOCK O_NDELAY
390 /* Approximate O_NOCTTY. */
395 /* Define well known filenos if the system does not define them. */
397 # define STDIN_FILENO 0
399 #ifndef STDOUT_FILENO
400 # define STDOUT_FILENO 1
402 #ifndef STDERR_FILENO
403 # define STDERR_FILENO 2
406 /* Some systems have mkdir that takes a single argument. */
407 #ifdef MKDIR_TAKES_ONE_ARG
408 # define mkdir(a,b) mkdir(a)
411 /* Provide a way to print an address via printf. */
412 #ifndef HOST_PTR_PRINTF
413 # ifdef HAVE_PRINTF_PTR
414 # define HOST_PTR_PRINTF "%p"
416 # define HOST_PTR_PRINTF \
417 (sizeof (int) == sizeof (char *) ? "%x" \
418 : sizeof (long) == sizeof (char *) ? "%lx" : "%llx")
420 #endif /* ! HOST_PTR_PRINTF */
422 /* By default, colon separates directories in a path. */
423 #ifndef PATH_SEPARATOR
424 #define PATH_SEPARATOR ':'
427 #ifndef DIR_SEPARATOR
428 #define DIR_SEPARATOR '/'
431 /* Define IS_DIR_SEPARATOR. */
432 #ifndef DIR_SEPARATOR_2
433 # define IS_DIR_SEPARATOR(CH) ((CH) == DIR_SEPARATOR)
434 #else /* DIR_SEPARATOR_2 */
435 # define IS_DIR_SEPARATOR(CH) \
436 (((CH) == DIR_SEPARATOR) || ((CH) == DIR_SEPARATOR_2))
437 #endif /* DIR_SEPARATOR_2 */
439 /* Say how to test for an absolute pathname. On Unix systems, this is if
440 it starts with a leading slash or a '$', the latter meaning the value of
441 an environment variable is to be used. On machien with DOS-based
442 file systems, it is also absolute if it starts with a drive identifier. */
443 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
444 #define IS_ABSOLUTE_PATHNAME(STR) \
445 (IS_DIR_SEPARATOR ((STR)[0]) || (STR)[0] == '$' \
446 || ((STR)[0] != '\0' && (STR)[1] == ':' && IS_DIR_SEPARATOR ((STR)[2])))
448 #define IS_ABSOLUTE_PATHNAME(STR) \
449 (IS_DIR_SEPARATOR ((STR)[0]) || (STR)[0] == '$')
452 /* Get libiberty declarations. */
453 #include "libiberty.h"
456 /* Provide a default for the HOST_BIT_BUCKET.
457 This suffices for POSIX-like hosts. */
459 #ifndef HOST_BIT_BUCKET
460 #define HOST_BIT_BUCKET "/dev/null"
463 /* Be conservative and only use enum bitfields with GCC.
464 FIXME: provide a complete autoconf test for buggy enum bitfields. */
466 #if (GCC_VERSION > 2000)
467 #define ENUM_BITFIELD(TYPE) enum TYPE
469 #define ENUM_BITFIELD(TYPE) unsigned int
473 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
476 /* Traditional C cannot initialize union members of structs. Provide
477 a macro which expands appropriately to handle it. This only works
478 if you intend to initalize the union member to zero since it relies
479 on default initialization to zero in the traditional C case. */
481 #define UNION_INIT_ZERO , {0}
483 #define UNION_INIT_ZERO
486 /* Various error reporting routines want to use __FUNCTION__. */
487 #if (GCC_VERSION < 2007)
489 #define __FUNCTION__ "?"
490 #endif /* ! __FUNCTION__ */
493 /* Provide some sort of boolean type. We use stdbool.h if it's
494 available. This must be after all inclusion of system headers,
495 as some of them will mess us up. */
502 #ifdef HAVE_STDBOOL_H
503 # include <stdbool.h>
516 /* Provide three core typedefs used by everything, if we are compiling
517 GCC. These used to be found in rtl.h and tree.h, but this is no
523 typedef struct rtx_def
*rtx
;
524 typedef struct rtvec_def
*rtvec
;
525 typedef union tree_node
*tree
;
528 /* As the last action in this file, we poison the identifiers that
529 shouldn't be used. Note, luckily gcc-3.0's token-based integrated
530 preprocessor won't trip on poisoned identifiers that arrive from
531 the expansion of macros. E.g. #define strrchr rindex, won't error
532 if rindex is poisoned after this directive is issued and later on
535 Note: We define bypass macros for the few cases where we really
536 want to use the libc memory allocation routines. Otherwise we
537 insist you use the "x" versions from libiberty. */
539 #define really_call_malloc malloc
540 #define really_call_calloc calloc
541 #define really_call_realloc realloc
543 #if (GCC_VERSION >= 3000)
545 /* Note autoconf checks for prototype declarations and includes
546 system.h while doing so. Only poison these tokens if actually
547 compiling gcc, so that the autoconf declaration tests for malloc
548 etc don't spuriously fail. */
554 #pragma GCC poison malloc realloc calloc strdup
557 /* Note: not all uses of the `index' token (e.g. variable names and
558 structure members) have been eliminated. */
563 #pragma GCC poison bcopy bzero bcmp rindex
565 #endif /* GCC >= 3.0 */
567 #endif /* ! GCC_SYSTEM_H */