1 /* system.h - Get common system includes and various definitions and
2 declarations based 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)
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. */
22 #ifndef __GCC_SYSTEM_H__
23 #define __GCC_SYSTEM_H__
25 /* This is the location of the online document giving information how
26 to report bugs. If you change this string, also check for strings
27 not under control of the preprocessor. */
28 #define GCCBUGURL "<URL:http://www.gnu.org/software/gcc/bugs.html>"
30 /* We must include stdarg.h/varargs.h before stdio.h. */
31 #ifdef ANSI_PROTOTYPES
39 /* Define a generic NULL if one hasn't already been defined. */
44 /* The compiler is not a multi-threaded application and therefore we
45 do not have to use the locking functions.
47 NEED_DECLARATION_PUTC_UNLOCKED actually indicates whether or not
48 the IO code is multi-thread safe by default. If it is not declared,
49 then do not worry about using the _unlocked functions.
51 fputs_unlocked is an extension and needs to be prototyped specially. */
53 #if defined HAVE_PUTC_UNLOCKED && !defined NEED_DECLARATION_PUTC_UNLOCKED
55 # define putc(C, Stream) putc_unlocked (C, Stream)
57 #if defined HAVE_FPUTC_UNLOCKED && !defined NEED_DECLARATION_PUTC_UNLOCKED
59 # define fputc(C, Stream) fputc_unlocked (C, Stream)
61 #if defined HAVE_FPUTS_UNLOCKED && !defined NEED_DECLARATION_PUTC_UNLOCKED
63 # define fputs(String, Stream) fputs_unlocked (String, Stream)
64 # ifdef NEED_DECLARATION_FPUTS_UNLOCKED
65 extern int fputs_unlocked PROTO ((const char *, FILE *));
71 /* Jim Meyering writes:
73 "... Some ctype macros are valid only for character codes that
74 isascii says are ASCII (SGI's IRIX-4.0.5 is one such system --when
75 using /bin/cc or gcc but without giving an ansi option). So, all
76 ctype uses should be through macros like ISPRINT... If
77 STDC_HEADERS is defined, then autoconf has verified that the ctype
78 macros don't need to be guarded with references to isascii. ...
79 Defining isascii to 1 should let any compiler worth its salt
80 eliminate the && through constant folding."
84 "... Furthermore, isupper(c) etc. have an undefined result if c is
85 outside the range -1 <= c <= 255. One is tempted to write isupper(c)
86 with c being of type `char', but this is wrong if c is an 8-bit
87 character >= 128 which gets sign-extended to a negative value.
88 The macro ISUPPER protects against this as well." */
90 #if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII))
91 # define IN_CTYPE_DOMAIN(c) 1
93 # define IN_CTYPE_DOMAIN(c) isascii(c)
97 # define ISBLANK(c) (IN_CTYPE_DOMAIN (c) && isblank (c))
99 # define ISBLANK(c) ((c) == ' ' || (c) == '\t')
102 # define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isgraph (c))
104 # define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isprint (c) && !isspace (c))
107 #define ISPRINT(c) (IN_CTYPE_DOMAIN (c) && isprint (c))
108 #define ISALNUM(c) (IN_CTYPE_DOMAIN (c) && isalnum (c))
109 #define ISALPHA(c) (IN_CTYPE_DOMAIN (c) && isalpha (c))
110 #define ISCNTRL(c) (IN_CTYPE_DOMAIN (c) && iscntrl (c))
111 #define ISLOWER(c) (IN_CTYPE_DOMAIN (c) && islower (c))
112 #define ISPUNCT(c) (IN_CTYPE_DOMAIN (c) && ispunct (c))
113 #define ISSPACE(c) (IN_CTYPE_DOMAIN (c) && isspace (c))
114 #define ISUPPER(c) (IN_CTYPE_DOMAIN (c) && isupper (c))
115 #define ISXDIGIT(c) (IN_CTYPE_DOMAIN (c) && isxdigit (c))
116 #define ISDIGIT_LOCALE(c) (IN_CTYPE_DOMAIN (c) && isdigit (c))
118 /* ISDIGIT differs from ISDIGIT_LOCALE, as follows:
119 - Its arg may be any int or unsigned int; it need not be an unsigned char.
120 - It's guaranteed to evaluate its argument exactly once.
121 - It's typically faster.
122 Posix 1003.2-1992 section 2.5.2.1 page 50 lines 1556-1558 says that
123 only '0' through '9' are digits. Prefer ISDIGIT to ISDIGIT_LOCALE unless
124 it's important to use the locale's definition of `digit' even when the
125 host does not conform to Posix. */
126 #define ISDIGIT(c) ((unsigned) (c) - '0' <= 9)
129 #include <sys/types.h>
136 #ifdef STRING_WITH_STRINGS
138 # include <strings.h>
140 # ifdef HAVE_STRING_H
143 # ifdef HAVE_STRINGS_H
144 # include <strings.h>
157 #ifdef HAVE_SYS_PARAM_H
158 # include <sys/param.h>
165 /* Find HOST_WIDEST_INT and set its bit size, type and print macros.
166 It will be the largest integer mode supported by the host which may
167 (or may not) be larger than HOST_WIDE_INT. This must appear after
168 <limits.h> since we only use `long long' if its bigger than a
169 `long' and also if it is supported by macros in limits.h. For old
170 hosts which don't have a limits.h (and thus won't include it in
171 stage2 cause we don't rerun configure) we assume gcc supports long
172 long.) Note, you won't get these defined if you don't include
173 {ht}config.h before this file to set the HOST_BITS_PER_* macros. */
175 #ifndef HOST_WIDEST_INT
176 # if defined (HOST_BITS_PER_LONG) && defined (HOST_BITS_PER_LONGLONG)
177 # if (HOST_BITS_PER_LONGLONG > HOST_BITS_PER_LONG) && (defined (LONG_LONG_MAX) || defined (LONGLONG_MAX) || defined (LLONG_MAX) || defined (__GNUC__))
178 # define HOST_BITS_PER_WIDEST_INT HOST_BITS_PER_LONGLONG
179 # define HOST_WIDEST_INT long long
180 # define HOST_WIDEST_INT_PRINT_DEC "%lld"
181 # define HOST_WIDEST_INT_PRINT_UNSIGNED "%llu"
182 # define HOST_WIDEST_INT_PRINT_HEX "0x%llx"
184 # define HOST_BITS_PER_WIDEST_INT HOST_BITS_PER_LONG
185 # define HOST_WIDEST_INT long
186 # define HOST_WIDEST_INT_PRINT_DEC "%ld"
187 # define HOST_WIDEST_INT_PRINT_UNSIGNED "%lu"
188 # define HOST_WIDEST_INT_PRINT_HEX "0x%lx"
189 # endif /*(long long>long) && (LONG_LONG_MAX||LONGLONG_MAX||LLONG_MAX||GNUC)*/
190 # endif /* defined(HOST_BITS_PER_LONG) && defined(HOST_BITS_PER_LONGLONG) */
191 #endif /* ! HOST_WIDEST_INT */
193 #ifdef TIME_WITH_SYS_TIME
194 # include <sys/time.h>
198 # include <sys/time.h>
209 # ifdef HAVE_SYS_FILE_H
210 # include <sys/file.h>
232 /* Some systems define these in, e.g., param.h. We undefine these names
233 here to avoid the warnings. We prefer to use our definitions since we
234 know they are correct. */
238 #define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
239 #define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
241 #ifdef HAVE_SYS_WAIT_H
242 #include <sys/wait.h>
246 #define WIFSIGNALED(S) (((S) & 0xff) != 0 && ((S) & 0xff) != 0x7f)
249 #define WTERMSIG(S) ((S) & 0x7f)
252 #define WIFEXITED(S) (((S) & 0xff) == 0)
255 #define WEXITSTATUS(S) (((S) & 0xff00) >> 8)
258 #define WSTOPSIG WEXITSTATUS
265 # ifdef NEED_DECLARATION_BCOPY
266 extern void bcopy ();
268 # else /* ! HAVE_BCOPY */
269 # define bcopy(src,dst,len) memmove((dst),(src),(len))
275 # ifdef NEED_DECLARATION_BCMP
278 # else /* ! HAVE_BCMP */
279 # define bcmp(left,right,len) memcmp ((left),(right),(len))
285 # ifdef NEED_DECLARATION_BZERO
286 extern void bzero ();
288 # else /* ! HAVE_BZERO */
289 # define bzero(dst,len) memset ((dst),0,(len))
295 # ifdef NEED_DECLARATION_INDEX
296 extern char *index ();
298 # else /* ! HAVE_INDEX */
299 # define index strchr
305 # ifdef NEED_DECLARATION_RINDEX
306 extern char *rindex ();
308 # else /* ! HAVE_RINDEX */
309 # define rindex strrchr
313 #ifdef NEED_DECLARATION_ATOF
314 extern double atof ();
317 #ifdef NEED_DECLARATION_ATOL
321 #ifdef NEED_DECLARATION_FREE
325 #ifdef NEED_DECLARATION_GETCWD
326 extern char *getcwd ();
329 #ifdef NEED_DECLARATION_GETENV
330 extern char *getenv ();
333 #ifdef NEED_DECLARATION_GETWD
334 extern char *getwd ();
337 #ifdef NEED_DECLARATION_SBRK
338 extern char *sbrk ();
341 #ifdef NEED_DECLARATION_STRSTR
342 extern char *strstr ();
346 # ifdef NEED_DECLARATION_STRERROR
348 extern char *strerror ();
351 #else /* ! HAVE_STRERROR */
353 extern char *sys_errlist[];
354 #endif /* HAVE_STRERROR */
356 #ifdef HAVE_STRSIGNAL
357 # ifdef NEED_DECLARATION_STRSIGNAL
359 extern char * strsignal ();
362 #else /* ! HAVE_STRSIGNAL */
363 # ifndef SYS_SIGLIST_DECLARED
364 # ifndef NO_SYS_SIGLIST
365 extern char * sys_siglist[];
368 #endif /* HAVE_STRSIGNAL */
370 #ifdef HAVE_GETRLIMIT
371 # ifdef NEED_DECLARATION_GETRLIMIT
373 extern int getrlimit ();
378 #ifdef HAVE_SETRLIMIT
379 # ifdef NEED_DECLARATION_SETRLIMIT
381 extern int setrlimit ();
386 /* HAVE_VOLATILE only refers to the stage1 compiler. We also check
387 __STDC__ and assume gcc sets it and has volatile in stage >=2. */
388 #if !defined(HAVE_VOLATILE) && !defined(__STDC__) && !defined(volatile)
392 /* Redefine abort to report an internal error w/o coredump, and reporting the
393 location of the error in the source file.
394 Some files undefine abort again, so we must prototype the real thing
396 #ifdef NEED_DECLARATION_ABORT
397 extern void abort ();
399 extern void fatal PVPROTO((const char *, ...)) ATTRIBUTE_PRINTF_1 ATTRIBUTE_NORETURN;
401 #if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
402 #define abort() fatal ("Internal compiler error at %s:%d\n", \
403 trim_filename (__FILE__), __LINE__)
405 #define abort() fatal ("Internal compiler error in `%s', at %s:%d\n" \
406 "Please submit a full bug report.\n" \
407 "See %s for instructions.", \
408 __PRETTY_FUNCTION__, trim_filename (__FILE__), __LINE__, GCCBUGURL)
409 #endif /* recent gcc */
411 /* trim_filename is in toplev.c. Define a stub macro for files that
412 don't link toplev.c. toplev.h will reset it to the real version. */
413 #define trim_filename(x) (x)
415 /* Define a STRINGIFY macro that's right for ANSI or traditional C.
416 HAVE_CPP_STRINGIFY only refers to the stage1 compiler. Assume that
417 (non-traditional) gcc used in stage2 or later has this feature.
419 Note: if the argument passed to STRINGIFY is itself a macro, eg
420 #define foo bar, STRINGIFY(foo) will produce "foo", not "bar".
421 Although the __STDC__ case could be made to expand this via a layer
422 of indirection, the traditional C case can not do so. Therefore
423 this behavior is not supported. */
425 # if defined(HAVE_CPP_STRINGIFY) || (defined(__GNUC__) && defined(__STDC__))
426 # define STRINGIFY(STRING) #STRING
428 # define STRINGIFY(STRING) "STRING"
430 #endif /* ! STRINGIFY */
433 # include <sys/stat.h>
436 /* Test if something is a normal file. */
438 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
441 /* Test if something is a directory. */
443 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
446 /* Test if something is a character special file. */
448 #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
451 /* Test if something is a socket. */
454 # define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
456 # define S_ISSOCK(m) 0
460 /* Test if something is a FIFO. */
463 # define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
465 # define S_ISFIFO(m) 0
469 /* Approximate O_NONBLOCK. */
471 #define O_NONBLOCK O_NDELAY
474 /* Approximate O_NOCTTY. */
479 /* Define well known filenos if the system does not define them. */
481 # define STDIN_FILENO 0
483 #ifndef STDOUT_FILENO
484 # define STDOUT_FILENO 1
486 #ifndef STDERR_FILENO
487 # define STDERR_FILENO 2
490 /* Some systems have mkdir that takes a single argument. */
491 #ifdef MKDIR_TAKES_ONE_ARG
492 # define mkdir(a,b) mkdir(a)
495 /* Get libiberty declarations. */
496 #include "libiberty.h"
498 #endif /* __GCC_SYSTEM_H__ */