OSDN Git Service

* optabs.h (OTI_flodiv, flodiv_optab): Kill.
[pf3gnuchains/gcc-fork.git] / gcc / system.h
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.
4
5 This file is part of GNU CC.
6
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.
11
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.
16
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.  */
21
22
23 #ifndef GCC_SYSTEM_H
24 #define GCC_SYSTEM_H
25
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
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
37
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
46 #ifdef HAVE_STDDEF_H
47 # include <stddef.h>
48 #endif
49
50 #include <stdio.h>
51
52 /* Define a generic NULL if one hasn't already been defined.  */
53 #ifndef NULL
54 #define NULL 0
55 #endif
56
57 /* The compiler is not a multi-threaded application and therefore we
58    do not have to use the locking functions.
59
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.
63    
64    fputs_unlocked is an extension and needs to be prototyped specially.  */
65
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
81
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>
86
87 #include <sys/types.h>
88
89 #include <errno.h>
90
91 #if !defined (errno) && defined (HAVE_DECL_ERRNO) && !HAVE_DECL_ERRNO
92 extern int errno;
93 #endif
94
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
107
108 #ifdef HAVE_STDLIB_H
109 # include <stdlib.h>
110 #endif
111
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
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
143 /* Get definitions of HOST_WIDE_INT and HOST_WIDEST_INT.  */
144 #include "hwint.h"
145
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
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
174
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
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
194 #ifndef O_RDONLY
195 # define O_RDONLY 0
196 #endif
197 #ifndef O_WRONLY
198 # define O_WRONLY 1
199 #endif
200
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
210 /* Returns the least number N such that N * Y >= X.  */
211 #define CEIL(x,y) (((x) + (y) - 1) / (y))
212
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
229 #ifndef WSTOPSIG
230 #define WSTOPSIG WEXITSTATUS
231 #endif
232
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_*)".  */
237
238 #if defined (HAVE_DECL_ATOF) && !HAVE_DECL_ATOF
239 extern double atof PARAMS ((const char *));
240 #endif
241
242 #if defined (HAVE_DECL_ATOL) && !HAVE_DECL_ATOL
243 extern long atol PARAMS ((const char *));
244 #endif
245
246 #if defined (HAVE_DECL_FREE) && !HAVE_DECL_FREE
247 extern void free PARAMS ((PTR));
248 #endif
249
250 #if defined (HAVE_DECL_GETCWD) && !HAVE_DECL_GETCWD
251 extern char *getcwd PARAMS ((char *, size_t));
252 #endif
253
254 #if defined (HAVE_DECL_GETENV) && !HAVE_DECL_GETENV
255 extern char *getenv PARAMS ((const char *));
256 #endif
257
258 #if defined (HAVE_DECL_GETOPT) && !HAVE_DECL_GETOPT
259 extern int getopt PARAMS ((int, char * const *, const char *));
260 #endif
261
262 #if defined (HAVE_DECL_GETWD) && !HAVE_DECL_GETWD
263 extern char *getwd PARAMS ((char *));
264 #endif
265
266 #if defined (HAVE_DECL_SBRK) && !HAVE_DECL_SBRK
267 extern PTR sbrk PARAMS ((int));
268 #endif
269
270 #if defined (HAVE_DECL_STRSTR) && !HAVE_DECL_STRSTR
271 extern char *strstr PARAMS ((const char *, const char *));
272 #endif
273
274 #ifdef HAVE_MALLOC_H
275 #include <malloc.h>
276 #endif
277
278 #if defined (HAVE_DECL_MALLOC) && !HAVE_DECL_MALLOC
279 extern PTR malloc PARAMS ((size_t));
280 #endif
281
282 #if defined (HAVE_DECL_CALLOC) && !HAVE_DECL_CALLOC
283 extern PTR calloc PARAMS ((size_t, size_t));
284 #endif
285
286 #if defined (HAVE_DECL_REALLOC) && !HAVE_DECL_REALLOC
287 extern PTR realloc PARAMS ((PTR, size_t));
288 #endif
289
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
297
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
308
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
319
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
326 #if defined (HAVE_DECL_ABORT) && !HAVE_DECL_ABORT
327 extern void abort PARAMS ((void));
328 #endif
329
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
335
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
343 #if HAVE_SYS_STAT_H
344 # include <sys/stat.h>
345 #endif
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
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
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
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
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
405
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
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
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
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 */
438
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
452 /* Get libiberty declarations. */
453 #include "libiberty.h"
454 #include "symcat.h"
455
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
463 /* Be conservative and only use enum bitfields with GCC.
464    FIXME: provide a complete autoconf test for buggy enum bitfields.  */
465
466 #if (GCC_VERSION > 2000)
467 #define ENUM_BITFIELD(TYPE) enum TYPE
468 #else
469 #define ENUM_BITFIELD(TYPE) unsigned int
470 #endif
471
472 #ifndef offsetof
473 #define offsetof(TYPE, MEMBER)  ((size_t) &((TYPE *)0)->MEMBER)
474 #endif
475
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
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
492
493 /* Provide some sort of boolean type.  We use stdbool.h if it's
494   available.  This must be after all inclusion of system headers,
495   as some of them will mess us up.  */
496 #undef bool
497 #undef true
498 #undef false
499 #undef TRUE
500 #undef FALSE
501
502 #ifdef HAVE_STDBOOL_H
503 # include <stdbool.h>
504 #else
505 # if !HAVE__BOOL
506 typedef char _Bool;
507 # endif
508 # define bool _Bool
509 # define true 1
510 # define false 0
511 #endif
512
513 #define TRUE true
514 #define FALSE false
515
516 /* Provide three core typedefs used by everything, if we are compiling
517    GCC.  These used to be found in rtl.h and tree.h, but this is no
518    longer practical.  */
519 #ifdef IN_GCC
520 struct rtx_def;
521 struct rtvec_def;
522 union tree_node;
523 typedef struct rtx_def *rtx;
524 typedef struct rtvec_def *rtvec;
525 typedef union tree_node *tree;
526 #endif
527
528 /* As the last action in this file, we poison the identifiers that
529    shouldn't be used.  Note, luckily gcc-3.0's token-based integrated
530    preprocessor won't trip on poisoned identifiers that arrive from
531    the expansion of macros.  E.g. #define strrchr rindex, won't error
532    if rindex is poisoned after this directive is issued and later on
533    strrchr is called.
534
535    Note: We define bypass macros for the few cases where we really
536    want to use the libc memory allocation routines.  Otherwise we
537    insist you use the "x" versions from libiberty.  */
538
539 #define really_call_malloc malloc
540 #define really_call_calloc calloc
541 #define really_call_realloc realloc
542
543 #if (GCC_VERSION >= 3000)
544
545 /* Note autoconf checks for prototype declarations and includes
546    system.h while doing so.  Only poison these tokens if actually
547    compiling gcc, so that the autoconf declaration tests for malloc
548    etc don't spuriously fail.  */
549 #ifdef IN_GCC
550 #undef malloc
551 #undef realloc
552 #undef calloc
553 #undef strdup
554  #pragma GCC poison malloc realloc calloc strdup
555 #endif /* IN_GCC */
556
557 /* Note: not all uses of the `index' token (e.g. variable names and
558    structure members) have been eliminated.  */
559 #undef bcopy
560 #undef bzero
561 #undef bcmp
562 #undef rindex
563  #pragma GCC poison bcopy bzero bcmp rindex
564
565 #endif /* GCC >= 3.0 */
566
567 #endif /* ! GCC_SYSTEM_H */