1 /* Get common system includes and various definitions and declarations based
3 Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2009
4 Free Software Foundation, Inc.
6 This file is part of GCC.
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 3, 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 COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
23 #ifndef LIBCPP_SYSTEM_H
24 #define LIBCPP_SYSTEM_H
26 /* We must include stdarg.h before stdio.h. */
35 /* Define a generic NULL if one hasn't already been defined. */
40 /* Use the unlocked open routines from libiberty. */
41 #define fopen(PATH,MODE) fopen_unlocked(PATH,MODE)
42 #define fdopen(FILDES,MODE) fdopen_unlocked(FILDES,MODE)
43 #define freopen(PATH,MODE,STREAM) freopen_unlocked(PATH,MODE,STREAM)
45 /* The compiler is not a multi-threaded application and therefore we
46 do not have to use the locking functions. In fact, using the locking
47 functions can cause the compiler to be significantly slower under
48 I/O bound conditions (such as -g -O0 on very large source files).
50 HAVE_DECL_PUTC_UNLOCKED actually indicates whether or not the stdio
51 code is multi-thread safe by default. If it is set to 0, then do
52 not worry about using the _unlocked functions.
54 fputs_unlocked, fwrite_unlocked, and fprintf_unlocked are
55 extensions and need to be prototyped by hand (since we do not
56 define _GNU_SOURCE). */
58 #if defined HAVE_DECL_PUTC_UNLOCKED && HAVE_DECL_PUTC_UNLOCKED
60 # ifdef HAVE_PUTC_UNLOCKED
62 # define putc(C, Stream) putc_unlocked (C, Stream)
64 # ifdef HAVE_PUTCHAR_UNLOCKED
66 # define putchar(C) putchar_unlocked (C)
68 # ifdef HAVE_GETC_UNLOCKED
70 # define getc(Stream) getc_unlocked (Stream)
72 # ifdef HAVE_GETCHAR_UNLOCKED
74 # define getchar() getchar_unlocked ()
76 # ifdef HAVE_FPUTC_UNLOCKED
78 # define fputc(C, Stream) fputc_unlocked (C, Stream)
81 # ifdef HAVE_CLEARERR_UNLOCKED
83 # define clearerr(Stream) clearerr_unlocked (Stream)
84 # if defined (HAVE_DECL_CLEARERR_UNLOCKED) && !HAVE_DECL_CLEARERR_UNLOCKED
85 extern void clearerr_unlocked (FILE *);
88 # ifdef HAVE_FEOF_UNLOCKED
90 # define feof(Stream) feof_unlocked (Stream)
91 # if defined (HAVE_DECL_FEOF_UNLOCKED) && !HAVE_DECL_FEOF_UNLOCKED
92 extern int feof_unlocked (FILE *);
95 # ifdef HAVE_FILENO_UNLOCKED
97 # define fileno(Stream) fileno_unlocked (Stream)
98 # if defined (HAVE_DECL_FILENO_UNLOCKED) && !HAVE_DECL_FILENO_UNLOCKED
99 extern int fileno_unlocked (FILE *);
102 # ifdef HAVE_FFLUSH_UNLOCKED
104 # define fflush(Stream) fflush_unlocked (Stream)
105 # if defined (HAVE_DECL_FFLUSH_UNLOCKED) && !HAVE_DECL_FFLUSH_UNLOCKED
106 extern int fflush_unlocked (FILE *);
109 # ifdef HAVE_FGETC_UNLOCKED
111 # define fgetc(Stream) fgetc_unlocked (Stream)
112 # if defined (HAVE_DECL_FGETC_UNLOCKED) && !HAVE_DECL_FGETC_UNLOCKED
113 extern int fgetc_unlocked (FILE *);
116 # ifdef HAVE_FGETS_UNLOCKED
118 # define fgets(S, n, Stream) fgets_unlocked (S, n, Stream)
119 # if defined (HAVE_DECL_FGETS_UNLOCKED) && !HAVE_DECL_FGETS_UNLOCKED
120 extern char *fgets_unlocked (char *, int, FILE *);
123 # ifdef HAVE_FPUTS_UNLOCKED
125 # define fputs(String, Stream) fputs_unlocked (String, Stream)
126 # if defined (HAVE_DECL_FPUTS_UNLOCKED) && !HAVE_DECL_FPUTS_UNLOCKED
127 extern int fputs_unlocked (const char *, FILE *);
130 # ifdef HAVE_FERROR_UNLOCKED
132 # define ferror(Stream) ferror_unlocked (Stream)
133 # if defined (HAVE_DECL_FERROR_UNLOCKED) && !HAVE_DECL_FERROR_UNLOCKED
134 extern int ferror_unlocked (FILE *);
137 # ifdef HAVE_FREAD_UNLOCKED
139 # define fread(Ptr, Size, N, Stream) fread_unlocked (Ptr, Size, N, Stream)
140 # if defined (HAVE_DECL_FREAD_UNLOCKED) && !HAVE_DECL_FREAD_UNLOCKED
141 extern size_t fread_unlocked (void *, size_t, size_t, FILE *);
144 # ifdef HAVE_FWRITE_UNLOCKED
146 # define fwrite(Ptr, Size, N, Stream) fwrite_unlocked (Ptr, Size, N, Stream)
147 # if defined (HAVE_DECL_FWRITE_UNLOCKED) && !HAVE_DECL_FWRITE_UNLOCKED
148 extern size_t fwrite_unlocked (const void *, size_t, size_t, FILE *);
151 # ifdef HAVE_FPRINTF_UNLOCKED
153 /* We can't use a function-like macro here because we don't know if
154 we have varargs macros. */
155 # define fprintf fprintf_unlocked
156 # if defined (HAVE_DECL_FPRINTF_UNLOCKED) && !HAVE_DECL_FPRINTF_UNLOCKED
157 extern int fprintf_unlocked (FILE *, const char *, ...);
163 /* ??? Glibc's fwrite/fread_unlocked macros cause
164 "warning: signed and unsigned type in conditional expression". */
165 #undef fread_unlocked
166 #undef fwrite_unlocked
168 #include <sys/types.h>
171 #if !defined (errno) && defined (HAVE_DECL_ERRNO) && !HAVE_DECL_ERRNO
175 /* Some of glibc's string inlines cause warnings. Plus we'd rather
176 rely on (and therefore test) GCC's string builtins. */
177 #define __NO_STRING_INLINES
179 #ifdef STRING_WITH_STRINGS
181 # include <strings.h>
183 # ifdef HAVE_STRING_H
186 # ifdef HAVE_STRINGS_H
187 # include <strings.h>
204 /* Infrastructure for defining missing _MAX and _MIN macros. Note that
205 macros defined with these cannot be used in #if. */
207 /* The extra casts work around common compiler bugs. */
208 #define INTTYPE_SIGNED(t) (! ((t) 0 < (t) -1))
209 /* The outer cast is needed to work around a bug in Cray C 5.0.3.0.
210 It is necessary at least when t == time_t. */
211 #define INTTYPE_MINIMUM(t) ((t) (INTTYPE_SIGNED (t) \
212 ? ~ (t) 0 << (sizeof(t) * CHAR_BIT - 1) : (t) 0))
213 #define INTTYPE_MAXIMUM(t) ((t) (~ (t) 0 - INTTYPE_MINIMUM (t)))
215 /* Use that infrastructure to provide a few constants. */
217 # define UCHAR_MAX INTTYPE_MAXIMUM (unsigned char)
220 #ifdef TIME_WITH_SYS_TIME
221 # include <sys/time.h>
225 # include <sys/time.h>
236 # ifdef HAVE_SYS_FILE_H
237 # include <sys/file.h>
245 #ifdef HAVE_LANGINFO_CODESET
246 # include <langinfo.h>
249 #ifndef HAVE_SETLOCALE
250 # define setlocale(category, locale) (locale)
258 # define dgettext(package, msgid) (msgid)
262 # define _(msgid) dgettext (PACKAGE, msgid)
266 # define N_(msgid) msgid
269 /* Some systems define these in, e.g., param.h. We undefine these names
270 here to avoid the warnings. We prefer to use our definitions since we
271 know they are correct. */
275 #define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
276 #define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
278 /* The HAVE_DECL_* macros are three-state, undefined, 0 or 1. If they
279 are defined to 0 then we must provide the relevant declaration
280 here. These checks will be in the undefined state while configure
281 is running so be careful to test "defined (HAVE_DECL_*)". */
283 #if defined (HAVE_DECL_ABORT) && !HAVE_DECL_ABORT
284 extern void abort (void);
288 # include <sys/stat.h>
291 /* Test if something is a normal file. */
293 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
296 /* Test if something is a directory. */
298 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
301 /* Test if something is a character special file. */
303 #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
306 /* Test if something is a block special file. */
308 #define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
311 /* Test if something is a socket. */
314 # define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
316 # define S_ISSOCK(m) 0
320 /* Test if something is a FIFO. */
323 # define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
325 # define S_ISFIFO(m) 0
329 /* Approximate O_NOCTTY and O_BINARY. */
337 /* Filename handling macros. */
338 #include "filenames.h"
340 /* Get libiberty declarations. */
341 #include "libiberty.h"
342 #include "safe-ctype.h"
344 /* 1 if we have C99 designated initializers.
346 ??? C99 designated initializers are not supported by most C++
347 compilers, including G++. -- gdr, 2005-05-18 */
348 #if !defined(HAVE_DESIGNATED_INITIALIZERS)
349 #define HAVE_DESIGNATED_INITIALIZERS \
350 ((!defined(__cplusplus) && (GCC_VERSION >= 2007)) \
351 || (__STDC_VERSION__ >= 199901L))
354 /* Be conservative and only use enum bitfields with GCC.
355 FIXME: provide a complete autoconf test for buggy enum bitfields. */
357 #if (GCC_VERSION > 2000)
358 #define ENUM_BITFIELD(TYPE) __extension__ enum TYPE
360 #define ENUM_BITFIELD(TYPE) unsigned int
364 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *) 0)->MEMBER)
367 /* __builtin_expect(A, B) evaluates to A, but notifies the compiler that
368 the most likely value of A is B. This feature was added at some point
369 between 2.95 and 3.0. Let's use 3.0 as the lower bound for now. */
370 #if (GCC_VERSION < 3000)
371 #define __builtin_expect(a, b) (a)
374 /* Provide a fake boolean type. We make no attempt to use the
375 C99 _Bool, as it may not be available in the bootstrap compiler,
376 and even if it is, it is liable to be buggy.
377 This must be after all inclusion of system headers, as some of
378 them will mess us up. */
386 #define bool unsigned char
391 /* Some compilers do not allow the use of unsigned char in bitfields. */
392 #define BOOL_BITFIELD unsigned int
394 /* Poison identifiers we do not want to use. */
395 #if (GCC_VERSION >= 3000)
400 #pragma GCC poison calloc strdup
401 #pragma GCC poison malloc realloc
403 /* Libiberty macros that are no longer used in GCC. */
404 #undef ANSI_PROTOTYPES
412 #pragma GCC poison ANSI_PROTOTYPES PTR_CONST LONG_DOUBLE VPARAMS VA_OPEN \
413 VA_FIXEDARG VA_CLOSE VA_START
415 /* Note: not all uses of the `index' token (e.g. variable names and
416 structure members) have been eliminated. */
421 #pragma GCC poison bcopy bzero bcmp rindex
423 #endif /* GCC >= 3.0 */
424 #endif /* ! LIBCPP_SYSTEM_H */