1 /* Get common system includes and various definitions and declarations based
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. */
23 #ifndef __GCC_SYSTEM_H__
24 #define __GCC_SYSTEM_H__
26 /* We must include stdarg.h/varargs.h before stdio.h. */
27 #ifdef ANSI_PROTOTYPES
35 /* Define a generic NULL if one hasn't already been defined. */
40 /* The compiler is not a multi-threaded application and therefore we
41 do not have to use the locking functions.
43 NEED_DECLARATION_PUTC_UNLOCKED actually indicates whether or not
44 the IO code is multi-thread safe by default. If it is not declared,
45 then do not worry about using the _unlocked functions.
47 fputs_unlocked is an extension and needs to be prototyped specially. */
49 #if defined HAVE_PUTC_UNLOCKED && !defined NEED_DECLARATION_PUTC_UNLOCKED
51 # define putc(C, Stream) putc_unlocked (C, Stream)
53 #if defined HAVE_FPUTC_UNLOCKED && !defined NEED_DECLARATION_PUTC_UNLOCKED
55 # define fputc(C, Stream) fputc_unlocked (C, Stream)
57 #if defined HAVE_FPUTS_UNLOCKED && !defined NEED_DECLARATION_PUTC_UNLOCKED
59 # define fputs(String, Stream) fputs_unlocked (String, Stream)
60 # ifdef NEED_DECLARATION_FPUTS_UNLOCKED
61 extern int fputs_unlocked PROTO ((const char *, FILE *));
67 /* Jim Meyering writes:
69 "... Some ctype macros are valid only for character codes that
70 isascii says are ASCII (SGI's IRIX-4.0.5 is one such system --when
71 using /bin/cc or gcc but without giving an ansi option). So, all
72 ctype uses should be through macros like ISPRINT... If
73 STDC_HEADERS is defined, then autoconf has verified that the ctype
74 macros don't need to be guarded with references to isascii. ...
75 Defining isascii to 1 should let any compiler worth its salt
76 eliminate the && through constant folding."
80 "... Furthermore, isupper(c) etc. have an undefined result if c is
81 outside the range -1 <= c <= 255. One is tempted to write isupper(c)
82 with c being of type `char', but this is wrong if c is an 8-bit
83 character >= 128 which gets sign-extended to a negative value.
84 The macro ISUPPER protects against this as well." */
86 #if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII))
87 # define IN_CTYPE_DOMAIN(c) 1
89 # define IN_CTYPE_DOMAIN(c) isascii(c)
93 # define ISBLANK(c) (IN_CTYPE_DOMAIN (c) && isblank (c))
95 # define ISBLANK(c) ((c) == ' ' || (c) == '\t')
98 # define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isgraph (c))
100 # define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isprint (c) && !isspace (c))
103 #define ISPRINT(c) (IN_CTYPE_DOMAIN (c) && isprint (c))
104 #define ISALNUM(c) (IN_CTYPE_DOMAIN (c) && isalnum (c))
105 #define ISALPHA(c) (IN_CTYPE_DOMAIN (c) && isalpha (c))
106 #define ISCNTRL(c) (IN_CTYPE_DOMAIN (c) && iscntrl (c))
107 #define ISLOWER(c) (IN_CTYPE_DOMAIN (c) && islower (c))
108 #define ISPUNCT(c) (IN_CTYPE_DOMAIN (c) && ispunct (c))
109 #define ISSPACE(c) (IN_CTYPE_DOMAIN (c) && isspace (c))
110 #define ISUPPER(c) (IN_CTYPE_DOMAIN (c) && isupper (c))
111 #define ISXDIGIT(c) (IN_CTYPE_DOMAIN (c) && isxdigit (c))
112 #define ISDIGIT_LOCALE(c) (IN_CTYPE_DOMAIN (c) && isdigit (c))
114 /* ISDIGIT differs from ISDIGIT_LOCALE, as follows:
115 - Its arg may be any int or unsigned int; it need not be an unsigned char.
116 - It's guaranteed to evaluate its argument exactly once.
117 - It's typically faster.
118 Posix 1003.2-1992 section 2.5.2.1 page 50 lines 1556-1558 says that
119 only '0' through '9' are digits. Prefer ISDIGIT to ISDIGIT_LOCALE unless
120 it's important to use the locale's definition of `digit' even when the
121 host does not conform to Posix. */
122 #define ISDIGIT(c) ((unsigned) (c) - '0' <= 9)
125 #ifdef HAVE_SYS_TYPES_H
126 #include <sys/types.h>
135 #ifdef STRING_WITH_STRINGS
137 # include <strings.h>
139 # ifdef HAVE_STRING_H
142 # ifdef HAVE_STRINGS_H
143 # include <strings.h>
156 #ifdef HAVE_SYS_PARAM_H
157 # include <sys/param.h>
164 /* Find HOST_WIDEST_INT and set its bit size, type and print macros.
165 It will be the largest integer mode supported by the host which may
166 (or may not) be larger than HOST_WIDE_INT. This must appear after
167 <limits.h> since we only use `long long' if its bigger than a
168 `long' and also if it is supported by macros in limits.h. For old
169 hosts which don't have a limits.h (and thus won't include it in
170 stage2 cause we don't rerun configure) we assume gcc supports long
171 long.) Note, you won't get these defined if you don't include
172 {ht}config.h before this file to set the HOST_BITS_PER_* macros. */
174 #ifndef HOST_WIDEST_INT
175 # if defined (HOST_BITS_PER_LONG) && defined (HOST_BITS_PER_LONGLONG)
176 # if (HOST_BITS_PER_LONGLONG > HOST_BITS_PER_LONG) && (defined (LONG_LONG_MAX) || defined (LONGLONG_MAX) || defined (LLONG_MAX) || defined (__GNUC__))
177 # define HOST_BITS_PER_WIDEST_INT HOST_BITS_PER_LONGLONG
178 # define HOST_WIDEST_INT long long
179 # define HOST_WIDEST_INT_PRINT_DEC "%lld"
180 # define HOST_WIDEST_INT_PRINT_UNSIGNED "%llu"
181 # define HOST_WIDEST_INT_PRINT_HEX "0x%llx"
183 # define HOST_BITS_PER_WIDEST_INT HOST_BITS_PER_LONG
184 # define HOST_WIDEST_INT long
185 # define HOST_WIDEST_INT_PRINT_DEC "%ld"
186 # define HOST_WIDEST_INT_PRINT_UNSIGNED "%lu"
187 # define HOST_WIDEST_INT_PRINT_HEX "0x%lx"
188 # endif /*(long long>long) && (LONG_LONG_MAX||LONGLONG_MAX||LLONG_MAX||GNUC)*/
189 # endif /* defined(HOST_BITS_PER_LONG) && defined(HOST_BITS_PER_LONGLONG) */
190 #endif /* ! HOST_WIDEST_INT */
192 #ifdef TIME_WITH_SYS_TIME
193 # include <sys/time.h>
197 # include <sys/time.h>
208 # ifdef HAVE_SYS_FILE_H
209 # include <sys/file.h>
231 /* Some systems define these in, e.g., param.h. We undefine these names
232 here to avoid the warnings. We prefer to use our definitions since we
233 know they are correct. */
237 #define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
238 #define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
240 #ifdef HAVE_SYS_WAIT_H
241 #include <sys/wait.h>
245 #define WIFSIGNALED(S) (((S) & 0xff) != 0 && ((S) & 0xff) != 0x7f)
248 #define WTERMSIG(S) ((S) & 0x7f)
251 #define WIFEXITED(S) (((S) & 0xff) == 0)
254 #define WEXITSTATUS(S) (((S) & 0xff00) >> 8)
257 #define WSTOPSIG WEXITSTATUS
264 # ifdef NEED_DECLARATION_BCOPY
265 extern void bcopy ();
267 # else /* ! HAVE_BCOPY */
268 # define bcopy(src,dst,len) memmove((dst),(src),(len))
274 # ifdef NEED_DECLARATION_BCMP
277 # else /* ! HAVE_BCMP */
278 # define bcmp(left,right,len) memcmp ((left),(right),(len))
284 # ifdef NEED_DECLARATION_BZERO
285 extern void bzero ();
287 # else /* ! HAVE_BZERO */
288 # define bzero(dst,len) memset ((dst),0,(len))
294 # ifdef NEED_DECLARATION_INDEX
295 extern char *index ();
297 # else /* ! HAVE_INDEX */
298 # define index strchr
304 # ifdef NEED_DECLARATION_RINDEX
305 extern char *rindex ();
307 # else /* ! HAVE_RINDEX */
308 # define rindex strrchr
312 #ifdef NEED_DECLARATION_ATOF
313 extern double atof ();
316 #ifdef NEED_DECLARATION_ATOL
320 #ifdef NEED_DECLARATION_FREE
324 #ifdef NEED_DECLARATION_GETCWD
325 extern char *getcwd ();
328 #ifdef NEED_DECLARATION_GETENV
329 extern char *getenv ();
332 #ifdef NEED_DECLARATION_GETWD
333 extern char *getwd ();
336 #ifdef NEED_DECLARATION_SBRK
337 extern char *sbrk ();
340 #ifdef NEED_DECLARATION_STRSTR
341 extern char *strstr ();
348 #ifdef NEED_DECLARATION_MALLOC
349 extern char *malloc ();
352 #ifdef NEED_DECLARATION_CALLOC
353 extern char *calloc ();
356 #ifdef NEED_DECLARATION_REMALLOC
357 extern char *realloc ();
361 # ifdef NEED_DECLARATION_STRERROR
363 extern char *strerror ();
366 #else /* ! HAVE_STRERROR */
368 extern char *sys_errlist[];
369 #endif /* HAVE_STRERROR */
371 #ifdef HAVE_STRSIGNAL
372 # ifdef NEED_DECLARATION_STRSIGNAL
374 extern char * strsignal ();
377 #else /* ! HAVE_STRSIGNAL */
378 # ifndef SYS_SIGLIST_DECLARED
379 # ifndef NO_SYS_SIGLIST
380 extern char * sys_siglist[];
383 #endif /* HAVE_STRSIGNAL */
385 #ifdef HAVE_GETRLIMIT
386 # ifdef NEED_DECLARATION_GETRLIMIT
388 extern int getrlimit ();
393 #ifdef HAVE_SETRLIMIT
394 # ifdef NEED_DECLARATION_SETRLIMIT
396 extern int setrlimit ();
401 /* HAVE_VOLATILE only refers to the stage1 compiler. We also check
402 __STDC__ and assume gcc sets it and has volatile in stage >=2. */
403 #if !defined(HAVE_VOLATILE) && !defined(__STDC__) && !defined(volatile)
407 #ifdef NEED_DECLARATION_ABORT
408 extern void abort ();
411 /* Define a STRINGIFY macro that's right for ANSI or traditional C.
412 HAVE_CPP_STRINGIFY only refers to the stage1 compiler. Assume that
413 (non-traditional) gcc used in stage2 or later has this feature.
415 Note: if the argument passed to STRINGIFY is itself a macro, eg
416 #define foo bar, STRINGIFY(foo) will produce "foo", not "bar".
417 Although the __STDC__ case could be made to expand this via a layer
418 of indirection, the traditional C case can not do so. Therefore
419 this behavior is not supported. */
421 # if defined(HAVE_CPP_STRINGIFY) || (defined(__GNUC__) && defined(__STDC__))
422 # define STRINGIFY(STRING) #STRING
424 # define STRINGIFY(STRING) "STRING"
426 #endif /* ! STRINGIFY */
429 # include <sys/stat.h>
432 /* Test if something is a normal file. */
434 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
437 /* Test if something is a directory. */
439 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
442 /* Test if something is a character special file. */
444 #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
447 /* Test if something is a socket. */
450 # define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
452 # define S_ISSOCK(m) 0
456 /* Test if something is a FIFO. */
459 # define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
461 # define S_ISFIFO(m) 0
465 /* Approximate O_NONBLOCK. */
467 #define O_NONBLOCK O_NDELAY
470 /* Approximate O_NOCTTY. */
475 /* Define well known filenos if the system does not define them. */
477 # define STDIN_FILENO 0
479 #ifndef STDOUT_FILENO
480 # define STDOUT_FILENO 1
482 #ifndef STDERR_FILENO
483 # define STDERR_FILENO 2
486 /* Some systems have mkdir that takes a single argument. */
487 #ifdef MKDIR_TAKES_ONE_ARG
488 # define mkdir(a,b) mkdir(a)
491 /* Get libiberty declarations. */
492 #include "libiberty.h"
494 #endif /* __GCC_SYSTEM_H__ */