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, 59 Temple Place - Suite 330, 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 /* The compiler is not a multi-threaded application and therefore we
42 do not have to use the locking functions. In fact, using the locking
43 functions can cause the compiler to be significantly slower under
44 I/O bound conditions (such as -g -O0 on very large source files).
46 HAVE_DECL_PUTC_UNLOCKED actually indicates whether or not the stdio
47 code is multi-thread safe by default. If it is set to 0, then do
48 not worry about using the _unlocked functions.
50 fputs_unlocked, fwrite_unlocked, and fprintf_unlocked are
51 extensions and need to be prototyped by hand (since we do not
52 define _GNU_SOURCE). */
54 #if defined HAVE_DECL_PUTC_UNLOCKED && HAVE_DECL_PUTC_UNLOCKED
56 # ifdef HAVE_PUTC_UNLOCKED
58 # define putc(C, Stream) putc_unlocked (C, Stream)
60 # ifdef HAVE_FPUTC_UNLOCKED
62 # define fputc(C, Stream) fputc_unlocked (C, Stream)
65 # ifdef HAVE_FPUTS_UNLOCKED
67 # define fputs(String, Stream) fputs_unlocked (String, Stream)
68 # if defined (HAVE_DECL_FPUTS_UNLOCKED) && !HAVE_DECL_FPUTS_UNLOCKED
69 extern int fputs_unlocked (const char *, FILE *);
72 # ifdef HAVE_FWRITE_UNLOCKED
74 # define fwrite(Ptr, Size, N, Stream) fwrite_unlocked (Ptr, Size, N, Stream)
75 # if defined (HAVE_DECL_FWRITE_UNLOCKED) && !HAVE_DECL_FWRITE_UNLOCKED
76 extern int fwrite_unlocked (const void *, size_t, size_t, FILE *);
79 # ifdef HAVE_FPRINTF_UNLOCKED
81 /* We can't use a function-like macro here because we don't know if
82 we have varargs macros. */
83 # define fprintf fprintf_unlocked
84 # if defined (HAVE_DECL_FPRINTF_UNLOCKED) && !HAVE_DECL_FPRINTF_UNLOCKED
85 extern int fprintf_unlocked (FILE *, const char *, ...);
91 /* ??? Glibc's fwrite/fread_unlocked macros cause
92 "warning: signed and unsigned type in conditional expression". */
94 #undef fwrite_unlocked
96 #include <sys/types.h>
99 #if !defined (errno) && defined (HAVE_DECL_ERRNO) && !HAVE_DECL_ERRNO
103 /* Some of glibc's string inlines cause warnings. Plus we'd rather
104 rely on (and therefore test) GCC's string builtins. */
105 #define __NO_STRING_INLINES
107 #ifdef STRING_WITH_STRINGS
109 # include <strings.h>
111 # ifdef HAVE_STRING_H
114 # ifdef HAVE_STRINGS_H
115 # include <strings.h>
132 /* Infrastructure for defining missing _MAX and _MIN macros. Note that
133 macros defined with these cannot be used in #if. */
135 /* The extra casts work around common compiler bugs. */
136 #define INTTYPE_SIGNED(t) (! ((t) 0 < (t) -1))
137 /* The outer cast is needed to work around a bug in Cray C 5.0.3.0.
138 It is necessary at least when t == time_t. */
139 #define INTTYPE_MINIMUM(t) ((t) (INTTYPE_SIGNED (t) \
140 ? ~ (t) 0 << (sizeof(t) * CHAR_BIT - 1) : (t) 0))
141 #define INTTYPE_MAXIMUM(t) ((t) (~ (t) 0 - INTTYPE_MINIMUM (t)))
143 /* Use that infrastructure to provide a few constants. */
145 # define UCHAR_MAX INTTYPE_MAXIMUM (unsigned char)
148 #ifdef TIME_WITH_SYS_TIME
149 # include <sys/time.h>
153 # include <sys/time.h>
164 # ifdef HAVE_SYS_FILE_H
165 # include <sys/file.h>
173 #ifdef HAVE_LANGINFO_CODESET
174 # include <langinfo.h>
177 #ifndef HAVE_SETLOCALE
178 # define setlocale(category, locale) (locale)
186 # define dgettext(package, msgid) (msgid)
190 # define _(msgid) dgettext (PACKAGE, msgid)
194 # define N_(msgid) msgid
197 /* Some systems define these in, e.g., param.h. We undefine these names
198 here to avoid the warnings. We prefer to use our definitions since we
199 know they are correct. */
203 #define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
204 #define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
206 /* The HAVE_DECL_* macros are three-state, undefined, 0 or 1. If they
207 are defined to 0 then we must provide the relevant declaration
208 here. These checks will be in the undefined state while configure
209 is running so be careful to test "defined (HAVE_DECL_*)". */
211 #if defined (HAVE_DECL_ABORT) && !HAVE_DECL_ABORT
212 extern void abort (void);
216 # include <sys/stat.h>
219 /* Test if something is a normal file. */
221 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
224 /* Test if something is a directory. */
226 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
229 /* Test if something is a character special file. */
231 #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
234 /* Test if something is a block special file. */
236 #define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
239 /* Test if something is a socket. */
242 # define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
244 # define S_ISSOCK(m) 0
248 /* Test if something is a FIFO. */
251 # define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
253 # define S_ISFIFO(m) 0
257 /* Approximate O_NOCTTY and O_BINARY. */
265 /* Filename handling macros. */
266 #include "filenames.h"
268 /* Get libiberty declarations. */
269 #include "libiberty.h"
270 #include "safe-ctype.h"
272 /* 1 if we have C99 designated initializers. */
273 #if !defined(HAVE_DESIGNATED_INITIALIZERS)
274 #define HAVE_DESIGNATED_INITIALIZERS \
275 ((GCC_VERSION >= 2007) || (__STDC_VERSION__ >= 199901L))
278 /* Be conservative and only use enum bitfields with GCC.
279 FIXME: provide a complete autoconf test for buggy enum bitfields. */
281 #if (GCC_VERSION > 2000)
282 #define ENUM_BITFIELD(TYPE) __extension__ enum TYPE
284 #define ENUM_BITFIELD(TYPE) unsigned int
288 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *) 0)->MEMBER)
291 /* __builtin_expect(A, B) evaluates to A, but notifies the compiler that
292 the most likely value of A is B. This feature was added at some point
293 between 2.95 and 3.0. Let's use 3.0 as the lower bound for now. */
294 #if (GCC_VERSION < 3000)
295 #define __builtin_expect(a, b) (a)
298 /* Provide a fake boolean type. We make no attempt to use the
299 C99 _Bool, as it may not be available in the bootstrap compiler,
300 and even if it is, it is liable to be buggy.
301 This must be after all inclusion of system headers, as some of
302 them will mess us up. */
309 #define bool unsigned char
313 /* Some compilers do not allow the use of unsigned char in bitfields. */
314 #define BOOL_BITFIELD unsigned int
316 /* Poison identifiers we do not want to use. */
317 #if (GCC_VERSION >= 3000)
322 #pragma GCC poison calloc strdup
323 #pragma GCC poison malloc realloc
325 /* Libiberty macros that are no longer used in GCC. */
326 #undef ANSI_PROTOTYPES
334 #pragma GCC poison ANSI_PROTOTYPES PTR_CONST LONG_DOUBLE VPARAMS VA_OPEN \
335 VA_FIXEDARG VA_CLOSE VA_START
337 /* Note: not all uses of the `index' token (e.g. variable names and
338 structure members) have been eliminated. */
343 #pragma GCC poison bcopy bzero bcmp rindex
345 #endif /* GCC >= 3.0 */
346 #endif /* ! LIBCPP_SYSTEM_H */