190075Sobrien/* Get common system includes and various definitions and declarations based
290075Sobrien   on autoconf macros.
3169689Skan   Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
4132718Skan   Free Software Foundation, Inc.
550397Sobrien
690075SobrienThis file is part of GCC.
750397Sobrien
890075SobrienGCC is free software; you can redistribute it and/or modify it under
990075Sobrienthe terms of the GNU General Public License as published by the Free
1090075SobrienSoftware Foundation; either version 2, or (at your option) any later
1190075Sobrienversion.
1252284Sobrien
1390075SobrienGCC is distributed in the hope that it will be useful, but WITHOUT ANY
1490075SobrienWARRANTY; without even the implied warranty of MERCHANTABILITY or
1590075SobrienFITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1690075Sobrienfor more details.
1752284Sobrien
1852284SobrienYou should have received a copy of the GNU General Public License
1990075Sobrienalong with GCC; see the file COPYING.  If not, write to the Free
20169689SkanSoftware Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
21169689Skan02110-1301, USA.  */
2252284Sobrien
2350397Sobrien
2490075Sobrien#ifndef GCC_SYSTEM_H
2590075Sobrien#define GCC_SYSTEM_H
2690075Sobrien
27132718Skan/* We must include stdarg.h before stdio.h.  */
2852284Sobrien#include <stdarg.h>
2952284Sobrien
3090075Sobrien#ifndef va_copy
3190075Sobrien# ifdef __va_copy
3290075Sobrien#   define va_copy(d,s)  __va_copy((d),(s))
3390075Sobrien# else
3490075Sobrien#   define va_copy(d,s)  ((d) = (s))
3590075Sobrien# endif
3690075Sobrien#endif
3790075Sobrien
3890075Sobrien#ifdef HAVE_STDDEF_H
3990075Sobrien# include <stddef.h>
4090075Sobrien#endif
4190075Sobrien
4250397Sobrien#include <stdio.h>
4350397Sobrien
4450397Sobrien/* Define a generic NULL if one hasn't already been defined.  */
4550397Sobrien#ifndef NULL
4650397Sobrien#define NULL 0
4750397Sobrien#endif
4850397Sobrien
49169689Skan/* Use the unlocked open routines from libiberty.  */
50169689Skan#define fopen(PATH,MODE) fopen_unlocked(PATH,MODE)
51169689Skan#define fdopen(FILDES,MODE) fdopen_unlocked(FILDES,MODE)
52169689Skan#define freopen(PATH,MODE,STREAM) freopen_unlocked(PATH,MODE,STREAM)
53169689Skan
5452284Sobrien/* The compiler is not a multi-threaded application and therefore we
5590075Sobrien   do not have to use the locking functions.  In fact, using the locking
5690075Sobrien   functions can cause the compiler to be significantly slower under
5790075Sobrien   I/O bound conditions (such as -g -O0 on very large source files).
5852284Sobrien
5990075Sobrien   HAVE_DECL_PUTC_UNLOCKED actually indicates whether or not the stdio
6090075Sobrien   code is multi-thread safe by default.  If it is set to 0, then do
6190075Sobrien   not worry about using the _unlocked functions.
62132718Skan
6390075Sobrien   fputs_unlocked, fwrite_unlocked, and fprintf_unlocked are
6490075Sobrien   extensions and need to be prototyped by hand (since we do not
6590075Sobrien   define _GNU_SOURCE).  */
6652284Sobrien
6790075Sobrien#if defined HAVE_DECL_PUTC_UNLOCKED && HAVE_DECL_PUTC_UNLOCKED
6890075Sobrien
6990075Sobrien# ifdef HAVE_PUTC_UNLOCKED
7090075Sobrien#  undef putc
7190075Sobrien#  define putc(C, Stream) putc_unlocked (C, Stream)
7252284Sobrien# endif
73169689Skan# ifdef HAVE_PUTCHAR_UNLOCKED
74169689Skan#  undef putchar
75169689Skan#  define putchar(C) putchar_unlocked (C)
76169689Skan# endif
77169689Skan# ifdef HAVE_GETC_UNLOCKED
78169689Skan#  undef getc
79169689Skan#  define getc(Stream) getc_unlocked (Stream)
80169689Skan# endif
81169689Skan# ifdef HAVE_GETCHAR_UNLOCKED
82169689Skan#  undef getchar
83169689Skan#  define getchar() getchar_unlocked ()
84169689Skan# endif
8590075Sobrien# ifdef HAVE_FPUTC_UNLOCKED
8690075Sobrien#  undef fputc
8790075Sobrien#  define fputc(C, Stream) fputc_unlocked (C, Stream)
8890075Sobrien# endif
8952284Sobrien
90169689Skan# ifdef HAVE_CLEARERR_UNLOCKED
91169689Skan#  undef clearerr
92169689Skan#  define clearerr(Stream) clearerr_unlocked (Stream)
93169689Skan#  if defined (HAVE_DECL_CLEARERR_UNLOCKED) && !HAVE_DECL_CLEARERR_UNLOCKED
94169689Skanextern void clearerr_unlocked (FILE *);
95169689Skan#  endif
96169689Skan# endif
97169689Skan# ifdef HAVE_FEOF_UNLOCKED
98169689Skan#  undef feof
99169689Skan#  define feof(Stream) feof_unlocked (Stream)
100169689Skan#  if defined (HAVE_DECL_FEOF_UNLOCKED) && !HAVE_DECL_FEOF_UNLOCKED
101169689Skanextern int feof_unlocked (FILE *);
102169689Skan#  endif
103169689Skan# endif
104169689Skan# ifdef HAVE_FILENO_UNLOCKED
105169689Skan#  undef fileno
106169689Skan#  define fileno(Stream) fileno_unlocked (Stream)
107169689Skan#  if defined (HAVE_DECL_FILENO_UNLOCKED) && !HAVE_DECL_FILENO_UNLOCKED
108169689Skanextern int fileno_unlocked (FILE *);
109169689Skan#  endif
110169689Skan# endif
111169689Skan# ifdef HAVE_FFLUSH_UNLOCKED
112169689Skan#  undef fflush
113169689Skan#  define fflush(Stream) fflush_unlocked (Stream)
114169689Skan#  if defined (HAVE_DECL_FFLUSH_UNLOCKED) && !HAVE_DECL_FFLUSH_UNLOCKED
115169689Skanextern int fflush_unlocked (FILE *);
116169689Skan#  endif
117169689Skan# endif
118169689Skan# ifdef HAVE_FGETC_UNLOCKED
119169689Skan#  undef fgetc
120169689Skan#  define fgetc(Stream) fgetc_unlocked (Stream)
121169689Skan#  if defined (HAVE_DECL_FGETC_UNLOCKED) && !HAVE_DECL_FGETC_UNLOCKED
122169689Skanextern int fgetc_unlocked (FILE *);
123169689Skan#  endif
124169689Skan# endif
125169689Skan# ifdef HAVE_FGETS_UNLOCKED
126169689Skan#  undef fgets
127169689Skan#  define fgets(S, n, Stream) fgets_unlocked (S, n, Stream)
128169689Skan#  if defined (HAVE_DECL_FGETS_UNLOCKED) && !HAVE_DECL_FGETS_UNLOCKED
129169689Skanextern char *fgets_unlocked (char *, int, FILE *);
130169689Skan#  endif
131169689Skan# endif
13290075Sobrien# ifdef HAVE_FPUTS_UNLOCKED
13390075Sobrien#  undef fputs
13490075Sobrien#  define fputs(String, Stream) fputs_unlocked (String, Stream)
13590075Sobrien#  if defined (HAVE_DECL_FPUTS_UNLOCKED) && !HAVE_DECL_FPUTS_UNLOCKED
136132718Skanextern int fputs_unlocked (const char *, FILE *);
13790075Sobrien#  endif
13890075Sobrien# endif
139169689Skan# ifdef HAVE_FERROR_UNLOCKED
140169689Skan#  undef ferror
141169689Skan#  define ferror(Stream) ferror_unlocked (Stream)
142169689Skan#  if defined (HAVE_DECL_FERROR_UNLOCKED) && !HAVE_DECL_FERROR_UNLOCKED
143169689Skanextern int ferror_unlocked (FILE *);
144169689Skan#  endif
145169689Skan# endif
146169689Skan# ifdef HAVE_FREAD_UNLOCKED
147169689Skan#  undef fread
148169689Skan#  define fread(Ptr, Size, N, Stream) fread_unlocked (Ptr, Size, N, Stream)
149169689Skan#  if defined (HAVE_DECL_FREAD_UNLOCKED) && !HAVE_DECL_FREAD_UNLOCKED
150169689Skanextern size_t fread_unlocked (void *, size_t, size_t, FILE *);
151169689Skan#  endif
152169689Skan# endif
15390075Sobrien# ifdef HAVE_FWRITE_UNLOCKED
15490075Sobrien#  undef fwrite
15590075Sobrien#  define fwrite(Ptr, Size, N, Stream) fwrite_unlocked (Ptr, Size, N, Stream)
15690075Sobrien#  if defined (HAVE_DECL_FWRITE_UNLOCKED) && !HAVE_DECL_FWRITE_UNLOCKED
157169689Skanextern size_t fwrite_unlocked (const void *, size_t, size_t, FILE *);
15890075Sobrien#  endif
15990075Sobrien# endif
16090075Sobrien# ifdef HAVE_FPRINTF_UNLOCKED
16190075Sobrien#  undef fprintf
16290075Sobrien/* We can't use a function-like macro here because we don't know if
16390075Sobrien   we have varargs macros.  */
16490075Sobrien#  define fprintf fprintf_unlocked
16590075Sobrien#  if defined (HAVE_DECL_FPRINTF_UNLOCKED) && !HAVE_DECL_FPRINTF_UNLOCKED
166132718Skanextern int fprintf_unlocked (FILE *, const char *, ...);
16790075Sobrien#  endif
16890075Sobrien# endif
16950397Sobrien
17050397Sobrien#endif
17150397Sobrien
172132718Skan/* ??? Glibc's fwrite/fread_unlocked macros cause
173132718Skan   "warning: signed and unsigned type in conditional expression".  */
174132718Skan#undef fread_unlocked
175132718Skan#undef fwrite_unlocked
176132718Skan
17790075Sobrien/* There are an extraordinary number of issues with <ctype.h>.
17890075Sobrien   The last straw is that it varies with the locale.  Use libiberty's
17990075Sobrien   replacement instead.  */
18090075Sobrien#include <safe-ctype.h>
18150397Sobrien
18290075Sobrien#include <sys/types.h>
18350397Sobrien
18450397Sobrien#include <errno.h>
18550397Sobrien
18690075Sobrien#if !defined (errno) && defined (HAVE_DECL_ERRNO) && !HAVE_DECL_ERRNO
18750397Sobrienextern int errno;
18850397Sobrien#endif
18950397Sobrien
190132718Skan/* Some of glibc's string inlines cause warnings.  Plus we'd rather
191132718Skan   rely on (and therefore test) GCC's string builtins.  */
192132718Skan#define __NO_STRING_INLINES
193132718Skan
19452284Sobrien#ifdef STRING_WITH_STRINGS
19550397Sobrien# include <string.h>
19652284Sobrien# include <strings.h>
19750397Sobrien#else
19852284Sobrien# ifdef HAVE_STRING_H
19952284Sobrien#  include <string.h>
20052284Sobrien# else
20152284Sobrien#  ifdef HAVE_STRINGS_H
20252284Sobrien#   include <strings.h>
20352284Sobrien#  endif
20450397Sobrien# endif
20550397Sobrien#endif
20650397Sobrien
20750397Sobrien#ifdef HAVE_STDLIB_H
20850397Sobrien# include <stdlib.h>
20950397Sobrien#endif
21050397Sobrien
21190075Sobrien/* If we don't have an overriding definition, set SUCCESS_EXIT_CODE and
21290075Sobrien   FATAL_EXIT_CODE to EXIT_SUCCESS and EXIT_FAILURE respectively,
21390075Sobrien   or 0 and 1 if those macros are not defined.  */
21490075Sobrien#ifndef SUCCESS_EXIT_CODE
21590075Sobrien# ifdef EXIT_SUCCESS
21690075Sobrien#  define SUCCESS_EXIT_CODE EXIT_SUCCESS
21790075Sobrien# else
21890075Sobrien#  define SUCCESS_EXIT_CODE 0
21990075Sobrien# endif
22090075Sobrien#endif
22190075Sobrien
22290075Sobrien#ifndef FATAL_EXIT_CODE
22390075Sobrien# ifdef EXIT_FAILURE
22490075Sobrien#  define FATAL_EXIT_CODE EXIT_FAILURE
22590075Sobrien# else
22690075Sobrien#  define FATAL_EXIT_CODE 1
22790075Sobrien# endif
22890075Sobrien#endif
22990075Sobrien
230169689Skan#define ICE_EXIT_CODE 4
231169689Skan
23250397Sobrien#ifdef HAVE_UNISTD_H
23350397Sobrien# include <unistd.h>
23450397Sobrien#endif
23550397Sobrien
23650397Sobrien#ifdef HAVE_SYS_PARAM_H
23750397Sobrien# include <sys/param.h>
23890075Sobrien/* We use this identifier later and it appears in some vendor param.h's.  */
23990075Sobrien# undef PREFETCH
24050397Sobrien#endif
24150397Sobrien
24250397Sobrien#if HAVE_LIMITS_H
24350397Sobrien# include <limits.h>
24450397Sobrien#endif
24550397Sobrien
24690075Sobrien/* Get definitions of HOST_WIDE_INT and HOST_WIDEST_INT.  */
24790075Sobrien#include "hwint.h"
24852284Sobrien
24990075Sobrien/* A macro to determine whether a VALUE lies inclusively within a
25090075Sobrien   certain range without evaluating the VALUE more than once.  This
25190075Sobrien   macro won't warn if the VALUE is unsigned and the LOWER bound is
25290075Sobrien   zero, as it would e.g. with "VALUE >= 0 && ...".  Note the LOWER
25390075Sobrien   bound *is* evaluated twice, and LOWER must not be greater than
25490075Sobrien   UPPER.  However the bounds themselves can be either positive or
25590075Sobrien   negative.  */
25690075Sobrien#define IN_RANGE(VALUE, LOWER, UPPER) \
257169689Skan  ((unsigned HOST_WIDE_INT)((VALUE) - (LOWER)) <= ((UPPER) - (LOWER)))
25852284Sobrien
25990075Sobrien/* Infrastructure for defining missing _MAX and _MIN macros.  Note that
26090075Sobrien   macros defined with these cannot be used in #if.  */
26190075Sobrien
26290075Sobrien/* The extra casts work around common compiler bugs.  */
26390075Sobrien#define INTTYPE_SIGNED(t) (! ((t) 0 < (t) -1))
26490075Sobrien/* The outer cast is needed to work around a bug in Cray C 5.0.3.0.
26590075Sobrien   It is necessary at least when t == time_t.  */
26690075Sobrien#define INTTYPE_MINIMUM(t) ((t) (INTTYPE_SIGNED (t) \
26790075Sobrien                             ? ~ (t) 0 << (sizeof(t) * CHAR_BIT - 1) : (t) 0))
26890075Sobrien#define INTTYPE_MAXIMUM(t) ((t) (~ (t) 0 - INTTYPE_MINIMUM (t)))
26990075Sobrien
27090075Sobrien/* Use that infrastructure to provide a few constants.  */
27190075Sobrien#ifndef UCHAR_MAX
27290075Sobrien# define UCHAR_MAX INTTYPE_MAXIMUM (unsigned char)
27390075Sobrien#endif
27490075Sobrien
27550397Sobrien#ifdef TIME_WITH_SYS_TIME
27650397Sobrien# include <sys/time.h>
27750397Sobrien# include <time.h>
27850397Sobrien#else
27950397Sobrien# if HAVE_SYS_TIME_H
28050397Sobrien#  include <sys/time.h>
28150397Sobrien# else
28250397Sobrien#  ifdef HAVE_TIME_H
28350397Sobrien#   include <time.h>
28450397Sobrien#  endif
28550397Sobrien# endif
28650397Sobrien#endif
28750397Sobrien
28850397Sobrien#ifdef HAVE_FCNTL_H
28950397Sobrien# include <fcntl.h>
29050397Sobrien#else
29150397Sobrien# ifdef HAVE_SYS_FILE_H
29250397Sobrien#  include <sys/file.h>
29350397Sobrien# endif
29450397Sobrien#endif
29550397Sobrien
29650397Sobrien#ifndef SEEK_SET
29750397Sobrien# define SEEK_SET 0
29850397Sobrien# define SEEK_CUR 1
29950397Sobrien# define SEEK_END 2
30050397Sobrien#endif
30150397Sobrien#ifndef F_OK
30250397Sobrien# define F_OK 0
30350397Sobrien# define X_OK 1
30450397Sobrien# define W_OK 2
30550397Sobrien# define R_OK 4
30650397Sobrien#endif
30750397Sobrien#ifndef O_RDONLY
30850397Sobrien# define O_RDONLY 0
30950397Sobrien#endif
31050397Sobrien#ifndef O_WRONLY
31150397Sobrien# define O_WRONLY 1
31250397Sobrien#endif
31350397Sobrien
31452284Sobrien/* Some systems define these in, e.g., param.h.  We undefine these names
31552284Sobrien   here to avoid the warnings.  We prefer to use our definitions since we
31652284Sobrien   know they are correct.  */
31750397Sobrien
31852284Sobrien#undef MIN
31952284Sobrien#undef MAX
32052284Sobrien#define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
32152284Sobrien#define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
32250397Sobrien
32390075Sobrien/* Returns the least number N such that N * Y >= X.  */
32490075Sobrien#define CEIL(x,y) (((x) + (y) - 1) / (y))
32590075Sobrien
32652284Sobrien#ifdef HAVE_SYS_WAIT_H
32752284Sobrien#include <sys/wait.h>
32852284Sobrien#endif
32952284Sobrien
33052284Sobrien#ifndef WIFSIGNALED
33152284Sobrien#define WIFSIGNALED(S) (((S) & 0xff) != 0 && ((S) & 0xff) != 0x7f)
33252284Sobrien#endif
33352284Sobrien#ifndef WTERMSIG
33452284Sobrien#define WTERMSIG(S) ((S) & 0x7f)
33552284Sobrien#endif
33652284Sobrien#ifndef WIFEXITED
33752284Sobrien#define WIFEXITED(S) (((S) & 0xff) == 0)
33852284Sobrien#endif
33952284Sobrien#ifndef WEXITSTATUS
34052284Sobrien#define WEXITSTATUS(S) (((S) & 0xff00) >> 8)
34152284Sobrien#endif
34252284Sobrien#ifndef WSTOPSIG
34352284Sobrien#define WSTOPSIG WEXITSTATUS
34452284Sobrien#endif
345117395Skan#ifndef WCOREDUMP
346117395Skan#define WCOREDUMP(S) ((S) & WCOREFLG)
347117395Skan#endif
348117395Skan#ifndef WCOREFLG
349117395Skan#define WCOREFLG 0200
350117395Skan#endif
35152284Sobrien
35290075Sobrien/* The HAVE_DECL_* macros are three-state, undefined, 0 or 1.  If they
35390075Sobrien   are defined to 0 then we must provide the relevant declaration
35490075Sobrien   here.  These checks will be in the undefined state while configure
35590075Sobrien   is running so be careful to test "defined (HAVE_DECL_*)".  */
35652284Sobrien
35790075Sobrien#if defined (HAVE_DECL_ATOF) && !HAVE_DECL_ATOF
358132718Skanextern double atof (const char *);
35950397Sobrien#endif
36050397Sobrien
36190075Sobrien#if defined (HAVE_DECL_ATOL) && !HAVE_DECL_ATOL
362132718Skanextern long atol (const char *);
36350397Sobrien#endif
36450397Sobrien
36590075Sobrien#if defined (HAVE_DECL_FREE) && !HAVE_DECL_FREE
366132718Skanextern void free (void *);
36750397Sobrien#endif
36850397Sobrien
36990075Sobrien#if defined (HAVE_DECL_GETCWD) && !HAVE_DECL_GETCWD
370132718Skanextern char *getcwd (char *, size_t);
37150397Sobrien#endif
37250397Sobrien
37390075Sobrien#if defined (HAVE_DECL_GETENV) && !HAVE_DECL_GETENV
374132718Skanextern char *getenv (const char *);
37550397Sobrien#endif
37650397Sobrien
37790075Sobrien#if defined (HAVE_DECL_GETOPT) && !HAVE_DECL_GETOPT
378132718Skanextern int getopt (int, char * const *, const char *);
37950397Sobrien#endif
38050397Sobrien
381169689Skan#if defined (HAVE_DECL_GETPAGESIZE) && !HAVE_DECL_GETPAGESIZE
382169689Skanextern int getpagesize (void);
383169689Skan#endif
384169689Skan
38590075Sobrien#if defined (HAVE_DECL_GETWD) && !HAVE_DECL_GETWD
386132718Skanextern char *getwd (char *);
38750397Sobrien#endif
38850397Sobrien
38990075Sobrien#if defined (HAVE_DECL_SBRK) && !HAVE_DECL_SBRK
390132718Skanextern void *sbrk (int);
39150397Sobrien#endif
39250397Sobrien
39390075Sobrien#if defined (HAVE_DECL_STRSTR) && !HAVE_DECL_STRSTR
394132718Skanextern char *strstr (const char *, const char *);
39550397Sobrien#endif
39650397Sobrien
39790075Sobrien#ifdef HAVE_MALLOC_H
39890075Sobrien#include <malloc.h>
39950397Sobrien#endif
40050397Sobrien
40190075Sobrien#if defined (HAVE_DECL_MALLOC) && !HAVE_DECL_MALLOC
402132718Skanextern void *malloc (size_t);
40350397Sobrien#endif
40450397Sobrien
40590075Sobrien#if defined (HAVE_DECL_CALLOC) && !HAVE_DECL_CALLOC
406132718Skanextern void *calloc (size_t, size_t);
40750397Sobrien#endif
40850397Sobrien
40990075Sobrien#if defined (HAVE_DECL_REALLOC) && !HAVE_DECL_REALLOC
410132718Skanextern void *realloc (void *, size_t);
41152284Sobrien#endif
41252284Sobrien
41390075Sobrien/* If the system doesn't provide strsignal, we get it defined in
41490075Sobrien   libiberty but no declaration is supplied.  */
415132718Skan#if !defined (HAVE_STRSIGNAL) \
416132718Skan    || (defined (HAVE_DECL_STRSIGNAL) && !HAVE_DECL_STRSIGNAL)
41790075Sobrien# ifndef strsignal
418132718Skanextern const char *strsignal (int);
41950397Sobrien# endif
42090075Sobrien#endif
42150397Sobrien
42250397Sobrien#ifdef HAVE_GETRLIMIT
42390075Sobrien# if defined (HAVE_DECL_GETRLIMIT) && !HAVE_DECL_GETRLIMIT
42450397Sobrien#  ifndef getrlimit
42590075Sobrienstruct rlimit;
426132718Skanextern int getrlimit (int, struct rlimit *);
42750397Sobrien#  endif
42850397Sobrien# endif
42950397Sobrien#endif
43050397Sobrien
43150397Sobrien#ifdef HAVE_SETRLIMIT
43290075Sobrien# if defined (HAVE_DECL_SETRLIMIT) && !HAVE_DECL_SETRLIMIT
43350397Sobrien#  ifndef setrlimit
43490075Sobrienstruct rlimit;
435132718Skanextern int setrlimit (int, const struct rlimit *);
43650397Sobrien#  endif
43750397Sobrien# endif
43850397Sobrien#endif
43950397Sobrien
440132718Skan#if defined (HAVE_DECL_ABORT) && !HAVE_DECL_ABORT
441132718Skanextern void abort (void);
44250397Sobrien#endif
44350397Sobrien
444132718Skan#if defined (HAVE_DECL_SNPRINTF) && !HAVE_DECL_SNPRINTF
445132718Skanextern int snprintf (char *, size_t, const char *, ...);
44652284Sobrien#endif
44750397Sobrien
448169689Skan#if defined (HAVE_DECL_VSNPRINTF) && !HAVE_DECL_VSNPRINTF
449169689Skanextern int vsnprintf(char *, size_t, const char *, va_list);
450169689Skan#endif
451169689Skan
45290075Sobrien/* 1 if we have C99 designated initializers.  */
45390075Sobrien#if !defined(HAVE_DESIGNATED_INITIALIZERS)
45490075Sobrien#define HAVE_DESIGNATED_INITIALIZERS \
45590075Sobrien  ((GCC_VERSION >= 2007) || (__STDC_VERSION__ >= 199901L))
45690075Sobrien#endif
45750397Sobrien
45852284Sobrien#if HAVE_SYS_STAT_H
45952284Sobrien# include <sys/stat.h>
46052284Sobrien#endif
46150397Sobrien
46252284Sobrien/* Test if something is a normal file.  */
46352284Sobrien#ifndef S_ISREG
46452284Sobrien#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
46552284Sobrien#endif
46650397Sobrien
46752284Sobrien/* Test if something is a directory.  */
46852284Sobrien#ifndef S_ISDIR
46952284Sobrien#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
47052284Sobrien#endif
47152284Sobrien
47252284Sobrien/* Test if something is a character special file.  */
47352284Sobrien#ifndef S_ISCHR
47452284Sobrien#define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
47552284Sobrien#endif
47652284Sobrien
47790075Sobrien/* Test if something is a block special file.  */
47890075Sobrien#ifndef S_ISBLK
47990075Sobrien#define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
48090075Sobrien#endif
48190075Sobrien
48252284Sobrien/* Test if something is a socket.  */
48352284Sobrien#ifndef S_ISSOCK
48452284Sobrien# ifdef S_IFSOCK
48552284Sobrien#   define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
48652284Sobrien# else
48752284Sobrien#   define S_ISSOCK(m) 0
48852284Sobrien# endif
48952284Sobrien#endif
49052284Sobrien
49152284Sobrien/* Test if something is a FIFO.  */
49252284Sobrien#ifndef S_ISFIFO
49352284Sobrien# ifdef S_IFIFO
49452284Sobrien#  define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
49552284Sobrien# else
49652284Sobrien#  define S_ISFIFO(m) 0
49752284Sobrien# endif
49852284Sobrien#endif
49952284Sobrien
50052284Sobrien/* Define well known filenos if the system does not define them.  */
50152284Sobrien#ifndef STDIN_FILENO
50252284Sobrien# define STDIN_FILENO   0
50352284Sobrien#endif
50452284Sobrien#ifndef STDOUT_FILENO
50552284Sobrien# define STDOUT_FILENO  1
50652284Sobrien#endif
50752284Sobrien#ifndef STDERR_FILENO
50852284Sobrien# define STDERR_FILENO  2
50952284Sobrien#endif
51052284Sobrien
51190075Sobrien/* Some systems have mkdir that takes a single argument.  */
51252284Sobrien#ifdef MKDIR_TAKES_ONE_ARG
51352284Sobrien# define mkdir(a,b) mkdir(a)
51452284Sobrien#endif
51552284Sobrien
51690075Sobrien/* By default, colon separates directories in a path.  */
51790075Sobrien#ifndef PATH_SEPARATOR
51890075Sobrien#define PATH_SEPARATOR ':'
51990075Sobrien#endif
52090075Sobrien
521132718Skan/* Filename handling macros.  */
522132718Skan#include "filenames.h"
523132718Skan
524132718Skan/* These should be phased out in favor of IS_DIR_SEPARATOR, where possible.  */
52590075Sobrien#ifndef DIR_SEPARATOR
526132718Skan# define DIR_SEPARATOR '/'
527132718Skan# ifdef HAVE_DOS_BASED_FILE_SYSTEM
528132718Skan#  define DIR_SEPARATOR_2 '\\'
529132718Skan# endif
53090075Sobrien#endif
53190075Sobrien
53290075Sobrien/* Get libiberty declarations.  */
53352284Sobrien#include "libiberty.h"
53452284Sobrien
53590075Sobrien/* Provide a default for the HOST_BIT_BUCKET.
53690075Sobrien   This suffices for POSIX-like hosts.  */
53790075Sobrien
53890075Sobrien#ifndef HOST_BIT_BUCKET
53990075Sobrien#define HOST_BIT_BUCKET "/dev/null"
54090075Sobrien#endif
54190075Sobrien
54290075Sobrien/* Be conservative and only use enum bitfields with GCC.
54390075Sobrien   FIXME: provide a complete autoconf test for buggy enum bitfields.  */
54490075Sobrien
54590075Sobrien#if (GCC_VERSION > 2000)
546132718Skan#define ENUM_BITFIELD(TYPE) __extension__ enum TYPE
54790075Sobrien#else
54890075Sobrien#define ENUM_BITFIELD(TYPE) unsigned int
54990075Sobrien#endif
55090075Sobrien
55190075Sobrien#ifndef offsetof
55290075Sobrien#define offsetof(TYPE, MEMBER)	((size_t) &((TYPE *) 0)->MEMBER)
55390075Sobrien#endif
55490075Sobrien
55590075Sobrien/* Various error reporting routines want to use __FUNCTION__.  */
55690075Sobrien#if (GCC_VERSION < 2007)
55790075Sobrien#ifndef __FUNCTION__
55890075Sobrien#define __FUNCTION__ "?"
55990075Sobrien#endif /* ! __FUNCTION__ */
56090075Sobrien#endif
56190075Sobrien
56290075Sobrien/* __builtin_expect(A, B) evaluates to A, but notifies the compiler that
56390075Sobrien   the most likely value of A is B.  This feature was added at some point
56490075Sobrien   between 2.95 and 3.0.  Let's use 3.0 as the lower bound for now.  */
56590075Sobrien#if (GCC_VERSION < 3000)
56690075Sobrien#define __builtin_expect(a, b) (a)
56790075Sobrien#endif
56890075Sobrien
569169689Skan/* Redefine abort to report an internal error w/o coredump, and
570169689Skan   reporting the location of the error in the source file.  */
571169689Skanextern void fancy_abort (const char *, int, const char *) ATTRIBUTE_NORETURN;
572169689Skan#define abort() fancy_abort (__FILE__, __LINE__, __FUNCTION__)
573169689Skan
574169689Skan/* Use gcc_assert(EXPR) to test invariants.  */
575169689Skan#if ENABLE_ASSERT_CHECKING
576169689Skan#define gcc_assert(EXPR) 						\
577169689Skan   ((void)(!(EXPR) ? fancy_abort (__FILE__, __LINE__, __FUNCTION__), 0 : 0))
578169689Skan#else
579169689Skan/* Include EXPR, so that unused variable warnings do not occur.  */
580169689Skan#define gcc_assert(EXPR) ((void)(0 && (EXPR)))
581169689Skan#endif
582169689Skan
583169689Skan/* Use gcc_unreachable() to mark unreachable locations (like an
584169689Skan   unreachable default case of a switch.  Do not use gcc_assert(0).  */
585169689Skan#define gcc_unreachable() (fancy_abort (__FILE__, __LINE__, __FUNCTION__))
586169689Skan
587169689Skan/* Provide a fake boolean type.  We make no attempt to use the
588169689Skan   C99 _Bool, as it may not be available in the bootstrap compiler,
589169689Skan   and even if it is, it is liable to be buggy.
590169689Skan   This must be after all inclusion of system headers, as some of
591169689Skan   them will mess us up.  */
592169689Skan
59390075Sobrien#undef TRUE
59490075Sobrien#undef FALSE
59590075Sobrien
596169689Skan#ifdef __cplusplus
597169689Skan  /* Obsolete.  */
598169689Skan# define TRUE true
599169689Skan# define FALSE false
600169689Skan#else /* !__cplusplus */
601169689Skan# undef bool
602169689Skan# undef true
603169689Skan# undef false
604169689Skan
605169689Skan# define bool unsigned char
60690075Sobrien# define true 1
60790075Sobrien# define false 0
60890075Sobrien
609169689Skan  /* Obsolete.  */
610169689Skan# define TRUE true
611169689Skan# define FALSE false
612169689Skan#endif /* !__cplusplus */
61390075Sobrien
614169689Skan/* Get definition of double_int.  */
615169689Skan#include "double-int.h"
616169689Skan
617169689Skan/* Some compilers do not allow the use of unsigned char in bitfields.  */
618169689Skan#define BOOL_BITFIELD unsigned int
619169689Skan
62090075Sobrien/* As the last action in this file, we poison the identifiers that
62190075Sobrien   shouldn't be used.  Note, luckily gcc-3.0's token-based integrated
62290075Sobrien   preprocessor won't trip on poisoned identifiers that arrive from
62390075Sobrien   the expansion of macros.  E.g. #define strrchr rindex, won't error
62490075Sobrien   if rindex is poisoned after this directive is issued and later on
62590075Sobrien   strrchr is called.
62690075Sobrien
62790075Sobrien   Note: We define bypass macros for the few cases where we really
62890075Sobrien   want to use the libc memory allocation routines.  Otherwise we
62990075Sobrien   insist you use the "x" versions from libiberty.  */
63090075Sobrien
63190075Sobrien#define really_call_malloc malloc
63290075Sobrien#define really_call_calloc calloc
63390075Sobrien#define really_call_realloc realloc
63490075Sobrien
635132718Skan#if defined(FLEX_SCANNER) || defined(YYBISON) || defined(YYBYACC)
636132718Skan/* Flex and bison use malloc and realloc.  Yuk.  Note that this means
637132718Skan   really_call_* cannot be used in a .l or .y file.  */
638132718Skan#define malloc xmalloc
639132718Skan#define realloc xrealloc
640132718Skan#endif
641132718Skan
64290075Sobrien#if (GCC_VERSION >= 3000)
64390075Sobrien
64490075Sobrien/* Note autoconf checks for prototype declarations and includes
64590075Sobrien   system.h while doing so.  Only poison these tokens if actually
64690075Sobrien   compiling gcc, so that the autoconf declaration tests for malloc
64790075Sobrien   etc don't spuriously fail.  */
64890075Sobrien#ifdef IN_GCC
64990075Sobrien#undef calloc
65090075Sobrien#undef strdup
651117395Skan #pragma GCC poison calloc strdup
65290075Sobrien
653132718Skan#if !defined(FLEX_SCANNER) && !defined(YYBISON)
654117395Skan#undef malloc
655117395Skan#undef realloc
656117395Skan #pragma GCC poison malloc realloc
657117395Skan#endif
658117395Skan
65990075Sobrien/* Old target macros that have moved to the target hooks structure.  */
66090075Sobrien #pragma GCC poison ASM_OPEN_PAREN ASM_CLOSE_PAREN			\
66190075Sobrien	FUNCTION_PROLOGUE FUNCTION_EPILOGUE				\
66290075Sobrien	FUNCTION_END_PROLOGUE FUNCTION_BEGIN_EPILOGUE			\
66390075Sobrien	DECL_MACHINE_ATTRIBUTES COMP_TYPE_ATTRIBUTES INSERT_ATTRIBUTES	\
66490075Sobrien	VALID_MACHINE_DECL_ATTRIBUTE VALID_MACHINE_TYPE_ATTRIBUTE	\
66590075Sobrien	SET_DEFAULT_TYPE_ATTRIBUTES SET_DEFAULT_DECL_ATTRIBUTES		\
66690075Sobrien	MERGE_MACHINE_TYPE_ATTRIBUTES MERGE_MACHINE_DECL_ATTRIBUTES	\
66790075Sobrien	MD_INIT_BUILTINS MD_EXPAND_BUILTIN ASM_OUTPUT_CONSTRUCTOR	\
668117395Skan	ASM_OUTPUT_DESTRUCTOR SIGNED_CHAR_SPEC MAX_CHAR_TYPE_SIZE	\
669117395Skan	WCHAR_UNSIGNED UNIQUE_SECTION SELECT_SECTION SELECT_RTX_SECTION	\
670117395Skan	ENCODE_SECTION_INFO STRIP_NAME_ENCODING ASM_GLOBALIZE_LABEL	\
671132718Skan	ASM_OUTPUT_MI_THUNK CONST_COSTS RTX_COSTS DEFAULT_RTX_COSTS	\
672132718Skan	ADDRESS_COST MACHINE_DEPENDENT_REORG ASM_FILE_START ASM_FILE_END \
673132718Skan	ASM_SIMPLIFY_DWARF_ADDR INIT_TARGET_OPTABS INIT_SUBTARGET_OPTABS \
674132718Skan	INIT_GOFAST_OPTABS MULSI3_LIBCALL MULDI3_LIBCALL DIVSI3_LIBCALL \
675132718Skan	DIVDI3_LIBCALL UDIVSI3_LIBCALL UDIVDI3_LIBCALL MODSI3_LIBCALL	\
676132718Skan	MODDI3_LIBCALL UMODSI3_LIBCALL UMODDI3_LIBCALL BUILD_VA_LIST_TYPE \
677132718Skan	PRETEND_OUTGOING_VARARGS_NAMED STRUCT_VALUE_INCOMING_REGNUM	\
678169689Skan	ASM_OUTPUT_SECTION_NAME PROMOTE_FUNCTION_ARGS			\
679169689Skan	STRUCT_VALUE_INCOMING STRICT_ARGUMENT_NAMING			\
680169689Skan	PROMOTE_FUNCTION_RETURN PROMOTE_PROTOTYPES STRUCT_VALUE_REGNUM	\
681169689Skan	SETUP_INCOMING_VARARGS EXPAND_BUILTIN_SAVEREGS			\
682169689Skan	DEFAULT_SHORT_ENUMS SPLIT_COMPLEX_ARGS MD_ASM_CLOBBERS		\
683169689Skan	HANDLE_PRAGMA_REDEFINE_EXTNAME HANDLE_PRAGMA_EXTERN_PREFIX	\
684169689Skan	MUST_PASS_IN_STACK FUNCTION_ARG_PASS_BY_REFERENCE               \
685169689Skan        VECTOR_MODE_SUPPORTED_P TARGET_SUPPORTS_HIDDEN 			\
686169689Skan	FUNCTION_ARG_PARTIAL_NREGS ASM_OUTPUT_DWARF_DTPREL		\
687169689Skan	ALLOCATE_INITIAL_VALUE
68890075Sobrien
689117395Skan/* Other obsolete target macros, or macros that used to be in target
69090075Sobrien   headers and were not used, and may be obsolete or may never have
69190075Sobrien   been used.  */
692132718Skan #pragma GCC poison INT_ASM_OP ASM_OUTPUT_EH_REGION_BEG CPP_PREDEFINES	   \
693132718Skan	ASM_OUTPUT_EH_REGION_END ASM_OUTPUT_LABELREF_AS_INT SMALL_STACK    \
69490075Sobrien	DOESNT_NEED_UNWINDER EH_TABLE_LOOKUP OBJC_SELECTORS_WITHOUT_LABELS \
69590075Sobrien	OMIT_EH_TABLE EASY_DIV_EXPR IMPLICIT_FIX_EXPR			   \
69690075Sobrien	LONGJMP_RESTORE_FROM_STACK MAX_INT_TYPE_SIZE ASM_IDENTIFY_GCC	   \
69790075Sobrien	STDC_VALUE TRAMPOLINE_ALIGN ASM_IDENTIFY_GCC_AFTER_SOURCE	   \
698102780Skan	SLOW_ZERO_EXTEND SUBREG_REGNO_OFFSET DWARF_LINE_MIN_INSTR_LENGTH   \
699117395Skan	TRADITIONAL_RETURN_FLOAT NO_BUILTIN_SIZE_TYPE			   \
700117395Skan	NO_BUILTIN_PTRDIFF_TYPE NO_BUILTIN_WCHAR_TYPE NO_BUILTIN_WINT_TYPE \
701117395Skan	BLOCK_PROFILER BLOCK_PROFILER_CODE FUNCTION_BLOCK_PROFILER	   \
702117395Skan	FUNCTION_BLOCK_PROFILER_EXIT MACHINE_STATE_SAVE			   \
703169689Skan	MACHINE_STATE_RESTORE SCCS_DIRECTIVE SECTION_ASM_OP BYTEORDER	   \
704169689Skan	ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL HOST_WORDS_BIG_ENDIAN	   \
705132718Skan	OBJC_PROLOGUE ALLOCATE_TRAMPOLINE HANDLE_PRAGMA ROUND_TYPE_SIZE	   \
706132718Skan	ROUND_TYPE_SIZE_UNIT CONST_SECTION_ASM_OP CRT_GET_RFIB_TEXT	   \
707132718Skan	DBX_LBRAC_FIRST DBX_OUTPUT_ENUM DBX_OUTPUT_SOURCE_FILENAME	   \
708132718Skan	DBX_WORKING_DIRECTORY INSN_CACHE_DEPTH INSN_CACHE_SIZE		   \
709132718Skan	INSN_CACHE_LINE_WIDTH INIT_SECTION_PREAMBLE NEED_ATEXIT ON_EXIT	   \
710132718Skan	EXIT_BODY OBJECT_FORMAT_ROSE MULTIBYTE_CHARS MAP_CHARACTER	   \
711132718Skan	LIBGCC_NEEDS_DOUBLE FINAL_PRESCAN_LABEL DEFAULT_CALLER_SAVES	   \
712132718Skan	LOAD_ARGS_REVERSED MAX_INTEGER_COMPUTATION_MODE			   \
713132718Skan	CONVERT_HARD_REGISTER_TO_SSA_P ASM_OUTPUT_MAIN_SOURCE_FILENAME	   \
714132718Skan	FIRST_INSN_ADDRESS TEXT_SECTION SHARED_BSS_SECTION_ASM_OP	   \
715132718Skan	PROMOTED_MODE EXPAND_BUILTIN_VA_END				   \
716169689Skan	LINKER_DOES_NOT_WORK_WITH_DWARF2 FUNCTION_ARG_KEEP_AS_REFERENCE	   \
717169689Skan	GIV_SORT_CRITERION MAX_LONG_TYPE_SIZE MAX_LONG_DOUBLE_TYPE_SIZE	   \
718169689Skan	MAX_WCHAR_TYPE_SIZE SHARED_SECTION_ASM_OP INTEGRATE_THRESHOLD      \
719169689Skan	FINAL_REG_PARM_STACK_SPACE MAYBE_REG_PARM_STACK_SPACE		   \
720169689Skan	TRADITIONAL_PIPELINE_INTERFACE DFA_PIPELINE_INTERFACE		   \
721169689Skan	DBX_OUTPUT_STANDARD_TYPES BUILTIN_SETJMP_FRAME_VALUE		   \
722169689Skan	SUNOS4_SHARED_LIBRARIES PROMOTE_FOR_CALL_ONLY			   \
723169689Skan	SPACE_AFTER_L_OPTION NO_RECURSIVE_FUNCTION_CSE			   \
724169689Skan	DEFAULT_MAIN_RETURN TARGET_MEM_FUNCTIONS EXPAND_BUILTIN_VA_ARG	   \
725169689Skan	COLLECT_PARSE_FLAG DWARF2_GENERATE_TEXT_SECTION_LABEL WINNING_GDB  \
726169689Skan	ASM_OUTPUT_FILENAME ASM_OUTPUT_SOURCE_LINE FILE_NAME_JOINER	   \
727169689Skan	GDB_INV_REF_REGPARM_STABS_LETTER DBX_MEMPARM_STABS_LETTER	   \
728169689Skan	PUT_SDB_SRC_FILE STABS_GCC_MARKER DBX_OUTPUT_FUNCTION_END	   \
729169689Skan	DBX_OUTPUT_GCC_MARKER DBX_FINISH_SYMBOL SDB_GENERATE_FAKE	   \
730169689Skan	NON_SAVING_SETJMP TARGET_LATE_RTL_PROLOGUE_EPILOGUE		   \
731169689Skan	CASE_DROPS_THROUGH TARGET_BELL TARGET_BS TARGET_CR TARGET_DIGIT0   \
732169689Skan        TARGET_ESC TARGET_FF TARGET_NEWLINE TARGET_TAB TARGET_VT	   \
733169689Skan        LINK_LIBGCC_SPECIAL DONT_ACCESS_GBLS_AFTER_EPILOGUE		   \
734169689Skan	TARGET_OPTIONS TARGET_SWITCHES EXTRA_CC_MODES FINALIZE_PIC	   \
735169689Skan	PREDICATE_CODES SPECIAL_MODE_PREDICATES HOST_PTR_PRINTF		   \
736169689Skan	EXTRA_SECTIONS EXTRA_SECTION_FUNCTIONS READONLY_DATA_SECTION	   \
737169689Skan	TARGET_ASM_EXCEPTION_SECTION TARGET_ASM_EH_FRAME_SECTION	   \
738169689Skan	SMALL_ARG_MAX ASM_OUTPUT_SHARED_BSS ASM_OUTPUT_SHARED_COMMON	   \
739169689Skan	ASM_OUTPUT_SHARED_LOCAL UNALIGNED_WORD_ASM_OP
74090075Sobrien
741117395Skan/* Hooks that are no longer used.  */
742117395Skan #pragma GCC poison LANG_HOOKS_FUNCTION_MARK LANG_HOOKS_FUNCTION_FREE	\
743169689Skan	LANG_HOOKS_MARK_TREE LANG_HOOKS_INSERT_DEFAULT_ATTRIBUTES \
744169689Skan	LANG_HOOKS_TREE_INLINING_ESTIMATE_NUM_INSNS \
745169689Skan	LANG_HOOKS_PUSHLEVEL LANG_HOOKS_SET_BLOCK \
746169689Skan	LANG_HOOKS_MAYBE_BUILD_CLEANUP LANG_HOOKS_UPDATE_DECL_AFTER_SAVING \
747169689Skan	LANG_HOOKS_POPLEVEL LANG_HOOKS_TRUTHVALUE_CONVERSION
748117395Skan
749132718Skan/* Libiberty macros that are no longer used in GCC.  */
750132718Skan#undef ANSI_PROTOTYPES
751132718Skan#undef PTR_CONST
752132718Skan#undef LONG_DOUBLE
753132718Skan#undef VPARAMS
754132718Skan#undef VA_OPEN
755132718Skan#undef VA_FIXEDARG
756132718Skan#undef VA_CLOSE
757132718Skan#undef VA_START
758132718Skan #pragma GCC poison ANSI_PROTOTYPES PTR_CONST LONG_DOUBLE VPARAMS VA_OPEN \
759132718Skan  VA_FIXEDARG VA_CLOSE VA_START
76090075Sobrien#endif /* IN_GCC */
76190075Sobrien
76290075Sobrien/* Note: not all uses of the `index' token (e.g. variable names and
76390075Sobrien   structure members) have been eliminated.  */
76490075Sobrien#undef bcopy
76590075Sobrien#undef bzero
76690075Sobrien#undef bcmp
76790075Sobrien#undef rindex
76890075Sobrien #pragma GCC poison bcopy bzero bcmp rindex
76990075Sobrien
77090075Sobrien#endif /* GCC >= 3.0 */
77190075Sobrien
77290075Sobrien#endif /* ! GCC_SYSTEM_H */
773