1 /* Get common system includes and various definitions and declarations based
3 Copyright (C) 1998, 1999, 2000, 2001 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)
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. */
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>"
33 /* We must include stdarg.h/varargs.h before stdio.h. */
34 #ifdef ANSI_PROTOTYPES
42 # define va_copy(d,s) __va_copy((d),(s))
44 # define va_copy(d,s) ((d) = (s))
56 /* Define a generic NULL if one hasn't already been defined. */
61 /* There are an extraordinary number of issues with <ctype.h>.
62 The last straw is that it varies with the locale. Use libiberty's
63 replacement instead. */
64 #if defined(__APPLE__) && defined(__MACH__)
65 #include <libiberty/safe-ctype.h>
67 #include <safe-ctype.h>
70 /* Define a default escape character; it's different for EBCDIC. */
72 #define TARGET_ESC 033
75 #include <sys/types.h>
79 #if !defined (errno) && defined (HAVE_DECL_ERRNO) && !HAVE_DECL_ERRNO
83 #ifdef STRING_WITH_STRINGS
90 # ifdef HAVE_STRINGS_H
100 /* If we don't have an overriding definition, set SUCCESS_EXIT_CODE and
101 FATAL_EXIT_CODE to EXIT_SUCCESS and EXIT_FAILURE respectively,
102 or 0 and 1 if those macros are not defined. */
103 #ifndef SUCCESS_EXIT_CODE
105 # define SUCCESS_EXIT_CODE EXIT_SUCCESS
107 # define SUCCESS_EXIT_CODE 0
111 #ifndef FATAL_EXIT_CODE
113 # define FATAL_EXIT_CODE EXIT_FAILURE
115 # define FATAL_EXIT_CODE 1
123 #ifdef HAVE_SYS_PARAM_H
124 # include <sys/param.h>
131 /* Get definitions of HOST_WIDE_INT and HOST_WIDEST_INT. */
134 /* Infrastructure for defining missing _MAX and _MIN macros. Note that
135 macros defined with these cannot be used in #if. */
137 /* The extra casts work around common compiler bugs. */
138 #define INTTYPE_SIGNED(t) (! ((t) 0 < (t) -1))
139 /* The outer cast is needed to work around a bug in Cray C 5.0.3.0.
140 It is necessary at least when t == time_t. */
141 #define INTTYPE_MINIMUM(t) ((t) (INTTYPE_SIGNED (t) \
142 ? ~ (t) 0 << (sizeof(t) * CHAR_BIT - 1) : (t) 0))
143 #define INTTYPE_MAXIMUM(t) ((t) (~ (t) 0 - INTTYPE_MINIMUM (t)))
145 /* Use that infrastructure to provide a few constants. */
147 # define UCHAR_MAX INTTYPE_MAXIMUM (unsigned char)
150 #ifdef TIME_WITH_SYS_TIME
151 # include <sys/time.h>
155 # include <sys/time.h>
166 # ifdef HAVE_SYS_FILE_H
167 # include <sys/file.h>
189 /* Some systems define these in, e.g., param.h. We undefine these names
190 here to avoid the warnings. We prefer to use our definitions since we
191 know they are correct. */
195 #define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
196 #define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
198 /* Returns the least number N such that N * Y >= X. */
199 #define CEIL(x,y) (((x) + (y) - 1) / (y))
201 #ifdef HAVE_SYS_WAIT_H
202 #include <sys/wait.h>
206 #define WIFSIGNALED(S) (((S) & 0xff) != 0 && ((S) & 0xff) != 0x7f)
209 #define WTERMSIG(S) ((S) & 0x7f)
212 #define WIFEXITED(S) (((S) & 0xff) == 0)
215 #define WEXITSTATUS(S) (((S) & 0xff00) >> 8)
218 #define WSTOPSIG WEXITSTATUS
221 /* The HAVE_DECL_* macros are three-state, undefined, 0 or 1. If they
222 are defined to 0 then we must provide the relevant declaration
223 here. These checks will be in the undefined state while configure
224 is running so be careful to test "defined (HAVE_DECL_*)". */
226 #if defined (HAVE_DECL_ATOF) && !HAVE_DECL_ATOF
227 extern double atof PARAMS ((const char *));
230 #if defined (HAVE_DECL_ATOL) && !HAVE_DECL_ATOL
231 extern long atol PARAMS ((const char *));
234 #if defined (HAVE_DECL_FREE) && !HAVE_DECL_FREE
235 extern void free PARAMS ((PTR));
238 #if defined (HAVE_DECL_GETENV) && !HAVE_DECL_GETENV
239 extern char *getenv PARAMS ((const char *));
242 #if defined (HAVE_DECL_STRSTR) && !HAVE_DECL_STRSTR
243 extern char *strstr PARAMS ((const char *, const char *));
250 #if defined (HAVE_DECL_MALLOC) && !HAVE_DECL_MALLOC
251 extern PTR malloc PARAMS ((size_t));
254 #if defined (HAVE_DECL_CALLOC) && !HAVE_DECL_CALLOC
255 extern PTR calloc PARAMS ((size_t, size_t));
258 #if defined (HAVE_DECL_REALLOC) && !HAVE_DECL_REALLOC
259 extern PTR realloc PARAMS ((PTR, size_t));
262 #if !defined(__STDC__) && !defined(volatile)
266 #if defined (HAVE_DECL_ABORT) && !HAVE_DECL_ABORT
267 extern void abort PARAMS ((void));
270 /* 1 if we have C99 designated initializers. */
271 #if !defined(HAVE_DESIGNATED_INITIALIZERS)
272 #if defined(__APPLE__) && (__MACH__)
273 #define HAVE_DESIGNATED_INITIALIZERS 0
275 #define HAVE_DESIGNATED_INITIALIZERS \
276 ((GCC_VERSION >= 2007) || (__STDC_VERSION__ >= 199901L))
281 # include <sys/stat.h>
284 /* Test if something is a normal file. */
286 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
289 /* Test if something is a directory. */
291 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
294 /* Test if something is a character special file. */
296 #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
299 /* Test if something is a block special file. */
301 #define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
304 /* Test if something is a socket. */
307 # define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
309 # define S_ISSOCK(m) 0
313 /* Test if something is a FIFO. */
316 # define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
318 # define S_ISFIFO(m) 0
322 /* Approximate O_NONBLOCK. */
324 #define O_NONBLOCK O_NDELAY
327 /* Approximate O_NOCTTY. */
332 /* Define well known filenos if the system does not define them. */
334 # define STDIN_FILENO 0
336 #ifndef STDOUT_FILENO
337 # define STDOUT_FILENO 1
339 #ifndef STDERR_FILENO
340 # define STDERR_FILENO 2
343 /* Some systems have mkdir that takes a single argument. */
344 #ifdef MKDIR_TAKES_ONE_ARG
345 # define mkdir(a,b) mkdir(a)
348 /* Provide a way to print an address via printf. */
349 #ifndef HOST_PTR_PRINTF
350 # ifdef HAVE_PRINTF_PTR
351 # define HOST_PTR_PRINTF "%p"
353 # define HOST_PTR_PRINTF \
354 (sizeof (int) == sizeof (char *) ? "%x" \
355 : sizeof (long) == sizeof (char *) ? "%lx" : "%llx")
357 #endif /* ! HOST_PTR_PRINTF */
359 /* By default, colon separates directories in a path. */
360 #ifndef PATH_SEPARATOR
361 #define PATH_SEPARATOR ':'
364 #ifndef DIR_SEPARATOR
365 #define DIR_SEPARATOR '/'
368 /* Define IS_DIR_SEPARATOR. */
369 #ifndef DIR_SEPARATOR_2
370 # define IS_DIR_SEPARATOR(CH) ((CH) == DIR_SEPARATOR)
371 #else /* DIR_SEPARATOR_2 */
372 # define IS_DIR_SEPARATOR(CH) \
373 (((CH) == DIR_SEPARATOR) || ((CH) == DIR_SEPARATOR_2))
374 #endif /* DIR_SEPARATOR_2 */
376 /* Say how to test for an absolute pathname. On Unix systems, this is if
377 it starts with a leading slash or a '$', the latter meaning the value of
378 an environment variable is to be used. On machien with DOS-based
379 file systems, it is also absolute if it starts with a drive identifier. */
380 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
381 #define IS_ABSOLUTE_PATHNAME(STR) \
382 (IS_DIR_SEPARATOR ((STR)[0]) || (STR)[0] == '$' \
383 || ((STR)[0] != '\0' && (STR)[1] == ':' && IS_DIR_SEPARATOR ((STR)[2])))
385 #define IS_ABSOLUTE_PATHNAME(STR) \
386 (IS_DIR_SEPARATOR ((STR)[0]) || (STR)[0] == '$')
389 /* Get libiberty declarations. */
390 /* #include "libiberty.h" */
394 /* Provide a default for the HOST_BIT_BUCKET.
395 This suffices for POSIX-like hosts. */
397 #ifndef HOST_BIT_BUCKET
398 #define HOST_BIT_BUCKET "/dev/null"
401 /* Be conservative and only use enum bitfields with GCC.
402 FIXME: provide a complete autoconf test for buggy enum bitfields. */
404 #if (GCC_VERSION > 2000)
405 #define ENUM_BITFIELD(TYPE) enum TYPE
407 #define ENUM_BITFIELD(TYPE) unsigned int
411 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
414 /* Traditional C cannot initialize union members of structs. Provide
415 a macro which expands appropriately to handle it. This only works
416 if you intend to initalize the union member to zero since it relies
417 on default initialization to zero in the traditional C case. */
419 #define UNION_INIT_ZERO , {0}
421 #define UNION_INIT_ZERO
424 /* Various error reporting routines want to use __FUNCTION__. */
425 #if (GCC_VERSION < 2007)
427 #define __FUNCTION__ "?"
428 #endif /* ! __FUNCTION__ */
431 /* As the last action in this file, we poison the identifiers that
432 shouldn't be used. Note, luckily gcc-3.0's token-based integrated
433 preprocessor won't trip on poisoned identifiers that arrive from
434 the expansion of macros. E.g. #define strrchr rindex, won't error
435 if rindex is poisoned after this directive is issued and later on
438 Note: We define bypass macros for the few cases where we really
439 want to use the libc memory allocation routines. Otherwise we
440 insist you use the "x" versions from libiberty. */
442 #define really_call_malloc malloc
443 #define really_call_calloc calloc
444 #define really_call_realloc realloc
446 #if (GCC_VERSION >= 3000)
448 /* Note autoconf checks for prototype declarations and includes
449 system.h while doing so. Only poison these tokens if actually
450 compiling gcc, so that the autoconf declaration tests for malloc
451 etc don't spuriously fail. */
457 #pragma GCC poison malloc realloc calloc strdup
460 /* Note: not all uses of the `index' token (e.g. variable names and
461 structure members) have been eliminated. */
466 #pragma GCC poison bcopy bzero bcmp rindex
468 #endif /* GCC >= 3.0 */
470 #endif /* ! GCC_SYSTEM_H */