system.h revision 90075
190075Sobrien/* Get common system includes and various definitions and declarations based
290075Sobrien   on autoconf macros.
390075Sobrien   Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
450397Sobrien
590075SobrienThis file is part of GCC.
650397Sobrien
790075SobrienGCC is free software; you can redistribute it and/or modify it under
890075Sobrienthe terms of the GNU General Public License as published by the Free
990075SobrienSoftware Foundation; either version 2, or (at your option) any later
1090075Sobrienversion.
1152284Sobrien
1290075SobrienGCC is distributed in the hope that it will be useful, but WITHOUT ANY
1390075SobrienWARRANTY; without even the implied warranty of MERCHANTABILITY or
1490075SobrienFITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1590075Sobrienfor more details.
1652284Sobrien
1752284SobrienYou should have received a copy of the GNU General Public License
1890075Sobrienalong with GCC; see the file COPYING.  If not, write to the Free
1990075SobrienSoftware Foundation, 59 Temple Place - Suite 330, Boston, MA
2090075Sobrien02111-1307, USA.  */
2152284Sobrien
2250397Sobrien
2390075Sobrien#ifndef GCC_SYSTEM_H
2490075Sobrien#define GCC_SYSTEM_H
2590075Sobrien
2657844Sobrien/* This is the location of the online document giving information how
2757844Sobrien   to report bugs. If you change this string, also check for strings
2857844Sobrien   not under control of the preprocessor.  */
2957844Sobrien#define GCCBUGURL "<URL:http://www.gnu.org/software/gcc/bugs.html>"
3057844Sobrien
3190075Sobrien/* We must include stdarg.h/varargs.h before stdio.h.  */
3252284Sobrien#ifdef ANSI_PROTOTYPES
3352284Sobrien#include <stdarg.h>
3452284Sobrien#else
3552284Sobrien#include <varargs.h>
3652284Sobrien#endif
3752284Sobrien
3890075Sobrien#ifndef va_copy
3990075Sobrien# ifdef __va_copy
4090075Sobrien#   define va_copy(d,s)  __va_copy((d),(s))
4190075Sobrien# else
4290075Sobrien#   define va_copy(d,s)  ((d) = (s))
4390075Sobrien# endif
4490075Sobrien#endif
4590075Sobrien
4690075Sobrien#ifdef HAVE_STDDEF_H
4790075Sobrien# include <stddef.h>
4890075Sobrien#endif
4990075Sobrien
5050397Sobrien#include <stdio.h>
5150397Sobrien
5250397Sobrien/* Define a generic NULL if one hasn't already been defined.  */
5350397Sobrien#ifndef NULL
5450397Sobrien#define NULL 0
5550397Sobrien#endif
5650397Sobrien
5752284Sobrien/* The compiler is not a multi-threaded application and therefore we
5890075Sobrien   do not have to use the locking functions.  In fact, using the locking
5990075Sobrien   functions can cause the compiler to be significantly slower under
6090075Sobrien   I/O bound conditions (such as -g -O0 on very large source files).
6152284Sobrien
6290075Sobrien   HAVE_DECL_PUTC_UNLOCKED actually indicates whether or not the stdio
6390075Sobrien   code is multi-thread safe by default.  If it is set to 0, then do
6490075Sobrien   not worry about using the _unlocked functions.
6552284Sobrien
6690075Sobrien   fputs_unlocked, fwrite_unlocked, and fprintf_unlocked are
6790075Sobrien   extensions and need to be prototyped by hand (since we do not
6890075Sobrien   define _GNU_SOURCE).  */
6952284Sobrien
7090075Sobrien#if defined HAVE_DECL_PUTC_UNLOCKED && HAVE_DECL_PUTC_UNLOCKED
7190075Sobrien
7290075Sobrien# ifdef HAVE_PUTC_UNLOCKED
7390075Sobrien#  undef putc
7490075Sobrien#  define putc(C, Stream) putc_unlocked (C, Stream)
7552284Sobrien# endif
7690075Sobrien# ifdef HAVE_FPUTC_UNLOCKED
7790075Sobrien#  undef fputc
7890075Sobrien#  define fputc(C, Stream) fputc_unlocked (C, Stream)
7990075Sobrien# endif
8052284Sobrien
8190075Sobrien# ifdef HAVE_FPUTS_UNLOCKED
8290075Sobrien#  undef fputs
8390075Sobrien#  define fputs(String, Stream) fputs_unlocked (String, Stream)
8490075Sobrien#  if defined (HAVE_DECL_FPUTS_UNLOCKED) && !HAVE_DECL_FPUTS_UNLOCKED
8590075Sobrienextern int fputs_unlocked PARAMS ((const char *, FILE *));
8690075Sobrien#  endif
8790075Sobrien# endif
8890075Sobrien# ifdef HAVE_FWRITE_UNLOCKED
8990075Sobrien#  undef fwrite
9090075Sobrien#  define fwrite(Ptr, Size, N, Stream) fwrite_unlocked (Ptr, Size, N, Stream)
9190075Sobrien#  if defined (HAVE_DECL_FWRITE_UNLOCKED) && !HAVE_DECL_FWRITE_UNLOCKED
9290075Sobrienextern int fwrite_unlocked PARAMS ((const PTR, size_t, size_t, FILE *));
9390075Sobrien#  endif
9490075Sobrien# endif
9590075Sobrien# ifdef HAVE_FPRINTF_UNLOCKED
9690075Sobrien#  undef fprintf
9790075Sobrien/* We can't use a function-like macro here because we don't know if
9890075Sobrien   we have varargs macros.  */
9990075Sobrien#  define fprintf fprintf_unlocked
10090075Sobrien#  if defined (HAVE_DECL_FPRINTF_UNLOCKED) && !HAVE_DECL_FPRINTF_UNLOCKED
10190075Sobrienextern int fprintf_unlocked PARAMS ((FILE *, const char *, ...));
10290075Sobrien#  endif
10390075Sobrien# endif
10450397Sobrien
10550397Sobrien#endif
10650397Sobrien
10790075Sobrien/* There are an extraordinary number of issues with <ctype.h>.
10890075Sobrien   The last straw is that it varies with the locale.  Use libiberty's
10990075Sobrien   replacement instead.  */
11090075Sobrien#include <safe-ctype.h>
11150397Sobrien
11290075Sobrien#include <sys/types.h>
11350397Sobrien
11450397Sobrien#include <errno.h>
11550397Sobrien
11690075Sobrien#if !defined (errno) && defined (HAVE_DECL_ERRNO) && !HAVE_DECL_ERRNO
11750397Sobrienextern int errno;
11850397Sobrien#endif
11950397Sobrien
12052284Sobrien#ifdef STRING_WITH_STRINGS
12150397Sobrien# include <string.h>
12252284Sobrien# include <strings.h>
12350397Sobrien#else
12452284Sobrien# ifdef HAVE_STRING_H
12552284Sobrien#  include <string.h>
12652284Sobrien# else
12752284Sobrien#  ifdef HAVE_STRINGS_H
12852284Sobrien#   include <strings.h>
12952284Sobrien#  endif
13050397Sobrien# endif
13150397Sobrien#endif
13250397Sobrien
13350397Sobrien#ifdef HAVE_STDLIB_H
13450397Sobrien# include <stdlib.h>
13550397Sobrien#endif
13650397Sobrien
13790075Sobrien/* If we don't have an overriding definition, set SUCCESS_EXIT_CODE and
13890075Sobrien   FATAL_EXIT_CODE to EXIT_SUCCESS and EXIT_FAILURE respectively,
13990075Sobrien   or 0 and 1 if those macros are not defined.  */
14090075Sobrien#ifndef SUCCESS_EXIT_CODE
14190075Sobrien# ifdef EXIT_SUCCESS
14290075Sobrien#  define SUCCESS_EXIT_CODE EXIT_SUCCESS
14390075Sobrien# else
14490075Sobrien#  define SUCCESS_EXIT_CODE 0
14590075Sobrien# endif
14690075Sobrien#endif
14790075Sobrien
14890075Sobrien#ifndef FATAL_EXIT_CODE
14990075Sobrien# ifdef EXIT_FAILURE
15090075Sobrien#  define FATAL_EXIT_CODE EXIT_FAILURE
15190075Sobrien# else
15290075Sobrien#  define FATAL_EXIT_CODE 1
15390075Sobrien# endif
15490075Sobrien#endif
15590075Sobrien
15650397Sobrien#ifdef HAVE_UNISTD_H
15750397Sobrien# include <unistd.h>
15850397Sobrien#endif
15950397Sobrien
16050397Sobrien#ifdef HAVE_SYS_PARAM_H
16150397Sobrien# include <sys/param.h>
16290075Sobrien/* We use this identifier later and it appears in some vendor param.h's.  */
16390075Sobrien# undef PREFETCH
16450397Sobrien#endif
16550397Sobrien
16650397Sobrien#if HAVE_LIMITS_H
16750397Sobrien# include <limits.h>
16850397Sobrien#endif
16950397Sobrien
17090075Sobrien/* Get definitions of HOST_WIDE_INT and HOST_WIDEST_INT.  */
17190075Sobrien#include "hwint.h"
17252284Sobrien
17390075Sobrien/* A macro to determine whether a VALUE lies inclusively within a
17490075Sobrien   certain range without evaluating the VALUE more than once.  This
17590075Sobrien   macro won't warn if the VALUE is unsigned and the LOWER bound is
17690075Sobrien   zero, as it would e.g. with "VALUE >= 0 && ...".  Note the LOWER
17790075Sobrien   bound *is* evaluated twice, and LOWER must not be greater than
17890075Sobrien   UPPER.  However the bounds themselves can be either positive or
17990075Sobrien   negative.  */
18090075Sobrien#define IN_RANGE(VALUE, LOWER, UPPER) \
18190075Sobrien  ((unsigned HOST_WIDE_INT) ((VALUE) - (LOWER)) <= ((UPPER) - (LOWER)))
18252284Sobrien
18390075Sobrien/* Infrastructure for defining missing _MAX and _MIN macros.  Note that
18490075Sobrien   macros defined with these cannot be used in #if.  */
18590075Sobrien
18690075Sobrien/* The extra casts work around common compiler bugs.  */
18790075Sobrien#define INTTYPE_SIGNED(t) (! ((t) 0 < (t) -1))
18890075Sobrien/* The outer cast is needed to work around a bug in Cray C 5.0.3.0.
18990075Sobrien   It is necessary at least when t == time_t.  */
19090075Sobrien#define INTTYPE_MINIMUM(t) ((t) (INTTYPE_SIGNED (t) \
19190075Sobrien                             ? ~ (t) 0 << (sizeof(t) * CHAR_BIT - 1) : (t) 0))
19290075Sobrien#define INTTYPE_MAXIMUM(t) ((t) (~ (t) 0 - INTTYPE_MINIMUM (t)))
19390075Sobrien
19490075Sobrien/* Use that infrastructure to provide a few constants.  */
19590075Sobrien#ifndef UCHAR_MAX
19690075Sobrien# define UCHAR_MAX INTTYPE_MAXIMUM (unsigned char)
19790075Sobrien#endif
19890075Sobrien
19950397Sobrien#ifdef TIME_WITH_SYS_TIME
20050397Sobrien# include <sys/time.h>
20150397Sobrien# include <time.h>
20250397Sobrien#else
20350397Sobrien# if HAVE_SYS_TIME_H
20450397Sobrien#  include <sys/time.h>
20550397Sobrien# else
20650397Sobrien#  ifdef HAVE_TIME_H
20750397Sobrien#   include <time.h>
20850397Sobrien#  endif
20950397Sobrien# endif
21050397Sobrien#endif
21150397Sobrien
21250397Sobrien#ifdef HAVE_FCNTL_H
21350397Sobrien# include <fcntl.h>
21450397Sobrien#else
21550397Sobrien# ifdef HAVE_SYS_FILE_H
21650397Sobrien#  include <sys/file.h>
21750397Sobrien# endif
21850397Sobrien#endif
21950397Sobrien
22050397Sobrien#ifndef SEEK_SET
22150397Sobrien# define SEEK_SET 0
22250397Sobrien# define SEEK_CUR 1
22350397Sobrien# define SEEK_END 2
22450397Sobrien#endif
22550397Sobrien#ifndef F_OK
22650397Sobrien# define F_OK 0
22750397Sobrien# define X_OK 1
22850397Sobrien# define W_OK 2
22950397Sobrien# define R_OK 4
23050397Sobrien#endif
23150397Sobrien#ifndef O_RDONLY
23250397Sobrien# define O_RDONLY 0
23350397Sobrien#endif
23450397Sobrien#ifndef O_WRONLY
23550397Sobrien# define O_WRONLY 1
23650397Sobrien#endif
23750397Sobrien
23852284Sobrien/* Some systems define these in, e.g., param.h.  We undefine these names
23952284Sobrien   here to avoid the warnings.  We prefer to use our definitions since we
24052284Sobrien   know they are correct.  */
24150397Sobrien
24252284Sobrien#undef MIN
24352284Sobrien#undef MAX
24452284Sobrien#define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
24552284Sobrien#define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
24650397Sobrien
24790075Sobrien/* Returns the least number N such that N * Y >= X.  */
24890075Sobrien#define CEIL(x,y) (((x) + (y) - 1) / (y))
24990075Sobrien
25052284Sobrien#ifdef HAVE_SYS_WAIT_H
25152284Sobrien#include <sys/wait.h>
25252284Sobrien#endif
25352284Sobrien
25452284Sobrien#ifndef WIFSIGNALED
25552284Sobrien#define WIFSIGNALED(S) (((S) & 0xff) != 0 && ((S) & 0xff) != 0x7f)
25652284Sobrien#endif
25752284Sobrien#ifndef WTERMSIG
25852284Sobrien#define WTERMSIG(S) ((S) & 0x7f)
25952284Sobrien#endif
26052284Sobrien#ifndef WIFEXITED
26152284Sobrien#define WIFEXITED(S) (((S) & 0xff) == 0)
26252284Sobrien#endif
26352284Sobrien#ifndef WEXITSTATUS
26452284Sobrien#define WEXITSTATUS(S) (((S) & 0xff00) >> 8)
26552284Sobrien#endif
26652284Sobrien#ifndef WSTOPSIG
26752284Sobrien#define WSTOPSIG WEXITSTATUS
26852284Sobrien#endif
26952284Sobrien
27090075Sobrien/* The HAVE_DECL_* macros are three-state, undefined, 0 or 1.  If they
27190075Sobrien   are defined to 0 then we must provide the relevant declaration
27290075Sobrien   here.  These checks will be in the undefined state while configure
27390075Sobrien   is running so be careful to test "defined (HAVE_DECL_*)".  */
27452284Sobrien
27590075Sobrien#if defined (HAVE_DECL_ATOF) && !HAVE_DECL_ATOF
27690075Sobrienextern double atof PARAMS ((const char *));
27750397Sobrien#endif
27850397Sobrien
27990075Sobrien#if defined (HAVE_DECL_ATOL) && !HAVE_DECL_ATOL
28090075Sobrienextern long atol PARAMS ((const char *));
28150397Sobrien#endif
28250397Sobrien
28390075Sobrien#if defined (HAVE_DECL_FREE) && !HAVE_DECL_FREE
28490075Sobrienextern void free PARAMS ((PTR));
28550397Sobrien#endif
28650397Sobrien
28790075Sobrien#if defined (HAVE_DECL_GETCWD) && !HAVE_DECL_GETCWD
28890075Sobrienextern char *getcwd PARAMS ((char *, size_t));
28950397Sobrien#endif
29050397Sobrien
29190075Sobrien#if defined (HAVE_DECL_GETENV) && !HAVE_DECL_GETENV
29290075Sobrienextern char *getenv PARAMS ((const char *));
29350397Sobrien#endif
29450397Sobrien
29590075Sobrien#if defined (HAVE_DECL_GETOPT) && !HAVE_DECL_GETOPT
29690075Sobrienextern int getopt PARAMS ((int, char * const *, const char *));
29750397Sobrien#endif
29850397Sobrien
29990075Sobrien#if defined (HAVE_DECL_GETWD) && !HAVE_DECL_GETWD
30090075Sobrienextern char *getwd PARAMS ((char *));
30150397Sobrien#endif
30250397Sobrien
30390075Sobrien#if defined (HAVE_DECL_SBRK) && !HAVE_DECL_SBRK
30490075Sobrienextern PTR sbrk PARAMS ((int));
30550397Sobrien#endif
30650397Sobrien
30790075Sobrien#if defined (HAVE_DECL_STRSTR) && !HAVE_DECL_STRSTR
30890075Sobrienextern char *strstr PARAMS ((const char *, const char *));
30950397Sobrien#endif
31050397Sobrien
31190075Sobrien#ifdef HAVE_MALLOC_H
31290075Sobrien#include <malloc.h>
31350397Sobrien#endif
31450397Sobrien
31590075Sobrien#if defined (HAVE_DECL_MALLOC) && !HAVE_DECL_MALLOC
31690075Sobrienextern PTR malloc PARAMS ((size_t));
31750397Sobrien#endif
31850397Sobrien
31990075Sobrien#if defined (HAVE_DECL_CALLOC) && !HAVE_DECL_CALLOC
32090075Sobrienextern PTR calloc PARAMS ((size_t, size_t));
32150397Sobrien#endif
32250397Sobrien
32390075Sobrien#if defined (HAVE_DECL_REALLOC) && !HAVE_DECL_REALLOC
32490075Sobrienextern PTR realloc PARAMS ((PTR, size_t));
32552284Sobrien#endif
32652284Sobrien
32790075Sobrien/* If the system doesn't provide strsignal, we get it defined in
32890075Sobrien   libiberty but no declaration is supplied.  */
32990075Sobrien#ifndef HAVE_STRSIGNAL
33090075Sobrien# ifndef strsignal
33190075Sobrienextern const char *strsignal PARAMS ((int));
33250397Sobrien# endif
33390075Sobrien#endif
33450397Sobrien
33550397Sobrien#ifdef HAVE_GETRLIMIT
33690075Sobrien# if defined (HAVE_DECL_GETRLIMIT) && !HAVE_DECL_GETRLIMIT
33750397Sobrien#  ifndef getrlimit
33890075Sobrien#   ifdef ANSI_PROTOTYPES
33990075Sobrienstruct rlimit;
34090075Sobrien#   endif
34190075Sobrienextern int getrlimit PARAMS ((int, struct rlimit *));
34250397Sobrien#  endif
34350397Sobrien# endif
34450397Sobrien#endif
34550397Sobrien
34650397Sobrien#ifdef HAVE_SETRLIMIT
34790075Sobrien# if defined (HAVE_DECL_SETRLIMIT) && !HAVE_DECL_SETRLIMIT
34850397Sobrien#  ifndef setrlimit
34990075Sobrien#   ifdef ANSI_PROTOTYPES
35090075Sobrienstruct rlimit;
35190075Sobrien#   endif
35290075Sobrienextern int setrlimit PARAMS ((int, const struct rlimit *));
35350397Sobrien#  endif
35450397Sobrien# endif
35550397Sobrien#endif
35650397Sobrien
35750397Sobrien/* HAVE_VOLATILE only refers to the stage1 compiler.  We also check
35890075Sobrien   __STDC__ and assume gcc sets it and has volatile in stage >=2.  */
35950397Sobrien#if !defined(HAVE_VOLATILE) && !defined(__STDC__) && !defined(volatile)
36050397Sobrien#define volatile
36150397Sobrien#endif
36250397Sobrien
36390075Sobrien#if defined (HAVE_DECL_ABORT) && !HAVE_DECL_ABORT
36490075Sobrienextern void abort PARAMS ((void));
36552284Sobrien#endif
36650397Sobrien
36790075Sobrien/* 1 if we have C99 designated initializers.  */
36890075Sobrien#if !defined(HAVE_DESIGNATED_INITIALIZERS)
36990075Sobrien#define HAVE_DESIGNATED_INITIALIZERS \
37090075Sobrien  ((GCC_VERSION >= 2007) || (__STDC_VERSION__ >= 199901L))
37190075Sobrien#endif
37250397Sobrien
37390075Sobrien/* 1 if we have _Bool.  */
37490075Sobrien#ifndef HAVE__BOOL
37590075Sobrien# define HAVE__BOOL \
37690075Sobrien   ((GCC_VERSION >= 3000) || (__STDC_VERSION__ >= 199901L))
37790075Sobrien#endif
37850397Sobrien
37950397Sobrien
38052284Sobrien#if HAVE_SYS_STAT_H
38152284Sobrien# include <sys/stat.h>
38252284Sobrien#endif
38350397Sobrien
38452284Sobrien/* Test if something is a normal file.  */
38552284Sobrien#ifndef S_ISREG
38652284Sobrien#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
38752284Sobrien#endif
38850397Sobrien
38952284Sobrien/* Test if something is a directory.  */
39052284Sobrien#ifndef S_ISDIR
39152284Sobrien#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
39252284Sobrien#endif
39352284Sobrien
39452284Sobrien/* Test if something is a character special file.  */
39552284Sobrien#ifndef S_ISCHR
39652284Sobrien#define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
39752284Sobrien#endif
39852284Sobrien
39990075Sobrien/* Test if something is a block special file.  */
40090075Sobrien#ifndef S_ISBLK
40190075Sobrien#define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
40290075Sobrien#endif
40390075Sobrien
40452284Sobrien/* Test if something is a socket.  */
40552284Sobrien#ifndef S_ISSOCK
40652284Sobrien# ifdef S_IFSOCK
40752284Sobrien#   define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
40852284Sobrien# else
40952284Sobrien#   define S_ISSOCK(m) 0
41052284Sobrien# endif
41152284Sobrien#endif
41252284Sobrien
41352284Sobrien/* Test if something is a FIFO.  */
41452284Sobrien#ifndef S_ISFIFO
41552284Sobrien# ifdef S_IFIFO
41652284Sobrien#  define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
41752284Sobrien# else
41852284Sobrien#  define S_ISFIFO(m) 0
41952284Sobrien# endif
42052284Sobrien#endif
42152284Sobrien
42252284Sobrien/* Approximate O_NONBLOCK.  */
42352284Sobrien#ifndef O_NONBLOCK
42452284Sobrien#define O_NONBLOCK O_NDELAY
42552284Sobrien#endif
42652284Sobrien
42752284Sobrien/* Approximate O_NOCTTY.  */
42852284Sobrien#ifndef O_NOCTTY
42952284Sobrien#define O_NOCTTY 0
43052284Sobrien#endif
43152284Sobrien
43252284Sobrien/* Define well known filenos if the system does not define them.  */
43352284Sobrien#ifndef STDIN_FILENO
43452284Sobrien# define STDIN_FILENO   0
43552284Sobrien#endif
43652284Sobrien#ifndef STDOUT_FILENO
43752284Sobrien# define STDOUT_FILENO  1
43852284Sobrien#endif
43952284Sobrien#ifndef STDERR_FILENO
44052284Sobrien# define STDERR_FILENO  2
44152284Sobrien#endif
44252284Sobrien
44390075Sobrien/* Some systems have mkdir that takes a single argument.  */
44452284Sobrien#ifdef MKDIR_TAKES_ONE_ARG
44552284Sobrien# define mkdir(a,b) mkdir(a)
44652284Sobrien#endif
44752284Sobrien
44890075Sobrien/* Provide a way to print an address via printf.  */
44990075Sobrien#ifndef HOST_PTR_PRINTF
45090075Sobrien# ifdef HAVE_PRINTF_PTR
45190075Sobrien#  define HOST_PTR_PRINTF "%p"
45290075Sobrien# else
45390075Sobrien#  define HOST_PTR_PRINTF \
45490075Sobrien    (sizeof (int) == sizeof (char *) ? "%x" \
45590075Sobrien     : sizeof (long) == sizeof (char *) ? "%lx" : "%llx")
45690075Sobrien# endif
45790075Sobrien#endif /* ! HOST_PTR_PRINTF */
45890075Sobrien
45990075Sobrien/* By default, colon separates directories in a path.  */
46090075Sobrien#ifndef PATH_SEPARATOR
46190075Sobrien#define PATH_SEPARATOR ':'
46290075Sobrien#endif
46390075Sobrien
46490075Sobrien#ifndef DIR_SEPARATOR
46590075Sobrien#define DIR_SEPARATOR '/'
46690075Sobrien#endif
46790075Sobrien
46890075Sobrien/* Define IS_DIR_SEPARATOR.  */
46990075Sobrien#ifndef DIR_SEPARATOR_2
47090075Sobrien# define IS_DIR_SEPARATOR(CH) ((CH) == DIR_SEPARATOR)
47190075Sobrien#else /* DIR_SEPARATOR_2 */
47290075Sobrien# define IS_DIR_SEPARATOR(CH) \
47390075Sobrien	(((CH) == DIR_SEPARATOR) || ((CH) == DIR_SEPARATOR_2))
47490075Sobrien#endif /* DIR_SEPARATOR_2 */
47590075Sobrien
47690075Sobrien/* Say how to test for an absolute pathname.  On Unix systems, this is if
47790075Sobrien   it starts with a leading slash or a '$', the latter meaning the value of
47890075Sobrien   an environment variable is to be used.  On machien with DOS-based
47990075Sobrien   file systems, it is also absolute if it starts with a drive identifier.  */
48090075Sobrien#ifdef HAVE_DOS_BASED_FILE_SYSTEM
48190075Sobrien#define IS_ABSOLUTE_PATHNAME(STR) \
48290075Sobrien  (IS_DIR_SEPARATOR ((STR)[0]) || (STR)[0] == '$' \
48390075Sobrien   || ((STR)[0] != '\0' && (STR)[1] == ':' && IS_DIR_SEPARATOR ((STR)[2])))
48490075Sobrien#else
48590075Sobrien#define IS_ABSOLUTE_PATHNAME(STR) \
48690075Sobrien  (IS_DIR_SEPARATOR ((STR)[0]) || (STR)[0] == '$')
48790075Sobrien#endif
48890075Sobrien
48990075Sobrien/* Get libiberty declarations.  */
49052284Sobrien#include "libiberty.h"
49190075Sobrien#include "symcat.h"
49252284Sobrien
49390075Sobrien/* Provide a default for the HOST_BIT_BUCKET.
49490075Sobrien   This suffices for POSIX-like hosts.  */
49590075Sobrien
49690075Sobrien#ifndef HOST_BIT_BUCKET
49790075Sobrien#define HOST_BIT_BUCKET "/dev/null"
49890075Sobrien#endif
49990075Sobrien
50090075Sobrien/* Be conservative and only use enum bitfields with GCC.
50190075Sobrien   FIXME: provide a complete autoconf test for buggy enum bitfields.  */
50290075Sobrien
50390075Sobrien#if (GCC_VERSION > 2000)
50490075Sobrien#define ENUM_BITFIELD(TYPE) enum TYPE
50590075Sobrien#else
50690075Sobrien#define ENUM_BITFIELD(TYPE) unsigned int
50790075Sobrien#endif
50890075Sobrien
50990075Sobrien#ifndef offsetof
51090075Sobrien#define offsetof(TYPE, MEMBER)	((size_t) &((TYPE *) 0)->MEMBER)
51190075Sobrien#endif
51290075Sobrien
51390075Sobrien/* Traditional C cannot initialize union members of structs.  Provide
51490075Sobrien   a macro which expands appropriately to handle it.  This only works
51590075Sobrien   if you intend to initialize the union member to zero since it relies
51690075Sobrien   on default initialization to zero in the traditional C case.  */
51790075Sobrien#ifdef __STDC__
51890075Sobrien#define UNION_INIT_ZERO , {0}
51990075Sobrien#else
52090075Sobrien#define UNION_INIT_ZERO
52190075Sobrien#endif
52290075Sobrien
52390075Sobrien/* Various error reporting routines want to use __FUNCTION__.  */
52490075Sobrien#if (GCC_VERSION < 2007)
52590075Sobrien#ifndef __FUNCTION__
52690075Sobrien#define __FUNCTION__ "?"
52790075Sobrien#endif /* ! __FUNCTION__ */
52890075Sobrien#endif
52990075Sobrien
53090075Sobrien/* __builtin_expect(A, B) evaluates to A, but notifies the compiler that
53190075Sobrien   the most likely value of A is B.  This feature was added at some point
53290075Sobrien   between 2.95 and 3.0.  Let's use 3.0 as the lower bound for now.  */
53390075Sobrien#if (GCC_VERSION < 3000)
53490075Sobrien#define __builtin_expect(a, b) (a)
53590075Sobrien#endif
53690075Sobrien
53790075Sobrien/* Provide some sort of boolean type.  We use stdbool.h if it's
53890075Sobrien  available.  This must be after all inclusion of system headers,
53990075Sobrien  as some of them will mess us up.  */
54090075Sobrien#undef bool
54190075Sobrien#undef true
54290075Sobrien#undef false
54390075Sobrien#undef TRUE
54490075Sobrien#undef FALSE
54590075Sobrien
54690075Sobrien#ifdef HAVE_STDBOOL_H
54790075Sobrien# include <stdbool.h>
54890075Sobrien#else
54990075Sobrien# if !HAVE__BOOL
55090075Sobrientypedef char _Bool;
55190075Sobrien# endif
55290075Sobrien# define bool _Bool
55390075Sobrien# define true 1
55490075Sobrien# define false 0
55590075Sobrien#endif
55690075Sobrien
55790075Sobrien#define TRUE true
55890075Sobrien#define FALSE false
55990075Sobrien
56090075Sobrien/* As the last action in this file, we poison the identifiers that
56190075Sobrien   shouldn't be used.  Note, luckily gcc-3.0's token-based integrated
56290075Sobrien   preprocessor won't trip on poisoned identifiers that arrive from
56390075Sobrien   the expansion of macros.  E.g. #define strrchr rindex, won't error
56490075Sobrien   if rindex is poisoned after this directive is issued and later on
56590075Sobrien   strrchr is called.
56690075Sobrien
56790075Sobrien   Note: We define bypass macros for the few cases where we really
56890075Sobrien   want to use the libc memory allocation routines.  Otherwise we
56990075Sobrien   insist you use the "x" versions from libiberty.  */
57090075Sobrien
57190075Sobrien#define really_call_malloc malloc
57290075Sobrien#define really_call_calloc calloc
57390075Sobrien#define really_call_realloc realloc
57490075Sobrien
57590075Sobrien#if (GCC_VERSION >= 3000)
57690075Sobrien
57790075Sobrien/* Note autoconf checks for prototype declarations and includes
57890075Sobrien   system.h while doing so.  Only poison these tokens if actually
57990075Sobrien   compiling gcc, so that the autoconf declaration tests for malloc
58090075Sobrien   etc don't spuriously fail.  */
58190075Sobrien#ifdef IN_GCC
58290075Sobrien#undef malloc
58390075Sobrien#undef realloc
58490075Sobrien#undef calloc
58590075Sobrien#undef strdup
58690075Sobrien #pragma GCC poison malloc realloc calloc strdup
58790075Sobrien
58890075Sobrien/* Old target macros that have moved to the target hooks structure.  */
58990075Sobrien #pragma GCC poison ASM_OPEN_PAREN ASM_CLOSE_PAREN			\
59090075Sobrien	FUNCTION_PROLOGUE FUNCTION_EPILOGUE				\
59190075Sobrien	FUNCTION_END_PROLOGUE FUNCTION_BEGIN_EPILOGUE			\
59290075Sobrien	DECL_MACHINE_ATTRIBUTES COMP_TYPE_ATTRIBUTES INSERT_ATTRIBUTES	\
59390075Sobrien	VALID_MACHINE_DECL_ATTRIBUTE VALID_MACHINE_TYPE_ATTRIBUTE	\
59490075Sobrien	SET_DEFAULT_TYPE_ATTRIBUTES SET_DEFAULT_DECL_ATTRIBUTES		\
59590075Sobrien	MERGE_MACHINE_TYPE_ATTRIBUTES MERGE_MACHINE_DECL_ATTRIBUTES	\
59690075Sobrien	MD_INIT_BUILTINS MD_EXPAND_BUILTIN ASM_OUTPUT_CONSTRUCTOR	\
59790075Sobrien	ASM_OUTPUT_DESTRUCTOR
59890075Sobrien
59990075Sobrien/* And other obsolete target macros, or macros that used to be in target
60090075Sobrien   headers and were not used, and may be obsolete or may never have
60190075Sobrien   been used.  */
60290075Sobrien #pragma GCC poison INT_ASM_OP ASM_OUTPUT_EH_REGION_BEG			   \
60390075Sobrien	ASM_OUTPUT_EH_REGION_END ASM_OUTPUT_LABELREF_AS_INT		   \
60490075Sobrien	DOESNT_NEED_UNWINDER EH_TABLE_LOOKUP OBJC_SELECTORS_WITHOUT_LABELS \
60590075Sobrien	OMIT_EH_TABLE EASY_DIV_EXPR IMPLICIT_FIX_EXPR			   \
60690075Sobrien	LONGJMP_RESTORE_FROM_STACK MAX_INT_TYPE_SIZE ASM_IDENTIFY_GCC	   \
60790075Sobrien	STDC_VALUE TRAMPOLINE_ALIGN ASM_IDENTIFY_GCC_AFTER_SOURCE	   \
60890075Sobrien	SLOW_ZERO_EXTEND SUBREG_REGNO_OFFSET
60990075Sobrien
61090075Sobrien#endif /* IN_GCC */
61190075Sobrien
61290075Sobrien/* Note: not all uses of the `index' token (e.g. variable names and
61390075Sobrien   structure members) have been eliminated.  */
61490075Sobrien#undef bcopy
61590075Sobrien#undef bzero
61690075Sobrien#undef bcmp
61790075Sobrien#undef rindex
61890075Sobrien #pragma GCC poison bcopy bzero bcmp rindex
61990075Sobrien
62090075Sobrien#endif /* GCC >= 3.0 */
62190075Sobrien
62290075Sobrien#endif /* ! GCC_SYSTEM_H */
623