1 /* Get common system includes and various definitions and declarations based
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)
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
40 # define va_copy(d,s) __va_copy((d),(s))
42 # define va_copy(d,s) ((d) = (s))
48 /* Define a generic NULL if one hasn't already been defined. */
53 /* The compiler is not a multi-threaded application and therefore we
54 do not have to use the locking functions.
56 HAVE_DECL_PUTC_UNLOCKED actually indicates whether or not the IO
57 code is multi-thread safe by default. If it is set to 0, then do
58 not worry about using the _unlocked functions.
60 fputs_unlocked is an extension and needs to be prototyped specially. */
62 #if defined HAVE_PUTC_UNLOCKED && (defined (HAVE_DECL_PUTC_UNLOCKED) && HAVE_DECL_PUTC_UNLOCKED)
64 # define putc(C, Stream) putc_unlocked (C, Stream)
66 #if defined HAVE_FPUTC_UNLOCKED && (defined (HAVE_DECL_PUTC_UNLOCKED) && HAVE_DECL_PUTC_UNLOCKED)
68 # define fputc(C, Stream) fputc_unlocked (C, Stream)
70 #if defined HAVE_FPUTS_UNLOCKED && (defined (HAVE_DECL_PUTC_UNLOCKED) && HAVE_DECL_PUTC_UNLOCKED)
72 # define fputs(String, Stream) fputs_unlocked (String, Stream)
73 # if defined (HAVE_DECL_FPUTS_UNLOCKED) && !HAVE_DECL_FPUTS_UNLOCKED
74 extern int fputs_unlocked PARAMS ((const char *, FILE *));
80 /* Jim Meyering writes:
82 "... Some ctype macros are valid only for character codes that
83 isascii says are ASCII (SGI's IRIX-4.0.5 is one such system --when
84 using /bin/cc or gcc but without giving an ansi option). So, all
85 ctype uses should be through macros like ISPRINT... If
86 STDC_HEADERS is defined, then autoconf has verified that the ctype
87 macros don't need to be guarded with references to isascii. ...
88 Defining isascii to 1 should let any compiler worth its salt
89 eliminate the && through constant folding."
93 "... Furthermore, isupper(c) etc. have an undefined result if c is
94 outside the range -1 <= c <= 255. One is tempted to write isupper(c)
95 with c being of type `char', but this is wrong if c is an 8-bit
96 character >= 128 which gets sign-extended to a negative value.
97 The macro ISUPPER protects against this as well." */
99 #if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII)) || defined(HOST_EBCDIC)
100 # define IN_CTYPE_DOMAIN(c) 1
102 # define IN_CTYPE_DOMAIN(c) isascii(c)
105 /* The ctype functions are often implemented as macros which do
106 lookups in arrays using the parameter as the offset. If the ctype
107 function parameter is a char, then gcc will (appropriately) warn
108 that a "subscript has type char". Using a (signed) char as a subscript
109 is bad because you may get negative offsets and thus it is not 8-bit
110 safe. The CTYPE_CONV macro ensures that the parameter is cast to an
111 unsigned char when a char is passed in. When an int is passed in, the
112 parameter is left alone so we don't lose EOF.
115 #define CTYPE_CONV(CH) \
116 (sizeof(CH) == sizeof(unsigned char) ? (int)(unsigned char)(CH) : (int)(CH))
119 /* WARNING! The argument to the ctype replacement macros below is
120 evaluated more than once so it must not have side effects! */
123 # define ISBLANK(c) (IN_CTYPE_DOMAIN (c) && isblank (CTYPE_CONV(c)))
125 # define ISBLANK(c) ((c) == ' ' || (c) == '\t')
128 # define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isgraph (CTYPE_CONV(c)))
130 # define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isprint (CTYPE_CONV(c)) && !isspace (CTYPE_CONV(c)))
133 #define ISPRINT(c) (IN_CTYPE_DOMAIN (c) && isprint (CTYPE_CONV(c)))
134 #define ISALNUM(c) (IN_CTYPE_DOMAIN (c) && isalnum (CTYPE_CONV(c)))
135 #define ISALPHA(c) (IN_CTYPE_DOMAIN (c) && isalpha (CTYPE_CONV(c)))
136 #define ISCNTRL(c) (IN_CTYPE_DOMAIN (c) && iscntrl (CTYPE_CONV(c)))
137 #define ISLOWER(c) (IN_CTYPE_DOMAIN (c) && islower (CTYPE_CONV(c)))
138 #define ISPUNCT(c) (IN_CTYPE_DOMAIN (c) && ispunct (CTYPE_CONV(c)))
139 #define ISSPACE(c) (IN_CTYPE_DOMAIN (c) && isspace (CTYPE_CONV(c)))
140 #define ISUPPER(c) (IN_CTYPE_DOMAIN (c) && isupper (CTYPE_CONV(c)))
141 #define ISXDIGIT(c) (IN_CTYPE_DOMAIN (c) && isxdigit (CTYPE_CONV(c)))
142 #define ISDIGIT_LOCALE(c) (IN_CTYPE_DOMAIN (c) && isdigit (CTYPE_CONV(c)))
145 # define TOLOWER(c) (tolower (CTYPE_CONV(c)))
146 # define TOUPPER(c) (toupper (CTYPE_CONV(c)))
148 # define TOLOWER(c) (ISUPPER (c) ? tolower (CTYPE_CONV(c)) : (c))
149 # define TOUPPER(c) (ISLOWER (c) ? toupper (CTYPE_CONV(c)) : (c))
152 /* ISDIGIT differs from ISDIGIT_LOCALE, as follows:
153 - Its arg may be any int or unsigned int; it need not be an unsigned char.
154 - It's guaranteed to evaluate its argument exactly once.
155 - It's typically faster.
156 Posix 1003.2-1992 section 2.5.2.1 page 50 lines 1556-1558 says that
157 only '0' through '9' are digits. Prefer ISDIGIT to ISDIGIT_LOCALE unless
158 it's important to use the locale's definition of `digit' even when the
159 host does not conform to Posix. */
160 #define ISDIGIT(c) ((unsigned) (c) - '0' <= 9)
162 /* Define a default escape character; its different for EBCDIC. */
164 #define TARGET_ESC 033
167 #include <sys/types.h>
175 #ifdef STRING_WITH_STRINGS
177 # include <strings.h>
179 # ifdef HAVE_STRING_H
182 # ifdef HAVE_STRINGS_H
183 # include <strings.h>
191 /* Note that systems that use glibc have a <stdlib.h> that includes
192 <alloca.h> that defines alloca, so let USE_C_ALLOCA override this. */
201 #ifdef HAVE_SYS_PARAM_H
202 # include <sys/param.h>
209 /* Find HOST_WIDEST_INT and set its bit size, type and print macros.
210 It will be the largest integer mode supported by the host which may
211 (or may not) be larger than HOST_WIDE_INT. This must appear after
212 <limits.h> since we only use `long long' if its bigger than a
213 `long' and also if it is supported by macros in limits.h. For old
214 hosts which don't have a limits.h (and thus won't include it in
215 stage2 cause we don't rerun configure) we assume gcc supports long
216 long.) Note, you won't get these defined if you don't include
217 {ht}config.h before this file to set the HOST_BITS_PER_* macros. */
219 #ifndef HOST_WIDEST_INT
220 # if defined (HOST_BITS_PER_LONG) && defined (HOST_BITS_PER_LONGLONG)
221 # if (HOST_BITS_PER_LONGLONG > HOST_BITS_PER_LONG) && (defined (LONG_LONG_MAX) || defined (LONGLONG_MAX) || defined (LLONG_MAX) || defined (__GNUC__))
222 # define HOST_BITS_PER_WIDEST_INT HOST_BITS_PER_LONGLONG
223 # define HOST_WIDEST_INT long long
224 # define HOST_WIDEST_INT_PRINT_DEC "%lld"
225 # define HOST_WIDEST_INT_PRINT_UNSIGNED "%llu"
226 # define HOST_WIDEST_INT_PRINT_HEX "0x%llx"
228 # define HOST_BITS_PER_WIDEST_INT HOST_BITS_PER_LONG
229 # define HOST_WIDEST_INT long
230 # define HOST_WIDEST_INT_PRINT_DEC "%ld"
231 # define HOST_WIDEST_INT_PRINT_UNSIGNED "%lu"
232 # define HOST_WIDEST_INT_PRINT_HEX "0x%lx"
233 # endif /*(long long>long) && (LONG_LONG_MAX||LONGLONG_MAX||LLONG_MAX||GNUC)*/
234 # endif /* defined(HOST_BITS_PER_LONG) && defined(HOST_BITS_PER_LONGLONG) */
235 #endif /* ! HOST_WIDEST_INT */
237 #ifdef TIME_WITH_SYS_TIME
238 # include <sys/time.h>
242 # include <sys/time.h>
253 # ifdef HAVE_SYS_FILE_H
254 # include <sys/file.h>
276 /* Some systems define these in, e.g., param.h. We undefine these names
277 here to avoid the warnings. We prefer to use our definitions since we
278 know they are correct. */
282 #define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
283 #define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
285 /* Returns the least number N such that N * Y >= X. */
286 #define CEIL(x,y) (((x) + (y) - 1) / (y))
288 #ifdef HAVE_SYS_WAIT_H
289 #include <sys/wait.h>
293 #define WIFSIGNALED(S) (((S) & 0xff) != 0 && ((S) & 0xff) != 0x7f)
296 #define WTERMSIG(S) ((S) & 0x7f)
299 #define WIFEXITED(S) (((S) & 0xff) == 0)
302 #define WEXITSTATUS(S) (((S) & 0xff00) >> 8)
305 #define WSTOPSIG WEXITSTATUS
308 /* The HAVE_DECL_* macros are three-state, undefined, 0 or 1. If they
309 are defined to 0 then we must provide the relevant declaration
310 here. These checks will be in the undefined state while configure
311 is running so be careful to test "defined (HAVE_DECL_*)". */
315 # if defined (HAVE_DECL_BCOPY) && !HAVE_DECL_BCOPY
316 extern void bcopy PARAMS ((const PTR, PTR, size_t));
318 # else /* ! HAVE_BCOPY */
319 # define bcopy(src,dst,len) memmove((dst),(src),(len))
325 # if defined (HAVE_DECL_BCMP) && !HAVE_DECL_BCMP
326 extern int bcmp PARAMS ((const PTR, const PTR, size_t));
328 # else /* ! HAVE_BCMP */
329 # define bcmp(left,right,len) memcmp ((left),(right),(len))
335 # if defined (HAVE_DECL_BZERO) && !HAVE_DECL_BZERO
336 extern void bzero PARAMS ((PTR, size_t));
338 # else /* ! HAVE_BZERO */
339 # define bzero(dst,len) memset ((dst),0,(len))
345 # if defined (HAVE_DECL_INDEX) && !HAVE_DECL_INDEX
346 extern char *index PARAMS ((const char *, int));
348 # else /* ! HAVE_INDEX */
349 # define index strchr
355 # if defined (HAVE_DECL_RINDEX) && !HAVE_DECL_RINDEX
356 extern char *rindex PARAMS ((const char *, int));
358 # else /* ! HAVE_RINDEX */
359 # define rindex strrchr
363 #if defined (HAVE_DECL_ATOF) && !HAVE_DECL_ATOF
364 extern double atof PARAMS ((const char *));
367 #if defined (HAVE_DECL_ATOL) && !HAVE_DECL_ATOL
368 extern long atol PARAMS ((const char *));
371 #if defined (HAVE_DECL_FREE) && !HAVE_DECL_FREE
372 extern void free PARAMS ((PTR));
375 #if defined (HAVE_DECL_GETCWD) && !HAVE_DECL_GETCWD
376 extern char *getcwd PARAMS ((char *, size_t));
379 #if defined (HAVE_DECL_GETENV) && !HAVE_DECL_GETENV
380 extern char *getenv PARAMS ((const char *));
383 #if defined (HAVE_DECL_GETWD) && !HAVE_DECL_GETWD
384 extern char *getwd PARAMS ((char *));
387 #if defined (HAVE_DECL_SBRK) && !HAVE_DECL_SBRK
388 extern PTR sbrk PARAMS ((int));
391 #if defined (HAVE_DECL_STRSTR) && !HAVE_DECL_STRSTR
392 extern char *strstr PARAMS ((const char *, const char *));
399 #if defined (HAVE_DECL_MALLOC) && !HAVE_DECL_MALLOC
400 extern PTR malloc PARAMS ((size_t));
403 #if defined (HAVE_DECL_CALLOC) && !HAVE_DECL_CALLOC
404 extern PTR calloc PARAMS ((size_t, size_t));
407 #if defined (HAVE_DECL_REALLOC) && !HAVE_DECL_REALLOC
408 extern PTR realloc PARAMS ((PTR, size_t));
411 /* If the system doesn't provide strsignal, we get it defined in
412 libiberty but no declaration is supplied. */
413 #if defined (HAVE_DECL_STRSIGNAL) && !HAVE_DECL_STRSIGNAL
415 extern const char *strsignal PARAMS ((int));
419 #ifdef HAVE_GETRLIMIT
420 # if defined (HAVE_DECL_GETRLIMIT) && !HAVE_DECL_GETRLIMIT
422 # ifdef ANSI_PROTOTYPES
425 extern int getrlimit PARAMS ((int, struct rlimit *));
430 #ifdef HAVE_SETRLIMIT
431 # if defined (HAVE_DECL_SETRLIMIT) && !HAVE_DECL_SETRLIMIT
433 # ifdef ANSI_PROTOTYPES
436 extern int setrlimit PARAMS ((int, const struct rlimit *));
441 /* HAVE_VOLATILE only refers to the stage1 compiler. We also check
442 __STDC__ and assume gcc sets it and has volatile in stage >=2. */
443 #if !defined(HAVE_VOLATILE) && !defined(__STDC__) && !defined(volatile)
447 #if defined (HAVE_DECL_ABORT) && !HAVE_DECL_ABORT
448 extern void abort PARAMS ((void));
451 /* Define a STRINGIFY macro that's right for ANSI or traditional C.
452 Note: if the argument passed to STRINGIFY is itself a macro, eg
453 #define foo bar, STRINGIFY(foo) will produce "foo", not "bar".
454 Although the __STDC__ case could be made to expand this via a layer
455 of indirection, the traditional C case can not do so. Therefore
456 this behavior is not supported. */
458 # ifdef HAVE_STRINGIZE
459 # define STRINGIFY(STRING) #STRING
461 # define STRINGIFY(STRING) "STRING"
463 #endif /* ! STRINGIFY */
466 # include <sys/stat.h>
469 /* Test if something is a normal file. */
471 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
474 /* Test if something is a directory. */
476 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
479 /* Test if something is a character special file. */
481 #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
484 /* Test if something is a block special file. */
486 #define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
489 /* Test if something is a socket. */
492 # define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
494 # define S_ISSOCK(m) 0
498 /* Test if something is a FIFO. */
501 # define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
503 # define S_ISFIFO(m) 0
507 /* Approximate O_NONBLOCK. */
509 #define O_NONBLOCK O_NDELAY
512 /* Approximate O_NOCTTY. */
517 /* Define well known filenos if the system does not define them. */
519 # define STDIN_FILENO 0
521 #ifndef STDOUT_FILENO
522 # define STDOUT_FILENO 1
524 #ifndef STDERR_FILENO
525 # define STDERR_FILENO 2
528 /* Some systems have mkdir that takes a single argument. */
529 #ifdef MKDIR_TAKES_ONE_ARG
530 # define mkdir(a,b) mkdir(a)
533 /* Provide a way to print an address via printf. */
534 #ifndef HOST_PTR_PRINTF
535 # ifdef HAVE_PRINTF_PTR
536 # define HOST_PTR_PRINTF "%p"
538 # define HOST_PTR_PRINTF \
539 (sizeof (int) == sizeof (char *) ? "%x" \
540 : sizeof (long) == sizeof (char *) ? "%lx" : "%llx")
542 #endif /* ! HOST_PTR_PRINTF */
544 /* By default, colon separates directories in a path. */
545 #ifndef PATH_SEPARATOR
546 #define PATH_SEPARATOR ':'
549 #ifndef DIR_SEPARATOR
550 #define DIR_SEPARATOR '/'
553 /* Define IS_DIR_SEPARATOR. */
554 #ifndef DIR_SEPARATOR_2
555 # define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
556 #else /* DIR_SEPARATOR_2 */
557 # define IS_DIR_SEPARATOR(ch) \
558 (((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
559 #endif /* DIR_SEPARATOR_2 */
561 /* Get libiberty declarations. */
562 #include "libiberty.h"
564 /* Make sure that ONLY_INT_FIELDS has an integral value. */
565 #ifdef ONLY_INT_FIELDS
566 #undef ONLY_INT_FIELDS
567 #define ONLY_INT_FIELDS 1
569 #define ONLY_INT_FIELDS 0
572 /* Enumerated bitfields are safe to use unless we've been explictly told
573 otherwise or if they are signed. */
575 #define USE_ENUM_BITFIELDS (__GNUC__ || (!ONLY_INT_FIELDS && ENUM_BITFIELDS_ARE_UNSIGNED))
577 #if USE_ENUM_BITFIELDS
578 #define ENUM_BITFIELD(TYPE) enum TYPE
580 #define ENUM_BITFIELD(TYPE) unsigned int
584 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
587 #endif /* __GCC_SYSTEM_H__ */