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>
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 /* Find HOST_WIDEST_INT and set its bit size, type and print macros.
149 It will be the largest integer mode supported by the host which may
150 (or may not) be larger than HOST_WIDE_INT. This must appear after
151 <limits.h> since we only use `long long' if its bigger than a
152 `long' and also if it is supported by macros in limits.h. For old
153 hosts which don't have a limits.h (and thus won't include it in
154 stage2 cause we don't rerun configure) we assume gcc supports long
155 long.) Note, you won't get these defined if you don't include
156 {ht}config.h before this file to set the HOST_BITS_PER_* macros. */
158 #ifndef HOST_WIDEST_INT
159 # if defined (HOST_BITS_PER_LONG) && defined (HOST_BITS_PER_LONGLONG)
160 # if (HOST_BITS_PER_LONGLONG > HOST_BITS_PER_LONG) && (defined (LONG_LONG_MAX) || defined (LONGLONG_MAX) || defined (LLONG_MAX) || defined (__GNUC__))
161 # define HOST_BITS_PER_WIDEST_INT HOST_BITS_PER_LONGLONG
162 # define HOST_WIDEST_INT long long
163 # define HOST_WIDEST_INT_PRINT_DEC "%lld"
164 # define HOST_WIDEST_INT_PRINT_UNSIGNED "%llu"
165 # define HOST_WIDEST_INT_PRINT_HEX "0x%llx"
167 # define HOST_BITS_PER_WIDEST_INT HOST_BITS_PER_LONG
168 # define HOST_WIDEST_INT long
169 # define HOST_WIDEST_INT_PRINT_DEC "%ld"
170 # define HOST_WIDEST_INT_PRINT_UNSIGNED "%lu"
171 # define HOST_WIDEST_INT_PRINT_HEX "0x%lx"
172 # endif /*(long long>long) && (LONG_LONG_MAX||LONGLONG_MAX||LLONG_MAX||GNUC)*/
173 # endif /* defined(HOST_BITS_PER_LONG) && defined(HOST_BITS_PER_LONGLONG) */
174 #endif /* ! HOST_WIDEST_INT */
176 /* Infrastructure for defining missing _MAX and _MIN macros. Note that
177 macros defined with these cannot be used in #if. */
179 /* The extra casts work around common compiler bugs. */
180 #define INTTYPE_SIGNED(t) (! ((t) 0 < (t) -1))
181 /* The outer cast is needed to work around a bug in Cray C 5.0.3.0.
182 It is necessary at least when t == time_t. */
183 #define INTTYPE_MINIMUM(t) ((t) (INTTYPE_SIGNED (t) \
184 ? ~ (t) 0 << (sizeof(t) * CHAR_BIT - 1) : (t) 0))
185 #define INTTYPE_MAXIMUM(t) ((t) (~ (t) 0 - INTTYPE_MINIMUM (t)))
187 /* Use that infrastructure to provide a few constants. */
189 # define UCHAR_MAX INTTYPE_MAXIMUM (unsigned char)
192 #ifdef TIME_WITH_SYS_TIME
193 # include <sys/time.h>
197 # include <sys/time.h>
208 # ifdef HAVE_SYS_FILE_H
209 # include <sys/file.h>
231 /* Some systems define these in, e.g., param.h. We undefine these names
232 here to avoid the warnings. We prefer to use our definitions since we
233 know they are correct. */
237 #define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
238 #define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
240 /* Returns the least number N such that N * Y >= X. */
241 #define CEIL(x,y) (((x) + (y) - 1) / (y))
243 #ifdef HAVE_SYS_WAIT_H
244 #include <sys/wait.h>
248 #define WIFSIGNALED(S) (((S) & 0xff) != 0 && ((S) & 0xff) != 0x7f)
251 #define WTERMSIG(S) ((S) & 0x7f)
254 #define WIFEXITED(S) (((S) & 0xff) == 0)
257 #define WEXITSTATUS(S) (((S) & 0xff00) >> 8)
260 #define WSTOPSIG WEXITSTATUS
263 /* The HAVE_DECL_* macros are three-state, undefined, 0 or 1. If they
264 are defined to 0 then we must provide the relevant declaration
265 here. These checks will be in the undefined state while configure
266 is running so be careful to test "defined (HAVE_DECL_*)". */
270 # if defined (HAVE_DECL_BCOPY) && !HAVE_DECL_BCOPY
271 extern void bcopy PARAMS ((const PTR, PTR, size_t));
273 # else /* ! HAVE_BCOPY */
274 # define bcopy(src,dst,len) memmove((dst),(src),(len))
278 #if defined (HAVE_DECL_ATOF) && !HAVE_DECL_ATOF
279 extern double atof PARAMS ((const char *));
282 #if defined (HAVE_DECL_ATOL) && !HAVE_DECL_ATOL
283 extern long atol PARAMS ((const char *));
286 #if defined (HAVE_DECL_FREE) && !HAVE_DECL_FREE
287 extern void free PARAMS ((PTR));
290 #if defined (HAVE_DECL_GETCWD) && !HAVE_DECL_GETCWD
291 extern char *getcwd PARAMS ((char *, size_t));
294 #if defined (HAVE_DECL_GETENV) && !HAVE_DECL_GETENV
295 extern char *getenv PARAMS ((const char *));
298 #if defined (HAVE_DECL_GETOPT) && !HAVE_DECL_GETOPT
299 extern int getopt PARAMS ((int, char * const *, const char *));
302 #if defined (HAVE_DECL_GETWD) && !HAVE_DECL_GETWD
303 extern char *getwd PARAMS ((char *));
306 #if defined (HAVE_DECL_SBRK) && !HAVE_DECL_SBRK
307 extern PTR sbrk PARAMS ((int));
310 #if defined (HAVE_DECL_STRSTR) && !HAVE_DECL_STRSTR
311 extern char *strstr PARAMS ((const char *, const char *));
318 #if defined (HAVE_DECL_MALLOC) && !HAVE_DECL_MALLOC
319 extern PTR malloc PARAMS ((size_t));
322 #if defined (HAVE_DECL_CALLOC) && !HAVE_DECL_CALLOC
323 extern PTR calloc PARAMS ((size_t, size_t));
326 #if defined (HAVE_DECL_REALLOC) && !HAVE_DECL_REALLOC
327 extern PTR realloc PARAMS ((PTR, size_t));
330 /* If the system doesn't provide strsignal, we get it defined in
331 libiberty but no declaration is supplied. */
332 #ifndef HAVE_STRSIGNAL
334 extern const char *strsignal PARAMS ((int));
338 #ifdef HAVE_GETRLIMIT
339 # if defined (HAVE_DECL_GETRLIMIT) && !HAVE_DECL_GETRLIMIT
341 # ifdef ANSI_PROTOTYPES
344 extern int getrlimit PARAMS ((int, struct rlimit *));
349 #ifdef HAVE_SETRLIMIT
350 # if defined (HAVE_DECL_SETRLIMIT) && !HAVE_DECL_SETRLIMIT
352 # ifdef ANSI_PROTOTYPES
355 extern int setrlimit PARAMS ((int, const struct rlimit *));
360 /* HAVE_VOLATILE only refers to the stage1 compiler. We also check
361 __STDC__ and assume gcc sets it and has volatile in stage >=2. */
362 #if !defined(HAVE_VOLATILE) && !defined(__STDC__) && !defined(volatile)
366 #if defined (HAVE_DECL_ABORT) && !HAVE_DECL_ABORT
367 extern void abort PARAMS ((void));
370 /* 1 if we have C99 designated initializers. */
371 #if !defined(HAVE_DESIGNATED_INITIALIZERS)
372 #define HAVE_DESIGNATED_INITIALIZERS \
373 ((GCC_VERSION >= 2007) || (__STDC_VERSION__ >= 199901L))
376 /* 1 if we have _Bool. */
378 # define HAVE__BOOL \
379 ((GCC_VERSION >= 3000) || (__STDC_VERSION__ >= 199901L))
384 /* Define a STRINGIFY macro that's right for ANSI or traditional C.
385 Note: if the argument passed to STRINGIFY is itself a macro, eg
386 #define foo bar, STRINGIFY(foo) will produce "foo", not "bar".
387 Although the __STDC__ case could be made to expand this via a layer
388 of indirection, the traditional C case can not do so. Therefore
389 this behavior is not supported. */
391 # ifdef HAVE_STRINGIZE
392 # define STRINGIFY(STRING) #STRING
394 # define STRINGIFY(STRING) "STRING"
396 #endif /* ! STRINGIFY */
399 # include <sys/stat.h>
402 /* Test if something is a normal file. */
404 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
407 /* Test if something is a directory. */
409 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
412 /* Test if something is a character special file. */
414 #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
417 /* Test if something is a block special file. */
419 #define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
422 /* Test if something is a socket. */
425 # define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
427 # define S_ISSOCK(m) 0
431 /* Test if something is a FIFO. */
434 # define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
436 # define S_ISFIFO(m) 0
440 /* Approximate O_NONBLOCK. */
442 #define O_NONBLOCK O_NDELAY
445 /* Approximate O_NOCTTY. */
450 /* Define well known filenos if the system does not define them. */
452 # define STDIN_FILENO 0
454 #ifndef STDOUT_FILENO
455 # define STDOUT_FILENO 1
457 #ifndef STDERR_FILENO
458 # define STDERR_FILENO 2
461 /* Some systems have mkdir that takes a single argument. */
462 #ifdef MKDIR_TAKES_ONE_ARG
463 # define mkdir(a,b) mkdir(a)
466 /* Provide a way to print an address via printf. */
467 #ifndef HOST_PTR_PRINTF
468 # ifdef HAVE_PRINTF_PTR
469 # define HOST_PTR_PRINTF "%p"
471 # define HOST_PTR_PRINTF \
472 (sizeof (int) == sizeof (char *) ? "%x" \
473 : sizeof (long) == sizeof (char *) ? "%lx" : "%llx")
475 #endif /* ! HOST_PTR_PRINTF */
477 /* By default, colon separates directories in a path. */
478 #ifndef PATH_SEPARATOR
479 #define PATH_SEPARATOR ':'
482 #ifndef DIR_SEPARATOR
483 #define DIR_SEPARATOR '/'
486 /* Define IS_DIR_SEPARATOR. */
487 #ifndef DIR_SEPARATOR_2
488 # define IS_DIR_SEPARATOR(CH) ((CH) == DIR_SEPARATOR)
489 #else /* DIR_SEPARATOR_2 */
490 # define IS_DIR_SEPARATOR(CH) \
491 (((CH) == DIR_SEPARATOR) || ((CH) == DIR_SEPARATOR_2))
492 #endif /* DIR_SEPARATOR_2 */
494 /* Say how to test for an absolute pathname. On Unix systems, this is if
495 it starts with a leading slash or a '$', the latter meaning the value of
496 an environment variable is to be used. On machien with DOS-based
497 file systems, it is also absolute if it starts with a drive identifier. */
498 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
499 #define IS_ABSOLUTE_PATHNAME(STR) \
500 (IS_DIR_SEPARATOR ((STR)[0]) || (STR)[0] == '$' \
501 || ((STR)[0] != '\0' && (STR)[1] == ':' && IS_DIR_SEPARATOR ((STR)[2])))
503 #define IS_ABSOLUTE_PATHNAME(STR) \
504 (IS_DIR_SEPARATOR ((STR)[0]) || (STR)[0] == '$')
507 /* Get libiberty declarations. */
508 #include "libiberty.h"
510 /* Make sure that ONLY_INT_FIELDS has an integral value. */
511 #ifdef ONLY_INT_FIELDS
512 #undef ONLY_INT_FIELDS
513 #define ONLY_INT_FIELDS 1
515 #define ONLY_INT_FIELDS 0
518 /* Provide a default for the HOST_BIT_BUCKET.
519 This suffices for POSIX-like hosts. */
521 #ifndef HOST_BIT_BUCKET
522 #define HOST_BIT_BUCKET "/dev/null"
525 /* Enumerated bitfields are safe to use unless we've been explictly told
526 otherwise or if they are signed. */
528 #define USE_ENUM_BITFIELDS (__GNUC__ || (!ONLY_INT_FIELDS && ENUM_BITFIELDS_ARE_UNSIGNED))
530 #if USE_ENUM_BITFIELDS
531 #define ENUM_BITFIELD(TYPE) enum TYPE
533 #define ENUM_BITFIELD(TYPE) unsigned int
537 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
540 /* Traditional C cannot initialize union members of structs. Provide
541 a macro which expands appropriately to handle it. This only works
542 if you intend to initalize the union member to zero since it relies
543 on default initialization to zero in the traditional C case. */
545 #define UNION_INIT_ZERO , {0}
547 #define UNION_INIT_ZERO
550 /* Various error reporting routines want to use __FUNCTION__. */
551 #if (GCC_VERSION < 2007)
553 #define __FUNCTION__ "?"
554 #endif /* ! __FUNCTION__ */
557 /* Provide some sort of boolean type. We use stdbool.h if it's
558 available. This is dead last because various system headers might
566 #ifdef HAVE_STDBOOL_H
567 # include <stdbool.h>
580 /* As the last action in this file, we poison the identifiers that
581 shouldn't be used. Note, luckily gcc-3.0's token-based integrated
582 preprocessor won't trip on poisoned identifiers that arrive from
583 the expansion of macros. E.g. #define strrchr rindex, won't error
584 if rindex is poisoned after this directive is issued and later on
587 Note: We define bypass macros for the few cases where we really
588 want to use the libc memory allocation routines. Otherwise we
589 insist you use the "x" versions from libiberty. */
591 #define really_call_malloc malloc
592 #define really_call_calloc calloc
593 #define really_call_realloc realloc
595 #if (GCC_VERSION >= 3000)
601 #pragma GCC poison malloc realloc calloc strdup
603 /* Note: not all uses of `bcopy' and `index' (esp. variable names)
604 have been eliminated. */
608 #pragma GCC poison bzero bcmp rindex
610 #endif /* GCC >= 3.0 */
612 #endif /* __GCC_SYSTEM_H__ */