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