1 /* system.h - Get common system includes and various definitions and
2 declarations based on autoconf macros.
3 Copyright (C) 1998 Free Software Foundation, Inc.
7 #ifndef __GCC_SYSTEM_H__
8 #define __GCC_SYSTEM_H__
10 /* We must include stdarg.h/varargs.h before stdio.h. */
11 #ifdef ANSI_PROTOTYPES
19 /* Define a generic NULL if one hasn't already been defined. */
24 /* The compiler is not a multi-threaded application and therefore we
25 do not have to use the locking functions. */
26 #ifdef HAVE_PUTC_UNLOCKED
28 # define putc(C, Stream) putc_unlocked (C, Stream)
30 #ifdef HAVE_FPUTC_UNLOCKED
32 # define fputc(C, Stream) fputc_unlocked (C, Stream)
34 #ifdef HAVE_FPUTS_UNLOCKED
36 # define fputs(String, Stream) fputs_unlocked (String, Stream)
41 /* Jim Meyering writes:
43 "... Some ctype macros are valid only for character codes that
44 isascii says are ASCII (SGI's IRIX-4.0.5 is one such system --when
45 using /bin/cc or gcc but without giving an ansi option). So, all
46 ctype uses should be through macros like ISPRINT... If
47 STDC_HEADERS is defined, then autoconf has verified that the ctype
48 macros don't need to be guarded with references to isascii. ...
49 Defining isascii to 1 should let any compiler worth its salt
50 eliminate the && through constant folding."
54 "... Furthermore, isupper(c) etc. have an undefined result if c is
55 outside the range -1 <= c <= 255. One is tempted to write isupper(c)
56 with c being of type `char', but this is wrong if c is an 8-bit
57 character >= 128 which gets sign-extended to a negative value.
58 The macro ISUPPER protects against this as well." */
60 #if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII))
61 # define IN_CTYPE_DOMAIN(c) 1
63 # define IN_CTYPE_DOMAIN(c) isascii(c)
67 # define ISBLANK(c) (IN_CTYPE_DOMAIN (c) && isblank (c))
69 # define ISBLANK(c) ((c) == ' ' || (c) == '\t')
72 # define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isgraph (c))
74 # define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isprint (c) && !isspace (c))
77 #define ISPRINT(c) (IN_CTYPE_DOMAIN (c) && isprint (c))
78 #define ISALNUM(c) (IN_CTYPE_DOMAIN (c) && isalnum (c))
79 #define ISALPHA(c) (IN_CTYPE_DOMAIN (c) && isalpha (c))
80 #define ISCNTRL(c) (IN_CTYPE_DOMAIN (c) && iscntrl (c))
81 #define ISLOWER(c) (IN_CTYPE_DOMAIN (c) && islower (c))
82 #define ISPUNCT(c) (IN_CTYPE_DOMAIN (c) && ispunct (c))
83 #define ISSPACE(c) (IN_CTYPE_DOMAIN (c) && isspace (c))
84 #define ISUPPER(c) (IN_CTYPE_DOMAIN (c) && isupper (c))
85 #define ISXDIGIT(c) (IN_CTYPE_DOMAIN (c) && isxdigit (c))
86 #define ISDIGIT_LOCALE(c) (IN_CTYPE_DOMAIN (c) && isdigit (c))
88 /* ISDIGIT differs from ISDIGIT_LOCALE, as follows:
89 - Its arg may be any int or unsigned int; it need not be an unsigned char.
90 - It's guaranteed to evaluate its argument exactly once.
91 - It's typically faster.
92 Posix 1003.2-1992 section 2.5.2.1 page 50 lines 1556-1558 says that
93 only '0' through '9' are digits. Prefer ISDIGIT to ISDIGIT_LOCALE unless
94 it's important to use the locale's definition of `digit' even when the
95 host does not conform to Posix. */
96 #define ISDIGIT(c) ((unsigned) (c) - '0' <= 9)
99 #include <sys/types.h>
106 #ifdef STRING_WITH_STRINGS
108 # include <strings.h>
110 # ifdef HAVE_STRING_H
113 # ifdef HAVE_STRINGS_H
114 # include <strings.h>
127 #ifdef HAVE_SYS_PARAM_H
128 # include <sys/param.h>
135 #ifdef TIME_WITH_SYS_TIME
136 # include <sys/time.h>
140 # include <sys/time.h>
151 # ifdef HAVE_SYS_FILE_H
152 # include <sys/file.h>
174 /* Some systems define these in, e.g., param.h. We undefine these names
175 here to avoid the warnings. We prefer to use our definitions since we
176 know they are correct. */
180 #define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
181 #define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
183 #ifdef HAVE_SYS_WAIT_H
184 #include <sys/wait.h>
188 #define WIFSIGNALED(S) (((S) & 0xff) != 0 && ((S) & 0xff) != 0x7f)
191 #define WTERMSIG(S) ((S) & 0x7f)
194 #define WIFEXITED(S) (((S) & 0xff) == 0)
197 #define WEXITSTATUS(S) (((S) & 0xff00) >> 8)
204 # ifdef NEED_DECLARATION_BCOPY
205 extern void bcopy ();
207 # else /* ! HAVE_BCOPY */
208 # define bcopy(src,dst,len) memcpy ((dst),(src),(len))
214 # ifdef NEED_DECLARATION_BCMP
217 # else /* ! HAVE_BCMP */
218 # define bcmp(left,right,len) memcmp ((left),(right),(len))
224 # ifdef NEED_DECLARATION_BZERO
225 extern void bzero ();
227 # else /* ! HAVE_BZERO */
228 # define bzero(dst,len) memset ((dst),0,(len))
234 # ifdef NEED_DECLARATION_INDEX
235 extern char *index ();
237 # else /* ! HAVE_INDEX */
238 # define index strchr
244 # ifdef NEED_DECLARATION_RINDEX
245 extern char *rindex ();
247 # else /* ! HAVE_RINDEX */
248 # define rindex strrchr
252 #ifdef NEED_DECLARATION_ATOF
253 extern double atof ();
256 #ifdef NEED_DECLARATION_ATOL
260 #ifdef NEED_DECLARATION_FREE
264 #ifdef NEED_DECLARATION_GETCWD
265 extern char *getcwd ();
268 #ifdef NEED_DECLARATION_GETENV
269 extern char *getenv ();
272 #ifdef NEED_DECLARATION_GETWD
273 extern char *getwd ();
276 #ifdef NEED_DECLARATION_SBRK
277 extern char *sbrk ();
281 # ifdef NEED_DECLARATION_STRERROR
283 extern char *strerror ();
286 #else /* ! HAVE_STRERROR */
288 extern char *sys_errlist[];
289 #endif /* HAVE_STRERROR */
291 #ifdef HAVE_STRSIGNAL
292 # ifdef NEED_DECLARATION_STRSIGNAL
294 extern char * strsignal ();
297 #else /* ! HAVE_STRSIGNAL */
298 # ifndef SYS_SIGLIST_DECLARED
299 # ifndef NO_SYS_SIGLIST
300 extern char * sys_siglist[];
303 #endif /* HAVE_STRSIGNAL */
305 #ifdef HAVE_GETRLIMIT
306 # ifdef NEED_DECLARATION_GETRLIMIT
308 extern int getrlimit ();
313 #ifdef HAVE_SETRLIMIT
314 # ifdef NEED_DECLARATION_SETRLIMIT
316 extern int setrlimit ();
321 /* HAVE_VOLATILE only refers to the stage1 compiler. We also check
322 __STDC__ and assume gcc sets it and has volatile in stage >=2. */
323 #if !defined(HAVE_VOLATILE) && !defined(__STDC__) && !defined(volatile)
327 /* Redefine abort to report an internal error w/o coredump, and reporting the
328 location of the error in the source file. */
332 #ifndef USE_SYSTEM_ABORT
333 #define USE_SYSTEM_ABORT
334 #endif /* !USE_SYSTEM_ABORT */
335 #endif /* !__GNUC__ */
336 #endif /* !__STDC__ */
338 #ifdef USE_SYSTEM_ABORT
339 # ifdef NEED_DECLARATION_ABORT
340 extern void abort ();
343 #if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
346 "%s:%d: Internal compiler error\n", __FILE__, __LINE__), \
347 exit (FATAL_EXIT_CODE))
352 "%s:%d: Internal compiler error in function %s\n", \
353 __FILE__, __LINE__, __PRETTY_FUNCTION__), \
354 exit (FATAL_EXIT_CODE))
356 #endif /* recent gcc */
357 #endif /* USE_SYSTEM_ABORT */
361 /* Define a STRINGIFY macro that's right for ANSI or traditional C.
362 HAVE_CPP_STRINGIFY only refers to the stage1 compiler. Assume that
363 (non-traditional) gcc used in stage2 or later has this feature.
365 Note: if the argument passed to STRINGIFY is itself a macro, eg
366 #define foo bar, STRINGIFY(foo) will produce "foo", not "bar".
367 Although the __STDC__ case could be made to expand this via a layer
368 of indirection, the traditional C case can not do so. Therefore
369 this behavior is not supported. */
371 # if defined(HAVE_CPP_STRINGIFY) || (defined(__GNUC__) && defined(__STDC__))
372 # define STRINGIFY(STRING) #STRING
374 # define STRINGIFY(STRING) "STRING"
376 #endif /* ! STRINGIFY */
379 /* These macros are here in preparation for the use of gettext in egcs. */
380 #define _(String) String
381 #define N_(String) String
384 # include <sys/stat.h>
387 /* Test if something is a normal file. */
389 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
392 /* Test if something is a directory. */
394 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
397 /* Get libiberty declarations. */
398 #include "libiberty.h"
400 #endif /* __GCC_SYSTEM_H__ */