oops - omitted in previous delta
[official-gcc.git] / gcc / system.h
blob7938fb6bdf29efcba8446e8bf6d7205183201c48
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.
60 HAVE_DECL_PUTC_UNLOCKED actually indicates whether or not the IO
61 code is multi-thread safe by default. If it is set to 0, then do
62 not worry about using the _unlocked functions.
64 fputs_unlocked is an extension and needs to be prototyped specially. */
66 #if defined HAVE_PUTC_UNLOCKED && (defined (HAVE_DECL_PUTC_UNLOCKED) && HAVE_DECL_PUTC_UNLOCKED)
67 # undef putc
68 # define putc(C, Stream) putc_unlocked (C, Stream)
69 #endif
70 #if defined HAVE_FPUTC_UNLOCKED && (defined (HAVE_DECL_PUTC_UNLOCKED) && HAVE_DECL_PUTC_UNLOCKED)
71 # undef fputc
72 # define fputc(C, Stream) fputc_unlocked (C, Stream)
73 #endif
74 #if defined HAVE_FPUTS_UNLOCKED && (defined (HAVE_DECL_PUTC_UNLOCKED) && HAVE_DECL_PUTC_UNLOCKED)
75 # undef fputs
76 # define fputs(String, Stream) fputs_unlocked (String, Stream)
77 # if defined (HAVE_DECL_FPUTS_UNLOCKED) && !HAVE_DECL_FPUTS_UNLOCKED
78 extern int fputs_unlocked PARAMS ((const char *, FILE *));
79 # endif
80 #endif
82 /* There are an extraordinary number of issues with <ctype.h>.
83 The last straw is that it varies with the locale. Use libiberty's
84 replacement instead. */
85 #include <safe-ctype.h>
87 #include <sys/types.h>
89 #include <errno.h>
91 #if !defined (errno) && defined (HAVE_DECL_ERRNO) && !HAVE_DECL_ERRNO
92 extern int errno;
93 #endif
95 #ifdef STRING_WITH_STRINGS
96 # include <string.h>
97 # include <strings.h>
98 #else
99 # ifdef HAVE_STRING_H
100 # include <string.h>
101 # else
102 # ifdef HAVE_STRINGS_H
103 # include <strings.h>
104 # endif
105 # endif
106 #endif
108 #ifdef HAVE_STDLIB_H
109 # include <stdlib.h>
110 #endif
112 /* If we don't have an overriding definition, set SUCCESS_EXIT_CODE and
113 FATAL_EXIT_CODE to EXIT_SUCCESS and EXIT_FAILURE respectively,
114 or 0 and 1 if those macros are not defined. */
115 #ifndef SUCCESS_EXIT_CODE
116 # ifdef EXIT_SUCCESS
117 # define SUCCESS_EXIT_CODE EXIT_SUCCESS
118 # else
119 # define SUCCESS_EXIT_CODE 0
120 # endif
121 #endif
123 #ifndef FATAL_EXIT_CODE
124 # ifdef EXIT_FAILURE
125 # define FATAL_EXIT_CODE EXIT_FAILURE
126 # else
127 # define FATAL_EXIT_CODE 1
128 # endif
129 #endif
131 #ifdef HAVE_UNISTD_H
132 # include <unistd.h>
133 #endif
135 #ifdef HAVE_SYS_PARAM_H
136 # include <sys/param.h>
137 #endif
139 #if HAVE_LIMITS_H
140 # include <limits.h>
141 #endif
143 /* Get definitions of HOST_WIDE_INT and HOST_WIDEST_INT. */
144 #include "hwint.h"
146 /* Infrastructure for defining missing _MAX and _MIN macros. Note that
147 macros defined with these cannot be used in #if. */
149 /* The extra casts work around common compiler bugs. */
150 #define INTTYPE_SIGNED(t) (! ((t) 0 < (t) -1))
151 /* The outer cast is needed to work around a bug in Cray C 5.0.3.0.
152 It is necessary at least when t == time_t. */
153 #define INTTYPE_MINIMUM(t) ((t) (INTTYPE_SIGNED (t) \
154 ? ~ (t) 0 << (sizeof(t) * CHAR_BIT - 1) : (t) 0))
155 #define INTTYPE_MAXIMUM(t) ((t) (~ (t) 0 - INTTYPE_MINIMUM (t)))
157 /* Use that infrastructure to provide a few constants. */
158 #ifndef UCHAR_MAX
159 # define UCHAR_MAX INTTYPE_MAXIMUM (unsigned char)
160 #endif
162 #ifdef TIME_WITH_SYS_TIME
163 # include <sys/time.h>
164 # include <time.h>
165 #else
166 # if HAVE_SYS_TIME_H
167 # include <sys/time.h>
168 # else
169 # ifdef HAVE_TIME_H
170 # include <time.h>
171 # endif
172 # endif
173 #endif
175 #ifdef HAVE_FCNTL_H
176 # include <fcntl.h>
177 #else
178 # ifdef HAVE_SYS_FILE_H
179 # include <sys/file.h>
180 # endif
181 #endif
183 #ifndef SEEK_SET
184 # define SEEK_SET 0
185 # define SEEK_CUR 1
186 # define SEEK_END 2
187 #endif
188 #ifndef F_OK
189 # define F_OK 0
190 # define X_OK 1
191 # define W_OK 2
192 # define R_OK 4
193 #endif
194 #ifndef O_RDONLY
195 # define O_RDONLY 0
196 #endif
197 #ifndef O_WRONLY
198 # define O_WRONLY 1
199 #endif
201 /* Some systems define these in, e.g., param.h. We undefine these names
202 here to avoid the warnings. We prefer to use our definitions since we
203 know they are correct. */
205 #undef MIN
206 #undef MAX
207 #define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
208 #define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
210 /* Returns the least number N such that N * Y >= X. */
211 #define CEIL(x,y) (((x) + (y) - 1) / (y))
213 #ifdef HAVE_SYS_WAIT_H
214 #include <sys/wait.h>
215 #endif
217 #ifndef WIFSIGNALED
218 #define WIFSIGNALED(S) (((S) & 0xff) != 0 && ((S) & 0xff) != 0x7f)
219 #endif
220 #ifndef WTERMSIG
221 #define WTERMSIG(S) ((S) & 0x7f)
222 #endif
223 #ifndef WIFEXITED
224 #define WIFEXITED(S) (((S) & 0xff) == 0)
225 #endif
226 #ifndef WEXITSTATUS
227 #define WEXITSTATUS(S) (((S) & 0xff00) >> 8)
228 #endif
229 #ifndef WSTOPSIG
230 #define WSTOPSIG WEXITSTATUS
231 #endif
233 /* The HAVE_DECL_* macros are three-state, undefined, 0 or 1. If they
234 are defined to 0 then we must provide the relevant declaration
235 here. These checks will be in the undefined state while configure
236 is running so be careful to test "defined (HAVE_DECL_*)". */
238 #if defined (HAVE_DECL_ATOF) && !HAVE_DECL_ATOF
239 extern double atof PARAMS ((const char *));
240 #endif
242 #if defined (HAVE_DECL_ATOL) && !HAVE_DECL_ATOL
243 extern long atol PARAMS ((const char *));
244 #endif
246 #if defined (HAVE_DECL_FREE) && !HAVE_DECL_FREE
247 extern void free PARAMS ((PTR));
248 #endif
250 #if defined (HAVE_DECL_GETCWD) && !HAVE_DECL_GETCWD
251 extern char *getcwd PARAMS ((char *, size_t));
252 #endif
254 #if defined (HAVE_DECL_GETENV) && !HAVE_DECL_GETENV
255 extern char *getenv PARAMS ((const char *));
256 #endif
258 #if defined (HAVE_DECL_GETOPT) && !HAVE_DECL_GETOPT
259 extern int getopt PARAMS ((int, char * const *, const char *));
260 #endif
262 #if defined (HAVE_DECL_GETWD) && !HAVE_DECL_GETWD
263 extern char *getwd PARAMS ((char *));
264 #endif
266 #if defined (HAVE_DECL_SBRK) && !HAVE_DECL_SBRK
267 extern PTR sbrk PARAMS ((int));
268 #endif
270 #if defined (HAVE_DECL_STRSTR) && !HAVE_DECL_STRSTR
271 extern char *strstr PARAMS ((const char *, const char *));
272 #endif
274 #ifdef HAVE_MALLOC_H
275 #include <malloc.h>
276 #endif
278 #if defined (HAVE_DECL_MALLOC) && !HAVE_DECL_MALLOC
279 extern PTR malloc PARAMS ((size_t));
280 #endif
282 #if defined (HAVE_DECL_CALLOC) && !HAVE_DECL_CALLOC
283 extern PTR calloc PARAMS ((size_t, size_t));
284 #endif
286 #if defined (HAVE_DECL_REALLOC) && !HAVE_DECL_REALLOC
287 extern PTR realloc PARAMS ((PTR, size_t));
288 #endif
290 /* If the system doesn't provide strsignal, we get it defined in
291 libiberty but no declaration is supplied. */
292 #ifndef HAVE_STRSIGNAL
293 # ifndef strsignal
294 extern const char *strsignal PARAMS ((int));
295 # endif
296 #endif
298 #ifdef HAVE_GETRLIMIT
299 # if defined (HAVE_DECL_GETRLIMIT) && !HAVE_DECL_GETRLIMIT
300 # ifndef getrlimit
301 # ifdef ANSI_PROTOTYPES
302 struct rlimit;
303 # endif
304 extern int getrlimit PARAMS ((int, struct rlimit *));
305 # endif
306 # endif
307 #endif
309 #ifdef HAVE_SETRLIMIT
310 # if defined (HAVE_DECL_SETRLIMIT) && !HAVE_DECL_SETRLIMIT
311 # ifndef setrlimit
312 # ifdef ANSI_PROTOTYPES
313 struct rlimit;
314 # endif
315 extern int setrlimit PARAMS ((int, const struct rlimit *));
316 # endif
317 # endif
318 #endif
320 /* HAVE_VOLATILE only refers to the stage1 compiler. We also check
321 __STDC__ and assume gcc sets it and has volatile in stage >=2. */
322 #if !defined(HAVE_VOLATILE) && !defined(__STDC__) && !defined(volatile)
323 #define volatile
324 #endif
326 #if defined (HAVE_DECL_ABORT) && !HAVE_DECL_ABORT
327 extern void abort PARAMS ((void));
328 #endif
330 /* 1 if we have C99 designated initializers. */
331 #if !defined(HAVE_DESIGNATED_INITIALIZERS)
332 #define HAVE_DESIGNATED_INITIALIZERS \
333 ((GCC_VERSION >= 2007) || (__STDC_VERSION__ >= 199901L))
334 #endif
336 /* 1 if we have _Bool. */
337 #ifndef HAVE__BOOL
338 # define HAVE__BOOL \
339 ((GCC_VERSION >= 3000) || (__STDC_VERSION__ >= 199901L))
340 #endif
343 #if HAVE_SYS_STAT_H
344 # include <sys/stat.h>
345 #endif
347 /* Test if something is a normal file. */
348 #ifndef S_ISREG
349 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
350 #endif
352 /* Test if something is a directory. */
353 #ifndef S_ISDIR
354 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
355 #endif
357 /* Test if something is a character special file. */
358 #ifndef S_ISCHR
359 #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
360 #endif
362 /* Test if something is a block special file. */
363 #ifndef S_ISBLK
364 #define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
365 #endif
367 /* Test if something is a socket. */
368 #ifndef S_ISSOCK
369 # ifdef S_IFSOCK
370 # define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
371 # else
372 # define S_ISSOCK(m) 0
373 # endif
374 #endif
376 /* Test if something is a FIFO. */
377 #ifndef S_ISFIFO
378 # ifdef S_IFIFO
379 # define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
380 # else
381 # define S_ISFIFO(m) 0
382 # endif
383 #endif
385 /* Approximate O_NONBLOCK. */
386 #ifndef O_NONBLOCK
387 #define O_NONBLOCK O_NDELAY
388 #endif
390 /* Approximate O_NOCTTY. */
391 #ifndef O_NOCTTY
392 #define O_NOCTTY 0
393 #endif
395 /* Define well known filenos if the system does not define them. */
396 #ifndef STDIN_FILENO
397 # define STDIN_FILENO 0
398 #endif
399 #ifndef STDOUT_FILENO
400 # define STDOUT_FILENO 1
401 #endif
402 #ifndef STDERR_FILENO
403 # define STDERR_FILENO 2
404 #endif
406 /* Some systems have mkdir that takes a single argument. */
407 #ifdef MKDIR_TAKES_ONE_ARG
408 # define mkdir(a,b) mkdir(a)
409 #endif
411 /* Provide a way to print an address via printf. */
412 #ifndef HOST_PTR_PRINTF
413 # ifdef HAVE_PRINTF_PTR
414 # define HOST_PTR_PRINTF "%p"
415 # else
416 # define HOST_PTR_PRINTF \
417 (sizeof (int) == sizeof (char *) ? "%x" \
418 : sizeof (long) == sizeof (char *) ? "%lx" : "%llx")
419 # endif
420 #endif /* ! HOST_PTR_PRINTF */
422 /* By default, colon separates directories in a path. */
423 #ifndef PATH_SEPARATOR
424 #define PATH_SEPARATOR ':'
425 #endif
427 #ifndef DIR_SEPARATOR
428 #define DIR_SEPARATOR '/'
429 #endif
431 /* Define IS_DIR_SEPARATOR. */
432 #ifndef DIR_SEPARATOR_2
433 # define IS_DIR_SEPARATOR(CH) ((CH) == DIR_SEPARATOR)
434 #else /* DIR_SEPARATOR_2 */
435 # define IS_DIR_SEPARATOR(CH) \
436 (((CH) == DIR_SEPARATOR) || ((CH) == DIR_SEPARATOR_2))
437 #endif /* DIR_SEPARATOR_2 */
439 /* Say how to test for an absolute pathname. On Unix systems, this is if
440 it starts with a leading slash or a '$', the latter meaning the value of
441 an environment variable is to be used. On machien with DOS-based
442 file systems, it is also absolute if it starts with a drive identifier. */
443 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
444 #define IS_ABSOLUTE_PATHNAME(STR) \
445 (IS_DIR_SEPARATOR ((STR)[0]) || (STR)[0] == '$' \
446 || ((STR)[0] != '\0' && (STR)[1] == ':' && IS_DIR_SEPARATOR ((STR)[2])))
447 #else
448 #define IS_ABSOLUTE_PATHNAME(STR) \
449 (IS_DIR_SEPARATOR ((STR)[0]) || (STR)[0] == '$')
450 #endif
452 /* Get libiberty declarations. */
453 #include "libiberty.h"
454 #include "symcat.h"
456 /* Provide a default for the HOST_BIT_BUCKET.
457 This suffices for POSIX-like hosts. */
459 #ifndef HOST_BIT_BUCKET
460 #define HOST_BIT_BUCKET "/dev/null"
461 #endif
463 /* Be conservative and only use enum bitfields with GCC.
464 FIXME: provide a complete autoconf test for buggy enum bitfields. */
466 #if (GCC_VERSION > 2000)
467 #define ENUM_BITFIELD(TYPE) enum TYPE
468 #else
469 #define ENUM_BITFIELD(TYPE) unsigned int
470 #endif
472 #ifndef offsetof
473 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
474 #endif
476 /* Traditional C cannot initialize union members of structs. Provide
477 a macro which expands appropriately to handle it. This only works
478 if you intend to initalize the union member to zero since it relies
479 on default initialization to zero in the traditional C case. */
480 #ifdef __STDC__
481 #define UNION_INIT_ZERO , {0}
482 #else
483 #define UNION_INIT_ZERO
484 #endif
486 /* Various error reporting routines want to use __FUNCTION__. */
487 #if (GCC_VERSION < 2007)
488 #ifndef __FUNCTION__
489 #define __FUNCTION__ "?"
490 #endif /* ! __FUNCTION__ */
491 #endif
493 /* __builtin_expect(A, B) evaluates to A, but notifies the compiler that
494 the most likely value of A is B. This feature was added at some point
495 between 2.95 and 3.0. Let's use 3.0 as the lower bound for now. */
496 #if (GCC_VERSION < 3000)
497 #define __builtin_expect(a, b) (a)
498 #endif
500 /* Provide some sort of boolean type. We use stdbool.h if it's
501 available. This must be after all inclusion of system headers,
502 as some of them will mess us up. */
503 #undef bool
504 #undef true
505 #undef false
506 #undef TRUE
507 #undef FALSE
509 #ifdef HAVE_STDBOOL_H
510 # include <stdbool.h>
511 #else
512 # if !HAVE__BOOL
513 typedef char _Bool;
514 # endif
515 # define bool _Bool
516 # define true 1
517 # define false 0
518 #endif
520 #define TRUE true
521 #define FALSE false
523 /* Provide three core typedefs used by everything, if we are compiling
524 GCC. These used to be found in rtl.h and tree.h, but this is no
525 longer practical. */
526 #ifdef IN_GCC
527 struct rtx_def;
528 struct rtvec_def;
529 union tree_node;
530 typedef struct rtx_def *rtx;
531 typedef struct rtvec_def *rtvec;
532 typedef union tree_node *tree;
533 #endif
535 /* As the last action in this file, we poison the identifiers that
536 shouldn't be used. Note, luckily gcc-3.0's token-based integrated
537 preprocessor won't trip on poisoned identifiers that arrive from
538 the expansion of macros. E.g. #define strrchr rindex, won't error
539 if rindex is poisoned after this directive is issued and later on
540 strrchr is called.
542 Note: We define bypass macros for the few cases where we really
543 want to use the libc memory allocation routines. Otherwise we
544 insist you use the "x" versions from libiberty. */
546 #define really_call_malloc malloc
547 #define really_call_calloc calloc
548 #define really_call_realloc realloc
550 #if (GCC_VERSION >= 3000)
552 /* Note autoconf checks for prototype declarations and includes
553 system.h while doing so. Only poison these tokens if actually
554 compiling gcc, so that the autoconf declaration tests for malloc
555 etc don't spuriously fail. */
556 #ifdef IN_GCC
557 #undef malloc
558 #undef realloc
559 #undef calloc
560 #undef strdup
561 #pragma GCC poison malloc realloc calloc strdup
562 #endif /* IN_GCC */
564 /* Note: not all uses of the `index' token (e.g. variable names and
565 structure members) have been eliminated. */
566 #undef bcopy
567 #undef bzero
568 #undef bcmp
569 #undef rindex
570 #pragma GCC poison bcopy bzero bcmp rindex
572 #endif /* GCC >= 3.0 */
574 #endif /* ! GCC_SYSTEM_H */