1 /* Get common system includes and various definitions and declarations based
3 Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004
4 Free Software Foundation, Inc.
6 This file is part of libcpp (aka cpplib).
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to the Free
20 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
24 #ifndef LIBCPP_SYSTEM_H
25 #define LIBCPP_SYSTEM_H
27 /* We must include stdarg.h before stdio.h. */
36 /* Define a generic NULL if one hasn't already been defined. */
41 /* Use the unlocked open routines from libiberty. */
42 #define fopen(PATH,MODE) fopen_unlocked(PATH,MODE)
43 #define fdopen(FILDES,MODE) fdopen_unlocked(FILDES,MODE)
44 #define freopen(PATH,MODE,STREAM) freopen_unlocked(PATH,MODE,STREAM)
46 /* The compiler is not a multi-threaded application and therefore we
47 do not have to use the locking functions. In fact, using the locking
48 functions can cause the compiler to be significantly slower under
49 I/O bound conditions (such as -g -O0 on very large source files).
51 HAVE_DECL_PUTC_UNLOCKED actually indicates whether or not the stdio
52 code is multi-thread safe by default. If it is set to 0, then do
53 not worry about using the _unlocked functions.
55 fputs_unlocked, fwrite_unlocked, and fprintf_unlocked are
56 extensions and need to be prototyped by hand (since we do not
57 define _GNU_SOURCE). */
59 #if defined HAVE_DECL_PUTC_UNLOCKED && HAVE_DECL_PUTC_UNLOCKED
61 # ifdef HAVE_PUTC_UNLOCKED
63 # define putc(C, Stream) putc_unlocked (C, Stream)
65 # ifdef HAVE_PUTCHAR_UNLOCKED
67 # define putchar(C) putchar_unlocked (C)
69 # ifdef HAVE_GETC_UNLOCKED
71 # define getc(Stream) getc_unlocked (Stream)
73 # ifdef HAVE_GETCHAR_UNLOCKED
75 # define getchar() getchar_unlocked ()
77 # ifdef HAVE_FPUTC_UNLOCKED
79 # define fputc(C, Stream) fputc_unlocked (C, Stream)
82 # ifdef HAVE_CLEARERR_UNLOCKED
84 # define clearerr(Stream) clearerr_unlocked (Stream)
85 # if defined (HAVE_DECL_CLEARERR_UNLOCKED) && !HAVE_DECL_CLEARERR_UNLOCKED
86 extern void clearerr_unlocked (FILE *);
89 # ifdef HAVE_FEOF_UNLOCKED
91 # define feof(Stream) feof_unlocked (Stream)
92 # if defined (HAVE_DECL_FEOF_UNLOCKED) && !HAVE_DECL_FEOF_UNLOCKED
93 extern int feof_unlocked (FILE *);
96 # ifdef HAVE_FILENO_UNLOCKED
98 # define fileno(Stream) fileno_unlocked (Stream)
99 # if defined (HAVE_DECL_FILENO_UNLOCKED) && !HAVE_DECL_FILENO_UNLOCKED
100 extern int fileno_unlocked (FILE *);
103 # ifdef HAVE_FFLUSH_UNLOCKED
105 # define fflush(Stream) fflush_unlocked (Stream)
106 # if defined (HAVE_DECL_FFLUSH_UNLOCKED) && !HAVE_DECL_FFLUSH_UNLOCKED
107 extern int fflush_unlocked (FILE *);
110 # ifdef HAVE_FGETC_UNLOCKED
112 # define fgetc(Stream) fgetc_unlocked (Stream)
113 # if defined (HAVE_DECL_FGETC_UNLOCKED) && !HAVE_DECL_FGETC_UNLOCKED
114 extern int fgetc_unlocked (FILE *);
117 # ifdef HAVE_FGETS_UNLOCKED
119 # define fgets(S, n, Stream) fgets_unlocked (S, n, Stream)
120 # if defined (HAVE_DECL_FGETS_UNLOCKED) && !HAVE_DECL_FGETS_UNLOCKED
121 extern char *fgets_unlocked (char *, int, FILE *);
124 # ifdef HAVE_FPUTS_UNLOCKED
126 # define fputs(String, Stream) fputs_unlocked (String, Stream)
127 # if defined (HAVE_DECL_FPUTS_UNLOCKED) && !HAVE_DECL_FPUTS_UNLOCKED
128 extern int fputs_unlocked (const char *, FILE *);
131 # ifdef HAVE_FERROR_UNLOCKED
133 # define ferror(Stream) ferror_unlocked (Stream)
134 # if defined (HAVE_DECL_FERROR_UNLOCKED) && !HAVE_DECL_FERROR_UNLOCKED
135 extern int ferror_unlocked (FILE *);
138 # ifdef HAVE_FREAD_UNLOCKED
140 # define fread(Ptr, Size, N, Stream) fread_unlocked (Ptr, Size, N, Stream)
141 # if defined (HAVE_DECL_FREAD_UNLOCKED) && !HAVE_DECL_FREAD_UNLOCKED
142 extern size_t fread_unlocked (void *, size_t, size_t, FILE *);
145 # ifdef HAVE_FWRITE_UNLOCKED
147 # define fwrite(Ptr, Size, N, Stream) fwrite_unlocked (Ptr, Size, N, Stream)
148 # if defined (HAVE_DECL_FWRITE_UNLOCKED) && !HAVE_DECL_FWRITE_UNLOCKED
149 extern size_t fwrite_unlocked (const void *, size_t, size_t, FILE *);
152 # ifdef HAVE_FPRINTF_UNLOCKED
154 /* We can't use a function-like macro here because we don't know if
155 we have varargs macros. */
156 # define fprintf fprintf_unlocked
157 # if defined (HAVE_DECL_FPRINTF_UNLOCKED) && !HAVE_DECL_FPRINTF_UNLOCKED
158 extern int fprintf_unlocked (FILE *, const char *, ...);
164 /* ??? Glibc's fwrite/fread_unlocked macros cause
165 "warning: signed and unsigned type in conditional expression". */
166 #undef fread_unlocked
167 #undef fwrite_unlocked
169 #include <sys/types.h>
172 #if !defined (errno) && defined (HAVE_DECL_ERRNO) && !HAVE_DECL_ERRNO
176 /* Some of glibc's string inlines cause warnings. Plus we'd rather
177 rely on (and therefore test) GCC's string builtins. */
178 #define __NO_STRING_INLINES
180 #ifdef STRING_WITH_STRINGS
182 # include <strings.h>
184 # ifdef HAVE_STRING_H
187 # ifdef HAVE_STRINGS_H
188 # include <strings.h>
205 /* Infrastructure for defining missing _MAX and _MIN macros. Note that
206 macros defined with these cannot be used in #if. */
208 /* The extra casts work around common compiler bugs. */
209 #define INTTYPE_SIGNED(t) (! ((t) 0 < (t) -1))
210 /* The outer cast is needed to work around a bug in Cray C 5.0.3.0.
211 It is necessary at least when t == time_t. */
212 #define INTTYPE_MINIMUM(t) ((t) (INTTYPE_SIGNED (t) \
213 ? ~ (t) 0 << (sizeof(t) * CHAR_BIT - 1) : (t) 0))
214 #define INTTYPE_MAXIMUM(t) ((t) (~ (t) 0 - INTTYPE_MINIMUM (t)))
216 /* Use that infrastructure to provide a few constants. */
218 # define UCHAR_MAX INTTYPE_MAXIMUM (unsigned char)
221 #ifdef TIME_WITH_SYS_TIME
222 # include <sys/time.h>
226 # include <sys/time.h>
237 # ifdef HAVE_SYS_FILE_H
238 # include <sys/file.h>
246 #ifdef HAVE_LANGINFO_CODESET
247 # include <langinfo.h>
250 #ifndef HAVE_SETLOCALE
251 # define setlocale(category, locale) (locale)
259 # define dgettext(package, msgid) (msgid)
263 # define _(msgid) dgettext (PACKAGE, msgid)
267 # define N_(msgid) msgid
270 /* Some systems define these in, e.g., param.h. We undefine these names
271 here to avoid the warnings. We prefer to use our definitions since we
272 know they are correct. */
276 #define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
277 #define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
279 /* The HAVE_DECL_* macros are three-state, undefined, 0 or 1. If they
280 are defined to 0 then we must provide the relevant declaration
281 here. These checks will be in the undefined state while configure
282 is running so be careful to test "defined (HAVE_DECL_*)". */
284 #if defined (HAVE_DECL_ABORT) && !HAVE_DECL_ABORT
285 extern void abort (void);
289 # include <sys/stat.h>
292 /* Test if something is a normal file. */
294 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
297 /* Test if something is a directory. */
299 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
302 /* Test if something is a character special file. */
304 #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
307 /* Test if something is a block special file. */
309 #define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
312 /* Test if something is a socket. */
315 # define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
317 # define S_ISSOCK(m) 0
321 /* Test if something is a FIFO. */
324 # define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
326 # define S_ISFIFO(m) 0
330 /* Approximate O_NOCTTY and O_BINARY. */
338 /* Filename handling macros. */
339 #include "filenames.h"
341 /* Get libiberty declarations. */
342 #include "libiberty.h"
343 #include "safe-ctype.h"
345 /* 1 if we have C99 designated initializers.
347 ??? C99 designated initializers are not supported by most C++
348 compilers, including G++. -- gdr, 2005-05-18 */
349 #if !defined(HAVE_DESIGNATED_INITIALIZERS)
350 #define HAVE_DESIGNATED_INITIALIZERS \
351 ((!defined(__cplusplus) && (GCC_VERSION >= 2007)) \
352 || (__STDC_VERSION__ >= 199901L))
355 /* Be conservative and only use enum bitfields with GCC.
356 FIXME: provide a complete autoconf test for buggy enum bitfields. */
358 #if (GCC_VERSION > 2000)
359 #define ENUM_BITFIELD(TYPE) __extension__ enum TYPE
361 #define ENUM_BITFIELD(TYPE) unsigned int
365 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *) 0)->MEMBER)
368 /* __builtin_expect(A, B) evaluates to A, but notifies the compiler that
369 the most likely value of A is B. This feature was added at some point
370 between 2.95 and 3.0. Let's use 3.0 as the lower bound for now. */
371 #if (GCC_VERSION < 3000)
372 #define __builtin_expect(a, b) (a)
375 /* Provide a fake boolean type. We make no attempt to use the
376 C99 _Bool, as it may not be available in the bootstrap compiler,
377 and even if it is, it is liable to be buggy.
378 This must be after all inclusion of system headers, as some of
379 them will mess us up. */
387 #define bool unsigned char
392 /* Some compilers do not allow the use of unsigned char in bitfields. */
393 #define BOOL_BITFIELD unsigned int
395 /* Poison identifiers we do not want to use. */
396 #if (GCC_VERSION >= 3000)
401 #pragma GCC poison calloc strdup
402 #pragma GCC poison malloc realloc
404 /* Libiberty macros that are no longer used in GCC. */
405 #undef ANSI_PROTOTYPES
413 #pragma GCC poison ANSI_PROTOTYPES PTR_CONST LONG_DOUBLE VPARAMS VA_OPEN \
414 VA_FIXEDARG VA_CLOSE VA_START
416 /* Note: not all uses of the `index' token (e.g. variable names and
417 structure members) have been eliminated. */
422 #pragma GCC poison bcopy bzero bcmp rindex
424 #endif /* GCC >= 3.0 */
425 #endif /* ! LIBCPP_SYSTEM_H */