1 /* Get common system includes and various definitions and declarations based
3 Copyright (C) 1998, 1999, 2000 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>
116 /* Note that systems that use glibc have a <stdlib.h> that includes
117 <alloca.h> that defines alloca, so let USE_C_ALLOCA override this. */
126 #ifdef HAVE_SYS_PARAM_H
127 # include <sys/param.h>
134 /* Find HOST_WIDEST_INT and set its bit size, type and print macros.
135 It will be the largest integer mode supported by the host which may
136 (or may not) be larger than HOST_WIDE_INT. This must appear after
137 <limits.h> since we only use `long long' if its bigger than a
138 `long' and also if it is supported by macros in limits.h. For old
139 hosts which don't have a limits.h (and thus won't include it in
140 stage2 cause we don't rerun configure) we assume gcc supports long
141 long.) Note, you won't get these defined if you don't include
142 {ht}config.h before this file to set the HOST_BITS_PER_* macros. */
144 #ifndef HOST_WIDEST_INT
145 # if defined (HOST_BITS_PER_LONG) && defined (HOST_BITS_PER_LONGLONG)
146 # if (HOST_BITS_PER_LONGLONG > HOST_BITS_PER_LONG) && (defined (LONG_LONG_MAX) || defined (LONGLONG_MAX) || defined (LLONG_MAX) || defined (__GNUC__))
147 # define HOST_BITS_PER_WIDEST_INT HOST_BITS_PER_LONGLONG
148 # define HOST_WIDEST_INT long long
149 # define HOST_WIDEST_INT_PRINT_DEC "%lld"
150 # define HOST_WIDEST_INT_PRINT_UNSIGNED "%llu"
151 # define HOST_WIDEST_INT_PRINT_HEX "0x%llx"
153 # define HOST_BITS_PER_WIDEST_INT HOST_BITS_PER_LONG
154 # define HOST_WIDEST_INT long
155 # define HOST_WIDEST_INT_PRINT_DEC "%ld"
156 # define HOST_WIDEST_INT_PRINT_UNSIGNED "%lu"
157 # define HOST_WIDEST_INT_PRINT_HEX "0x%lx"
158 # endif /*(long long>long) && (LONG_LONG_MAX||LONGLONG_MAX||LLONG_MAX||GNUC)*/
159 # endif /* defined(HOST_BITS_PER_LONG) && defined(HOST_BITS_PER_LONGLONG) */
160 #endif /* ! HOST_WIDEST_INT */
162 /* Infrastructure for defining missing _MAX and _MIN macros. Note that
163 macros defined with these cannot be used in #if. */
165 /* The extra casts work around common compiler bugs. */
166 #define INTTYPE_SIGNED(t) (! ((t) 0 < (t) -1))
167 /* The outer cast is needed to work around a bug in Cray C 5.0.3.0.
168 It is necessary at least when t == time_t. */
169 #define INTTYPE_MINIMUM(t) ((t) (INTTYPE_SIGNED (t) \
170 ? ~ (t) 0 << (sizeof(t) * CHAR_BIT - 1) : (t) 0))
171 #define INTTYPE_MAXIMUM(t) ((t) (~ (t) 0 - INTTYPE_MINIMUM (t)))
173 /* Use that infrastructure to provide a few constants. */
175 # define UCHAR_MAX INTTYPE_MAXIMUM (unsigned char)
178 #ifdef TIME_WITH_SYS_TIME
179 # include <sys/time.h>
183 # include <sys/time.h>
194 # ifdef HAVE_SYS_FILE_H
195 # include <sys/file.h>
217 /* Some systems define these in, e.g., param.h. We undefine these names
218 here to avoid the warnings. We prefer to use our definitions since we
219 know they are correct. */
223 #define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
224 #define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
226 /* Returns the least number N such that N * Y >= X. */
227 #define CEIL(x,y) (((x) + (y) - 1) / (y))
229 #ifdef HAVE_SYS_WAIT_H
230 #include <sys/wait.h>
234 #define WIFSIGNALED(S) (((S) & 0xff) != 0 && ((S) & 0xff) != 0x7f)
237 #define WTERMSIG(S) ((S) & 0x7f)
240 #define WIFEXITED(S) (((S) & 0xff) == 0)
243 #define WEXITSTATUS(S) (((S) & 0xff00) >> 8)
246 #define WSTOPSIG WEXITSTATUS
249 /* The HAVE_DECL_* macros are three-state, undefined, 0 or 1. If they
250 are defined to 0 then we must provide the relevant declaration
251 here. These checks will be in the undefined state while configure
252 is running so be careful to test "defined (HAVE_DECL_*)". */
256 # if defined (HAVE_DECL_BCOPY) && !HAVE_DECL_BCOPY
257 extern void bcopy
PARAMS ((const PTR
, PTR
, size_t));
259 # else /* ! HAVE_BCOPY */
260 # define bcopy(src,dst,len) memmove((dst),(src),(len))
264 #if defined (HAVE_DECL_ATOF) && !HAVE_DECL_ATOF
265 extern double atof
PARAMS ((const char *));
268 #if defined (HAVE_DECL_ATOL) && !HAVE_DECL_ATOL
269 extern long atol
PARAMS ((const char *));
272 #if defined (HAVE_DECL_FREE) && !HAVE_DECL_FREE
273 extern void free
PARAMS ((PTR
));
276 #if defined (HAVE_DECL_GETCWD) && !HAVE_DECL_GETCWD
277 extern char *getcwd
PARAMS ((char *, size_t));
280 #if defined (HAVE_DECL_GETENV) && !HAVE_DECL_GETENV
281 extern char *getenv
PARAMS ((const char *));
284 #if defined (HAVE_DECL_GETOPT) && !HAVE_DECL_GETOPT
285 extern int getopt
PARAMS ((int, char * const *, const char *));
288 #if defined (HAVE_DECL_GETWD) && !HAVE_DECL_GETWD
289 extern char *getwd
PARAMS ((char *));
292 #if defined (HAVE_DECL_SBRK) && !HAVE_DECL_SBRK
293 extern PTR sbrk
PARAMS ((int));
296 #if defined (HAVE_DECL_STRSTR) && !HAVE_DECL_STRSTR
297 extern char *strstr
PARAMS ((const char *, const char *));
304 #if defined (HAVE_DECL_MALLOC) && !HAVE_DECL_MALLOC
305 extern PTR malloc
PARAMS ((size_t));
308 #if defined (HAVE_DECL_CALLOC) && !HAVE_DECL_CALLOC
309 extern PTR calloc
PARAMS ((size_t, size_t));
312 #if defined (HAVE_DECL_REALLOC) && !HAVE_DECL_REALLOC
313 extern PTR realloc
PARAMS ((PTR
, size_t));
316 /* If the system doesn't provide strsignal, we get it defined in
317 libiberty but no declaration is supplied. */
318 #ifndef HAVE_STRSIGNAL
320 extern const char *strsignal
PARAMS ((int));
324 #ifdef HAVE_GETRLIMIT
325 # if defined (HAVE_DECL_GETRLIMIT) && !HAVE_DECL_GETRLIMIT
327 # ifdef ANSI_PROTOTYPES
330 extern int getrlimit
PARAMS ((int, struct rlimit
*));
335 #ifdef HAVE_SETRLIMIT
336 # if defined (HAVE_DECL_SETRLIMIT) && !HAVE_DECL_SETRLIMIT
338 # ifdef ANSI_PROTOTYPES
341 extern int setrlimit
PARAMS ((int, const struct rlimit
*));
346 /* HAVE_VOLATILE only refers to the stage1 compiler. We also check
347 __STDC__ and assume gcc sets it and has volatile in stage >=2. */
348 #if !defined(HAVE_VOLATILE) && !defined(__STDC__) && !defined(volatile)
352 #if defined (HAVE_DECL_ABORT) && !HAVE_DECL_ABORT
353 extern void abort
PARAMS ((void));
356 /* 1 if we have C99 designated initializers. */
357 #if !defined(HAVE_DESIGNATED_INITIALIZERS)
358 #define HAVE_DESIGNATED_INITIALIZERS \
359 ((GCC_VERSION >= 2007) || (__STDC_VERSION__ >= 199901L))
362 /* 1 if we have _Bool. */
364 # define HAVE__BOOL \
365 ((GCC_VERSION >= 3000) || (__STDC_VERSION__ >= 199901L))
370 /* Define a STRINGIFY macro that's right for ANSI or traditional C.
371 Note: if the argument passed to STRINGIFY is itself a macro, eg
372 #define foo bar, STRINGIFY(foo) will produce "foo", not "bar".
373 Although the __STDC__ case could be made to expand this via a layer
374 of indirection, the traditional C case can not do so. Therefore
375 this behavior is not supported. */
377 # ifdef HAVE_STRINGIZE
378 # define STRINGIFY(STRING) #STRING
380 # define STRINGIFY(STRING) "STRING"
382 #endif /* ! STRINGIFY */
385 # include <sys/stat.h>
388 /* Test if something is a normal file. */
390 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
393 /* Test if something is a directory. */
395 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
398 /* Test if something is a character special file. */
400 #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
403 /* Test if something is a block special file. */
405 #define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
408 /* Test if something is a socket. */
411 # define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
413 # define S_ISSOCK(m) 0
417 /* Test if something is a FIFO. */
420 # define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
422 # define S_ISFIFO(m) 0
426 /* Approximate O_NONBLOCK. */
428 #define O_NONBLOCK O_NDELAY
431 /* Approximate O_NOCTTY. */
436 /* Define well known filenos if the system does not define them. */
438 # define STDIN_FILENO 0
440 #ifndef STDOUT_FILENO
441 # define STDOUT_FILENO 1
443 #ifndef STDERR_FILENO
444 # define STDERR_FILENO 2
447 /* Some systems have mkdir that takes a single argument. */
448 #ifdef MKDIR_TAKES_ONE_ARG
449 # define mkdir(a,b) mkdir(a)
452 /* Provide a way to print an address via printf. */
453 #ifndef HOST_PTR_PRINTF
454 # ifdef HAVE_PRINTF_PTR
455 # define HOST_PTR_PRINTF "%p"
457 # define HOST_PTR_PRINTF \
458 (sizeof (int) == sizeof (char *) ? "%x" \
459 : sizeof (long) == sizeof (char *) ? "%lx" : "%llx")
461 #endif /* ! HOST_PTR_PRINTF */
463 /* By default, colon separates directories in a path. */
464 #ifndef PATH_SEPARATOR
465 #define PATH_SEPARATOR ':'
468 #ifndef DIR_SEPARATOR
469 #define DIR_SEPARATOR '/'
472 /* Define IS_DIR_SEPARATOR. */
473 #ifndef DIR_SEPARATOR_2
474 # define IS_DIR_SEPARATOR(CH) ((CH) == DIR_SEPARATOR)
475 #else /* DIR_SEPARATOR_2 */
476 # define IS_DIR_SEPARATOR(CH) \
477 (((CH) == DIR_SEPARATOR) || ((CH) == DIR_SEPARATOR_2))
478 #endif /* DIR_SEPARATOR_2 */
480 /* Say how to test for an absolute pathname. On Unix systems, this is if
481 it starts with a leading slash or a '$', the latter meaning the value of
482 an environment variable is to be used. On machien with DOS-based
483 file systems, it is also absolute if it starts with a drive identifier. */
484 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
485 #define IS_ABSOLUTE_PATHNAME(STR) \
486 (IS_DIR_SEPARATOR ((STR)[0]) || (STR)[0] == '$' \
487 || ((STR)[0] != '\0' && (STR)[1] == ':' && IS_DIR_SEPARATOR ((STR)[2])))
489 #define IS_ABSOLUTE_PATHNAME(STR) \
490 (IS_DIR_SEPARATOR ((STR)[0]) || (STR)[0] == '$')
493 /* Get libiberty declarations. */
494 #include "libiberty.h"
496 /* Make sure that ONLY_INT_FIELDS has an integral value. */
497 #ifdef ONLY_INT_FIELDS
498 #undef ONLY_INT_FIELDS
499 #define ONLY_INT_FIELDS 1
501 #define ONLY_INT_FIELDS 0
504 /* Provide a default for the HOST_BIT_BUCKET.
505 This suffices for POSIX-like hosts. */
507 #ifndef HOST_BIT_BUCKET
508 #define HOST_BIT_BUCKET "/dev/null"
511 /* Enumerated bitfields are safe to use unless we've been explictly told
512 otherwise or if they are signed. */
514 #define USE_ENUM_BITFIELDS (__GNUC__ || (!ONLY_INT_FIELDS && ENUM_BITFIELDS_ARE_UNSIGNED))
516 #if USE_ENUM_BITFIELDS
517 #define ENUM_BITFIELD(TYPE) enum TYPE
519 #define ENUM_BITFIELD(TYPE) unsigned int
523 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
526 /* Traditional C cannot initialize union members of structs. Provide
527 a macro which expands appropriately to handle it. This only works
528 if you intend to initalize the union member to zero since it relies
529 on default initialization to zero in the traditional C case. */
531 #define UNION_INIT_ZERO , {0}
533 #define UNION_INIT_ZERO
536 /* GCC now gives implicit declaration warnings for undeclared builtins. */
537 #if defined(__GNUC__) && defined (__SIZE_TYPE__)
538 extern void *alloca (__SIZE_TYPE__
);
541 /* Various error reporting routines want to use __FUNCTION__. */
542 #if (GCC_VERSION < 2007)
544 #define __FUNCTION__ "?"
545 #endif /* ! __FUNCTION__ */
548 /* Provide some sort of boolean type. We use stdbool.h if it's
549 available. This is dead last because various system headers might
557 #ifdef HAVE_STDBOOL_H
558 # include <stdbool.h>
571 #endif /* __GCC_SYSTEM_H__ */