]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/system.h
cp-tree.h (TYPE_LINKAGE_IDENTIFIER): New macro.
[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
1b0c6de6
JL
5This file is part of GNU CC.
6
7GNU CC is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2, or (at your option)
10any later version.
11
12GNU CC is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU CC; see the file COPYING. If not, write to
19the Free Software Foundation, 59 Temple Place - Suite 330,
20Boston, MA 02111-1307, USA. */
aca69483 21
c5c76735 22
aca69483
KG
23#ifndef __GCC_SYSTEM_H__
24#define __GCC_SYSTEM_H__
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
f6bbde28 87/* Define a default escape character; it's different for EBCDIC. */
64f8a718
RH
88#ifndef TARGET_ESC
89#define TARGET_ESC 033
90#endif
91
aca69483 92#include <sys/types.h>
c5c76735 93
aca69483
KG
94#include <errno.h>
95
96#ifndef errno
97extern int errno;
98#endif
99
ccc7d11a 100#ifdef STRING_WITH_STRINGS
aca69483 101# include <string.h>
ccc7d11a 102# include <strings.h>
aca69483 103#else
ccc7d11a
KG
104# ifdef HAVE_STRING_H
105# include <string.h>
106# else
107# ifdef HAVE_STRINGS_H
108# include <strings.h>
109# endif
aca69483
KG
110# endif
111#endif
112
113#ifdef HAVE_STDLIB_H
114# include <stdlib.h>
115#endif
116
eaf4e618
ZW
117/* If we don't have an overriding definition, set SUCCESS_EXIT_CODE and
118 FATAL_EXIT_CODE to EXIT_SUCCESS and EXIT_FAILURE respectively,
119 or 0 and 1 if those macros are not defined. */
120#ifndef SUCCESS_EXIT_CODE
121# ifdef EXIT_SUCCESS
122# define SUCCESS_EXIT_CODE EXIT_SUCCESS
123# else
124# define SUCCESS_EXIT_CODE 0
125# endif
126#endif
127
128#ifndef FATAL_EXIT_CODE
129# ifdef EXIT_FAILURE
130# define FATAL_EXIT_CODE EXIT_FAILURE
131# else
132# define FATAL_EXIT_CODE 1
133# endif
134#endif
135
aca69483
KG
136#ifdef HAVE_UNISTD_H
137# include <unistd.h>
138#endif
139
140#ifdef HAVE_SYS_PARAM_H
141# include <sys/param.h>
142#endif
143
144#if HAVE_LIMITS_H
145# include <limits.h>
146#endif
147
75e93faa
ZW
148/* Get definitions of HOST_WIDE_INT and HOST_WIDEST_INT. */
149#include "hwint.h"
f80d6fd7 150
f12bc141
ZW
151/* Infrastructure for defining missing _MAX and _MIN macros. Note that
152 macros defined with these cannot be used in #if. */
153
154/* The extra casts work around common compiler bugs. */
155#define INTTYPE_SIGNED(t) (! ((t) 0 < (t) -1))
156/* The outer cast is needed to work around a bug in Cray C 5.0.3.0.
157 It is necessary at least when t == time_t. */
158#define INTTYPE_MINIMUM(t) ((t) (INTTYPE_SIGNED (t) \
159 ? ~ (t) 0 << (sizeof(t) * CHAR_BIT - 1) : (t) 0))
160#define INTTYPE_MAXIMUM(t) ((t) (~ (t) 0 - INTTYPE_MINIMUM (t)))
161
162/* Use that infrastructure to provide a few constants. */
163#ifndef UCHAR_MAX
164# define UCHAR_MAX INTTYPE_MAXIMUM (unsigned char)
165#endif
166
aca69483
KG
167#ifdef TIME_WITH_SYS_TIME
168# include <sys/time.h>
169# include <time.h>
170#else
171# if HAVE_SYS_TIME_H
e572c0c6 172# include <sys/time.h>
aca69483 173# else
e572c0c6
KG
174# ifdef HAVE_TIME_H
175# include <time.h>
176# endif
177# endif
aca69483
KG
178#endif
179
180#ifdef HAVE_FCNTL_H
181# include <fcntl.h>
182#else
e572c0c6
KG
183# ifdef HAVE_SYS_FILE_H
184# include <sys/file.h>
185# endif
aca69483
KG
186#endif
187
188#ifndef SEEK_SET
189# define SEEK_SET 0
190# define SEEK_CUR 1
191# define SEEK_END 2
192#endif
193#ifndef F_OK
194# define F_OK 0
195# define X_OK 1
196# define W_OK 2
197# define R_OK 4
198#endif
e572c0c6
KG
199#ifndef O_RDONLY
200# define O_RDONLY 0
201#endif
202#ifndef O_WRONLY
203# define O_WRONLY 1
204#endif
aca69483 205
36b8337d
KG
206/* Some systems define these in, e.g., param.h. We undefine these names
207 here to avoid the warnings. We prefer to use our definitions since we
208 know they are correct. */
209
210#undef MIN
211#undef MAX
212#define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
213#define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
214
13799af3
MM
215/* Returns the least number N such that N * Y >= X. */
216#define CEIL(x,y) (((x) + (y) - 1) / (y))
217
e9831ca0
KG
218#ifdef HAVE_SYS_WAIT_H
219#include <sys/wait.h>
220#endif
221
222#ifndef WIFSIGNALED
223#define WIFSIGNALED(S) (((S) & 0xff) != 0 && ((S) & 0xff) != 0x7f)
224#endif
225#ifndef WTERMSIG
226#define WTERMSIG(S) ((S) & 0x7f)
227#endif
228#ifndef WIFEXITED
229#define WIFEXITED(S) (((S) & 0xff) == 0)
230#endif
231#ifndef WEXITSTATUS
232#define WEXITSTATUS(S) (((S) & 0xff00) >> 8)
233#endif
8fa213ac
PDM
234#ifndef WSTOPSIG
235#define WSTOPSIG WEXITSTATUS
236#endif
e9831ca0 237
f31e826b
KG
238/* The HAVE_DECL_* macros are three-state, undefined, 0 or 1. If they
239 are defined to 0 then we must provide the relevant declaration
240 here. These checks will be in the undefined state while configure
241 is running so be careful to test "defined (HAVE_DECL_*)". */
aca69483 242
f31e826b 243#if defined (HAVE_DECL_ATOF) && !HAVE_DECL_ATOF
d4d4ae5f 244extern double atof PARAMS ((const char *));
8f81384f
KG
245#endif
246
f31e826b 247#if defined (HAVE_DECL_ATOL) && !HAVE_DECL_ATOL
d4d4ae5f 248extern long atol PARAMS ((const char *));
8f81384f
KG
249#endif
250
f31e826b 251#if defined (HAVE_DECL_FREE) && !HAVE_DECL_FREE
d4d4ae5f 252extern void free PARAMS ((PTR));
aca69483
KG
253#endif
254
f31e826b 255#if defined (HAVE_DECL_GETCWD) && !HAVE_DECL_GETCWD
d4d4ae5f 256extern char *getcwd PARAMS ((char *, size_t));
6cd5dccd
KG
257#endif
258
f31e826b 259#if defined (HAVE_DECL_GETENV) && !HAVE_DECL_GETENV
d4d4ae5f 260extern char *getenv PARAMS ((const char *));
79e11844
KG
261#endif
262
ebb13e7e 263#if defined (HAVE_DECL_GETOPT) && !HAVE_DECL_GETOPT
fc608b03 264extern int getopt PARAMS ((int, char * const *, const char *));
ebb13e7e
RK
265#endif
266
f31e826b 267#if defined (HAVE_DECL_GETWD) && !HAVE_DECL_GETWD
d4d4ae5f 268extern char *getwd PARAMS ((char *));
6cd5dccd
KG
269#endif
270
f31e826b 271#if defined (HAVE_DECL_SBRK) && !HAVE_DECL_SBRK
d4d4ae5f 272extern PTR sbrk PARAMS ((int));
8f81384f
KG
273#endif
274
f31e826b 275#if defined (HAVE_DECL_STRSTR) && !HAVE_DECL_STRSTR
d4d4ae5f 276extern char *strstr PARAMS ((const char *, const char *));
d3d5cc97
JL
277#endif
278
c5c76735
JL
279#ifdef HAVE_MALLOC_H
280#include <malloc.h>
281#endif
282
f31e826b 283#if defined (HAVE_DECL_MALLOC) && !HAVE_DECL_MALLOC
d4d4ae5f 284extern PTR malloc PARAMS ((size_t));
c5c76735
JL
285#endif
286
f31e826b 287#if defined (HAVE_DECL_CALLOC) && !HAVE_DECL_CALLOC
d4d4ae5f 288extern PTR calloc PARAMS ((size_t, size_t));
c5c76735
JL
289#endif
290
f31e826b 291#if defined (HAVE_DECL_REALLOC) && !HAVE_DECL_REALLOC
d4d4ae5f 292extern PTR realloc PARAMS ((PTR, size_t));
c5c76735
JL
293#endif
294
759af044
KG
295/* If the system doesn't provide strsignal, we get it defined in
296 libiberty but no declaration is supplied. */
317639a8 297#ifndef HAVE_STRSIGNAL
759af044
KG
298# ifndef strsignal
299extern const char *strsignal PARAMS ((int));
007e8d2a 300# endif
759af044 301#endif
007e8d2a 302
d2cabf16 303#ifdef HAVE_GETRLIMIT
f31e826b 304# if defined (HAVE_DECL_GETRLIMIT) && !HAVE_DECL_GETRLIMIT
d2cabf16 305# ifndef getrlimit
d4d4ae5f
KG
306# ifdef ANSI_PROTOTYPES
307struct rlimit;
308# endif
309extern int getrlimit PARAMS ((int, struct rlimit *));
d2cabf16
KG
310# endif
311# endif
312#endif
313
314#ifdef HAVE_SETRLIMIT
f31e826b 315# if defined (HAVE_DECL_SETRLIMIT) && !HAVE_DECL_SETRLIMIT
d2cabf16 316# ifndef setrlimit
d4d4ae5f
KG
317# ifdef ANSI_PROTOTYPES
318struct rlimit;
319# endif
320extern int setrlimit PARAMS ((int, const struct rlimit *));
d2cabf16
KG
321# endif
322# endif
323#endif
324
e9b4fabf
JL
325/* HAVE_VOLATILE only refers to the stage1 compiler. We also check
326 __STDC__ and assume gcc sets it and has volatile in stage >=2. */
327#if !defined(HAVE_VOLATILE) && !defined(__STDC__) && !defined(volatile)
328#define volatile
329#endif
330
f31e826b 331#if defined (HAVE_DECL_ABORT) && !HAVE_DECL_ABORT
d4d4ae5f 332extern void abort PARAMS ((void));
2a611d21 333#endif
d4ba0ead 334
61d0346d 335/* 1 if we have C99 designated initializers. */
18922061 336#if !defined(HAVE_DESIGNATED_INITIALIZERS)
61d0346d
NB
337#define HAVE_DESIGNATED_INITIALIZERS \
338 ((GCC_VERSION >= 2007) || (__STDC_VERSION__ >= 199901L))
18922061 339#endif
61d0346d 340
d6edb99e
ZW
341/* 1 if we have _Bool. */
342#ifndef HAVE__BOOL
343# define HAVE__BOOL \
344 ((GCC_VERSION >= 3000) || (__STDC_VERSION__ >= 199901L))
345#endif
346
347
a05e22b8
RH
348#if HAVE_SYS_STAT_H
349# include <sys/stat.h>
350#endif
9855b854
MN
351
352/* Test if something is a normal file. */
353#ifndef S_ISREG
354#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
355#endif
356
357/* Test if something is a directory. */
358#ifndef S_ISDIR
359#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
360#endif
361
6458033d
ZW
362/* Test if something is a character special file. */
363#ifndef S_ISCHR
364#define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
365#endif
366
be3dad6f
PDM
367/* Test if something is a block special file. */
368#ifndef S_ISBLK
369#define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
370#endif
371
6458033d
ZW
372/* Test if something is a socket. */
373#ifndef S_ISSOCK
374# ifdef S_IFSOCK
375# define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
376# else
377# define S_ISSOCK(m) 0
378# endif
379#endif
380
381/* Test if something is a FIFO. */
382#ifndef S_ISFIFO
383# ifdef S_IFIFO
384# define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
385# else
386# define S_ISFIFO(m) 0
387# endif
388#endif
389
390/* Approximate O_NONBLOCK. */
391#ifndef O_NONBLOCK
392#define O_NONBLOCK O_NDELAY
393#endif
394
395/* Approximate O_NOCTTY. */
396#ifndef O_NOCTTY
397#define O_NOCTTY 0
398#endif
399
f3692274
ME
400/* Define well known filenos if the system does not define them. */
401#ifndef STDIN_FILENO
402# define STDIN_FILENO 0
403#endif
404#ifndef STDOUT_FILENO
405# define STDOUT_FILENO 1
406#endif
924d8a7c 407#ifndef STDERR_FILENO
f3692274
ME
408# define STDERR_FILENO 2
409#endif
410
75923b2f
MK
411/* Some systems have mkdir that takes a single argument. */
412#ifdef MKDIR_TAKES_ONE_ARG
413# define mkdir(a,b) mkdir(a)
414#endif
415
1eb14644
KG
416/* Provide a way to print an address via printf. */
417#ifndef HOST_PTR_PRINTF
418# ifdef HAVE_PRINTF_PTR
419# define HOST_PTR_PRINTF "%p"
420# else
421# define HOST_PTR_PRINTF \
422 (sizeof (int) == sizeof (char *) ? "%x" \
423 : sizeof (long) == sizeof (char *) ? "%lx" : "%llx")
424# endif
425#endif /* ! HOST_PTR_PRINTF */
426
d5b6516d
MK
427/* By default, colon separates directories in a path. */
428#ifndef PATH_SEPARATOR
429#define PATH_SEPARATOR ':'
430#endif
431
432#ifndef DIR_SEPARATOR
433#define DIR_SEPARATOR '/'
434#endif
435
436/* Define IS_DIR_SEPARATOR. */
437#ifndef DIR_SEPARATOR_2
c5c0b3d9 438# define IS_DIR_SEPARATOR(CH) ((CH) == DIR_SEPARATOR)
d5b6516d 439#else /* DIR_SEPARATOR_2 */
c5c0b3d9
RK
440# define IS_DIR_SEPARATOR(CH) \
441 (((CH) == DIR_SEPARATOR) || ((CH) == DIR_SEPARATOR_2))
d5b6516d
MK
442#endif /* DIR_SEPARATOR_2 */
443
c5c0b3d9
RK
444/* Say how to test for an absolute pathname. On Unix systems, this is if
445 it starts with a leading slash or a '$', the latter meaning the value of
446 an environment variable is to be used. On machien with DOS-based
447 file systems, it is also absolute if it starts with a drive identifier. */
448#ifdef HAVE_DOS_BASED_FILE_SYSTEM
449#define IS_ABSOLUTE_PATHNAME(STR) \
450 (IS_DIR_SEPARATOR ((STR)[0]) || (STR)[0] == '$' \
451 || ((STR)[0] != '\0' && (STR)[1] == ':' && IS_DIR_SEPARATOR ((STR)[2])))
452#else
453#define IS_ABSOLUTE_PATHNAME(STR) \
454 (IS_DIR_SEPARATOR ((STR)[0]) || (STR)[0] == '$')
455#endif
456
2778b98d
KG
457/* Get libiberty declarations. */
458#include "libiberty.h"
4bc5fbd4 459#include "symcat.h"
2778b98d 460
49009afd
JL
461/* Provide a default for the HOST_BIT_BUCKET.
462 This suffices for POSIX-like hosts. */
463
464#ifndef HOST_BIT_BUCKET
465#define HOST_BIT_BUCKET "/dev/null"
466#endif
467
9612ab65
ZW
468/* Be conservative and only use enum bitfields with GCC.
469 FIXME: provide a complete autoconf test for buggy enum bitfields. */
c149cc37 470
9612ab65 471#if (GCC_VERSION > 2000)
c149cc37
RL
472#define ENUM_BITFIELD(TYPE) enum TYPE
473#else
474#define ENUM_BITFIELD(TYPE) unsigned int
475#endif
476
e0125cf3
KG
477#ifndef offsetof
478#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
479#endif
c149cc37 480
7de9cc38
KG
481/* Traditional C cannot initialize union members of structs. Provide
482 a macro which expands appropriately to handle it. This only works
483 if you intend to initalize the union member to zero since it relies
484 on default initialization to zero in the traditional C case. */
485#ifdef __STDC__
486#define UNION_INIT_ZERO , {0}
487#else
488#define UNION_INIT_ZERO
489#endif
490
fbfc1192
ZW
491/* Various error reporting routines want to use __FUNCTION__. */
492#if (GCC_VERSION < 2007)
791ef777 493#ifndef __FUNCTION__
fbfc1192 494#define __FUNCTION__ "?"
791ef777 495#endif /* ! __FUNCTION__ */
fbfc1192
ZW
496#endif
497
d6edb99e
ZW
498/* Provide some sort of boolean type. We use stdbool.h if it's
499 available. This is dead last because various system headers might
500 mess us up. */
501#undef bool
502#undef true
503#undef false
504#undef TRUE
505#undef FALSE
506
507#ifdef HAVE_STDBOOL_H
508# include <stdbool.h>
509#else
510# if !HAVE__BOOL
511typedef char _Bool;
512# endif
513# define bool _Bool
514# define true 1
515# define false 0
516#endif
517
518#define TRUE true
519#define FALSE false
520
f4ce9d90
KG
521/* As the last action in this file, we poison the identifiers that
522 shouldn't be used. Note, luckily gcc-3.0's token-based integrated
523 preprocessor won't trip on poisoned identifiers that arrive from
524 the expansion of macros. E.g. #define strrchr rindex, won't error
525 if rindex is poisoned after this directive is issued and later on
526 strrchr is called.
527
528 Note: We define bypass macros for the few cases where we really
529 want to use the libc memory allocation routines. Otherwise we
530 insist you use the "x" versions from libiberty. */
531
532#define really_call_malloc malloc
533#define really_call_calloc calloc
534#define really_call_realloc realloc
535
536#if (GCC_VERSION >= 3000)
537
77b84559
KG
538/* Note autoconf checks for prototype declarations and includes
539 system.h while doing so. Only poison these tokens if actually
540 compiling gcc, so that the autoconf declaration tests for malloc
541 etc don't spuriously fail. */
542#ifdef IN_GCC
8a0e5115
KG
543#undef malloc
544#undef realloc
545#undef calloc
546#undef strdup
f4ce9d90 547 #pragma GCC poison malloc realloc calloc strdup
77b84559 548#endif /* IN_GCC */
f4ce9d90 549
8e944909
KG
550/* Note: not all uses of the `index' token (e.g. variable names and
551 structure members) have been eliminated. */
552#undef bcopy
8a0e5115
KG
553#undef bzero
554#undef bcmp
555#undef rindex
8e944909 556 #pragma GCC poison bcopy bzero bcmp rindex
f4ce9d90
KG
557
558#endif /* GCC >= 3.0 */
559
aca69483 560#endif /* __GCC_SYSTEM_H__ */