* tree-inline.c (walk_type_fields, walk_tree,
[official-gcc.git] / libcpp / system.h
blob4f91aa521163c750bb98d0fcd63480e18880945a
1 /* Get common system includes and various definitions and declarations based
2 on autoconf macros.
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
11 version.
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
16 for more details.
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
21 02111-1307, USA. */
24 #ifndef LIBCPP_SYSTEM_H
25 #define LIBCPP_SYSTEM_H
27 /* We must include stdarg.h before stdio.h. */
28 #include <stdarg.h>
30 #ifdef HAVE_STDDEF_H
31 # include <stddef.h>
32 #endif
34 #include <stdio.h>
36 /* Define a generic NULL if one hasn't already been defined. */
37 #ifndef NULL
38 #define NULL 0
39 #endif
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
57 # undef putc
58 # define putc(C, Stream) putc_unlocked (C, Stream)
59 # endif
60 # ifdef HAVE_FPUTC_UNLOCKED
61 # undef fputc
62 # define fputc(C, Stream) fputc_unlocked (C, Stream)
63 # endif
65 # ifdef HAVE_FPUTS_UNLOCKED
66 # undef fputs
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 *);
70 # endif
71 # endif
72 # ifdef HAVE_FWRITE_UNLOCKED
73 # undef fwrite
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 *);
77 # endif
78 # endif
79 # ifdef HAVE_FPRINTF_UNLOCKED
80 # undef fprintf
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 *, ...);
86 # endif
87 # endif
89 #endif
91 /* ??? Glibc's fwrite/fread_unlocked macros cause
92 "warning: signed and unsigned type in conditional expression". */
93 #undef fread_unlocked
94 #undef fwrite_unlocked
96 #include <sys/types.h>
97 #include <errno.h>
99 #if !defined (errno) && defined (HAVE_DECL_ERRNO) && !HAVE_DECL_ERRNO
100 extern int errno;
101 #endif
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
108 # include <string.h>
109 # include <strings.h>
110 #else
111 # ifdef HAVE_STRING_H
112 # include <string.h>
113 # else
114 # ifdef HAVE_STRINGS_H
115 # include <strings.h>
116 # endif
117 # endif
118 #endif
120 #ifdef HAVE_STDLIB_H
121 # include <stdlib.h>
122 #endif
124 #ifdef HAVE_UNISTD_H
125 # include <unistd.h>
126 #endif
128 #if HAVE_LIMITS_H
129 # include <limits.h>
130 #endif
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. */
144 #ifndef UCHAR_MAX
145 # define UCHAR_MAX INTTYPE_MAXIMUM (unsigned char)
146 #endif
148 #ifdef TIME_WITH_SYS_TIME
149 # include <sys/time.h>
150 # include <time.h>
151 #else
152 # if HAVE_SYS_TIME_H
153 # include <sys/time.h>
154 # else
155 # ifdef HAVE_TIME_H
156 # include <time.h>
157 # endif
158 # endif
159 #endif
161 #ifdef HAVE_FCNTL_H
162 # include <fcntl.h>
163 #else
164 # ifdef HAVE_SYS_FILE_H
165 # include <sys/file.h>
166 # endif
167 #endif
169 #ifdef HAVE_LOCALE_H
170 # include <locale.h>
171 #endif
173 #ifdef HAVE_LANGINFO_CODESET
174 # include <langinfo.h>
175 #endif
177 #ifndef HAVE_SETLOCALE
178 # define setlocale(category, locale) (locale)
179 #endif
181 #ifdef ENABLE_NLS
182 #include <libintl.h>
183 #else
184 /* Stubs. */
185 # undef dgettext
186 # define dgettext(package, msgid) (msgid)
187 #endif
189 #ifndef _
190 # define _(msgid) dgettext (PACKAGE, msgid)
191 #endif
193 #ifndef N_
194 # define N_(msgid) msgid
195 #endif
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. */
201 #undef MIN
202 #undef MAX
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);
213 #endif
215 #if HAVE_SYS_STAT_H
216 # include <sys/stat.h>
217 #endif
219 /* Test if something is a normal file. */
220 #ifndef S_ISREG
221 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
222 #endif
224 /* Test if something is a directory. */
225 #ifndef S_ISDIR
226 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
227 #endif
229 /* Test if something is a character special file. */
230 #ifndef S_ISCHR
231 #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
232 #endif
234 /* Test if something is a block special file. */
235 #ifndef S_ISBLK
236 #define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
237 #endif
239 /* Test if something is a socket. */
240 #ifndef S_ISSOCK
241 # ifdef S_IFSOCK
242 # define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
243 # else
244 # define S_ISSOCK(m) 0
245 # endif
246 #endif
248 /* Test if something is a FIFO. */
249 #ifndef S_ISFIFO
250 # ifdef S_IFIFO
251 # define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
252 # else
253 # define S_ISFIFO(m) 0
254 # endif
255 #endif
257 /* Approximate O_NOCTTY and O_BINARY. */
258 #ifndef O_NOCTTY
259 #define O_NOCTTY 0
260 #endif
261 #ifndef O_BINARY
262 # define O_BINARY 0
263 #endif
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))
276 #endif
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
283 #else
284 #define ENUM_BITFIELD(TYPE) unsigned int
285 #endif
287 #ifndef offsetof
288 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *) 0)->MEMBER)
289 #endif
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)
296 #endif
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. */
303 #undef bool
304 #undef true
305 #undef false
306 #undef TRUE
307 #undef FALSE
309 #define bool unsigned char
310 #define true 1
311 #define false 0
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)
318 #undef calloc
319 #undef strdup
320 #undef malloc
321 #undef realloc
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
327 #undef PTR_CONST
328 #undef LONG_DOUBLE
329 #undef VPARAMS
330 #undef VA_OPEN
331 #undef VA_FIXEDARG
332 #undef VA_CLOSE
333 #undef VA_START
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. */
339 #undef bcopy
340 #undef bzero
341 #undef bcmp
342 #undef rindex
343 #pragma GCC poison bcopy bzero bcmp rindex
345 #endif /* GCC >= 3.0 */
346 #endif /* ! LIBCPP_SYSTEM_H */