* expr.c (expand_expr, case ARRAY_REF): Do not replace
[official-gcc.git] / gcc / system.h
blob0ee1510aae08b4dd72114a598affe749a4be5ac0
1 /* Get common system includes and various definitions and declarations based
2 on autoconf macros.
3 Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 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 /* Define a default escape character; it's different for EBCDIC. */
88 #ifndef TARGET_ESC
89 #define TARGET_ESC 033
90 #endif
92 #include <sys/types.h>
94 #include <errno.h>
96 #ifndef errno
97 extern int errno;
98 #endif
100 #ifdef STRING_WITH_STRINGS
101 # include <string.h>
102 # include <strings.h>
103 #else
104 # ifdef HAVE_STRING_H
105 # include <string.h>
106 # else
107 # ifdef HAVE_STRINGS_H
108 # include <strings.h>
109 # endif
110 # endif
111 #endif
113 #ifdef HAVE_STDLIB_H
114 # include <stdlib.h>
115 # ifdef USE_C_ALLOCA
116 /* Note that systems that use glibc have a <stdlib.h> that includes
117 <alloca.h> that defines alloca, so let USE_C_ALLOCA override this. */
118 # undef alloca
119 #endif
120 #endif
122 #ifdef HAVE_UNISTD_H
123 # include <unistd.h>
124 #endif
126 #ifdef HAVE_SYS_PARAM_H
127 # include <sys/param.h>
128 #endif
130 #if HAVE_LIMITS_H
131 # include <limits.h>
132 #endif
134 /* Find HOST_WIDEST_INT and set its bit size, type and print macros.
135 It will be the largest integer mode supported by the host which may
136 (or may not) be larger than HOST_WIDE_INT. This must appear after
137 <limits.h> since we only use `long long' if its bigger than a
138 `long' and also if it is supported by macros in limits.h. For old
139 hosts which don't have a limits.h (and thus won't include it in
140 stage2 cause we don't rerun configure) we assume gcc supports long
141 long.) Note, you won't get these defined if you don't include
142 {ht}config.h before this file to set the HOST_BITS_PER_* macros. */
144 #ifndef HOST_WIDEST_INT
145 # if defined (HOST_BITS_PER_LONG) && defined (HOST_BITS_PER_LONGLONG)
146 # if (HOST_BITS_PER_LONGLONG > HOST_BITS_PER_LONG) && (defined (LONG_LONG_MAX) || defined (LONGLONG_MAX) || defined (LLONG_MAX) || defined (__GNUC__))
147 # define HOST_BITS_PER_WIDEST_INT HOST_BITS_PER_LONGLONG
148 # define HOST_WIDEST_INT long long
149 # define HOST_WIDEST_INT_PRINT_DEC "%lld"
150 # define HOST_WIDEST_INT_PRINT_UNSIGNED "%llu"
151 # define HOST_WIDEST_INT_PRINT_HEX "0x%llx"
152 # else
153 # define HOST_BITS_PER_WIDEST_INT HOST_BITS_PER_LONG
154 # define HOST_WIDEST_INT long
155 # define HOST_WIDEST_INT_PRINT_DEC "%ld"
156 # define HOST_WIDEST_INT_PRINT_UNSIGNED "%lu"
157 # define HOST_WIDEST_INT_PRINT_HEX "0x%lx"
158 # endif /*(long long>long) && (LONG_LONG_MAX||LONGLONG_MAX||LLONG_MAX||GNUC)*/
159 # endif /* defined(HOST_BITS_PER_LONG) && defined(HOST_BITS_PER_LONGLONG) */
160 #endif /* ! HOST_WIDEST_INT */
162 /* Infrastructure for defining missing _MAX and _MIN macros. Note that
163 macros defined with these cannot be used in #if. */
165 /* The extra casts work around common compiler bugs. */
166 #define INTTYPE_SIGNED(t) (! ((t) 0 < (t) -1))
167 /* The outer cast is needed to work around a bug in Cray C 5.0.3.0.
168 It is necessary at least when t == time_t. */
169 #define INTTYPE_MINIMUM(t) ((t) (INTTYPE_SIGNED (t) \
170 ? ~ (t) 0 << (sizeof(t) * CHAR_BIT - 1) : (t) 0))
171 #define INTTYPE_MAXIMUM(t) ((t) (~ (t) 0 - INTTYPE_MINIMUM (t)))
173 /* Use that infrastructure to provide a few constants. */
174 #ifndef UCHAR_MAX
175 # define UCHAR_MAX INTTYPE_MAXIMUM (unsigned char)
176 #endif
178 #ifdef TIME_WITH_SYS_TIME
179 # include <sys/time.h>
180 # include <time.h>
181 #else
182 # if HAVE_SYS_TIME_H
183 # include <sys/time.h>
184 # else
185 # ifdef HAVE_TIME_H
186 # include <time.h>
187 # endif
188 # endif
189 #endif
191 #ifdef HAVE_FCNTL_H
192 # include <fcntl.h>
193 #else
194 # ifdef HAVE_SYS_FILE_H
195 # include <sys/file.h>
196 # endif
197 #endif
199 #ifndef SEEK_SET
200 # define SEEK_SET 0
201 # define SEEK_CUR 1
202 # define SEEK_END 2
203 #endif
204 #ifndef F_OK
205 # define F_OK 0
206 # define X_OK 1
207 # define W_OK 2
208 # define R_OK 4
209 #endif
210 #ifndef O_RDONLY
211 # define O_RDONLY 0
212 #endif
213 #ifndef O_WRONLY
214 # define O_WRONLY 1
215 #endif
217 /* Some systems define these in, e.g., param.h. We undefine these names
218 here to avoid the warnings. We prefer to use our definitions since we
219 know they are correct. */
221 #undef MIN
222 #undef MAX
223 #define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
224 #define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
226 /* Returns the least number N such that N * Y >= X. */
227 #define CEIL(x,y) (((x) + (y) - 1) / (y))
229 #ifdef HAVE_SYS_WAIT_H
230 #include <sys/wait.h>
231 #endif
233 #ifndef WIFSIGNALED
234 #define WIFSIGNALED(S) (((S) & 0xff) != 0 && ((S) & 0xff) != 0x7f)
235 #endif
236 #ifndef WTERMSIG
237 #define WTERMSIG(S) ((S) & 0x7f)
238 #endif
239 #ifndef WIFEXITED
240 #define WIFEXITED(S) (((S) & 0xff) == 0)
241 #endif
242 #ifndef WEXITSTATUS
243 #define WEXITSTATUS(S) (((S) & 0xff00) >> 8)
244 #endif
245 #ifndef WSTOPSIG
246 #define WSTOPSIG WEXITSTATUS
247 #endif
249 /* The HAVE_DECL_* macros are three-state, undefined, 0 or 1. If they
250 are defined to 0 then we must provide the relevant declaration
251 here. These checks will be in the undefined state while configure
252 is running so be careful to test "defined (HAVE_DECL_*)". */
254 #ifndef bcopy
255 # ifdef HAVE_BCOPY
256 # if defined (HAVE_DECL_BCOPY) && !HAVE_DECL_BCOPY
257 extern void bcopy PARAMS ((const PTR, PTR, size_t));
258 # endif
259 # else /* ! HAVE_BCOPY */
260 # define bcopy(src,dst,len) memmove((dst),(src),(len))
261 # endif
262 #endif
264 #if defined (HAVE_DECL_ATOF) && !HAVE_DECL_ATOF
265 extern double atof PARAMS ((const char *));
266 #endif
268 #if defined (HAVE_DECL_ATOL) && !HAVE_DECL_ATOL
269 extern long atol PARAMS ((const char *));
270 #endif
272 #if defined (HAVE_DECL_FREE) && !HAVE_DECL_FREE
273 extern void free PARAMS ((PTR));
274 #endif
276 #if defined (HAVE_DECL_GETCWD) && !HAVE_DECL_GETCWD
277 extern char *getcwd PARAMS ((char *, size_t));
278 #endif
280 #if defined (HAVE_DECL_GETENV) && !HAVE_DECL_GETENV
281 extern char *getenv PARAMS ((const char *));
282 #endif
284 #if defined (HAVE_DECL_GETOPT) && !HAVE_DECL_GETOPT
285 extern int getopt PARAMS ((int, char * const *, const char *));
286 #endif
288 #if defined (HAVE_DECL_GETWD) && !HAVE_DECL_GETWD
289 extern char *getwd PARAMS ((char *));
290 #endif
292 #if defined (HAVE_DECL_SBRK) && !HAVE_DECL_SBRK
293 extern PTR sbrk PARAMS ((int));
294 #endif
296 #if defined (HAVE_DECL_STRSTR) && !HAVE_DECL_STRSTR
297 extern char *strstr PARAMS ((const char *, const char *));
298 #endif
300 #ifdef HAVE_MALLOC_H
301 #include <malloc.h>
302 #endif
304 #if defined (HAVE_DECL_MALLOC) && !HAVE_DECL_MALLOC
305 extern PTR malloc PARAMS ((size_t));
306 #endif
308 #if defined (HAVE_DECL_CALLOC) && !HAVE_DECL_CALLOC
309 extern PTR calloc PARAMS ((size_t, size_t));
310 #endif
312 #if defined (HAVE_DECL_REALLOC) && !HAVE_DECL_REALLOC
313 extern PTR realloc PARAMS ((PTR, size_t));
314 #endif
316 /* If the system doesn't provide strsignal, we get it defined in
317 libiberty but no declaration is supplied. */
318 #ifndef HAVE_STRSIGNAL
319 # ifndef strsignal
320 extern const char *strsignal PARAMS ((int));
321 # endif
322 #endif
324 #ifdef HAVE_GETRLIMIT
325 # if defined (HAVE_DECL_GETRLIMIT) && !HAVE_DECL_GETRLIMIT
326 # ifndef getrlimit
327 # ifdef ANSI_PROTOTYPES
328 struct rlimit;
329 # endif
330 extern int getrlimit PARAMS ((int, struct rlimit *));
331 # endif
332 # endif
333 #endif
335 #ifdef HAVE_SETRLIMIT
336 # if defined (HAVE_DECL_SETRLIMIT) && !HAVE_DECL_SETRLIMIT
337 # ifndef setrlimit
338 # ifdef ANSI_PROTOTYPES
339 struct rlimit;
340 # endif
341 extern int setrlimit PARAMS ((int, const struct rlimit *));
342 # endif
343 # endif
344 #endif
346 /* HAVE_VOLATILE only refers to the stage1 compiler. We also check
347 __STDC__ and assume gcc sets it and has volatile in stage >=2. */
348 #if !defined(HAVE_VOLATILE) && !defined(__STDC__) && !defined(volatile)
349 #define volatile
350 #endif
352 #if defined (HAVE_DECL_ABORT) && !HAVE_DECL_ABORT
353 extern void abort PARAMS ((void));
354 #endif
356 /* 1 if we have C99 designated initializers. */
357 #if !defined(HAVE_DESIGNATED_INITIALIZERS)
358 #define HAVE_DESIGNATED_INITIALIZERS \
359 ((GCC_VERSION >= 2007) || (__STDC_VERSION__ >= 199901L))
360 #endif
362 /* 1 if we have _Bool. */
363 #ifndef HAVE__BOOL
364 # define HAVE__BOOL \
365 ((GCC_VERSION >= 3000) || (__STDC_VERSION__ >= 199901L))
366 #endif
370 /* Define a STRINGIFY macro that's right for ANSI or traditional C.
371 Note: if the argument passed to STRINGIFY is itself a macro, eg
372 #define foo bar, STRINGIFY(foo) will produce "foo", not "bar".
373 Although the __STDC__ case could be made to expand this via a layer
374 of indirection, the traditional C case can not do so. Therefore
375 this behavior is not supported. */
376 #ifndef STRINGIFY
377 # ifdef HAVE_STRINGIZE
378 # define STRINGIFY(STRING) #STRING
379 # else
380 # define STRINGIFY(STRING) "STRING"
381 # endif
382 #endif /* ! STRINGIFY */
384 #if HAVE_SYS_STAT_H
385 # include <sys/stat.h>
386 #endif
388 /* Test if something is a normal file. */
389 #ifndef S_ISREG
390 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
391 #endif
393 /* Test if something is a directory. */
394 #ifndef S_ISDIR
395 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
396 #endif
398 /* Test if something is a character special file. */
399 #ifndef S_ISCHR
400 #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
401 #endif
403 /* Test if something is a block special file. */
404 #ifndef S_ISBLK
405 #define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
406 #endif
408 /* Test if something is a socket. */
409 #ifndef S_ISSOCK
410 # ifdef S_IFSOCK
411 # define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
412 # else
413 # define S_ISSOCK(m) 0
414 # endif
415 #endif
417 /* Test if something is a FIFO. */
418 #ifndef S_ISFIFO
419 # ifdef S_IFIFO
420 # define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
421 # else
422 # define S_ISFIFO(m) 0
423 # endif
424 #endif
426 /* Approximate O_NONBLOCK. */
427 #ifndef O_NONBLOCK
428 #define O_NONBLOCK O_NDELAY
429 #endif
431 /* Approximate O_NOCTTY. */
432 #ifndef O_NOCTTY
433 #define O_NOCTTY 0
434 #endif
436 /* Define well known filenos if the system does not define them. */
437 #ifndef STDIN_FILENO
438 # define STDIN_FILENO 0
439 #endif
440 #ifndef STDOUT_FILENO
441 # define STDOUT_FILENO 1
442 #endif
443 #ifndef STDERR_FILENO
444 # define STDERR_FILENO 2
445 #endif
447 /* Some systems have mkdir that takes a single argument. */
448 #ifdef MKDIR_TAKES_ONE_ARG
449 # define mkdir(a,b) mkdir(a)
450 #endif
452 /* Provide a way to print an address via printf. */
453 #ifndef HOST_PTR_PRINTF
454 # ifdef HAVE_PRINTF_PTR
455 # define HOST_PTR_PRINTF "%p"
456 # else
457 # define HOST_PTR_PRINTF \
458 (sizeof (int) == sizeof (char *) ? "%x" \
459 : sizeof (long) == sizeof (char *) ? "%lx" : "%llx")
460 # endif
461 #endif /* ! HOST_PTR_PRINTF */
463 /* By default, colon separates directories in a path. */
464 #ifndef PATH_SEPARATOR
465 #define PATH_SEPARATOR ':'
466 #endif
468 #ifndef DIR_SEPARATOR
469 #define DIR_SEPARATOR '/'
470 #endif
472 /* Define IS_DIR_SEPARATOR. */
473 #ifndef DIR_SEPARATOR_2
474 # define IS_DIR_SEPARATOR(CH) ((CH) == DIR_SEPARATOR)
475 #else /* DIR_SEPARATOR_2 */
476 # define IS_DIR_SEPARATOR(CH) \
477 (((CH) == DIR_SEPARATOR) || ((CH) == DIR_SEPARATOR_2))
478 #endif /* DIR_SEPARATOR_2 */
480 /* Say how to test for an absolute pathname. On Unix systems, this is if
481 it starts with a leading slash or a '$', the latter meaning the value of
482 an environment variable is to be used. On machien with DOS-based
483 file systems, it is also absolute if it starts with a drive identifier. */
484 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
485 #define IS_ABSOLUTE_PATHNAME(STR) \
486 (IS_DIR_SEPARATOR ((STR)[0]) || (STR)[0] == '$' \
487 || ((STR)[0] != '\0' && (STR)[1] == ':' && IS_DIR_SEPARATOR ((STR)[2])))
488 #else
489 #define IS_ABSOLUTE_PATHNAME(STR) \
490 (IS_DIR_SEPARATOR ((STR)[0]) || (STR)[0] == '$')
491 #endif
493 /* Get libiberty declarations. */
494 #include "libiberty.h"
496 /* Make sure that ONLY_INT_FIELDS has an integral value. */
497 #ifdef ONLY_INT_FIELDS
498 #undef ONLY_INT_FIELDS
499 #define ONLY_INT_FIELDS 1
500 #else
501 #define ONLY_INT_FIELDS 0
502 #endif
504 /* Provide a default for the HOST_BIT_BUCKET.
505 This suffices for POSIX-like hosts. */
507 #ifndef HOST_BIT_BUCKET
508 #define HOST_BIT_BUCKET "/dev/null"
509 #endif
511 /* Enumerated bitfields are safe to use unless we've been explictly told
512 otherwise or if they are signed. */
514 #define USE_ENUM_BITFIELDS (__GNUC__ || (!ONLY_INT_FIELDS && ENUM_BITFIELDS_ARE_UNSIGNED))
516 #if USE_ENUM_BITFIELDS
517 #define ENUM_BITFIELD(TYPE) enum TYPE
518 #else
519 #define ENUM_BITFIELD(TYPE) unsigned int
520 #endif
522 #ifndef offsetof
523 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
524 #endif
526 /* Traditional C cannot initialize union members of structs. Provide
527 a macro which expands appropriately to handle it. This only works
528 if you intend to initalize the union member to zero since it relies
529 on default initialization to zero in the traditional C case. */
530 #ifdef __STDC__
531 #define UNION_INIT_ZERO , {0}
532 #else
533 #define UNION_INIT_ZERO
534 #endif
536 /* GCC now gives implicit declaration warnings for undeclared builtins. */
537 #if defined(__GNUC__) && defined (__SIZE_TYPE__)
538 extern void *alloca (__SIZE_TYPE__);
539 #endif
541 /* Various error reporting routines want to use __FUNCTION__. */
542 #if (GCC_VERSION < 2007)
543 #ifndef __FUNCTION__
544 #define __FUNCTION__ "?"
545 #endif /* ! __FUNCTION__ */
546 #endif
548 /* Provide some sort of boolean type. We use stdbool.h if it's
549 available. This is dead last because various system headers might
550 mess us up. */
551 #undef bool
552 #undef true
553 #undef false
554 #undef TRUE
555 #undef FALSE
557 #ifdef HAVE_STDBOOL_H
558 # include <stdbool.h>
559 #else
560 # if !HAVE__BOOL
561 typedef char _Bool;
562 # endif
563 # define bool _Bool
564 # define true 1
565 # define false 0
566 #endif
568 #define TRUE true
569 #define FALSE false
571 #endif /* __GCC_SYSTEM_H__ */