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