OSDN Git Service

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