]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/system.h
expr.c (ffeexpr_sym_rhs_dimlist_): Allow array elements as bounds of adjustable arrays.
[thirdparty/gcc.git] / gcc / system.h
CommitLineData
c5c76735
JL
1/* Get common system includes and various definitions and declarations based
2 on autoconf macros.
d6edb99e 3 Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
aca69483 4
1322177d 5This file is part of GCC.
1b0c6de6 6
1322177d
LB
7GCC is free software; you can redistribute it and/or modify it under
8the terms of the GNU General Public License as published by the Free
9Software Foundation; either version 2, or (at your option) any later
10version.
1b0c6de6 11
1322177d
LB
12GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or
14FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15for more details.
1b0c6de6
JL
16
17You should have received a copy of the GNU General Public License
1322177d
LB
18along with GCC; see the file COPYING. If not, write to the Free
19Software Foundation, 59 Temple Place - Suite 330, Boston, MA
2002111-1307, USA. */
aca69483 21
c5c76735 22
88657302
RH
23#ifndef GCC_SYSTEM_H
24#define GCC_SYSTEM_H
aca69483 25
8b97e23b
ML
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>"
30
789f983a 31/* We must include stdarg.h/varargs.h before stdio.h. */
5148a72b 32#ifdef ANSI_PROTOTYPES
789f983a
KG
33#include <stdarg.h>
34#else
35#include <varargs.h>
36#endif
37
6f81b1ad
RH
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
45
d6edb99e
ZW
46#ifdef HAVE_STDDEF_H
47# include <stddef.h>
48#endif
49
aca69483 50#include <stdio.h>
51db713f
KG
51
52/* Define a generic NULL if one hasn't already been defined. */
53#ifndef NULL
54#define NULL 0
55#endif
56
54953b66 57/* The compiler is not a multi-threaded application and therefore we
9c30c0e7
ZW
58 do not have to use the locking functions.
59
f31e826b
KG
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.
9c30c0e7
ZW
63
64 fputs_unlocked is an extension and needs to be prototyped specially. */
65
f31e826b 66#if defined HAVE_PUTC_UNLOCKED && (defined (HAVE_DECL_PUTC_UNLOCKED) && HAVE_DECL_PUTC_UNLOCKED)
54953b66
UD
67# undef putc
68# define putc(C, Stream) putc_unlocked (C, Stream)
69#endif
f31e826b 70#if defined HAVE_FPUTC_UNLOCKED && (defined (HAVE_DECL_PUTC_UNLOCKED) && HAVE_DECL_PUTC_UNLOCKED)
54953b66
UD
71# undef fputc
72# define fputc(C, Stream) fputc_unlocked (C, Stream)
73#endif
f31e826b 74#if defined HAVE_FPUTS_UNLOCKED && (defined (HAVE_DECL_PUTC_UNLOCKED) && HAVE_DECL_PUTC_UNLOCKED)
54953b66
UD
75# undef fputs
76# define fputs(String, Stream) fputs_unlocked (String, Stream)
f31e826b 77# if defined (HAVE_DECL_FPUTS_UNLOCKED) && !HAVE_DECL_FPUTS_UNLOCKED
cdadb1dd 78extern int fputs_unlocked PARAMS ((const char *, FILE *));
9c30c0e7 79# endif
54953b66
UD
80#endif
81
f6bbde28
ZW
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>
aca69483 86
aca69483 87#include <sys/types.h>
c5c76735 88
aca69483
KG
89#include <errno.h>
90
6c889b67 91#if !defined (errno) && defined (HAVE_DECL_ERRNO) && !HAVE_DECL_ERRNO
aca69483
KG
92extern int errno;
93#endif
94
ccc7d11a 95#ifdef STRING_WITH_STRINGS
aca69483 96# include <string.h>
ccc7d11a 97# include <strings.h>
aca69483 98#else
ccc7d11a
KG
99# ifdef HAVE_STRING_H
100# include <string.h>
101# else
102# ifdef HAVE_STRINGS_H
103# include <strings.h>
104# endif
aca69483
KG
105# endif
106#endif
107
108#ifdef HAVE_STDLIB_H
109# include <stdlib.h>
110#endif
111
eaf4e618
ZW
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
122
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
130
aca69483
KG
131#ifdef HAVE_UNISTD_H
132# include <unistd.h>
133#endif
134
135#ifdef HAVE_SYS_PARAM_H
136# include <sys/param.h>
137#endif
138
139#if HAVE_LIMITS_H
140# include <limits.h>
141#endif
142
75e93faa
ZW
143/* Get definitions of HOST_WIDE_INT and HOST_WIDEST_INT. */
144#include "hwint.h"
f80d6fd7 145
f12bc141
ZW
146/* Infrastructure for defining missing _MAX and _MIN macros. Note that
147 macros defined with these cannot be used in #if. */
148
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)))
156
157/* Use that infrastructure to provide a few constants. */
158#ifndef UCHAR_MAX
159# define UCHAR_MAX INTTYPE_MAXIMUM (unsigned char)
160#endif
161
aca69483
KG
162#ifdef TIME_WITH_SYS_TIME
163# include <sys/time.h>
164# include <time.h>
165#else
166# if HAVE_SYS_TIME_H
e572c0c6 167# include <sys/time.h>
aca69483 168# else
e572c0c6
KG
169# ifdef HAVE_TIME_H
170# include <time.h>
171# endif
172# endif
aca69483
KG
173#endif
174
175#ifdef HAVE_FCNTL_H
176# include <fcntl.h>
177#else
e572c0c6
KG
178# ifdef HAVE_SYS_FILE_H
179# include <sys/file.h>
180# endif
aca69483
KG
181#endif
182
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
e572c0c6
KG
194#ifndef O_RDONLY
195# define O_RDONLY 0
196#endif
197#ifndef O_WRONLY
198# define O_WRONLY 1
199#endif
aca69483 200
36b8337d
KG
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. */
204
205#undef MIN
206#undef MAX
207#define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
208#define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
209
13799af3
MM
210/* Returns the least number N such that N * Y >= X. */
211#define CEIL(x,y) (((x) + (y) - 1) / (y))
212
e9831ca0
KG
213#ifdef HAVE_SYS_WAIT_H
214#include <sys/wait.h>
215#endif
216
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
8fa213ac
PDM
229#ifndef WSTOPSIG
230#define WSTOPSIG WEXITSTATUS
231#endif
e9831ca0 232
f31e826b
KG
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_*)". */
aca69483 237
f31e826b 238#if defined (HAVE_DECL_ATOF) && !HAVE_DECL_ATOF
d4d4ae5f 239extern double atof PARAMS ((const char *));
8f81384f
KG
240#endif
241
f31e826b 242#if defined (HAVE_DECL_ATOL) && !HAVE_DECL_ATOL
d4d4ae5f 243extern long atol PARAMS ((const char *));
8f81384f
KG
244#endif
245
f31e826b 246#if defined (HAVE_DECL_FREE) && !HAVE_DECL_FREE
d4d4ae5f 247extern void free PARAMS ((PTR));
aca69483
KG
248#endif
249
f31e826b 250#if defined (HAVE_DECL_GETCWD) && !HAVE_DECL_GETCWD
d4d4ae5f 251extern char *getcwd PARAMS ((char *, size_t));
6cd5dccd
KG
252#endif
253
f31e826b 254#if defined (HAVE_DECL_GETENV) && !HAVE_DECL_GETENV
d4d4ae5f 255extern char *getenv PARAMS ((const char *));
79e11844
KG
256#endif
257
ebb13e7e 258#if defined (HAVE_DECL_GETOPT) && !HAVE_DECL_GETOPT
fc608b03 259extern int getopt PARAMS ((int, char * const *, const char *));
ebb13e7e
RK
260#endif
261
f31e826b 262#if defined (HAVE_DECL_GETWD) && !HAVE_DECL_GETWD
d4d4ae5f 263extern char *getwd PARAMS ((char *));
6cd5dccd
KG
264#endif
265
f31e826b 266#if defined (HAVE_DECL_SBRK) && !HAVE_DECL_SBRK
d4d4ae5f 267extern PTR sbrk PARAMS ((int));
8f81384f
KG
268#endif
269
f31e826b 270#if defined (HAVE_DECL_STRSTR) && !HAVE_DECL_STRSTR
d4d4ae5f 271extern char *strstr PARAMS ((const char *, const char *));
d3d5cc97
JL
272#endif
273
c5c76735
JL
274#ifdef HAVE_MALLOC_H
275#include <malloc.h>
276#endif
277
f31e826b 278#if defined (HAVE_DECL_MALLOC) && !HAVE_DECL_MALLOC
d4d4ae5f 279extern PTR malloc PARAMS ((size_t));
c5c76735
JL
280#endif
281
f31e826b 282#if defined (HAVE_DECL_CALLOC) && !HAVE_DECL_CALLOC
d4d4ae5f 283extern PTR calloc PARAMS ((size_t, size_t));
c5c76735
JL
284#endif
285
f31e826b 286#if defined (HAVE_DECL_REALLOC) && !HAVE_DECL_REALLOC
d4d4ae5f 287extern PTR realloc PARAMS ((PTR, size_t));
c5c76735
JL
288#endif
289
759af044
KG
290/* If the system doesn't provide strsignal, we get it defined in
291 libiberty but no declaration is supplied. */
317639a8 292#ifndef HAVE_STRSIGNAL
759af044
KG
293# ifndef strsignal
294extern const char *strsignal PARAMS ((int));
007e8d2a 295# endif
759af044 296#endif
007e8d2a 297
d2cabf16 298#ifdef HAVE_GETRLIMIT
f31e826b 299# if defined (HAVE_DECL_GETRLIMIT) && !HAVE_DECL_GETRLIMIT
d2cabf16 300# ifndef getrlimit
d4d4ae5f
KG
301# ifdef ANSI_PROTOTYPES
302struct rlimit;
303# endif
304extern int getrlimit PARAMS ((int, struct rlimit *));
d2cabf16
KG
305# endif
306# endif
307#endif
308
309#ifdef HAVE_SETRLIMIT
f31e826b 310# if defined (HAVE_DECL_SETRLIMIT) && !HAVE_DECL_SETRLIMIT
d2cabf16 311# ifndef setrlimit
d4d4ae5f
KG
312# ifdef ANSI_PROTOTYPES
313struct rlimit;
314# endif
315extern int setrlimit PARAMS ((int, const struct rlimit *));
d2cabf16
KG
316# endif
317# endif
318#endif
319
e9b4fabf
JL
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
325
f31e826b 326#if defined (HAVE_DECL_ABORT) && !HAVE_DECL_ABORT
d4d4ae5f 327extern void abort PARAMS ((void));
2a611d21 328#endif
d4ba0ead 329
61d0346d 330/* 1 if we have C99 designated initializers. */
18922061 331#if !defined(HAVE_DESIGNATED_INITIALIZERS)
61d0346d
NB
332#define HAVE_DESIGNATED_INITIALIZERS \
333 ((GCC_VERSION >= 2007) || (__STDC_VERSION__ >= 199901L))
18922061 334#endif
61d0346d 335
d6edb99e
ZW
336/* 1 if we have _Bool. */
337#ifndef HAVE__BOOL
338# define HAVE__BOOL \
339 ((GCC_VERSION >= 3000) || (__STDC_VERSION__ >= 199901L))
340#endif
341
342
a05e22b8
RH
343#if HAVE_SYS_STAT_H
344# include <sys/stat.h>
345#endif
9855b854
MN
346
347/* Test if something is a normal file. */
348#ifndef S_ISREG
349#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
350#endif
351
352/* Test if something is a directory. */
353#ifndef S_ISDIR
354#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
355#endif
356
6458033d
ZW
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
361
be3dad6f
PDM
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
366
6458033d
ZW
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
375
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
384
385/* Approximate O_NONBLOCK. */
386#ifndef O_NONBLOCK
387#define O_NONBLOCK O_NDELAY
388#endif
389
390/* Approximate O_NOCTTY. */
391#ifndef O_NOCTTY
392#define O_NOCTTY 0
393#endif
394
f3692274
ME
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
924d8a7c 402#ifndef STDERR_FILENO
f3692274
ME
403# define STDERR_FILENO 2
404#endif
405
75923b2f
MK
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
410
1eb14644
KG
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 */
421
d5b6516d
MK
422/* By default, colon separates directories in a path. */
423#ifndef PATH_SEPARATOR
424#define PATH_SEPARATOR ':'
425#endif
426
427#ifndef DIR_SEPARATOR
428#define DIR_SEPARATOR '/'
429#endif
430
431/* Define IS_DIR_SEPARATOR. */
432#ifndef DIR_SEPARATOR_2
c5c0b3d9 433# define IS_DIR_SEPARATOR(CH) ((CH) == DIR_SEPARATOR)
d5b6516d 434#else /* DIR_SEPARATOR_2 */
c5c0b3d9
RK
435# define IS_DIR_SEPARATOR(CH) \
436 (((CH) == DIR_SEPARATOR) || ((CH) == DIR_SEPARATOR_2))
d5b6516d
MK
437#endif /* DIR_SEPARATOR_2 */
438
c5c0b3d9
RK
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
451
2778b98d
KG
452/* Get libiberty declarations. */
453#include "libiberty.h"
4bc5fbd4 454#include "symcat.h"
2778b98d 455
49009afd
JL
456/* Provide a default for the HOST_BIT_BUCKET.
457 This suffices for POSIX-like hosts. */
458
459#ifndef HOST_BIT_BUCKET
460#define HOST_BIT_BUCKET "/dev/null"
461#endif
462
9612ab65
ZW
463/* Be conservative and only use enum bitfields with GCC.
464 FIXME: provide a complete autoconf test for buggy enum bitfields. */
c149cc37 465
9612ab65 466#if (GCC_VERSION > 2000)
c149cc37
RL
467#define ENUM_BITFIELD(TYPE) enum TYPE
468#else
469#define ENUM_BITFIELD(TYPE) unsigned int
470#endif
471
e0125cf3
KG
472#ifndef offsetof
473#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
474#endif
c149cc37 475
7de9cc38
KG
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
485
fbfc1192
ZW
486/* Various error reporting routines want to use __FUNCTION__. */
487#if (GCC_VERSION < 2007)
791ef777 488#ifndef __FUNCTION__
fbfc1192 489#define __FUNCTION__ "?"
791ef777 490#endif /* ! __FUNCTION__ */
fbfc1192
ZW
491#endif
492
2c3fcba6
ZW
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
499
d6edb99e 500/* Provide some sort of boolean type. We use stdbool.h if it's
2f78c311
ZW
501 available. This must be after all inclusion of system headers,
502 as some of them will mess us up. */
d6edb99e
ZW
503#undef bool
504#undef true
505#undef false
506#undef TRUE
507#undef FALSE
508
509#ifdef HAVE_STDBOOL_H
510# include <stdbool.h>
511#else
512# if !HAVE__BOOL
513typedef char _Bool;
514# endif
515# define bool _Bool
516# define true 1
517# define false 0
518#endif
519
520#define TRUE true
521#define FALSE false
522
2f78c311
ZW
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
527struct rtx_def;
528struct rtvec_def;
529union tree_node;
530typedef struct rtx_def *rtx;
531typedef struct rtvec_def *rtvec;
532typedef union tree_node *tree;
533#endif
534
f4ce9d90
KG
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.
541
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. */
545
546#define really_call_malloc malloc
547#define really_call_calloc calloc
548#define really_call_realloc realloc
549
550#if (GCC_VERSION >= 3000)
551
77b84559
KG
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
8a0e5115
KG
557#undef malloc
558#undef realloc
559#undef calloc
560#undef strdup
f4ce9d90 561 #pragma GCC poison malloc realloc calloc strdup
77b84559 562#endif /* IN_GCC */
f4ce9d90 563
8e944909
KG
564/* Note: not all uses of the `index' token (e.g. variable names and
565 structure members) have been eliminated. */
566#undef bcopy
8a0e5115
KG
567#undef bzero
568#undef bcmp
569#undef rindex
8e944909 570 #pragma GCC poison bcopy bzero bcmp rindex
f4ce9d90
KG
571
572#endif /* GCC >= 3.0 */
573
88657302 574#endif /* ! GCC_SYSTEM_H */