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 GNU CC.
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)
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.
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. */
23 #ifndef __GCC_SYSTEM_H__
24 #define __GCC_SYSTEM_H__
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 /* Define a default escape character; it's different for EBCDIC. */
89 #define TARGET_ESC 033
92 #include <sys/types.h>
96 #if !defined (errno) && defined (HAVE_DECL_ERRNO) && !HAVE_DECL_ERRNO
100 #ifdef STRING_WITH_STRINGS
102 # include <strings.h>
104 # ifdef HAVE_STRING_H
107 # ifdef HAVE_STRINGS_H
108 # include <strings.h>
117 /* If we don't have an overriding definition, set SUCCESS_EXIT_CODE and
118 FATAL_EXIT_CODE to EXIT_SUCCESS and EXIT_FAILURE respectively,
119 or 0 and 1 if those macros are not defined. */
120 #ifndef SUCCESS_EXIT_CODE
122 # define SUCCESS_EXIT_CODE EXIT_SUCCESS
124 # define SUCCESS_EXIT_CODE 0
128 #ifndef FATAL_EXIT_CODE
130 # define FATAL_EXIT_CODE EXIT_FAILURE
132 # define FATAL_EXIT_CODE 1
140 #ifdef HAVE_SYS_PARAM_H
141 # include <sys/param.h>
148 /* Get definitions of HOST_WIDE_INT and HOST_WIDEST_INT. */
151 /* Infrastructure for defining missing _MAX and _MIN macros. Note that
152 macros defined with these cannot be used in #if. */
154 /* The extra casts work around common compiler bugs. */
155 #define INTTYPE_SIGNED(t) (! ((t) 0 < (t) -1))
156 /* The outer cast is needed to work around a bug in Cray C 5.0.3.0.
157 It is necessary at least when t == time_t. */
158 #define INTTYPE_MINIMUM(t) ((t) (INTTYPE_SIGNED (t) \
159 ? ~ (t) 0 << (sizeof(t) * CHAR_BIT - 1) : (t) 0))
160 #define INTTYPE_MAXIMUM(t) ((t) (~ (t) 0 - INTTYPE_MINIMUM (t)))
162 /* Use that infrastructure to provide a few constants. */
164 # define UCHAR_MAX INTTYPE_MAXIMUM (unsigned char)
167 #ifdef TIME_WITH_SYS_TIME
168 # include <sys/time.h>
172 # include <sys/time.h>
183 # ifdef HAVE_SYS_FILE_H
184 # include <sys/file.h>
206 /* Some systems define these in, e.g., param.h. We undefine these names
207 here to avoid the warnings. We prefer to use our definitions since we
208 know they are correct. */
212 #define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
213 #define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
215 /* Returns the least number N such that N * Y >= X. */
216 #define CEIL(x,y) (((x) + (y) - 1) / (y))
218 #ifdef HAVE_SYS_WAIT_H
219 #include <sys/wait.h>
223 #define WIFSIGNALED(S) (((S) & 0xff) != 0 && ((S) & 0xff) != 0x7f)
226 #define WTERMSIG(S) ((S) & 0x7f)
229 #define WIFEXITED(S) (((S) & 0xff) == 0)
232 #define WEXITSTATUS(S) (((S) & 0xff00) >> 8)
235 #define WSTOPSIG WEXITSTATUS
238 /* The HAVE_DECL_* macros are three-state, undefined, 0 or 1. If they
239 are defined to 0 then we must provide the relevant declaration
240 here. These checks will be in the undefined state while configure
241 is running so be careful to test "defined (HAVE_DECL_*)". */
243 #if defined (HAVE_DECL_ATOF) && !HAVE_DECL_ATOF
244 extern double atof
PARAMS ((const char *));
247 #if defined (HAVE_DECL_ATOL) && !HAVE_DECL_ATOL
248 extern long atol
PARAMS ((const char *));
251 #if defined (HAVE_DECL_FREE) && !HAVE_DECL_FREE
252 extern void free
PARAMS ((PTR
));
255 #if defined (HAVE_DECL_GETCWD) && !HAVE_DECL_GETCWD
256 extern char *getcwd
PARAMS ((char *, size_t));
259 #if defined (HAVE_DECL_GETENV) && !HAVE_DECL_GETENV
260 extern char *getenv
PARAMS ((const char *));
263 #if defined (HAVE_DECL_GETOPT) && !HAVE_DECL_GETOPT
264 extern int getopt
PARAMS ((int, char * const *, const char *));
267 #if defined (HAVE_DECL_GETWD) && !HAVE_DECL_GETWD
268 extern char *getwd
PARAMS ((char *));
271 #if defined (HAVE_DECL_SBRK) && !HAVE_DECL_SBRK
272 extern PTR sbrk
PARAMS ((int));
275 #if defined (HAVE_DECL_STRSTR) && !HAVE_DECL_STRSTR
276 extern char *strstr
PARAMS ((const char *, const char *));
283 #if defined (HAVE_DECL_MALLOC) && !HAVE_DECL_MALLOC
284 extern PTR malloc
PARAMS ((size_t));
287 #if defined (HAVE_DECL_CALLOC) && !HAVE_DECL_CALLOC
288 extern PTR calloc
PARAMS ((size_t, size_t));
291 #if defined (HAVE_DECL_REALLOC) && !HAVE_DECL_REALLOC
292 extern PTR realloc
PARAMS ((PTR
, size_t));
295 /* If the system doesn't provide strsignal, we get it defined in
296 libiberty but no declaration is supplied. */
297 #ifndef HAVE_STRSIGNAL
299 extern const char *strsignal
PARAMS ((int));
303 #ifdef HAVE_GETRLIMIT
304 # if defined (HAVE_DECL_GETRLIMIT) && !HAVE_DECL_GETRLIMIT
306 # ifdef ANSI_PROTOTYPES
309 extern int getrlimit
PARAMS ((int, struct rlimit
*));
314 #ifdef HAVE_SETRLIMIT
315 # if defined (HAVE_DECL_SETRLIMIT) && !HAVE_DECL_SETRLIMIT
317 # ifdef ANSI_PROTOTYPES
320 extern int setrlimit
PARAMS ((int, const struct rlimit
*));
325 /* HAVE_VOLATILE only refers to the stage1 compiler. We also check
326 __STDC__ and assume gcc sets it and has volatile in stage >=2. */
327 #if !defined(HAVE_VOLATILE) && !defined(__STDC__) && !defined(volatile)
331 #if defined (HAVE_DECL_ABORT) && !HAVE_DECL_ABORT
332 extern void abort
PARAMS ((void));
335 /* 1 if we have C99 designated initializers. */
336 #if !defined(HAVE_DESIGNATED_INITIALIZERS)
337 #define HAVE_DESIGNATED_INITIALIZERS \
338 ((GCC_VERSION >= 2007) || (__STDC_VERSION__ >= 199901L))
341 /* 1 if we have _Bool. */
343 # define HAVE__BOOL \
344 ((GCC_VERSION >= 3000) || (__STDC_VERSION__ >= 199901L))
349 # include <sys/stat.h>
352 /* Test if something is a normal file. */
354 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
357 /* Test if something is a directory. */
359 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
362 /* Test if something is a character special file. */
364 #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
367 /* Test if something is a block special file. */
369 #define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
372 /* Test if something is a socket. */
375 # define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
377 # define S_ISSOCK(m) 0
381 /* Test if something is a FIFO. */
384 # define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
386 # define S_ISFIFO(m) 0
390 /* Approximate O_NONBLOCK. */
392 #define O_NONBLOCK O_NDELAY
395 /* Approximate O_NOCTTY. */
400 /* Define well known filenos if the system does not define them. */
402 # define STDIN_FILENO 0
404 #ifndef STDOUT_FILENO
405 # define STDOUT_FILENO 1
407 #ifndef STDERR_FILENO
408 # define STDERR_FILENO 2
411 /* Some systems have mkdir that takes a single argument. */
412 #ifdef MKDIR_TAKES_ONE_ARG
413 # define mkdir(a,b) mkdir(a)
416 /* Provide a way to print an address via printf. */
417 #ifndef HOST_PTR_PRINTF
418 # ifdef HAVE_PRINTF_PTR
419 # define HOST_PTR_PRINTF "%p"
421 # define HOST_PTR_PRINTF \
422 (sizeof (int) == sizeof (char *) ? "%x" \
423 : sizeof (long) == sizeof (char *) ? "%lx" : "%llx")
425 #endif /* ! HOST_PTR_PRINTF */
427 /* By default, colon separates directories in a path. */
428 #ifndef PATH_SEPARATOR
429 #define PATH_SEPARATOR ':'
432 #ifndef DIR_SEPARATOR
433 #define DIR_SEPARATOR '/'
436 /* Define IS_DIR_SEPARATOR. */
437 #ifndef DIR_SEPARATOR_2
438 # define IS_DIR_SEPARATOR(CH) ((CH) == DIR_SEPARATOR)
439 #else /* DIR_SEPARATOR_2 */
440 # define IS_DIR_SEPARATOR(CH) \
441 (((CH) == DIR_SEPARATOR) || ((CH) == DIR_SEPARATOR_2))
442 #endif /* DIR_SEPARATOR_2 */
444 /* Say how to test for an absolute pathname. On Unix systems, this is if
445 it starts with a leading slash or a '$', the latter meaning the value of
446 an environment variable is to be used. On machien with DOS-based
447 file systems, it is also absolute if it starts with a drive identifier. */
448 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
449 #define IS_ABSOLUTE_PATHNAME(STR) \
450 (IS_DIR_SEPARATOR ((STR)[0]) || (STR)[0] == '$' \
451 || ((STR)[0] != '\0' && (STR)[1] == ':' && IS_DIR_SEPARATOR ((STR)[2])))
453 #define IS_ABSOLUTE_PATHNAME(STR) \
454 (IS_DIR_SEPARATOR ((STR)[0]) || (STR)[0] == '$')
457 /* Get libiberty declarations. */
458 #include "libiberty.h"
461 /* Provide a default for the HOST_BIT_BUCKET.
462 This suffices for POSIX-like hosts. */
464 #ifndef HOST_BIT_BUCKET
465 #define HOST_BIT_BUCKET "/dev/null"
468 /* Be conservative and only use enum bitfields with GCC.
469 FIXME: provide a complete autoconf test for buggy enum bitfields. */
471 #if (GCC_VERSION > 2000)
472 #define ENUM_BITFIELD(TYPE) enum TYPE
474 #define ENUM_BITFIELD(TYPE) unsigned int
478 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
481 /* Traditional C cannot initialize union members of structs. Provide
482 a macro which expands appropriately to handle it. This only works
483 if you intend to initalize the union member to zero since it relies
484 on default initialization to zero in the traditional C case. */
486 #define UNION_INIT_ZERO , {0}
488 #define UNION_INIT_ZERO
491 /* Various error reporting routines want to use __FUNCTION__. */
492 #if (GCC_VERSION < 2007)
494 #define __FUNCTION__ "?"
495 #endif /* ! __FUNCTION__ */
498 /* Provide some sort of boolean type. We use stdbool.h if it's
499 available. This is dead last because various system headers might
507 #ifdef HAVE_STDBOOL_H
508 # include <stdbool.h>
521 /* As the last action in this file, we poison the identifiers that
522 shouldn't be used. Note, luckily gcc-3.0's token-based integrated
523 preprocessor won't trip on poisoned identifiers that arrive from
524 the expansion of macros. E.g. #define strrchr rindex, won't error
525 if rindex is poisoned after this directive is issued and later on
528 Note: We define bypass macros for the few cases where we really
529 want to use the libc memory allocation routines. Otherwise we
530 insist you use the "x" versions from libiberty. */
532 #define really_call_malloc malloc
533 #define really_call_calloc calloc
534 #define really_call_realloc realloc
536 #if (GCC_VERSION >= 3000)
538 /* Note autoconf checks for prototype declarations and includes
539 system.h while doing so. Only poison these tokens if actually
540 compiling gcc, so that the autoconf declaration tests for malloc
541 etc don't spuriously fail. */
547 #pragma GCC poison malloc realloc calloc strdup
550 /* Note: not all uses of the `index' token (e.g. variable names and
551 structure members) have been eliminated. */
556 #pragma GCC poison bcopy bzero bcmp rindex
558 #endif /* GCC >= 3.0 */
560 #endif /* __GCC_SYSTEM_H__ */