* Makefile.in (rtlanal.o): Depend on $(TM_P_H).
[official-gcc.git] / gcc / system.h
blob55a9370aca4536c013737a7dcd57cd4e692a5edd
1 /* Get common system includes and various definitions and declarations based
2 on autoconf macros.
3 Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
5 This file is part of GCC.
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
9 Software Foundation; either version 2, or (at your option) any later
10 version.
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.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA. */
23 #ifndef GCC_SYSTEM_H
24 #define GCC_SYSTEM_H
26 /* This is the location of the online document giving information how
27 to report bugs. If you change this string, also check for strings
28 not under control of the preprocessor. */
29 #define GCCBUGURL "<URL:http://www.gnu.org/software/gcc/bugs.html>"
31 /* We must include stdarg.h/varargs.h before stdio.h. */
32 #ifdef ANSI_PROTOTYPES
33 #include <stdarg.h>
34 #else
35 #include <varargs.h>
36 #endif
38 #ifndef va_copy
39 # ifdef __va_copy
40 # define va_copy(d,s) __va_copy((d),(s))
41 # else
42 # define va_copy(d,s) ((d) = (s))
43 # endif
44 #endif
46 #ifdef HAVE_STDDEF_H
47 # include <stddef.h>
48 #endif
50 #include <stdio.h>
52 /* Define a generic NULL if one hasn't already been defined. */
53 #ifndef NULL
54 #define NULL 0
55 #endif
57 /* The compiler is not a multi-threaded application and therefore we
58 do not have to use the locking functions. In fact, using the locking
59 functions can cause the compiler to be significantly slower under
60 I/O bound conditions (such as -g -O0 on very large source files).
62 HAVE_DECL_PUTC_UNLOCKED actually indicates whether or not the stdio
63 code is multi-thread safe by default. If it is set to 0, then do
64 not worry about using the _unlocked functions.
66 fputs_unlocked, fwrite_unlocked, and fprintf_unlocked are
67 extensions and need to be prototyped by hand (since we do not
68 define _GNU_SOURCE). */
70 #if defined HAVE_DECL_PUTC_UNLOCKED && HAVE_DECL_PUTC_UNLOCKED
72 # ifdef HAVE_PUTC_UNLOCKED
73 # undef putc
74 # define putc(C, Stream) putc_unlocked (C, Stream)
75 # endif
76 # ifdef HAVE_FPUTC_UNLOCKED
77 # undef fputc
78 # define fputc(C, Stream) fputc_unlocked (C, Stream)
79 # endif
81 # ifdef HAVE_FPUTS_UNLOCKED
82 # undef fputs
83 # define fputs(String, Stream) fputs_unlocked (String, Stream)
84 # if defined (HAVE_DECL_FPUTS_UNLOCKED) && !HAVE_DECL_FPUTS_UNLOCKED
85 extern int fputs_unlocked PARAMS ((const char *, FILE *));
86 # endif
87 # endif
88 # ifdef HAVE_FWRITE_UNLOCKED
89 # undef fwrite
90 # define fwrite(Ptr, Size, N, Stream) fwrite_unlocked (Ptr, Size, N, Stream)
91 # if defined (HAVE_DECL_FWRITE_UNLOCKED) && !HAVE_DECL_FWRITE_UNLOCKED
92 extern int fwrite_unlocked PARAMS ((const PTR, size_t, size_t, FILE *));
93 # endif
94 # endif
95 # ifdef HAVE_FPRINTF_UNLOCKED
96 # undef fprintf
97 /* We can't use a function-like macro here because we don't know if
98 we have varargs macros. */
99 # define fprintf fprintf_unlocked
100 # if defined (HAVE_DECL_FPRINTF_UNLOCKED) && !HAVE_DECL_FPRINTF_UNLOCKED
101 extern int fprintf_unlocked PARAMS ((FILE *, const char *, ...));
102 # endif
103 # endif
105 #endif
107 /* There are an extraordinary number of issues with <ctype.h>.
108 The last straw is that it varies with the locale. Use libiberty's
109 replacement instead. */
110 #include <safe-ctype.h>
112 #include <sys/types.h>
114 #include <errno.h>
116 #if !defined (errno) && defined (HAVE_DECL_ERRNO) && !HAVE_DECL_ERRNO
117 extern int errno;
118 #endif
120 #ifdef STRING_WITH_STRINGS
121 # include <string.h>
122 # include <strings.h>
123 #else
124 # ifdef HAVE_STRING_H
125 # include <string.h>
126 # else
127 # ifdef HAVE_STRINGS_H
128 # include <strings.h>
129 # endif
130 # endif
131 #endif
133 #ifdef HAVE_STDLIB_H
134 # include <stdlib.h>
135 #endif
137 /* If we don't have an overriding definition, set SUCCESS_EXIT_CODE and
138 FATAL_EXIT_CODE to EXIT_SUCCESS and EXIT_FAILURE respectively,
139 or 0 and 1 if those macros are not defined. */
140 #ifndef SUCCESS_EXIT_CODE
141 # ifdef EXIT_SUCCESS
142 # define SUCCESS_EXIT_CODE EXIT_SUCCESS
143 # else
144 # define SUCCESS_EXIT_CODE 0
145 # endif
146 #endif
148 #ifndef FATAL_EXIT_CODE
149 # ifdef EXIT_FAILURE
150 # define FATAL_EXIT_CODE EXIT_FAILURE
151 # else
152 # define FATAL_EXIT_CODE 1
153 # endif
154 #endif
156 #ifdef HAVE_UNISTD_H
157 # include <unistd.h>
158 #endif
160 #ifdef HAVE_SYS_PARAM_H
161 # include <sys/param.h>
162 #endif
164 #if HAVE_LIMITS_H
165 # include <limits.h>
166 #endif
168 /* Get definitions of HOST_WIDE_INT and HOST_WIDEST_INT. */
169 #include "hwint.h"
171 /* Infrastructure for defining missing _MAX and _MIN macros. Note that
172 macros defined with these cannot be used in #if. */
174 /* The extra casts work around common compiler bugs. */
175 #define INTTYPE_SIGNED(t) (! ((t) 0 < (t) -1))
176 /* The outer cast is needed to work around a bug in Cray C 5.0.3.0.
177 It is necessary at least when t == time_t. */
178 #define INTTYPE_MINIMUM(t) ((t) (INTTYPE_SIGNED (t) \
179 ? ~ (t) 0 << (sizeof(t) * CHAR_BIT - 1) : (t) 0))
180 #define INTTYPE_MAXIMUM(t) ((t) (~ (t) 0 - INTTYPE_MINIMUM (t)))
182 /* Use that infrastructure to provide a few constants. */
183 #ifndef UCHAR_MAX
184 # define UCHAR_MAX INTTYPE_MAXIMUM (unsigned char)
185 #endif
187 #ifdef TIME_WITH_SYS_TIME
188 # include <sys/time.h>
189 # include <time.h>
190 #else
191 # if HAVE_SYS_TIME_H
192 # include <sys/time.h>
193 # else
194 # ifdef HAVE_TIME_H
195 # include <time.h>
196 # endif
197 # endif
198 #endif
200 #ifdef HAVE_FCNTL_H
201 # include <fcntl.h>
202 #else
203 # ifdef HAVE_SYS_FILE_H
204 # include <sys/file.h>
205 # endif
206 #endif
208 #ifndef SEEK_SET
209 # define SEEK_SET 0
210 # define SEEK_CUR 1
211 # define SEEK_END 2
212 #endif
213 #ifndef F_OK
214 # define F_OK 0
215 # define X_OK 1
216 # define W_OK 2
217 # define R_OK 4
218 #endif
219 #ifndef O_RDONLY
220 # define O_RDONLY 0
221 #endif
222 #ifndef O_WRONLY
223 # define O_WRONLY 1
224 #endif
226 /* Some systems define these in, e.g., param.h. We undefine these names
227 here to avoid the warnings. We prefer to use our definitions since we
228 know they are correct. */
230 #undef MIN
231 #undef MAX
232 #define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
233 #define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
235 /* Returns the least number N such that N * Y >= X. */
236 #define CEIL(x,y) (((x) + (y) - 1) / (y))
238 #ifdef HAVE_SYS_WAIT_H
239 #include <sys/wait.h>
240 #endif
242 #ifndef WIFSIGNALED
243 #define WIFSIGNALED(S) (((S) & 0xff) != 0 && ((S) & 0xff) != 0x7f)
244 #endif
245 #ifndef WTERMSIG
246 #define WTERMSIG(S) ((S) & 0x7f)
247 #endif
248 #ifndef WIFEXITED
249 #define WIFEXITED(S) (((S) & 0xff) == 0)
250 #endif
251 #ifndef WEXITSTATUS
252 #define WEXITSTATUS(S) (((S) & 0xff00) >> 8)
253 #endif
254 #ifndef WSTOPSIG
255 #define WSTOPSIG WEXITSTATUS
256 #endif
258 /* The HAVE_DECL_* macros are three-state, undefined, 0 or 1. If they
259 are defined to 0 then we must provide the relevant declaration
260 here. These checks will be in the undefined state while configure
261 is running so be careful to test "defined (HAVE_DECL_*)". */
263 #if defined (HAVE_DECL_ATOF) && !HAVE_DECL_ATOF
264 extern double atof PARAMS ((const char *));
265 #endif
267 #if defined (HAVE_DECL_ATOL) && !HAVE_DECL_ATOL
268 extern long atol PARAMS ((const char *));
269 #endif
271 #if defined (HAVE_DECL_FREE) && !HAVE_DECL_FREE
272 extern void free PARAMS ((PTR));
273 #endif
275 #if defined (HAVE_DECL_GETCWD) && !HAVE_DECL_GETCWD
276 extern char *getcwd PARAMS ((char *, size_t));
277 #endif
279 #if defined (HAVE_DECL_GETENV) && !HAVE_DECL_GETENV
280 extern char *getenv PARAMS ((const char *));
281 #endif
283 #if defined (HAVE_DECL_GETOPT) && !HAVE_DECL_GETOPT
284 extern int getopt PARAMS ((int, char * const *, const char *));
285 #endif
287 #if defined (HAVE_DECL_GETWD) && !HAVE_DECL_GETWD
288 extern char *getwd PARAMS ((char *));
289 #endif
291 #if defined (HAVE_DECL_SBRK) && !HAVE_DECL_SBRK
292 extern PTR sbrk PARAMS ((int));
293 #endif
295 #if defined (HAVE_DECL_STRSTR) && !HAVE_DECL_STRSTR
296 extern char *strstr PARAMS ((const char *, const char *));
297 #endif
299 #ifdef HAVE_MALLOC_H
300 #include <malloc.h>
301 #endif
303 #if defined (HAVE_DECL_MALLOC) && !HAVE_DECL_MALLOC
304 extern PTR malloc PARAMS ((size_t));
305 #endif
307 #if defined (HAVE_DECL_CALLOC) && !HAVE_DECL_CALLOC
308 extern PTR calloc PARAMS ((size_t, size_t));
309 #endif
311 #if defined (HAVE_DECL_REALLOC) && !HAVE_DECL_REALLOC
312 extern PTR realloc PARAMS ((PTR, size_t));
313 #endif
315 /* If the system doesn't provide strsignal, we get it defined in
316 libiberty but no declaration is supplied. */
317 #ifndef HAVE_STRSIGNAL
318 # ifndef strsignal
319 extern const char *strsignal PARAMS ((int));
320 # endif
321 #endif
323 #ifdef HAVE_GETRLIMIT
324 # if defined (HAVE_DECL_GETRLIMIT) && !HAVE_DECL_GETRLIMIT
325 # ifndef getrlimit
326 # ifdef ANSI_PROTOTYPES
327 struct rlimit;
328 # endif
329 extern int getrlimit PARAMS ((int, struct rlimit *));
330 # endif
331 # endif
332 #endif
334 #ifdef HAVE_SETRLIMIT
335 # if defined (HAVE_DECL_SETRLIMIT) && !HAVE_DECL_SETRLIMIT
336 # ifndef setrlimit
337 # ifdef ANSI_PROTOTYPES
338 struct rlimit;
339 # endif
340 extern int setrlimit PARAMS ((int, const struct rlimit *));
341 # endif
342 # endif
343 #endif
345 /* HAVE_VOLATILE only refers to the stage1 compiler. We also check
346 __STDC__ and assume gcc sets it and has volatile in stage >=2. */
347 #if !defined(HAVE_VOLATILE) && !defined(__STDC__) && !defined(volatile)
348 #define volatile
349 #endif
351 #if defined (HAVE_DECL_ABORT) && !HAVE_DECL_ABORT
352 extern void abort PARAMS ((void));
353 #endif
355 /* 1 if we have C99 designated initializers. */
356 #if !defined(HAVE_DESIGNATED_INITIALIZERS)
357 #define HAVE_DESIGNATED_INITIALIZERS \
358 ((GCC_VERSION >= 2007) || (__STDC_VERSION__ >= 199901L))
359 #endif
361 /* 1 if we have _Bool. */
362 #ifndef HAVE__BOOL
363 # define HAVE__BOOL \
364 ((GCC_VERSION >= 3000) || (__STDC_VERSION__ >= 199901L))
365 #endif
368 #if HAVE_SYS_STAT_H
369 # include <sys/stat.h>
370 #endif
372 /* Test if something is a normal file. */
373 #ifndef S_ISREG
374 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
375 #endif
377 /* Test if something is a directory. */
378 #ifndef S_ISDIR
379 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
380 #endif
382 /* Test if something is a character special file. */
383 #ifndef S_ISCHR
384 #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
385 #endif
387 /* Test if something is a block special file. */
388 #ifndef S_ISBLK
389 #define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
390 #endif
392 /* Test if something is a socket. */
393 #ifndef S_ISSOCK
394 # ifdef S_IFSOCK
395 # define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
396 # else
397 # define S_ISSOCK(m) 0
398 # endif
399 #endif
401 /* Test if something is a FIFO. */
402 #ifndef S_ISFIFO
403 # ifdef S_IFIFO
404 # define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
405 # else
406 # define S_ISFIFO(m) 0
407 # endif
408 #endif
410 /* Approximate O_NONBLOCK. */
411 #ifndef O_NONBLOCK
412 #define O_NONBLOCK O_NDELAY
413 #endif
415 /* Approximate O_NOCTTY. */
416 #ifndef O_NOCTTY
417 #define O_NOCTTY 0
418 #endif
420 /* Define well known filenos if the system does not define them. */
421 #ifndef STDIN_FILENO
422 # define STDIN_FILENO 0
423 #endif
424 #ifndef STDOUT_FILENO
425 # define STDOUT_FILENO 1
426 #endif
427 #ifndef STDERR_FILENO
428 # define STDERR_FILENO 2
429 #endif
431 /* Some systems have mkdir that takes a single argument. */
432 #ifdef MKDIR_TAKES_ONE_ARG
433 # define mkdir(a,b) mkdir(a)
434 #endif
436 /* Provide a way to print an address via printf. */
437 #ifndef HOST_PTR_PRINTF
438 # ifdef HAVE_PRINTF_PTR
439 # define HOST_PTR_PRINTF "%p"
440 # else
441 # define HOST_PTR_PRINTF \
442 (sizeof (int) == sizeof (char *) ? "%x" \
443 : sizeof (long) == sizeof (char *) ? "%lx" : "%llx")
444 # endif
445 #endif /* ! HOST_PTR_PRINTF */
447 /* By default, colon separates directories in a path. */
448 #ifndef PATH_SEPARATOR
449 #define PATH_SEPARATOR ':'
450 #endif
452 #ifndef DIR_SEPARATOR
453 #define DIR_SEPARATOR '/'
454 #endif
456 /* Define IS_DIR_SEPARATOR. */
457 #ifndef DIR_SEPARATOR_2
458 # define IS_DIR_SEPARATOR(CH) ((CH) == DIR_SEPARATOR)
459 #else /* DIR_SEPARATOR_2 */
460 # define IS_DIR_SEPARATOR(CH) \
461 (((CH) == DIR_SEPARATOR) || ((CH) == DIR_SEPARATOR_2))
462 #endif /* DIR_SEPARATOR_2 */
464 /* Say how to test for an absolute pathname. On Unix systems, this is if
465 it starts with a leading slash or a '$', the latter meaning the value of
466 an environment variable is to be used. On machien with DOS-based
467 file systems, it is also absolute if it starts with a drive identifier. */
468 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
469 #define IS_ABSOLUTE_PATHNAME(STR) \
470 (IS_DIR_SEPARATOR ((STR)[0]) || (STR)[0] == '$' \
471 || ((STR)[0] != '\0' && (STR)[1] == ':' && IS_DIR_SEPARATOR ((STR)[2])))
472 #else
473 #define IS_ABSOLUTE_PATHNAME(STR) \
474 (IS_DIR_SEPARATOR ((STR)[0]) || (STR)[0] == '$')
475 #endif
477 /* Get libiberty declarations. */
478 #include "libiberty.h"
479 #include "symcat.h"
481 /* Provide a default for the HOST_BIT_BUCKET.
482 This suffices for POSIX-like hosts. */
484 #ifndef HOST_BIT_BUCKET
485 #define HOST_BIT_BUCKET "/dev/null"
486 #endif
488 /* Be conservative and only use enum bitfields with GCC.
489 FIXME: provide a complete autoconf test for buggy enum bitfields. */
491 #if (GCC_VERSION > 2000)
492 #define ENUM_BITFIELD(TYPE) enum TYPE
493 #else
494 #define ENUM_BITFIELD(TYPE) unsigned int
495 #endif
497 #ifndef offsetof
498 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
499 #endif
501 /* Traditional C cannot initialize union members of structs. Provide
502 a macro which expands appropriately to handle it. This only works
503 if you intend to initalize the union member to zero since it relies
504 on default initialization to zero in the traditional C case. */
505 #ifdef __STDC__
506 #define UNION_INIT_ZERO , {0}
507 #else
508 #define UNION_INIT_ZERO
509 #endif
511 /* Various error reporting routines want to use __FUNCTION__. */
512 #if (GCC_VERSION < 2007)
513 #ifndef __FUNCTION__
514 #define __FUNCTION__ "?"
515 #endif /* ! __FUNCTION__ */
516 #endif
518 /* __builtin_expect(A, B) evaluates to A, but notifies the compiler that
519 the most likely value of A is B. This feature was added at some point
520 between 2.95 and 3.0. Let's use 3.0 as the lower bound for now. */
521 #if (GCC_VERSION < 3000)
522 #define __builtin_expect(a, b) (a)
523 #endif
525 /* Provide some sort of boolean type. We use stdbool.h if it's
526 available. This must be after all inclusion of system headers,
527 as some of them will mess us up. */
528 #undef bool
529 #undef true
530 #undef false
531 #undef TRUE
532 #undef FALSE
534 #ifdef HAVE_STDBOOL_H
535 # include <stdbool.h>
536 #else
537 # if !HAVE__BOOL
538 typedef char _Bool;
539 # endif
540 # define bool _Bool
541 # define true 1
542 # define false 0
543 #endif
545 #define TRUE true
546 #define FALSE false
548 /* Provide three core typedefs used by everything, if we are compiling
549 GCC. These used to be found in rtl.h and tree.h, but this is no
550 longer practical. */
551 #ifdef IN_GCC
552 struct rtx_def;
553 struct rtvec_def;
554 union tree_node;
555 typedef struct rtx_def *rtx;
556 typedef struct rtvec_def *rtvec;
557 typedef union tree_node *tree;
558 #endif
560 /* As the last action in this file, we poison the identifiers that
561 shouldn't be used. Note, luckily gcc-3.0's token-based integrated
562 preprocessor won't trip on poisoned identifiers that arrive from
563 the expansion of macros. E.g. #define strrchr rindex, won't error
564 if rindex is poisoned after this directive is issued and later on
565 strrchr is called.
567 Note: We define bypass macros for the few cases where we really
568 want to use the libc memory allocation routines. Otherwise we
569 insist you use the "x" versions from libiberty. */
571 #define really_call_malloc malloc
572 #define really_call_calloc calloc
573 #define really_call_realloc realloc
575 #if (GCC_VERSION >= 3000)
577 /* Note autoconf checks for prototype declarations and includes
578 system.h while doing so. Only poison these tokens if actually
579 compiling gcc, so that the autoconf declaration tests for malloc
580 etc don't spuriously fail. */
581 #ifdef IN_GCC
582 #undef malloc
583 #undef realloc
584 #undef calloc
585 #undef strdup
586 #pragma GCC poison malloc realloc calloc strdup
588 /* Old target macros that have moved to the target hooks structure. */
589 #pragma GCC poison ASM_OPEN_PAREN ASM_CLOSE_PAREN \
590 FUNCTION_PROLOGUE FUNCTION_EPILOGUE \
591 FUNCTION_END_PROLOGUE FUNCTION_BEGIN_EPILOGUE \
592 DECL_MACHINE_ATTRIBUTES COMP_TYPE_ATTRIBUTES INSERT_ATTRIBUTES \
593 VALID_MACHINE_DECL_ATTRIBUTE VALID_MACHINE_TYPE_ATTRIBUTE \
594 SET_DEFAULT_TYPE_ATTRIBUTES SET_DEFAULT_DECL_ATTRIBUTES \
595 MERGE_MACHINE_TYPE_ATTRIBUTES MERGE_MACHINE_DECL_ATTRIBUTES \
596 MD_INIT_BUILTINS MD_EXPAND_BUILTIN
597 #endif /* IN_GCC */
599 /* Note: not all uses of the `index' token (e.g. variable names and
600 structure members) have been eliminated. */
601 #undef bcopy
602 #undef bzero
603 #undef bcmp
604 #undef rindex
605 #pragma GCC poison bcopy bzero bcmp rindex
607 #endif /* GCC >= 3.0 */
609 #endif /* ! GCC_SYSTEM_H */