Daily bump.
[official-gcc.git] / gcc / system.h
blob93ba4c3a3652c022a7b299e7aa02e564c1f63041
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)
10 any later version.
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
27 #include <stdarg.h>
28 #else
29 #include <varargs.h>
30 #endif
32 #include <stdio.h>
34 /* Define a generic NULL if one hasn't already been defined. */
35 #ifndef NULL
36 #define NULL 0
37 #endif
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
49 # undef putc
50 # define putc(C, Stream) putc_unlocked (C, Stream)
51 #endif
52 #if defined HAVE_FPUTC_UNLOCKED && !defined NEED_DECLARATION_PUTC_UNLOCKED
53 # undef fputc
54 # define fputc(C, Stream) fputc_unlocked (C, Stream)
55 #endif
56 #if defined HAVE_FPUTS_UNLOCKED && !defined NEED_DECLARATION_PUTC_UNLOCKED
57 # undef fputs
58 # define fputs(String, Stream) fputs_unlocked (String, Stream)
59 # ifdef NEED_DECLARATION_FPUTS_UNLOCKED
60 extern int fputs_unlocked PROTO ((const char *, FILE *));
61 # endif
62 #endif
64 #include <ctype.h>
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."
77 Bruno Haible adds:
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
87 #else
88 # define IN_CTYPE_DOMAIN(c) isascii(c)
89 #endif
91 #ifdef isblank
92 # define ISBLANK(c) (IN_CTYPE_DOMAIN (c) && isblank (c))
93 #else
94 # define ISBLANK(c) ((c) == ' ' || (c) == '\t')
95 #endif
96 #ifdef isgraph
97 # define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isgraph (c))
98 #else
99 # define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isprint (c) && !isspace (c))
100 #endif
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>
125 #include <errno.h>
127 #ifndef errno
128 extern int errno;
129 #endif
131 #ifdef STRING_WITH_STRINGS
132 # include <string.h>
133 # include <strings.h>
134 #else
135 # ifdef HAVE_STRING_H
136 # include <string.h>
137 # else
138 # ifdef HAVE_STRINGS_H
139 # include <strings.h>
140 # endif
141 # endif
142 #endif
144 #ifdef HAVE_STDLIB_H
145 # include <stdlib.h>
146 #endif
148 #ifdef HAVE_UNISTD_H
149 # include <unistd.h>
150 #endif
152 #ifdef HAVE_SYS_PARAM_H
153 # include <sys/param.h>
154 #endif
156 #if HAVE_LIMITS_H
157 # include <limits.h>
158 #endif
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"
178 # else
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>
190 # include <time.h>
191 #else
192 # if HAVE_SYS_TIME_H
193 # include <sys/time.h>
194 # else
195 # ifdef HAVE_TIME_H
196 # include <time.h>
197 # endif
198 # endif
199 #endif
201 #ifdef HAVE_FCNTL_H
202 # include <fcntl.h>
203 #else
204 # ifdef HAVE_SYS_FILE_H
205 # include <sys/file.h>
206 # endif
207 #endif
209 #ifndef SEEK_SET
210 # define SEEK_SET 0
211 # define SEEK_CUR 1
212 # define SEEK_END 2
213 #endif
214 #ifndef F_OK
215 # define F_OK 0
216 # define X_OK 1
217 # define W_OK 2
218 # define R_OK 4
219 #endif
220 #ifndef O_RDONLY
221 # define O_RDONLY 0
222 #endif
223 #ifndef O_WRONLY
224 # define O_WRONLY 1
225 #endif
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. */
231 #undef MIN
232 #undef MAX
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>
238 #endif
240 #ifndef WIFSIGNALED
241 #define WIFSIGNALED(S) (((S) & 0xff) != 0 && ((S) & 0xff) != 0x7f)
242 #endif
243 #ifndef WTERMSIG
244 #define WTERMSIG(S) ((S) & 0x7f)
245 #endif
246 #ifndef WIFEXITED
247 #define WIFEXITED(S) (((S) & 0xff) == 0)
248 #endif
249 #ifndef WEXITSTATUS
250 #define WEXITSTATUS(S) (((S) & 0xff00) >> 8)
251 #endif
252 #ifndef WSTOPSIG
253 #define WSTOPSIG WEXITSTATUS
254 #endif
258 #ifndef bcopy
259 # ifdef HAVE_BCOPY
260 # ifdef NEED_DECLARATION_BCOPY
261 extern void bcopy ();
262 # endif
263 # else /* ! HAVE_BCOPY */
264 # define bcopy(src,dst,len) memmove((dst),(src),(len))
265 # endif
266 #endif
268 #ifndef bcmp
269 # ifdef HAVE_BCMP
270 # ifdef NEED_DECLARATION_BCMP
271 extern int bcmp ();
272 # endif
273 # else /* ! HAVE_BCMP */
274 # define bcmp(left,right,len) memcmp ((left),(right),(len))
275 # endif
276 #endif
278 #ifndef bzero
279 # ifdef HAVE_BZERO
280 # ifdef NEED_DECLARATION_BZERO
281 extern void bzero ();
282 # endif
283 # else /* ! HAVE_BZERO */
284 # define bzero(dst,len) memset ((dst),0,(len))
285 # endif
286 #endif
288 #ifndef index
289 # ifdef HAVE_INDEX
290 # ifdef NEED_DECLARATION_INDEX
291 extern char *index ();
292 # endif
293 # else /* ! HAVE_INDEX */
294 # define index strchr
295 # endif
296 #endif
298 #ifndef rindex
299 # ifdef HAVE_RINDEX
300 # ifdef NEED_DECLARATION_RINDEX
301 extern char *rindex ();
302 # endif
303 # else /* ! HAVE_RINDEX */
304 # define rindex strrchr
305 # endif
306 #endif
308 #ifdef NEED_DECLARATION_ATOF
309 extern double atof ();
310 #endif
312 #ifdef NEED_DECLARATION_ATOL
313 extern long atol();
314 #endif
316 #ifdef NEED_DECLARATION_FREE
317 extern void free ();
318 #endif
320 #ifdef NEED_DECLARATION_GETCWD
321 extern char *getcwd ();
322 #endif
324 #ifdef NEED_DECLARATION_GETENV
325 extern char *getenv ();
326 #endif
328 #ifdef NEED_DECLARATION_GETWD
329 extern char *getwd ();
330 #endif
332 #ifdef NEED_DECLARATION_SBRK
333 extern char *sbrk ();
334 #endif
336 #ifdef NEED_DECLARATION_STRSTR
337 extern char *strstr ();
338 #endif
340 #ifdef HAVE_STRERROR
341 # ifdef NEED_DECLARATION_STRERROR
342 # ifndef strerror
343 extern char *strerror ();
344 # endif
345 # endif
346 #else /* ! HAVE_STRERROR */
347 extern int sys_nerr;
348 extern char *sys_errlist[];
349 #endif /* HAVE_STRERROR */
351 #ifdef HAVE_STRSIGNAL
352 # ifdef NEED_DECLARATION_STRSIGNAL
353 # ifndef strsignal
354 extern char * strsignal ();
355 # endif
356 # endif
357 #else /* ! HAVE_STRSIGNAL */
358 # ifndef SYS_SIGLIST_DECLARED
359 # ifndef NO_SYS_SIGLIST
360 extern char * sys_siglist[];
361 # endif
362 # endif
363 #endif /* HAVE_STRSIGNAL */
365 #ifdef HAVE_GETRLIMIT
366 # ifdef NEED_DECLARATION_GETRLIMIT
367 # ifndef getrlimit
368 extern int getrlimit ();
369 # endif
370 # endif
371 #endif
373 #ifdef HAVE_SETRLIMIT
374 # ifdef NEED_DECLARATION_SETRLIMIT
375 # ifndef setrlimit
376 extern int setrlimit ();
377 # endif
378 # endif
379 #endif
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)
384 #define volatile
385 #endif
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
390 for their sake. */
391 #ifdef NEED_DECLARATION_ABORT
392 extern void abort ();
393 #endif
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__)
399 #else
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. */
419 #ifndef STRINGIFY
420 # if defined(HAVE_CPP_STRINGIFY) || (defined(__GNUC__) && defined(__STDC__))
421 # define STRINGIFY(STRING) #STRING
422 # else
423 # define STRINGIFY(STRING) "STRING"
424 # endif
425 #endif /* ! STRINGIFY */
427 #if HAVE_SYS_STAT_H
428 # include <sys/stat.h>
429 #endif
431 /* Test if something is a normal file. */
432 #ifndef S_ISREG
433 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
434 #endif
436 /* Test if something is a directory. */
437 #ifndef S_ISDIR
438 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
439 #endif
441 /* Test if something is a character special file. */
442 #ifndef S_ISCHR
443 #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
444 #endif
446 /* Test if something is a socket. */
447 #ifndef S_ISSOCK
448 # ifdef S_IFSOCK
449 # define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
450 # else
451 # define S_ISSOCK(m) 0
452 # endif
453 #endif
455 /* Test if something is a FIFO. */
456 #ifndef S_ISFIFO
457 # ifdef S_IFIFO
458 # define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
459 # else
460 # define S_ISFIFO(m) 0
461 # endif
462 #endif
464 /* Approximate O_NONBLOCK. */
465 #ifndef O_NONBLOCK
466 #define O_NONBLOCK O_NDELAY
467 #endif
469 /* Approximate O_NOCTTY. */
470 #ifndef O_NOCTTY
471 #define O_NOCTTY 0
472 #endif
474 /* Define well known filenos if the system does not define them. */
475 #ifndef STDIN_FILENO
476 # define STDIN_FILENO 0
477 #endif
478 #ifndef STDOUT_FILENO
479 # define STDOUT_FILENO 1
480 #endif
481 #ifndef STDERR_FILENO
482 # define STDERR_FILENO 2
483 #endif
485 /* Some systems have mkdir that takes a single argument. */
486 #ifdef MKDIR_TAKES_ONE_ARG
487 # define mkdir(a,b) mkdir(a)
488 #endif
490 /* Get libiberty declarations. */
491 #include "libiberty.h"
493 #endif /* __GCC_SYSTEM_H__ */