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 /* 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)) || defined(HOST_EBCDIC)
87 # define IN_CTYPE_DOMAIN(c) 1
89 # define IN_CTYPE_DOMAIN(c) isascii(c)
92 /* The ctype functions are often implemented as macros which do
93 lookups in arrays using the parameter as the offset. If the ctype
94 function parameter is a char, then gcc will (appropriately) warn
95 that a "subscript has type char". Using a (signed) char as a subscript
96 is bad because you may get negative offsets and thus it is not 8-bit
97 safe. The CTYPE_CONV macro ensures that the parameter is cast to an
98 unsigned char when a char is passed in. When an int is passed in, the
99 parameter is left alone so we don't lose EOF.
102 #define CTYPE_CONV(CH) \
103 (sizeof(CH) == sizeof(unsigned char) ? (int)(unsigned char)(CH) : (int)(CH))
106 /* WARNING! The argument to the ctype replacement macros below is
107 evaluated more than once so it must not have side effects! */
110 # define ISBLANK(c) (IN_CTYPE_DOMAIN (c) && isblank (CTYPE_CONV(c)))
112 # define ISBLANK(c) ((c) == ' ' || (c) == '\t')
115 # define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isgraph (CTYPE_CONV(c)))
117 # define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isprint (CTYPE_CONV(c)) && !isspace (CTYPE_CONV(c)))
120 #define ISPRINT(c) (IN_CTYPE_DOMAIN (c) && isprint (CTYPE_CONV(c)))
121 #define ISALNUM(c) (IN_CTYPE_DOMAIN (c) && isalnum (CTYPE_CONV(c)))
122 #define ISALPHA(c) (IN_CTYPE_DOMAIN (c) && isalpha (CTYPE_CONV(c)))
123 #define ISCNTRL(c) (IN_CTYPE_DOMAIN (c) && iscntrl (CTYPE_CONV(c)))
124 #define ISLOWER(c) (IN_CTYPE_DOMAIN (c) && islower (CTYPE_CONV(c)))
125 #define ISPUNCT(c) (IN_CTYPE_DOMAIN (c) && ispunct (CTYPE_CONV(c)))
126 #define ISSPACE(c) (IN_CTYPE_DOMAIN (c) && isspace (CTYPE_CONV(c)))
127 #define ISUPPER(c) (IN_CTYPE_DOMAIN (c) && isupper (CTYPE_CONV(c)))
128 #define ISXDIGIT(c) (IN_CTYPE_DOMAIN (c) && isxdigit (CTYPE_CONV(c)))
129 #define ISDIGIT_LOCALE(c) (IN_CTYPE_DOMAIN (c) && isdigit (CTYPE_CONV(c)))
132 # define TOLOWER(c) (tolower (CTYPE_CONV(c)))
133 # define TOUPPER(c) (toupper (CTYPE_CONV(c)))
135 # define TOLOWER(c) (ISUPPER (c) ? tolower (CTYPE_CONV(c)) : (c))
136 # define TOUPPER(c) (ISLOWER (c) ? toupper (CTYPE_CONV(c)) : (c))
139 /* ISDIGIT differs from ISDIGIT_LOCALE, as follows:
140 - Its arg may be any int or unsigned int; it need not be an unsigned char.
141 - It's guaranteed to evaluate its argument exactly once.
142 - It's typically faster.
143 Posix 1003.2-1992 section 2.5.2.1 page 50 lines 1556-1558 says that
144 only '0' through '9' are digits. Prefer ISDIGIT to ISDIGIT_LOCALE unless
145 it's important to use the locale's definition of `digit' even when the
146 host does not conform to Posix. */
147 #define ISDIGIT(c) ((unsigned) (c) - '0' <= 9)
149 /* Define a default escape character; its different for EBCDIC. */
151 #define TARGET_ESC 033
154 #ifdef HAVE_SYS_TYPES_H
155 #include <sys/types.h>
164 #ifdef STRING_WITH_STRINGS
166 # include <strings.h>
168 # ifdef HAVE_STRING_H
171 # ifdef HAVE_STRINGS_H
172 # include <strings.h>
185 #ifdef HAVE_SYS_PARAM_H
186 # include <sys/param.h>
193 /* Find HOST_WIDEST_INT and set its bit size, type and print macros.
194 It will be the largest integer mode supported by the host which may
195 (or may not) be larger than HOST_WIDE_INT. This must appear after
196 <limits.h> since we only use `long long' if its bigger than a
197 `long' and also if it is supported by macros in limits.h. For old
198 hosts which don't have a limits.h (and thus won't include it in
199 stage2 cause we don't rerun configure) we assume gcc supports long
200 long.) Note, you won't get these defined if you don't include
201 {ht}config.h before this file to set the HOST_BITS_PER_* macros. */
203 #ifndef HOST_WIDEST_INT
204 # if defined (HOST_BITS_PER_LONG) && defined (HOST_BITS_PER_LONGLONG)
205 # if (HOST_BITS_PER_LONGLONG > HOST_BITS_PER_LONG) && (defined (LONG_LONG_MAX) || defined (LONGLONG_MAX) || defined (LLONG_MAX) || defined (__GNUC__))
206 # define HOST_BITS_PER_WIDEST_INT HOST_BITS_PER_LONGLONG
207 # define HOST_WIDEST_INT long long
208 # define HOST_WIDEST_INT_PRINT_DEC "%lld"
209 # define HOST_WIDEST_INT_PRINT_UNSIGNED "%llu"
210 # define HOST_WIDEST_INT_PRINT_HEX "0x%llx"
212 # define HOST_BITS_PER_WIDEST_INT HOST_BITS_PER_LONG
213 # define HOST_WIDEST_INT long
214 # define HOST_WIDEST_INT_PRINT_DEC "%ld"
215 # define HOST_WIDEST_INT_PRINT_UNSIGNED "%lu"
216 # define HOST_WIDEST_INT_PRINT_HEX "0x%lx"
217 # endif /*(long long>long) && (LONG_LONG_MAX||LONGLONG_MAX||LLONG_MAX||GNUC)*/
218 # endif /* defined(HOST_BITS_PER_LONG) && defined(HOST_BITS_PER_LONGLONG) */
219 #endif /* ! HOST_WIDEST_INT */
221 #ifdef TIME_WITH_SYS_TIME
222 # include <sys/time.h>
226 # include <sys/time.h>
237 # ifdef HAVE_SYS_FILE_H
238 # include <sys/file.h>
260 /* Some systems define these in, e.g., param.h. We undefine these names
261 here to avoid the warnings. We prefer to use our definitions since we
262 know they are correct. */
266 #define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
267 #define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
269 /* Returns the least number N such that N * Y >= X. */
270 #define CEIL(x,y) (((x) + (y) - 1) / (y))
272 #ifdef HAVE_SYS_WAIT_H
273 #include <sys/wait.h>
277 #define WIFSIGNALED(S) (((S) & 0xff) != 0 && ((S) & 0xff) != 0x7f)
280 #define WTERMSIG(S) ((S) & 0x7f)
283 #define WIFEXITED(S) (((S) & 0xff) == 0)
286 #define WEXITSTATUS(S) (((S) & 0xff00) >> 8)
289 #define WSTOPSIG WEXITSTATUS
296 # ifdef NEED_DECLARATION_BCOPY
297 extern void bcopy PARAMS ((const PTR, PTR, size_t));
299 # else /* ! HAVE_BCOPY */
300 # define bcopy(src,dst,len) memmove((dst),(src),(len))
306 # ifdef NEED_DECLARATION_BCMP
307 extern int bcmp PARAMS ((const PTR, const PTR, size_t));
309 # else /* ! HAVE_BCMP */
310 # define bcmp(left,right,len) memcmp ((left),(right),(len))
316 # ifdef NEED_DECLARATION_BZERO
317 extern void bzero PARAMS ((PTR, size_t));
319 # else /* ! HAVE_BZERO */
320 # define bzero(dst,len) memset ((dst),0,(len))
326 # ifdef NEED_DECLARATION_INDEX
327 extern char *index PARAMS ((const char *, int));
329 # else /* ! HAVE_INDEX */
330 # define index strchr
336 # ifdef NEED_DECLARATION_RINDEX
337 extern char *rindex PARAMS ((const char *, int));
339 # else /* ! HAVE_RINDEX */
340 # define rindex strrchr
344 #ifdef NEED_DECLARATION_ATOF
345 extern double atof PARAMS ((const char *));
348 #ifdef NEED_DECLARATION_ATOL
349 extern long atol PARAMS ((const char *));
352 #ifdef NEED_DECLARATION_FREE
353 extern void free PARAMS ((PTR));
356 #ifdef NEED_DECLARATION_GETCWD
357 extern char *getcwd PARAMS ((char *, size_t));
360 #ifdef NEED_DECLARATION_GETENV
361 extern char *getenv PARAMS ((const char *));
364 #ifdef NEED_DECLARATION_GETWD
365 extern char *getwd PARAMS ((char *));
368 #ifdef NEED_DECLARATION_SBRK
369 extern PTR sbrk PARAMS ((int));
372 #ifdef NEED_DECLARATION_STRSTR
373 extern char *strstr PARAMS ((const char *, const char *));
380 #ifdef NEED_DECLARATION_MALLOC
381 extern PTR malloc PARAMS ((size_t));
384 #ifdef NEED_DECLARATION_CALLOC
385 extern PTR calloc PARAMS ((size_t, size_t));
388 #ifdef NEED_DECLARATION_REALLOC
389 extern PTR realloc PARAMS ((PTR, size_t));
393 # ifdef NEED_DECLARATION_STRERROR
395 extern char *strerror PARAMS ((int));
398 #else /* ! HAVE_STRERROR */
400 extern char *sys_errlist[];
401 #endif /* HAVE_STRERROR */
403 /* If the system doesn't provide strsignal, we get it defined in
404 libiberty but no declaration is supplied. */
405 #ifdef NEED_DECLARATION_STRSIGNAL
407 extern const char *strsignal PARAMS ((int));
411 #ifdef HAVE_GETRLIMIT
412 # ifdef NEED_DECLARATION_GETRLIMIT
414 # ifdef ANSI_PROTOTYPES
417 extern int getrlimit PARAMS ((int, struct rlimit *));
422 #ifdef HAVE_SETRLIMIT
423 # ifdef NEED_DECLARATION_SETRLIMIT
425 # ifdef ANSI_PROTOTYPES
428 extern int setrlimit PARAMS ((int, const struct rlimit *));
433 /* HAVE_VOLATILE only refers to the stage1 compiler. We also check
434 __STDC__ and assume gcc sets it and has volatile in stage >=2. */
435 #if !defined(HAVE_VOLATILE) && !defined(__STDC__) && !defined(volatile)
439 #ifdef NEED_DECLARATION_ABORT
440 extern void abort PARAMS ((void));
443 /* Define a STRINGIFY macro that's right for ANSI or traditional C.
444 Note: if the argument passed to STRINGIFY is itself a macro, eg
445 #define foo bar, STRINGIFY(foo) will produce "foo", not "bar".
446 Although the __STDC__ case could be made to expand this via a layer
447 of indirection, the traditional C case can not do so. Therefore
448 this behavior is not supported. */
450 # ifdef HAVE_STRINGIZE
451 # define STRINGIFY(STRING) #STRING
453 # define STRINGIFY(STRING) "STRING"
455 #endif /* ! STRINGIFY */
458 # include <sys/stat.h>
461 /* Test if something is a normal file. */
463 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
466 /* Test if something is a directory. */
468 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
471 /* Test if something is a character special file. */
473 #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
476 /* Test if something is a socket. */
479 # define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
481 # define S_ISSOCK(m) 0
485 /* Test if something is a FIFO. */
488 # define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
490 # define S_ISFIFO(m) 0
494 /* Approximate O_NONBLOCK. */
496 #define O_NONBLOCK O_NDELAY
499 /* Approximate O_NOCTTY. */
504 /* Define well known filenos if the system does not define them. */
506 # define STDIN_FILENO 0
508 #ifndef STDOUT_FILENO
509 # define STDOUT_FILENO 1
511 #ifndef STDERR_FILENO
512 # define STDERR_FILENO 2
515 /* Some systems have mkdir that takes a single argument. */
516 #ifdef MKDIR_TAKES_ONE_ARG
517 # define mkdir(a,b) mkdir(a)
520 /* Provide a way to print an address via printf. */
521 #ifndef HOST_PTR_PRINTF
522 # ifdef HAVE_PRINTF_PTR
523 # define HOST_PTR_PRINTF "%p"
525 # define HOST_PTR_PRINTF \
526 (sizeof (int) == sizeof (char *) ? "%x" \
527 : sizeof (long) == sizeof (char *) ? "%lx" : "%llx")
529 #endif /* ! HOST_PTR_PRINTF */
531 /* Get libiberty declarations. */
532 #include "libiberty.h"
534 #endif /* __GCC_SYSTEM_H__ */