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))
48 /* Define a generic NULL if one hasn't already been defined. */
53 /* The compiler is not a multi-threaded application and therefore we
54 do not have to use the locking functions.
56 HAVE_DECL_PUTC_UNLOCKED actually indicates whether or not the IO
57 code is multi-thread safe by default. If it is set to 0, then do
58 not worry about using the _unlocked functions.
60 fputs_unlocked is an extension and needs to be prototyped specially. */
62 #if defined HAVE_PUTC_UNLOCKED && (defined (HAVE_DECL_PUTC_UNLOCKED) && HAVE_DECL_PUTC_UNLOCKED)
64 # define putc(C, Stream) putc_unlocked (C, Stream)
66 #if defined HAVE_FPUTC_UNLOCKED && (defined (HAVE_DECL_PUTC_UNLOCKED) && HAVE_DECL_PUTC_UNLOCKED)
68 # define fputc(C, Stream) fputc_unlocked (C, Stream)
70 #if defined HAVE_FPUTS_UNLOCKED && (defined (HAVE_DECL_PUTC_UNLOCKED) && HAVE_DECL_PUTC_UNLOCKED)
72 # define fputs(String, Stream) fputs_unlocked (String, Stream)
73 # if defined (HAVE_DECL_FPUTS_UNLOCKED) && !HAVE_DECL_FPUTS_UNLOCKED
74 extern int fputs_unlocked
PARAMS ((const char *, FILE *));
78 /* There are an extraordinary number of issues with <ctype.h>.
79 The last straw is that it varies with the locale. Use libiberty's
80 replacement instead. */
81 #include <safe-ctype.h>
83 /* Define a default escape character; it's different for EBCDIC. */
85 #define TARGET_ESC 033
88 #include <sys/types.h>
96 #ifdef STRING_WITH_STRINGS
100 # ifdef HAVE_STRING_H
103 # ifdef HAVE_STRINGS_H
104 # include <strings.h>
112 /* Note that systems that use glibc have a <stdlib.h> that includes
113 <alloca.h> that defines alloca, so let USE_C_ALLOCA override this. */
122 #ifdef HAVE_SYS_PARAM_H
123 # include <sys/param.h>
130 /* Find HOST_WIDEST_INT and set its bit size, type and print macros.
131 It will be the largest integer mode supported by the host which may
132 (or may not) be larger than HOST_WIDE_INT. This must appear after
133 <limits.h> since we only use `long long' if its bigger than a
134 `long' and also if it is supported by macros in limits.h. For old
135 hosts which don't have a limits.h (and thus won't include it in
136 stage2 cause we don't rerun configure) we assume gcc supports long
137 long.) Note, you won't get these defined if you don't include
138 {ht}config.h before this file to set the HOST_BITS_PER_* macros. */
140 #ifndef HOST_WIDEST_INT
141 # if defined (HOST_BITS_PER_LONG) && defined (HOST_BITS_PER_LONGLONG)
142 # if (HOST_BITS_PER_LONGLONG > HOST_BITS_PER_LONG) && (defined (LONG_LONG_MAX) || defined (LONGLONG_MAX) || defined (LLONG_MAX) || defined (__GNUC__))
143 # define HOST_BITS_PER_WIDEST_INT HOST_BITS_PER_LONGLONG
144 # define HOST_WIDEST_INT long long
145 # define HOST_WIDEST_INT_PRINT_DEC "%lld"
146 # define HOST_WIDEST_INT_PRINT_UNSIGNED "%llu"
147 # define HOST_WIDEST_INT_PRINT_HEX "0x%llx"
149 # define HOST_BITS_PER_WIDEST_INT HOST_BITS_PER_LONG
150 # define HOST_WIDEST_INT long
151 # define HOST_WIDEST_INT_PRINT_DEC "%ld"
152 # define HOST_WIDEST_INT_PRINT_UNSIGNED "%lu"
153 # define HOST_WIDEST_INT_PRINT_HEX "0x%lx"
154 # endif /*(long long>long) && (LONG_LONG_MAX||LONGLONG_MAX||LLONG_MAX||GNUC)*/
155 # endif /* defined(HOST_BITS_PER_LONG) && defined(HOST_BITS_PER_LONGLONG) */
156 #endif /* ! HOST_WIDEST_INT */
158 /* Infrastructure for defining missing _MAX and _MIN macros. Note that
159 macros defined with these cannot be used in #if. */
161 /* The extra casts work around common compiler bugs. */
162 #define INTTYPE_SIGNED(t) (! ((t) 0 < (t) -1))
163 /* The outer cast is needed to work around a bug in Cray C 5.0.3.0.
164 It is necessary at least when t == time_t. */
165 #define INTTYPE_MINIMUM(t) ((t) (INTTYPE_SIGNED (t) \
166 ? ~ (t) 0 << (sizeof(t) * CHAR_BIT - 1) : (t) 0))
167 #define INTTYPE_MAXIMUM(t) ((t) (~ (t) 0 - INTTYPE_MINIMUM (t)))
169 /* Use that infrastructure to provide a few constants. */
171 # define UCHAR_MAX INTTYPE_MAXIMUM (unsigned char)
174 #ifdef TIME_WITH_SYS_TIME
175 # include <sys/time.h>
179 # include <sys/time.h>
190 # ifdef HAVE_SYS_FILE_H
191 # include <sys/file.h>
213 /* Some systems define these in, e.g., param.h. We undefine these names
214 here to avoid the warnings. We prefer to use our definitions since we
215 know they are correct. */
219 #define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
220 #define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
222 /* Returns the least number N such that N * Y >= X. */
223 #define CEIL(x,y) (((x) + (y) - 1) / (y))
225 #ifdef HAVE_SYS_WAIT_H
226 #include <sys/wait.h>
230 #define WIFSIGNALED(S) (((S) & 0xff) != 0 && ((S) & 0xff) != 0x7f)
233 #define WTERMSIG(S) ((S) & 0x7f)
236 #define WIFEXITED(S) (((S) & 0xff) == 0)
239 #define WEXITSTATUS(S) (((S) & 0xff00) >> 8)
242 #define WSTOPSIG WEXITSTATUS
245 /* The HAVE_DECL_* macros are three-state, undefined, 0 or 1. If they
246 are defined to 0 then we must provide the relevant declaration
247 here. These checks will be in the undefined state while configure
248 is running so be careful to test "defined (HAVE_DECL_*)". */
252 # if defined (HAVE_DECL_BCOPY) && !HAVE_DECL_BCOPY
253 extern void bcopy
PARAMS ((const PTR
, PTR
, size_t));
255 # else /* ! HAVE_BCOPY */
256 # define bcopy(src,dst,len) memmove((dst),(src),(len))
260 #if defined (HAVE_DECL_ATOF) && !HAVE_DECL_ATOF
261 extern double atof
PARAMS ((const char *));
264 #if defined (HAVE_DECL_ATOL) && !HAVE_DECL_ATOL
265 extern long atol
PARAMS ((const char *));
268 #if defined (HAVE_DECL_FREE) && !HAVE_DECL_FREE
269 extern void free
PARAMS ((PTR
));
272 #if defined (HAVE_DECL_GETCWD) && !HAVE_DECL_GETCWD
273 extern char *getcwd
PARAMS ((char *, size_t));
276 #if defined (HAVE_DECL_GETENV) && !HAVE_DECL_GETENV
277 extern char *getenv
PARAMS ((const char *));
280 #if defined (HAVE_DECL_GETOPT) && !HAVE_DECL_GETOPT
281 extern int getopt
PARAMS ((int, char * const *, const char *));
284 #if defined (HAVE_DECL_GETWD) && !HAVE_DECL_GETWD
285 extern char *getwd
PARAMS ((char *));
288 #if defined (HAVE_DECL_SBRK) && !HAVE_DECL_SBRK
289 extern PTR sbrk
PARAMS ((int));
292 #if defined (HAVE_DECL_STRSTR) && !HAVE_DECL_STRSTR
293 extern char *strstr
PARAMS ((const char *, const char *));
300 #if defined (HAVE_DECL_MALLOC) && !HAVE_DECL_MALLOC
301 extern PTR malloc
PARAMS ((size_t));
304 #if defined (HAVE_DECL_CALLOC) && !HAVE_DECL_CALLOC
305 extern PTR calloc
PARAMS ((size_t, size_t));
308 #if defined (HAVE_DECL_REALLOC) && !HAVE_DECL_REALLOC
309 extern PTR realloc
PARAMS ((PTR
, size_t));
312 /* If the system doesn't provide strsignal, we get it defined in
313 libiberty but no declaration is supplied. */
314 #ifndef HAVE_STRSIGNAL
316 extern const char *strsignal
PARAMS ((int));
320 #ifdef HAVE_GETRLIMIT
321 # if defined (HAVE_DECL_GETRLIMIT) && !HAVE_DECL_GETRLIMIT
323 # ifdef ANSI_PROTOTYPES
326 extern int getrlimit
PARAMS ((int, struct rlimit
*));
331 #ifdef HAVE_SETRLIMIT
332 # if defined (HAVE_DECL_SETRLIMIT) && !HAVE_DECL_SETRLIMIT
334 # ifdef ANSI_PROTOTYPES
337 extern int setrlimit
PARAMS ((int, const struct rlimit
*));
342 /* HAVE_VOLATILE only refers to the stage1 compiler. We also check
343 __STDC__ and assume gcc sets it and has volatile in stage >=2. */
344 #if !defined(HAVE_VOLATILE) && !defined(__STDC__) && !defined(volatile)
348 #if defined (HAVE_DECL_ABORT) && !HAVE_DECL_ABORT
349 extern void abort
PARAMS ((void));
352 /* 1 if we have C99 designated initializers. */
353 #if !defined(HAVE_DESIGNATED_INITIALIZERS)
354 #define HAVE_DESIGNATED_INITIALIZERS \
355 ((GCC_VERSION >= 2007) || (__STDC_VERSION__ >= 199901L))
358 /* Define a STRINGIFY macro that's right for ANSI or traditional C.
359 Note: if the argument passed to STRINGIFY is itself a macro, eg
360 #define foo bar, STRINGIFY(foo) will produce "foo", not "bar".
361 Although the __STDC__ case could be made to expand this via a layer
362 of indirection, the traditional C case can not do so. Therefore
363 this behavior is not supported. */
365 # ifdef HAVE_STRINGIZE
366 # define STRINGIFY(STRING) #STRING
368 # define STRINGIFY(STRING) "STRING"
370 #endif /* ! STRINGIFY */
373 # include <sys/stat.h>
376 /* Test if something is a normal file. */
378 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
381 /* Test if something is a directory. */
383 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
386 /* Test if something is a character special file. */
388 #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
391 /* Test if something is a block special file. */
393 #define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
396 /* Test if something is a socket. */
399 # define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
401 # define S_ISSOCK(m) 0
405 /* Test if something is a FIFO. */
408 # define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
410 # define S_ISFIFO(m) 0
414 /* Approximate O_NONBLOCK. */
416 #define O_NONBLOCK O_NDELAY
419 /* Approximate O_NOCTTY. */
424 /* Define well known filenos if the system does not define them. */
426 # define STDIN_FILENO 0
428 #ifndef STDOUT_FILENO
429 # define STDOUT_FILENO 1
431 #ifndef STDERR_FILENO
432 # define STDERR_FILENO 2
435 /* Some systems have mkdir that takes a single argument. */
436 #ifdef MKDIR_TAKES_ONE_ARG
437 # define mkdir(a,b) mkdir(a)
440 /* Provide a way to print an address via printf. */
441 #ifndef HOST_PTR_PRINTF
442 # ifdef HAVE_PRINTF_PTR
443 # define HOST_PTR_PRINTF "%p"
445 # define HOST_PTR_PRINTF \
446 (sizeof (int) == sizeof (char *) ? "%x" \
447 : sizeof (long) == sizeof (char *) ? "%lx" : "%llx")
449 #endif /* ! HOST_PTR_PRINTF */
451 /* By default, colon separates directories in a path. */
452 #ifndef PATH_SEPARATOR
453 #define PATH_SEPARATOR ':'
456 #ifndef DIR_SEPARATOR
457 #define DIR_SEPARATOR '/'
460 /* Define IS_DIR_SEPARATOR. */
461 #ifndef DIR_SEPARATOR_2
462 # define IS_DIR_SEPARATOR(CH) ((CH) == DIR_SEPARATOR)
463 #else /* DIR_SEPARATOR_2 */
464 # define IS_DIR_SEPARATOR(CH) \
465 (((CH) == DIR_SEPARATOR) || ((CH) == DIR_SEPARATOR_2))
466 #endif /* DIR_SEPARATOR_2 */
468 /* Say how to test for an absolute pathname. On Unix systems, this is if
469 it starts with a leading slash or a '$', the latter meaning the value of
470 an environment variable is to be used. On machien with DOS-based
471 file systems, it is also absolute if it starts with a drive identifier. */
472 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
473 #define IS_ABSOLUTE_PATHNAME(STR) \
474 (IS_DIR_SEPARATOR ((STR)[0]) || (STR)[0] == '$' \
475 || ((STR)[0] != '\0' && (STR)[1] == ':' && IS_DIR_SEPARATOR ((STR)[2])))
477 #define IS_ABSOLUTE_PATHNAME(STR) \
478 (IS_DIR_SEPARATOR ((STR)[0]) || (STR)[0] == '$')
481 /* Get libiberty declarations. */
482 #include "libiberty.h"
484 /* Make sure that ONLY_INT_FIELDS has an integral value. */
485 #ifdef ONLY_INT_FIELDS
486 #undef ONLY_INT_FIELDS
487 #define ONLY_INT_FIELDS 1
489 #define ONLY_INT_FIELDS 0
492 /* Provide a default for the HOST_BIT_BUCKET.
493 This suffices for POSIX-like hosts. */
495 #ifndef HOST_BIT_BUCKET
496 #define HOST_BIT_BUCKET "/dev/null"
499 /* Enumerated bitfields are safe to use unless we've been explictly told
500 otherwise or if they are signed. */
502 #define USE_ENUM_BITFIELDS (__GNUC__ || (!ONLY_INT_FIELDS && ENUM_BITFIELDS_ARE_UNSIGNED))
504 #if USE_ENUM_BITFIELDS
505 #define ENUM_BITFIELD(TYPE) enum TYPE
507 #define ENUM_BITFIELD(TYPE) unsigned int
511 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
514 /* Traditional C cannot initialize union members of structs. Provide
515 a macro which expands appropriately to handle it. This only works
516 if you intend to initalize the union member to zero since it relies
517 on default initialization to zero in the traditional C case. */
519 #define UNION_INIT_ZERO , {0}
521 #define UNION_INIT_ZERO
524 /* GCC now gives implicit declaration warnings for undeclared builtins. */
525 #if defined(__GNUC__) && defined (__SIZE_TYPE__)
526 extern void *alloca (__SIZE_TYPE__
);
529 /* Various error reporting routines want to use __FUNCTION__. */
530 #if (GCC_VERSION < 2007)
532 #define __FUNCTION__ "?"
533 #endif /* ! __FUNCTION__ */
536 #endif /* __GCC_SYSTEM_H__ */