OSDN Git Service

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