1*e4b17023SJohn Marino /* Get common system includes and various definitions and declarations based 2*e4b17023SJohn Marino on autoconf macros. 3*e4b17023SJohn Marino Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2009, 2010, 2011 4*e4b17023SJohn Marino Free Software Foundation, Inc. 5*e4b17023SJohn Marino 6*e4b17023SJohn Marino This file is part of GCC. 7*e4b17023SJohn Marino 8*e4b17023SJohn Marino GCC is free software; you can redistribute it and/or modify it under 9*e4b17023SJohn Marino the terms of the GNU General Public License as published by the Free 10*e4b17023SJohn Marino Software Foundation; either version 3, or (at your option) any later 11*e4b17023SJohn Marino version. 12*e4b17023SJohn Marino 13*e4b17023SJohn Marino GCC is distributed in the hope that it will be useful, but WITHOUT ANY 14*e4b17023SJohn Marino WARRANTY; without even the implied warranty of MERCHANTABILITY or 15*e4b17023SJohn Marino FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 16*e4b17023SJohn Marino for more details. 17*e4b17023SJohn Marino 18*e4b17023SJohn Marino You should have received a copy of the GNU General Public License 19*e4b17023SJohn Marino along with GCC; see the file COPYING3. If not see 20*e4b17023SJohn Marino <http://www.gnu.org/licenses/>. */ 21*e4b17023SJohn Marino 22*e4b17023SJohn Marino 23*e4b17023SJohn Marino #ifndef LIBCPP_SYSTEM_H 24*e4b17023SJohn Marino #define LIBCPP_SYSTEM_H 25*e4b17023SJohn Marino 26*e4b17023SJohn Marino /* We must include stdarg.h before stdio.h. */ 27*e4b17023SJohn Marino #include <stdarg.h> 28*e4b17023SJohn Marino 29*e4b17023SJohn Marino #ifdef HAVE_STDDEF_H 30*e4b17023SJohn Marino # include <stddef.h> 31*e4b17023SJohn Marino #endif 32*e4b17023SJohn Marino #ifdef HAVE_STDINT_H 33*e4b17023SJohn Marino # include <stdint.h> 34*e4b17023SJohn Marino #endif 35*e4b17023SJohn Marino #ifdef HAVE_INTTYPES_H 36*e4b17023SJohn Marino # include <inttypes.h> 37*e4b17023SJohn Marino #endif 38*e4b17023SJohn Marino 39*e4b17023SJohn Marino #include <stdio.h> 40*e4b17023SJohn Marino 41*e4b17023SJohn Marino /* Define a generic NULL if one hasn't already been defined. */ 42*e4b17023SJohn Marino #ifndef NULL 43*e4b17023SJohn Marino #define NULL 0 44*e4b17023SJohn Marino #endif 45*e4b17023SJohn Marino 46*e4b17023SJohn Marino /* Use the unlocked open routines from libiberty. */ 47*e4b17023SJohn Marino 48*e4b17023SJohn Marino /* Some of these are #define on some systems, e.g. on AIX to redirect 49*e4b17023SJohn Marino the names to 64bit capable functions for LARGE_FILES support. These 50*e4b17023SJohn Marino redefs are pointless here so we can override them. */ 51*e4b17023SJohn Marino 52*e4b17023SJohn Marino #undef fopen 53*e4b17023SJohn Marino #undef freopen 54*e4b17023SJohn Marino 55*e4b17023SJohn Marino #define fopen(PATH,MODE) fopen_unlocked(PATH,MODE) 56*e4b17023SJohn Marino #define fdopen(FILDES,MODE) fdopen_unlocked(FILDES,MODE) 57*e4b17023SJohn Marino #define freopen(PATH,MODE,STREAM) freopen_unlocked(PATH,MODE,STREAM) 58*e4b17023SJohn Marino 59*e4b17023SJohn Marino /* The compiler is not a multi-threaded application and therefore we 60*e4b17023SJohn Marino do not have to use the locking functions. In fact, using the locking 61*e4b17023SJohn Marino functions can cause the compiler to be significantly slower under 62*e4b17023SJohn Marino I/O bound conditions (such as -g -O0 on very large source files). 63*e4b17023SJohn Marino 64*e4b17023SJohn Marino HAVE_DECL_PUTC_UNLOCKED actually indicates whether or not the stdio 65*e4b17023SJohn Marino code is multi-thread safe by default. If it is set to 0, then do 66*e4b17023SJohn Marino not worry about using the _unlocked functions. 67*e4b17023SJohn Marino 68*e4b17023SJohn Marino fputs_unlocked, fwrite_unlocked, and fprintf_unlocked are 69*e4b17023SJohn Marino extensions and need to be prototyped by hand (since we do not 70*e4b17023SJohn Marino define _GNU_SOURCE). */ 71*e4b17023SJohn Marino 72*e4b17023SJohn Marino #if defined HAVE_DECL_PUTC_UNLOCKED && HAVE_DECL_PUTC_UNLOCKED 73*e4b17023SJohn Marino 74*e4b17023SJohn Marino # ifdef HAVE_PUTC_UNLOCKED 75*e4b17023SJohn Marino # undef putc 76*e4b17023SJohn Marino # define putc(C, Stream) putc_unlocked (C, Stream) 77*e4b17023SJohn Marino # endif 78*e4b17023SJohn Marino # ifdef HAVE_PUTCHAR_UNLOCKED 79*e4b17023SJohn Marino # undef putchar 80*e4b17023SJohn Marino # define putchar(C) putchar_unlocked (C) 81*e4b17023SJohn Marino # endif 82*e4b17023SJohn Marino # ifdef HAVE_GETC_UNLOCKED 83*e4b17023SJohn Marino # undef getc 84*e4b17023SJohn Marino # define getc(Stream) getc_unlocked (Stream) 85*e4b17023SJohn Marino # endif 86*e4b17023SJohn Marino # ifdef HAVE_GETCHAR_UNLOCKED 87*e4b17023SJohn Marino # undef getchar 88*e4b17023SJohn Marino # define getchar() getchar_unlocked () 89*e4b17023SJohn Marino # endif 90*e4b17023SJohn Marino # ifdef HAVE_FPUTC_UNLOCKED 91*e4b17023SJohn Marino # undef fputc 92*e4b17023SJohn Marino # define fputc(C, Stream) fputc_unlocked (C, Stream) 93*e4b17023SJohn Marino # endif 94*e4b17023SJohn Marino 95*e4b17023SJohn Marino #ifdef __cplusplus 96*e4b17023SJohn Marino extern "C" { 97*e4b17023SJohn Marino #endif 98*e4b17023SJohn Marino 99*e4b17023SJohn Marino # ifdef HAVE_CLEARERR_UNLOCKED 100*e4b17023SJohn Marino # undef clearerr 101*e4b17023SJohn Marino # define clearerr(Stream) clearerr_unlocked (Stream) 102*e4b17023SJohn Marino # if defined (HAVE_DECL_CLEARERR_UNLOCKED) && !HAVE_DECL_CLEARERR_UNLOCKED 103*e4b17023SJohn Marino extern void clearerr_unlocked (FILE *); 104*e4b17023SJohn Marino # endif 105*e4b17023SJohn Marino # endif 106*e4b17023SJohn Marino # ifdef HAVE_FEOF_UNLOCKED 107*e4b17023SJohn Marino # undef feof 108*e4b17023SJohn Marino # define feof(Stream) feof_unlocked (Stream) 109*e4b17023SJohn Marino # if defined (HAVE_DECL_FEOF_UNLOCKED) && !HAVE_DECL_FEOF_UNLOCKED 110*e4b17023SJohn Marino extern int feof_unlocked (FILE *); 111*e4b17023SJohn Marino # endif 112*e4b17023SJohn Marino # endif 113*e4b17023SJohn Marino # ifdef HAVE_FILENO_UNLOCKED 114*e4b17023SJohn Marino # undef fileno 115*e4b17023SJohn Marino # define fileno(Stream) fileno_unlocked (Stream) 116*e4b17023SJohn Marino # if defined (HAVE_DECL_FILENO_UNLOCKED) && !HAVE_DECL_FILENO_UNLOCKED 117*e4b17023SJohn Marino extern int fileno_unlocked (FILE *); 118*e4b17023SJohn Marino # endif 119*e4b17023SJohn Marino # endif 120*e4b17023SJohn Marino # ifdef HAVE_FFLUSH_UNLOCKED 121*e4b17023SJohn Marino # undef fflush 122*e4b17023SJohn Marino # define fflush(Stream) fflush_unlocked (Stream) 123*e4b17023SJohn Marino # if defined (HAVE_DECL_FFLUSH_UNLOCKED) && !HAVE_DECL_FFLUSH_UNLOCKED 124*e4b17023SJohn Marino extern int fflush_unlocked (FILE *); 125*e4b17023SJohn Marino # endif 126*e4b17023SJohn Marino # endif 127*e4b17023SJohn Marino # ifdef HAVE_FGETC_UNLOCKED 128*e4b17023SJohn Marino # undef fgetc 129*e4b17023SJohn Marino # define fgetc(Stream) fgetc_unlocked (Stream) 130*e4b17023SJohn Marino # if defined (HAVE_DECL_FGETC_UNLOCKED) && !HAVE_DECL_FGETC_UNLOCKED 131*e4b17023SJohn Marino extern int fgetc_unlocked (FILE *); 132*e4b17023SJohn Marino # endif 133*e4b17023SJohn Marino # endif 134*e4b17023SJohn Marino # ifdef HAVE_FGETS_UNLOCKED 135*e4b17023SJohn Marino # undef fgets 136*e4b17023SJohn Marino # define fgets(S, n, Stream) fgets_unlocked (S, n, Stream) 137*e4b17023SJohn Marino # if defined (HAVE_DECL_FGETS_UNLOCKED) && !HAVE_DECL_FGETS_UNLOCKED 138*e4b17023SJohn Marino extern char *fgets_unlocked (char *, int, FILE *); 139*e4b17023SJohn Marino # endif 140*e4b17023SJohn Marino # endif 141*e4b17023SJohn Marino # ifdef HAVE_FPUTS_UNLOCKED 142*e4b17023SJohn Marino # undef fputs 143*e4b17023SJohn Marino # define fputs(String, Stream) fputs_unlocked (String, Stream) 144*e4b17023SJohn Marino # if defined (HAVE_DECL_FPUTS_UNLOCKED) && !HAVE_DECL_FPUTS_UNLOCKED 145*e4b17023SJohn Marino extern int fputs_unlocked (const char *, FILE *); 146*e4b17023SJohn Marino # endif 147*e4b17023SJohn Marino # endif 148*e4b17023SJohn Marino # ifdef HAVE_FERROR_UNLOCKED 149*e4b17023SJohn Marino # undef ferror 150*e4b17023SJohn Marino # define ferror(Stream) ferror_unlocked (Stream) 151*e4b17023SJohn Marino # if defined (HAVE_DECL_FERROR_UNLOCKED) && !HAVE_DECL_FERROR_UNLOCKED 152*e4b17023SJohn Marino extern int ferror_unlocked (FILE *); 153*e4b17023SJohn Marino # endif 154*e4b17023SJohn Marino # endif 155*e4b17023SJohn Marino # ifdef HAVE_FREAD_UNLOCKED 156*e4b17023SJohn Marino # undef fread 157*e4b17023SJohn Marino # define fread(Ptr, Size, N, Stream) fread_unlocked (Ptr, Size, N, Stream) 158*e4b17023SJohn Marino # if defined (HAVE_DECL_FREAD_UNLOCKED) && !HAVE_DECL_FREAD_UNLOCKED 159*e4b17023SJohn Marino extern size_t fread_unlocked (void *, size_t, size_t, FILE *); 160*e4b17023SJohn Marino # endif 161*e4b17023SJohn Marino # endif 162*e4b17023SJohn Marino # ifdef HAVE_FWRITE_UNLOCKED 163*e4b17023SJohn Marino # undef fwrite 164*e4b17023SJohn Marino # define fwrite(Ptr, Size, N, Stream) fwrite_unlocked (Ptr, Size, N, Stream) 165*e4b17023SJohn Marino # if defined (HAVE_DECL_FWRITE_UNLOCKED) && !HAVE_DECL_FWRITE_UNLOCKED 166*e4b17023SJohn Marino extern size_t fwrite_unlocked (const void *, size_t, size_t, FILE *); 167*e4b17023SJohn Marino # endif 168*e4b17023SJohn Marino # endif 169*e4b17023SJohn Marino # ifdef HAVE_FPRINTF_UNLOCKED 170*e4b17023SJohn Marino # undef fprintf 171*e4b17023SJohn Marino /* We can't use a function-like macro here because we don't know if 172*e4b17023SJohn Marino we have varargs macros. */ 173*e4b17023SJohn Marino # define fprintf fprintf_unlocked 174*e4b17023SJohn Marino # if defined (HAVE_DECL_FPRINTF_UNLOCKED) && !HAVE_DECL_FPRINTF_UNLOCKED 175*e4b17023SJohn Marino extern int fprintf_unlocked (FILE *, const char *, ...); 176*e4b17023SJohn Marino # endif 177*e4b17023SJohn Marino # endif 178*e4b17023SJohn Marino 179*e4b17023SJohn Marino #ifdef __cplusplus 180*e4b17023SJohn Marino } 181*e4b17023SJohn Marino #endif 182*e4b17023SJohn Marino 183*e4b17023SJohn Marino #endif 184*e4b17023SJohn Marino 185*e4b17023SJohn Marino /* ??? Glibc's fwrite/fread_unlocked macros cause 186*e4b17023SJohn Marino "warning: signed and unsigned type in conditional expression". */ 187*e4b17023SJohn Marino #undef fread_unlocked 188*e4b17023SJohn Marino #undef fwrite_unlocked 189*e4b17023SJohn Marino 190*e4b17023SJohn Marino #include <sys/types.h> 191*e4b17023SJohn Marino #include <errno.h> 192*e4b17023SJohn Marino 193*e4b17023SJohn Marino #if !defined (errno) && defined (HAVE_DECL_ERRNO) && !HAVE_DECL_ERRNO 194*e4b17023SJohn Marino extern int errno; 195*e4b17023SJohn Marino #endif 196*e4b17023SJohn Marino 197*e4b17023SJohn Marino /* Some of glibc's string inlines cause warnings. Plus we'd rather 198*e4b17023SJohn Marino rely on (and therefore test) GCC's string builtins. */ 199*e4b17023SJohn Marino #define __NO_STRING_INLINES 200*e4b17023SJohn Marino 201*e4b17023SJohn Marino #ifdef STRING_WITH_STRINGS 202*e4b17023SJohn Marino # include <string.h> 203*e4b17023SJohn Marino # include <strings.h> 204*e4b17023SJohn Marino #else 205*e4b17023SJohn Marino # ifdef HAVE_STRING_H 206*e4b17023SJohn Marino # include <string.h> 207*e4b17023SJohn Marino # else 208*e4b17023SJohn Marino # ifdef HAVE_STRINGS_H 209*e4b17023SJohn Marino # include <strings.h> 210*e4b17023SJohn Marino # endif 211*e4b17023SJohn Marino # endif 212*e4b17023SJohn Marino #endif 213*e4b17023SJohn Marino 214*e4b17023SJohn Marino #ifdef HAVE_STDLIB_H 215*e4b17023SJohn Marino # include <stdlib.h> 216*e4b17023SJohn Marino #endif 217*e4b17023SJohn Marino 218*e4b17023SJohn Marino #ifdef HAVE_UNISTD_H 219*e4b17023SJohn Marino # include <unistd.h> 220*e4b17023SJohn Marino #endif 221*e4b17023SJohn Marino 222*e4b17023SJohn Marino #if HAVE_LIMITS_H 223*e4b17023SJohn Marino # include <limits.h> 224*e4b17023SJohn Marino #endif 225*e4b17023SJohn Marino 226*e4b17023SJohn Marino /* Infrastructure for defining missing _MAX and _MIN macros. Note that 227*e4b17023SJohn Marino macros defined with these cannot be used in #if. */ 228*e4b17023SJohn Marino 229*e4b17023SJohn Marino /* The extra casts work around common compiler bugs. */ 230*e4b17023SJohn Marino #define INTTYPE_SIGNED(t) (! ((t) 0 < (t) -1)) 231*e4b17023SJohn Marino /* The outer cast is needed to work around a bug in Cray C 5.0.3.0. 232*e4b17023SJohn Marino It is necessary at least when t == time_t. */ 233*e4b17023SJohn Marino #define INTTYPE_MINIMUM(t) ((t) (INTTYPE_SIGNED (t) \ 234*e4b17023SJohn Marino ? ~ (t) 0 << (sizeof(t) * CHAR_BIT - 1) : (t) 0)) 235*e4b17023SJohn Marino #define INTTYPE_MAXIMUM(t) ((t) (~ (t) 0 - INTTYPE_MINIMUM (t))) 236*e4b17023SJohn Marino 237*e4b17023SJohn Marino /* Use that infrastructure to provide a few constants. */ 238*e4b17023SJohn Marino #ifndef UCHAR_MAX 239*e4b17023SJohn Marino # define UCHAR_MAX INTTYPE_MAXIMUM (unsigned char) 240*e4b17023SJohn Marino #endif 241*e4b17023SJohn Marino 242*e4b17023SJohn Marino #ifdef TIME_WITH_SYS_TIME 243*e4b17023SJohn Marino # include <sys/time.h> 244*e4b17023SJohn Marino # include <time.h> 245*e4b17023SJohn Marino #else 246*e4b17023SJohn Marino # if HAVE_SYS_TIME_H 247*e4b17023SJohn Marino # include <sys/time.h> 248*e4b17023SJohn Marino # else 249*e4b17023SJohn Marino # ifdef HAVE_TIME_H 250*e4b17023SJohn Marino # include <time.h> 251*e4b17023SJohn Marino # endif 252*e4b17023SJohn Marino # endif 253*e4b17023SJohn Marino #endif 254*e4b17023SJohn Marino 255*e4b17023SJohn Marino #ifdef HAVE_FCNTL_H 256*e4b17023SJohn Marino # include <fcntl.h> 257*e4b17023SJohn Marino #else 258*e4b17023SJohn Marino # ifdef HAVE_SYS_FILE_H 259*e4b17023SJohn Marino # include <sys/file.h> 260*e4b17023SJohn Marino # endif 261*e4b17023SJohn Marino #endif 262*e4b17023SJohn Marino 263*e4b17023SJohn Marino #ifdef HAVE_LOCALE_H 264*e4b17023SJohn Marino # include <locale.h> 265*e4b17023SJohn Marino #endif 266*e4b17023SJohn Marino 267*e4b17023SJohn Marino #ifdef HAVE_LANGINFO_CODESET 268*e4b17023SJohn Marino # include <langinfo.h> 269*e4b17023SJohn Marino #endif 270*e4b17023SJohn Marino 271*e4b17023SJohn Marino #ifndef HAVE_SETLOCALE 272*e4b17023SJohn Marino # define setlocale(category, locale) (locale) 273*e4b17023SJohn Marino #endif 274*e4b17023SJohn Marino 275*e4b17023SJohn Marino #ifdef ENABLE_NLS 276*e4b17023SJohn Marino #include <libintl.h> 277*e4b17023SJohn Marino #else 278*e4b17023SJohn Marino /* Stubs. */ 279*e4b17023SJohn Marino # undef dgettext 280*e4b17023SJohn Marino # define dgettext(package, msgid) (msgid) 281*e4b17023SJohn Marino #endif 282*e4b17023SJohn Marino 283*e4b17023SJohn Marino #ifndef _ 284*e4b17023SJohn Marino # define _(msgid) dgettext (PACKAGE, msgid) 285*e4b17023SJohn Marino #endif 286*e4b17023SJohn Marino 287*e4b17023SJohn Marino #ifndef N_ 288*e4b17023SJohn Marino # define N_(msgid) msgid 289*e4b17023SJohn Marino #endif 290*e4b17023SJohn Marino 291*e4b17023SJohn Marino /* Some systems define these in, e.g., param.h. We undefine these names 292*e4b17023SJohn Marino here to avoid the warnings. We prefer to use our definitions since we 293*e4b17023SJohn Marino know they are correct. */ 294*e4b17023SJohn Marino 295*e4b17023SJohn Marino #undef MIN 296*e4b17023SJohn Marino #undef MAX 297*e4b17023SJohn Marino #define MIN(X,Y) ((X) < (Y) ? (X) : (Y)) 298*e4b17023SJohn Marino #define MAX(X,Y) ((X) > (Y) ? (X) : (Y)) 299*e4b17023SJohn Marino 300*e4b17023SJohn Marino /* The HAVE_DECL_* macros are three-state, undefined, 0 or 1. If they 301*e4b17023SJohn Marino are defined to 0 then we must provide the relevant declaration 302*e4b17023SJohn Marino here. These checks will be in the undefined state while configure 303*e4b17023SJohn Marino is running so be careful to test "defined (HAVE_DECL_*)". */ 304*e4b17023SJohn Marino 305*e4b17023SJohn Marino #ifdef __cplusplus 306*e4b17023SJohn Marino extern "C" { 307*e4b17023SJohn Marino #endif 308*e4b17023SJohn Marino 309*e4b17023SJohn Marino #if defined (HAVE_DECL_ABORT) && !HAVE_DECL_ABORT 310*e4b17023SJohn Marino extern void abort (void); 311*e4b17023SJohn Marino #endif 312*e4b17023SJohn Marino 313*e4b17023SJohn Marino #ifdef __cplusplus 314*e4b17023SJohn Marino } 315*e4b17023SJohn Marino #endif 316*e4b17023SJohn Marino 317*e4b17023SJohn Marino #if HAVE_SYS_STAT_H 318*e4b17023SJohn Marino # include <sys/stat.h> 319*e4b17023SJohn Marino #endif 320*e4b17023SJohn Marino 321*e4b17023SJohn Marino /* Test if something is a normal file. */ 322*e4b17023SJohn Marino #ifndef S_ISREG 323*e4b17023SJohn Marino #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) 324*e4b17023SJohn Marino #endif 325*e4b17023SJohn Marino 326*e4b17023SJohn Marino /* Test if something is a directory. */ 327*e4b17023SJohn Marino #ifndef S_ISDIR 328*e4b17023SJohn Marino #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) 329*e4b17023SJohn Marino #endif 330*e4b17023SJohn Marino 331*e4b17023SJohn Marino /* Test if something is a character special file. */ 332*e4b17023SJohn Marino #ifndef S_ISCHR 333*e4b17023SJohn Marino #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR) 334*e4b17023SJohn Marino #endif 335*e4b17023SJohn Marino 336*e4b17023SJohn Marino /* Test if something is a block special file. */ 337*e4b17023SJohn Marino #ifndef S_ISBLK 338*e4b17023SJohn Marino #define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK) 339*e4b17023SJohn Marino #endif 340*e4b17023SJohn Marino 341*e4b17023SJohn Marino /* Test if something is a socket. */ 342*e4b17023SJohn Marino #ifndef S_ISSOCK 343*e4b17023SJohn Marino # ifdef S_IFSOCK 344*e4b17023SJohn Marino # define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK) 345*e4b17023SJohn Marino # else 346*e4b17023SJohn Marino # define S_ISSOCK(m) 0 347*e4b17023SJohn Marino # endif 348*e4b17023SJohn Marino #endif 349*e4b17023SJohn Marino 350*e4b17023SJohn Marino /* Test if something is a FIFO. */ 351*e4b17023SJohn Marino #ifndef S_ISFIFO 352*e4b17023SJohn Marino # ifdef S_IFIFO 353*e4b17023SJohn Marino # define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO) 354*e4b17023SJohn Marino # else 355*e4b17023SJohn Marino # define S_ISFIFO(m) 0 356*e4b17023SJohn Marino # endif 357*e4b17023SJohn Marino #endif 358*e4b17023SJohn Marino 359*e4b17023SJohn Marino /* Approximate O_NOCTTY and O_BINARY. */ 360*e4b17023SJohn Marino #ifndef O_NOCTTY 361*e4b17023SJohn Marino #define O_NOCTTY 0 362*e4b17023SJohn Marino #endif 363*e4b17023SJohn Marino #ifndef O_BINARY 364*e4b17023SJohn Marino # define O_BINARY 0 365*e4b17023SJohn Marino #endif 366*e4b17023SJohn Marino 367*e4b17023SJohn Marino /* Filename handling macros. */ 368*e4b17023SJohn Marino #include "filenames.h" 369*e4b17023SJohn Marino 370*e4b17023SJohn Marino /* Get libiberty declarations. */ 371*e4b17023SJohn Marino #include "libiberty.h" 372*e4b17023SJohn Marino #include "safe-ctype.h" 373*e4b17023SJohn Marino 374*e4b17023SJohn Marino /* 1 if we have C99 designated initializers. 375*e4b17023SJohn Marino 376*e4b17023SJohn Marino ??? C99 designated initializers are not supported by most C++ 377*e4b17023SJohn Marino compilers, including G++. -- gdr, 2005-05-18 */ 378*e4b17023SJohn Marino #if !defined(HAVE_DESIGNATED_INITIALIZERS) 379*e4b17023SJohn Marino #define HAVE_DESIGNATED_INITIALIZERS \ 380*e4b17023SJohn Marino (!defined(__cplusplus) \ 381*e4b17023SJohn Marino && ((GCC_VERSION >= 2007) || (__STDC_VERSION__ >= 199901L))) 382*e4b17023SJohn Marino #endif 383*e4b17023SJohn Marino 384*e4b17023SJohn Marino #ifndef offsetof 385*e4b17023SJohn Marino #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *) 0)->MEMBER) 386*e4b17023SJohn Marino #endif 387*e4b17023SJohn Marino 388*e4b17023SJohn Marino /* __builtin_expect(A, B) evaluates to A, but notifies the compiler that 389*e4b17023SJohn Marino the most likely value of A is B. This feature was added at some point 390*e4b17023SJohn Marino between 2.95 and 3.0. Let's use 3.0 as the lower bound for now. */ 391*e4b17023SJohn Marino #if (GCC_VERSION < 3000) 392*e4b17023SJohn Marino #define __builtin_expect(a, b) (a) 393*e4b17023SJohn Marino #endif 394*e4b17023SJohn Marino 395*e4b17023SJohn Marino /* Provide a fake boolean type. We make no attempt to use the 396*e4b17023SJohn Marino C99 _Bool, as it may not be available in the bootstrap compiler, 397*e4b17023SJohn Marino and even if it is, it is liable to be buggy. 398*e4b17023SJohn Marino This must be after all inclusion of system headers, as some of 399*e4b17023SJohn Marino them will mess us up. */ 400*e4b17023SJohn Marino #undef bool 401*e4b17023SJohn Marino #undef true 402*e4b17023SJohn Marino #undef false 403*e4b17023SJohn Marino #undef TRUE 404*e4b17023SJohn Marino #undef FALSE 405*e4b17023SJohn Marino 406*e4b17023SJohn Marino #ifndef __cplusplus 407*e4b17023SJohn Marino #define bool unsigned char 408*e4b17023SJohn Marino #endif 409*e4b17023SJohn Marino #define true 1 410*e4b17023SJohn Marino #define false 0 411*e4b17023SJohn Marino 412*e4b17023SJohn Marino /* Some compilers do not allow the use of unsigned char in bitfields. */ 413*e4b17023SJohn Marino #define BOOL_BITFIELD unsigned int 414*e4b17023SJohn Marino 415*e4b17023SJohn Marino /* Poison identifiers we do not want to use. */ 416*e4b17023SJohn Marino #if (GCC_VERSION >= 3000) 417*e4b17023SJohn Marino #undef calloc 418*e4b17023SJohn Marino #undef strdup 419*e4b17023SJohn Marino #undef malloc 420*e4b17023SJohn Marino #undef realloc 421*e4b17023SJohn Marino #pragma GCC poison calloc strdup 422*e4b17023SJohn Marino #pragma GCC poison malloc realloc 423*e4b17023SJohn Marino 424*e4b17023SJohn Marino /* Libiberty macros that are no longer used in GCC. */ 425*e4b17023SJohn Marino #undef ANSI_PROTOTYPES 426*e4b17023SJohn Marino #undef PTR_CONST 427*e4b17023SJohn Marino #undef LONG_DOUBLE 428*e4b17023SJohn Marino #undef VPARAMS 429*e4b17023SJohn Marino #undef VA_OPEN 430*e4b17023SJohn Marino #undef VA_FIXEDARG 431*e4b17023SJohn Marino #undef VA_CLOSE 432*e4b17023SJohn Marino #undef VA_START 433*e4b17023SJohn Marino #pragma GCC poison ANSI_PROTOTYPES PTR_CONST LONG_DOUBLE VPARAMS VA_OPEN \ 434*e4b17023SJohn Marino VA_FIXEDARG VA_CLOSE VA_START 435*e4b17023SJohn Marino 436*e4b17023SJohn Marino /* Note: not all uses of the `index' token (e.g. variable names and 437*e4b17023SJohn Marino structure members) have been eliminated. */ 438*e4b17023SJohn Marino #undef bcopy 439*e4b17023SJohn Marino #undef bzero 440*e4b17023SJohn Marino #undef bcmp 441*e4b17023SJohn Marino #undef rindex 442*e4b17023SJohn Marino #pragma GCC poison bcopy bzero bcmp rindex 443*e4b17023SJohn Marino 444*e4b17023SJohn Marino #endif /* GCC >= 3.0 */ 445*e4b17023SJohn Marino #endif /* ! LIBCPP_SYSTEM_H */ 446