OSDN Git Service

* cccp.c: Don't define MIN/MAX anymore.
[pf3gnuchains/gcc-fork.git] / gcc / system.h
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.
4
5  */
6
7 #ifndef __GCC_SYSTEM_H__
8 #define __GCC_SYSTEM_H__
9
10 /* We must include stdarg.h/varargs.h before stdio.h. */
11 #ifdef ANSI_PROTOTYPES
12 #include <stdarg.h>
13 #else
14 #include <varargs.h>
15 #endif
16
17 #include <stdio.h>
18
19 /* Define a generic NULL if one hasn't already been defined.  */
20 #ifndef NULL
21 #define NULL 0
22 #endif
23
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
27 # undef putc
28 # define putc(C, Stream) putc_unlocked (C, Stream)
29 #endif
30 #ifdef HAVE_FPUTC_UNLOCKED
31 # undef fputc
32 # define fputc(C, Stream) fputc_unlocked (C, Stream)
33 #endif
34 #ifdef HAVE_FPUTS_UNLOCKED
35 # undef fputs
36 # define fputs(String, Stream) fputs_unlocked (String, Stream)
37 #endif
38
39 #include <ctype.h>
40
41 /* Jim Meyering writes:
42
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."
51
52    Bruno Haible adds:
53
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."  */
59
60 #if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII))
61 # define IN_CTYPE_DOMAIN(c) 1
62 #else
63 # define IN_CTYPE_DOMAIN(c) isascii(c)
64 #endif
65
66 #ifdef isblank
67 # define ISBLANK(c) (IN_CTYPE_DOMAIN (c) && isblank (c))
68 #else
69 # define ISBLANK(c) ((c) == ' ' || (c) == '\t')
70 #endif
71 #ifdef isgraph
72 # define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isgraph (c))
73 #else
74 # define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isprint (c) && !isspace (c))
75 #endif
76
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))
87
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)
97
98
99 #include <sys/types.h>
100 #include <errno.h>
101
102 #ifndef errno
103 extern int errno;
104 #endif
105
106 #ifdef STRING_WITH_STRINGS
107 # include <string.h>
108 # include <strings.h>
109 #else
110 # ifdef HAVE_STRING_H
111 #  include <string.h>
112 # else
113 #  ifdef HAVE_STRINGS_H
114 #   include <strings.h>
115 #  endif
116 # endif
117 #endif
118
119 #ifdef HAVE_STDLIB_H
120 # include <stdlib.h>
121 #endif
122
123 #ifdef HAVE_UNISTD_H
124 # include <unistd.h>
125 #endif
126
127 #ifdef HAVE_SYS_PARAM_H
128 # include <sys/param.h>
129 #endif
130
131 #if HAVE_LIMITS_H
132 # include <limits.h>
133 #endif
134
135 #ifdef TIME_WITH_SYS_TIME
136 # include <sys/time.h>
137 # include <time.h>
138 #else
139 # if HAVE_SYS_TIME_H
140 #  include <sys/time.h>
141 # else
142 #  ifdef HAVE_TIME_H
143 #   include <time.h>
144 #  endif
145 # endif
146 #endif
147
148 #ifdef HAVE_FCNTL_H
149 # include <fcntl.h>
150 #else
151 # ifdef HAVE_SYS_FILE_H
152 #  include <sys/file.h>
153 # endif
154 #endif
155
156 #ifndef SEEK_SET
157 # define SEEK_SET 0
158 # define SEEK_CUR 1
159 # define SEEK_END 2
160 #endif
161 #ifndef F_OK
162 # define F_OK 0
163 # define X_OK 1
164 # define W_OK 2
165 # define R_OK 4
166 #endif
167 #ifndef O_RDONLY
168 # define O_RDONLY 0
169 #endif
170 #ifndef O_WRONLY
171 # define O_WRONLY 1
172 #endif
173
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.  */
177
178 #undef MIN
179 #undef MAX
180 #define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
181 #define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
182
183 #ifdef HAVE_SYS_WAIT_H
184 #include <sys/wait.h>
185 #endif
186
187 #ifndef WIFSIGNALED
188 #define WIFSIGNALED(S) (((S) & 0xff) != 0 && ((S) & 0xff) != 0x7f)
189 #endif
190 #ifndef WTERMSIG
191 #define WTERMSIG(S) ((S) & 0x7f)
192 #endif
193 #ifndef WIFEXITED
194 #define WIFEXITED(S) (((S) & 0xff) == 0)
195 #endif
196 #ifndef WEXITSTATUS
197 #define WEXITSTATUS(S) (((S) & 0xff00) >> 8)
198 #endif
199
200
201
202 #ifndef bcopy
203 # ifdef HAVE_BCOPY
204 #  ifdef NEED_DECLARATION_BCOPY
205 extern void bcopy ();
206 #  endif
207 # else /* ! HAVE_BCOPY */
208 #  define bcopy(src,dst,len) memcpy ((dst),(src),(len))
209 # endif
210 #endif
211
212 #ifndef bcmp
213 # ifdef HAVE_BCMP
214 #  ifdef NEED_DECLARATION_BCMP
215 extern int bcmp ();
216 #  endif
217 # else /* ! HAVE_BCMP */
218 #  define bcmp(left,right,len) memcmp ((left),(right),(len))
219 # endif
220 #endif
221
222 #ifndef bzero
223 # ifdef HAVE_BZERO
224 #  ifdef NEED_DECLARATION_BZERO
225 extern void bzero ();
226 #  endif
227 # else /* ! HAVE_BZERO */
228 #  define bzero(dst,len) memset ((dst),0,(len))
229 # endif
230 #endif
231
232 #ifndef index
233 # ifdef HAVE_INDEX
234 #  ifdef NEED_DECLARATION_INDEX
235 extern char *index ();
236 #  endif
237 # else /* ! HAVE_INDEX */
238 #  define index strchr
239 # endif
240 #endif
241
242 #ifndef rindex
243 # ifdef HAVE_RINDEX
244 #  ifdef NEED_DECLARATION_RINDEX
245 extern char *rindex ();
246 #  endif
247 # else /* ! HAVE_RINDEX */
248 #  define rindex strrchr
249 # endif
250 #endif
251
252 #ifdef NEED_DECLARATION_ATOF
253 extern double atof ();
254 #endif
255
256 #ifdef NEED_DECLARATION_ATOL
257 extern long atol();
258 #endif
259
260 #ifdef NEED_DECLARATION_FREE
261 extern void free ();
262 #endif
263
264 #ifdef NEED_DECLARATION_GETCWD
265 extern char *getcwd ();
266 #endif
267
268 #ifdef NEED_DECLARATION_GETENV
269 extern char *getenv ();
270 #endif
271
272 #ifdef NEED_DECLARATION_GETWD
273 extern char *getwd ();
274 #endif
275
276 #ifdef NEED_DECLARATION_SBRK
277 extern char *sbrk ();
278 #endif
279
280 #ifdef HAVE_STRERROR
281 # ifdef NEED_DECLARATION_STRERROR
282 #  ifndef strerror
283 extern char *strerror ();
284 #  endif
285 # endif
286 #else /* ! HAVE_STRERROR */
287 extern int sys_nerr;
288 extern char *sys_errlist[];
289 #endif /* HAVE_STRERROR */
290
291 #ifdef HAVE_STRSIGNAL
292 # ifdef NEED_DECLARATION_STRSIGNAL
293 #  ifndef strsignal
294 extern char * strsignal ();
295 #  endif
296 # endif
297 #else /* ! HAVE_STRSIGNAL */
298 # ifndef SYS_SIGLIST_DECLARED
299 #  ifndef NO_SYS_SIGLIST
300 extern char * sys_siglist[];
301 #  endif
302 # endif
303 #endif /* HAVE_STRSIGNAL */
304
305 #ifdef HAVE_GETRLIMIT
306 # ifdef NEED_DECLARATION_GETRLIMIT
307 #  ifndef getrlimit
308 extern int getrlimit ();
309 #  endif
310 # endif
311 #endif
312
313 #ifdef HAVE_SETRLIMIT
314 # ifdef NEED_DECLARATION_SETRLIMIT
315 #  ifndef setrlimit
316 extern int setrlimit ();
317 #  endif
318 # endif
319 #endif
320
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)
324 #define volatile
325 #endif
326
327 /* Redefine abort to report an internal error w/o coredump, and reporting the
328    location of the error in the source file.  */
329 #ifndef abort
330 #ifndef __STDC__
331 #ifndef __GNUC__
332 #ifndef USE_SYSTEM_ABORT
333 #define USE_SYSTEM_ABORT
334 #endif /* !USE_SYSTEM_ABORT */
335 #endif /* !__GNUC__ */
336 #endif /* !__STDC__ */
337
338 #ifdef USE_SYSTEM_ABORT
339 # ifdef NEED_DECLARATION_ABORT
340 extern void abort ();
341 # endif
342 #else
343 #if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
344 #define abort()                                                         \
345 (fprintf (stderr,                                                       \
346           "%s:%d: Internal compiler error\n", __FILE__, __LINE__),      \
347  exit (FATAL_EXIT_CODE))
348
349 #else
350 #define abort()                                                         \
351 (fprintf (stderr,                                                       \
352           "%s:%d: Internal compiler error in function %s\n",            \
353           __FILE__, __LINE__, __PRETTY_FUNCTION__),                     \
354  exit (FATAL_EXIT_CODE))
355
356 #endif /* recent gcc */
357 #endif /* USE_SYSTEM_ABORT */
358 #endif /* !abort */
359
360
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.
364
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. */
370 #ifndef STRINGIFY
371 # if defined(HAVE_CPP_STRINGIFY) || (defined(__GNUC__) && defined(__STDC__))
372 #  define STRINGIFY(STRING) #STRING
373 # else
374 #  define STRINGIFY(STRING) "STRING"
375 # endif
376 #endif /* ! STRINGIFY */
377
378
379 /* These macros are here in preparation for the use of gettext in egcs.  */
380 #define _(String) String
381 #define N_(String) String
382
383 #if HAVE_SYS_STAT_H
384 # include <sys/stat.h>
385 #endif
386
387 /* Test if something is a normal file.  */
388 #ifndef S_ISREG
389 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
390 #endif
391
392 /* Test if something is a directory.  */
393 #ifndef S_ISDIR
394 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
395 #endif
396
397 /* Get libiberty declarations. */
398 #include "libiberty.h"
399
400 #endif /* __GCC_SYSTEM_H__ */