1 /* system.h - Get common system includes and various definitions and
2 declarations based on autoconf macros.
3 Copyright (C) 1998, 1999 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 /* We must include stdarg.h/varargs.h before stdio.h. */
26 #ifdef ANSI_PROTOTYPES
34 /* Define a generic NULL if one hasn't already been defined. */
39 /* The compiler is not a multi-threaded application and therefore we
40 do not have to use the locking functions.
42 NEED_DECLARATION_PUTC_UNLOCKED actually indicates whether or not
43 the IO code is multi-thread safe by default. If it is not declared,
44 then do not worry about using the _unlocked functions.
46 fputs_unlocked is an extension and needs to be prototyped specially. */
48 #if defined HAVE_PUTC_UNLOCKED && !defined NEED_DECLARATION_PUTC_UNLOCKED
50 # define putc(C, Stream) putc_unlocked (C, Stream)
52 #if defined HAVE_FPUTC_UNLOCKED && !defined NEED_DECLARATION_PUTC_UNLOCKED
54 # define fputc(C, Stream) fputc_unlocked (C, Stream)
56 #if defined HAVE_FPUTS_UNLOCKED && !defined NEED_DECLARATION_PUTC_UNLOCKED
58 # define fputs(String, Stream) fputs_unlocked (String, Stream)
59 # ifdef NEED_DECLARATION_FPUTS_UNLOCKED
60 extern int fputs_unlocked
PROTO ((const char *, FILE *));
66 /* Jim Meyering writes:
68 "... Some ctype macros are valid only for character codes that
69 isascii says are ASCII (SGI's IRIX-4.0.5 is one such system --when
70 using /bin/cc or gcc but without giving an ansi option). So, all
71 ctype uses should be through macros like ISPRINT... If
72 STDC_HEADERS is defined, then autoconf has verified that the ctype
73 macros don't need to be guarded with references to isascii. ...
74 Defining isascii to 1 should let any compiler worth its salt
75 eliminate the && through constant folding."
79 "... Furthermore, isupper(c) etc. have an undefined result if c is
80 outside the range -1 <= c <= 255. One is tempted to write isupper(c)
81 with c being of type `char', but this is wrong if c is an 8-bit
82 character >= 128 which gets sign-extended to a negative value.
83 The macro ISUPPER protects against this as well." */
85 #if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII))
86 # define IN_CTYPE_DOMAIN(c) 1
88 # define IN_CTYPE_DOMAIN(c) isascii(c)
92 # define ISBLANK(c) (IN_CTYPE_DOMAIN (c) && isblank (c))
94 # define ISBLANK(c) ((c) == ' ' || (c) == '\t')
97 # define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isgraph (c))
99 # define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isprint (c) && !isspace (c))
102 #define ISPRINT(c) (IN_CTYPE_DOMAIN (c) && isprint (c))
103 #define ISALNUM(c) (IN_CTYPE_DOMAIN (c) && isalnum (c))
104 #define ISALPHA(c) (IN_CTYPE_DOMAIN (c) && isalpha (c))
105 #define ISCNTRL(c) (IN_CTYPE_DOMAIN (c) && iscntrl (c))
106 #define ISLOWER(c) (IN_CTYPE_DOMAIN (c) && islower (c))
107 #define ISPUNCT(c) (IN_CTYPE_DOMAIN (c) && ispunct (c))
108 #define ISSPACE(c) (IN_CTYPE_DOMAIN (c) && isspace (c))
109 #define ISUPPER(c) (IN_CTYPE_DOMAIN (c) && isupper (c))
110 #define ISXDIGIT(c) (IN_CTYPE_DOMAIN (c) && isxdigit (c))
111 #define ISDIGIT_LOCALE(c) (IN_CTYPE_DOMAIN (c) && isdigit (c))
113 /* ISDIGIT differs from ISDIGIT_LOCALE, as follows:
114 - Its arg may be any int or unsigned int; it need not be an unsigned char.
115 - It's guaranteed to evaluate its argument exactly once.
116 - It's typically faster.
117 Posix 1003.2-1992 section 2.5.2.1 page 50 lines 1556-1558 says that
118 only '0' through '9' are digits. Prefer ISDIGIT to ISDIGIT_LOCALE unless
119 it's important to use the locale's definition of `digit' even when the
120 host does not conform to Posix. */
121 #define ISDIGIT(c) ((unsigned) (c) - '0' <= 9)
124 #include <sys/types.h>
131 #ifdef STRING_WITH_STRINGS
133 # include <strings.h>
135 # ifdef HAVE_STRING_H
138 # ifdef HAVE_STRINGS_H
139 # include <strings.h>
152 #ifdef HAVE_SYS_PARAM_H
153 # include <sys/param.h>
160 /* Find HOST_WIDEST_INT and set its bit size, type and print macros.
161 It will be the largest integer mode supported by the host which may
162 (or may not) be larger than HOST_WIDE_INT. This must appear after
163 <limits.h> since we only use `long long' if its bigger than a
164 `long' and also if it is supported by macros in limits.h. For old
165 hosts which don't have a limits.h (and thus won't include it in
166 stage2 cause we don't rerun configure) we assume gcc supports long
167 long.) Note, you won't get these defined if you don't include
168 {ht}config.h before this file to set the HOST_BITS_PER_* macros. */
170 #ifndef HOST_WIDEST_INT
171 # if defined (HOST_BITS_PER_LONG) && defined (HOST_BITS_PER_LONGLONG)
172 # if (HOST_BITS_PER_LONGLONG > HOST_BITS_PER_LONG) && (defined (LONG_LONG_MAX) || defined (LONGLONG_MAX) || defined (LLONG_MAX) || defined (__GNUC__))
173 # define HOST_BITS_PER_WIDEST_INT HOST_BITS_PER_LONGLONG
174 # define HOST_WIDEST_INT long long
175 # define HOST_WIDEST_INT_PRINT_DEC "%lld"
176 # define HOST_WIDEST_INT_PRINT_UNSIGNED "%llu"
177 # define HOST_WIDEST_INT_PRINT_HEX "0x%llx"
179 # define HOST_BITS_PER_WIDEST_INT HOST_BITS_PER_LONG
180 # define HOST_WIDEST_INT long
181 # define HOST_WIDEST_INT_PRINT_DEC "%ld"
182 # define HOST_WIDEST_INT_PRINT_UNSIGNED "%lu"
183 # define HOST_WIDEST_INT_PRINT_HEX "0x%lx"
184 # endif /*(long long>long) && (LONG_LONG_MAX||LONGLONG_MAX||LLONG_MAX||GNUC)*/
185 # endif /* defined(HOST_BITS_PER_LONG) && defined(HOST_BITS_PER_LONGLONG) */
186 #endif /* ! HOST_WIDEST_INT */
188 #ifdef TIME_WITH_SYS_TIME
189 # include <sys/time.h>
193 # include <sys/time.h>
204 # ifdef HAVE_SYS_FILE_H
205 # include <sys/file.h>
227 /* Some systems define these in, e.g., param.h. We undefine these names
228 here to avoid the warnings. We prefer to use our definitions since we
229 know they are correct. */
233 #define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
234 #define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
236 #ifdef HAVE_SYS_WAIT_H
237 #include <sys/wait.h>
241 #define WIFSIGNALED(S) (((S) & 0xff) != 0 && ((S) & 0xff) != 0x7f)
244 #define WTERMSIG(S) ((S) & 0x7f)
247 #define WIFEXITED(S) (((S) & 0xff) == 0)
250 #define WEXITSTATUS(S) (((S) & 0xff00) >> 8)
253 #define WSTOPSIG WEXITSTATUS
260 # ifdef NEED_DECLARATION_BCOPY
261 extern void bcopy ();
263 # else /* ! HAVE_BCOPY */
264 # define bcopy(src,dst,len) memmove((dst),(src),(len))
270 # ifdef NEED_DECLARATION_BCMP
273 # else /* ! HAVE_BCMP */
274 # define bcmp(left,right,len) memcmp ((left),(right),(len))
280 # ifdef NEED_DECLARATION_BZERO
281 extern void bzero ();
283 # else /* ! HAVE_BZERO */
284 # define bzero(dst,len) memset ((dst),0,(len))
290 # ifdef NEED_DECLARATION_INDEX
291 extern char *index ();
293 # else /* ! HAVE_INDEX */
294 # define index strchr
300 # ifdef NEED_DECLARATION_RINDEX
301 extern char *rindex ();
303 # else /* ! HAVE_RINDEX */
304 # define rindex strrchr
308 #ifdef NEED_DECLARATION_ATOF
309 extern double atof ();
312 #ifdef NEED_DECLARATION_ATOL
316 #ifdef NEED_DECLARATION_FREE
320 #ifdef NEED_DECLARATION_GETCWD
321 extern char *getcwd ();
324 #ifdef NEED_DECLARATION_GETENV
325 extern char *getenv ();
328 #ifdef NEED_DECLARATION_GETWD
329 extern char *getwd ();
332 #ifdef NEED_DECLARATION_SBRK
333 extern char *sbrk ();
336 #ifdef NEED_DECLARATION_STRSTR
337 extern char *strstr ();
341 # ifdef NEED_DECLARATION_STRERROR
343 extern char *strerror ();
346 #else /* ! HAVE_STRERROR */
348 extern char *sys_errlist
[];
349 #endif /* HAVE_STRERROR */
351 #ifdef HAVE_STRSIGNAL
352 # ifdef NEED_DECLARATION_STRSIGNAL
354 extern char * strsignal ();
357 #else /* ! HAVE_STRSIGNAL */
358 # ifndef SYS_SIGLIST_DECLARED
359 # ifndef NO_SYS_SIGLIST
360 extern char * sys_siglist
[];
363 #endif /* HAVE_STRSIGNAL */
365 #ifdef HAVE_GETRLIMIT
366 # ifdef NEED_DECLARATION_GETRLIMIT
368 extern int getrlimit ();
373 #ifdef HAVE_SETRLIMIT
374 # ifdef NEED_DECLARATION_SETRLIMIT
376 extern int setrlimit ();
381 /* HAVE_VOLATILE only refers to the stage1 compiler. We also check
382 __STDC__ and assume gcc sets it and has volatile in stage >=2. */
383 #if !defined(HAVE_VOLATILE) && !defined(__STDC__) && !defined(volatile)
387 /* Redefine abort to report an internal error w/o coredump, and reporting the
388 location of the error in the source file.
389 Some files undefine abort again, so we must prototype the real thing
391 #ifdef NEED_DECLARATION_ABORT
392 extern void abort ();
394 extern void fatal
PVPROTO((const char *, ...)) ATTRIBUTE_PRINTF_1 ATTRIBUTE_NORETURN
;
396 #if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
397 #define abort() fatal ("Internal compiler error at %s:%d\n", \
398 trim_filename (__FILE__), __LINE__)
400 #define abort() fatal ("Internal compiler error in `%s', at %s:%d\n" \
401 "Please submit a full bug report.\n" \
402 "See <URL:http://egcs.cygnus.com/faq.html#bugreport> for instructions.", \
403 __PRETTY_FUNCTION__, trim_filename (__FILE__), __LINE__)
404 #endif /* recent gcc */
406 /* trim_filename is in toplev.c. Define a stub macro for files that
407 don't link toplev.c. toplev.h will reset it to the real version. */
408 #define trim_filename(x) (x)
410 /* Define a STRINGIFY macro that's right for ANSI or traditional C.
411 HAVE_CPP_STRINGIFY only refers to the stage1 compiler. Assume that
412 (non-traditional) gcc used in stage2 or later has this feature.
414 Note: if the argument passed to STRINGIFY is itself a macro, eg
415 #define foo bar, STRINGIFY(foo) will produce "foo", not "bar".
416 Although the __STDC__ case could be made to expand this via a layer
417 of indirection, the traditional C case can not do so. Therefore
418 this behavior is not supported. */
420 # if defined(HAVE_CPP_STRINGIFY) || (defined(__GNUC__) && defined(__STDC__))
421 # define STRINGIFY(STRING) #STRING
423 # define STRINGIFY(STRING) "STRING"
425 #endif /* ! STRINGIFY */
428 # include <sys/stat.h>
431 /* Test if something is a normal file. */
433 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
436 /* Test if something is a directory. */
438 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
441 /* Test if something is a character special file. */
443 #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
446 /* Test if something is a socket. */
449 # define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
451 # define S_ISSOCK(m) 0
455 /* Test if something is a FIFO. */
458 # define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
460 # define S_ISFIFO(m) 0
464 /* Approximate O_NONBLOCK. */
466 #define O_NONBLOCK O_NDELAY
469 /* Approximate O_NOCTTY. */
474 /* Define well known filenos if the system does not define them. */
476 # define STDIN_FILENO 0
478 #ifndef STDOUT_FILENO
479 # define STDOUT_FILENO 1
481 #ifndef STDERR_FILENO
482 # define STDERR_FILENO 2
485 /* Some systems have mkdir that takes a single argument. */
486 #ifdef MKDIR_TAKES_ONE_ARG
487 # define mkdir(a,b) mkdir(a)
490 /* Get libiberty declarations. */
491 #include "libiberty.h"
493 #endif /* __GCC_SYSTEM_H__ */