OSDN Git Service

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