OSDN Git Service

* reload.c: PROTO -> PARAMS.
[pf3gnuchains/gcc-fork.git] / gcc / system.h
1 /* Get common system includes and various definitions and declarations based
2    on autoconf macros.
3    Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.
4
5 This file is part of GNU CC.
6
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.
11
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.
16
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.  */
21
22
23 #ifndef __GCC_SYSTEM_H__
24 #define __GCC_SYSTEM_H__
25
26 /* We must include stdarg.h/varargs.h before stdio.h. */
27 #ifdef ANSI_PROTOTYPES
28 #include <stdarg.h>
29 #else
30 #include <varargs.h>
31 #endif
32
33 #include <stdio.h>
34
35 /* Define a generic NULL if one hasn't already been defined.  */
36 #ifndef NULL
37 #define NULL 0
38 #endif
39
40 /* The compiler is not a multi-threaded application and therefore we
41    do not have to use the locking functions.
42
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.
46    
47    fputs_unlocked is an extension and needs to be prototyped specially.  */
48
49 #if defined HAVE_PUTC_UNLOCKED && !defined NEED_DECLARATION_PUTC_UNLOCKED
50 # undef putc
51 # define putc(C, Stream) putc_unlocked (C, Stream)
52 #endif
53 #if defined HAVE_FPUTC_UNLOCKED && !defined NEED_DECLARATION_PUTC_UNLOCKED
54 # undef fputc
55 # define fputc(C, Stream) fputc_unlocked (C, Stream)
56 #endif
57 #if defined HAVE_FPUTS_UNLOCKED && !defined NEED_DECLARATION_PUTC_UNLOCKED
58 # undef fputs
59 # define fputs(String, Stream) fputs_unlocked (String, Stream)
60 # ifdef NEED_DECLARATION_FPUTS_UNLOCKED
61 extern int fputs_unlocked PARAMS ((const char *, FILE *));
62 # endif
63 #endif
64
65 #include <ctype.h>
66
67 /* Jim Meyering writes:
68
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."
77
78    Bruno Haible adds:
79
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."  */
85
86 #if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII)) || defined(HOST_EBCDIC)
87 # define IN_CTYPE_DOMAIN(c) 1
88 #else
89 # define IN_CTYPE_DOMAIN(c) isascii(c)
90 #endif
91
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.
100 */
101
102 #define CTYPE_CONV(CH) \
103   (sizeof(CH) == sizeof(unsigned char) ? (int)(unsigned char)(CH) : (int)(CH))
104
105
106 /* WARNING!  The argument to the ctype replacement macros below is
107    evaluated more than once so it must not have side effects!  */
108
109 #ifdef isblank
110 # define ISBLANK(c) (IN_CTYPE_DOMAIN (c) && isblank (CTYPE_CONV(c)))
111 #else
112 # define ISBLANK(c) ((c) == ' ' || (c) == '\t')
113 #endif
114 #ifdef isgraph
115 # define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isgraph (CTYPE_CONV(c)))
116 #else
117 # define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isprint (CTYPE_CONV(c)) && !isspace (CTYPE_CONV(c)))
118 #endif
119
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)))
130
131 #if STDC_HEADERS
132 # define TOLOWER(c) (tolower (CTYPE_CONV(c)))
133 # define TOUPPER(c) (toupper (CTYPE_CONV(c)))
134 #else
135 # define TOLOWER(c) (ISUPPER (c) ? tolower (CTYPE_CONV(c)) : (c))
136 # define TOUPPER(c) (ISLOWER (c) ? toupper (CTYPE_CONV(c)) : (c))
137 #endif
138
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)
148
149 /* Define a default escape character; its different for EBCDIC.  */
150 #ifndef TARGET_ESC
151 #define TARGET_ESC 033
152 #endif
153
154 #ifdef HAVE_SYS_TYPES_H
155 #include <sys/types.h>
156 #endif
157
158 #include <errno.h>
159
160 #ifndef errno
161 extern int errno;
162 #endif
163
164 #ifdef STRING_WITH_STRINGS
165 # include <string.h>
166 # include <strings.h>
167 #else
168 # ifdef HAVE_STRING_H
169 #  include <string.h>
170 # else
171 #  ifdef HAVE_STRINGS_H
172 #   include <strings.h>
173 #  endif
174 # endif
175 #endif
176
177 #ifdef HAVE_STDLIB_H
178 # include <stdlib.h>
179 # ifdef USE_C_ALLOCA
180 /* Note that systems that use glibc have a <stdlib.h> that includes
181    <alloca.h> that defines alloca, so let USE_C_ALLOCA override this. */
182 # undef alloca
183 #endif
184 #endif
185
186 #ifdef HAVE_UNISTD_H
187 # include <unistd.h>
188 #endif
189
190 #ifdef HAVE_SYS_PARAM_H
191 # include <sys/param.h>
192 #endif
193
194 #if HAVE_LIMITS_H
195 # include <limits.h>
196 #endif
197
198 /* Find HOST_WIDEST_INT and set its bit size, type and print macros.
199    It will be the largest integer mode supported by the host which may
200    (or may not) be larger than HOST_WIDE_INT.  This must appear after
201    <limits.h> since we only use `long long' if its bigger than a
202    `long' and also if it is supported by macros in limits.h.  For old
203    hosts which don't have a limits.h (and thus won't include it in
204    stage2 cause we don't rerun configure) we assume gcc supports long
205    long.)  Note, you won't get these defined if you don't include
206    {ht}config.h before this file to set the HOST_BITS_PER_* macros. */
207
208 #ifndef HOST_WIDEST_INT
209 # if defined (HOST_BITS_PER_LONG) && defined (HOST_BITS_PER_LONGLONG)
210 #  if (HOST_BITS_PER_LONGLONG > HOST_BITS_PER_LONG) && (defined (LONG_LONG_MAX) || defined (LONGLONG_MAX) || defined (LLONG_MAX) || defined (__GNUC__))
211 #   define HOST_BITS_PER_WIDEST_INT HOST_BITS_PER_LONGLONG
212 #   define HOST_WIDEST_INT long long
213 #   define HOST_WIDEST_INT_PRINT_DEC "%lld"
214 #   define HOST_WIDEST_INT_PRINT_UNSIGNED "%llu"
215 #   define HOST_WIDEST_INT_PRINT_HEX "0x%llx"
216 #  else
217 #   define HOST_BITS_PER_WIDEST_INT HOST_BITS_PER_LONG
218 #   define HOST_WIDEST_INT long
219 #   define HOST_WIDEST_INT_PRINT_DEC "%ld"
220 #   define HOST_WIDEST_INT_PRINT_UNSIGNED "%lu"
221 #   define HOST_WIDEST_INT_PRINT_HEX "0x%lx"
222 #  endif /*(long long>long) && (LONG_LONG_MAX||LONGLONG_MAX||LLONG_MAX||GNUC)*/
223 # endif /* defined(HOST_BITS_PER_LONG) && defined(HOST_BITS_PER_LONGLONG) */
224 #endif /* ! HOST_WIDEST_INT */
225
226 #ifdef TIME_WITH_SYS_TIME
227 # include <sys/time.h>
228 # include <time.h>
229 #else
230 # if HAVE_SYS_TIME_H
231 #  include <sys/time.h>
232 # else
233 #  ifdef HAVE_TIME_H
234 #   include <time.h>
235 #  endif
236 # endif
237 #endif
238
239 #ifdef HAVE_FCNTL_H
240 # include <fcntl.h>
241 #else
242 # ifdef HAVE_SYS_FILE_H
243 #  include <sys/file.h>
244 # endif
245 #endif
246
247 #ifndef SEEK_SET
248 # define SEEK_SET 0
249 # define SEEK_CUR 1
250 # define SEEK_END 2
251 #endif
252 #ifndef F_OK
253 # define F_OK 0
254 # define X_OK 1
255 # define W_OK 2
256 # define R_OK 4
257 #endif
258 #ifndef O_RDONLY
259 # define O_RDONLY 0
260 #endif
261 #ifndef O_WRONLY
262 # define O_WRONLY 1
263 #endif
264
265 /* Some systems define these in, e.g., param.h.  We undefine these names
266    here to avoid the warnings.  We prefer to use our definitions since we
267    know they are correct.  */
268
269 #undef MIN
270 #undef MAX
271 #define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
272 #define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
273
274 /* Returns the least number N such that N * Y >= X.  */
275 #define CEIL(x,y) (((x) + (y) - 1) / (y))
276
277 #ifdef HAVE_SYS_WAIT_H
278 #include <sys/wait.h>
279 #endif
280
281 #ifndef WIFSIGNALED
282 #define WIFSIGNALED(S) (((S) & 0xff) != 0 && ((S) & 0xff) != 0x7f)
283 #endif
284 #ifndef WTERMSIG
285 #define WTERMSIG(S) ((S) & 0x7f)
286 #endif
287 #ifndef WIFEXITED
288 #define WIFEXITED(S) (((S) & 0xff) == 0)
289 #endif
290 #ifndef WEXITSTATUS
291 #define WEXITSTATUS(S) (((S) & 0xff00) >> 8)
292 #endif
293 #ifndef WSTOPSIG
294 #define WSTOPSIG WEXITSTATUS
295 #endif
296
297
298
299 #ifndef bcopy
300 # ifdef HAVE_BCOPY
301 #  ifdef NEED_DECLARATION_BCOPY
302 extern void bcopy PARAMS ((const PTR, PTR, size_t));
303 #  endif
304 # else /* ! HAVE_BCOPY */
305 #  define bcopy(src,dst,len) memmove((dst),(src),(len))
306 # endif
307 #endif
308
309 #ifndef bcmp
310 # ifdef HAVE_BCMP
311 #  ifdef NEED_DECLARATION_BCMP
312 extern int bcmp PARAMS ((const PTR, const PTR, size_t));
313 #  endif
314 # else /* ! HAVE_BCMP */
315 #  define bcmp(left,right,len) memcmp ((left),(right),(len))
316 # endif
317 #endif
318
319 #ifndef bzero
320 # ifdef HAVE_BZERO
321 #  ifdef NEED_DECLARATION_BZERO
322 extern void bzero PARAMS ((PTR, size_t));
323 #  endif
324 # else /* ! HAVE_BZERO */
325 #  define bzero(dst,len) memset ((dst),0,(len))
326 # endif
327 #endif
328
329 #ifndef index
330 # ifdef HAVE_INDEX
331 #  ifdef NEED_DECLARATION_INDEX
332 extern char *index PARAMS ((const char *, int));
333 #  endif
334 # else /* ! HAVE_INDEX */
335 #  define index strchr
336 # endif
337 #endif
338
339 #ifndef rindex
340 # ifdef HAVE_RINDEX
341 #  ifdef NEED_DECLARATION_RINDEX
342 extern char *rindex PARAMS ((const char *, int));
343 #  endif
344 # else /* ! HAVE_RINDEX */
345 #  define rindex strrchr
346 # endif
347 #endif
348
349 #ifdef NEED_DECLARATION_ATOF
350 extern double atof PARAMS ((const char *));
351 #endif
352
353 #ifdef NEED_DECLARATION_ATOL
354 extern long atol PARAMS ((const char *));
355 #endif
356
357 #ifdef NEED_DECLARATION_FREE
358 extern void free PARAMS ((PTR));
359 #endif
360
361 #ifdef NEED_DECLARATION_GETCWD
362 extern char *getcwd PARAMS ((char *, size_t));
363 #endif
364
365 #ifdef NEED_DECLARATION_GETENV
366 extern char *getenv PARAMS ((const char *));
367 #endif
368
369 #ifdef NEED_DECLARATION_GETWD
370 extern char *getwd PARAMS ((char *));
371 #endif
372
373 #ifdef NEED_DECLARATION_SBRK
374 extern PTR sbrk PARAMS ((int));
375 #endif
376
377 #ifdef NEED_DECLARATION_STRSTR
378 extern char *strstr PARAMS ((const char *, const char *));
379 #endif
380
381 #ifdef HAVE_MALLOC_H
382 #include <malloc.h>
383 #endif
384
385 #ifdef NEED_DECLARATION_MALLOC
386 extern PTR malloc PARAMS ((size_t));
387 #endif
388
389 #ifdef NEED_DECLARATION_CALLOC
390 extern PTR calloc PARAMS ((size_t, size_t));
391 #endif
392
393 #ifdef NEED_DECLARATION_REALLOC
394 extern PTR realloc PARAMS ((PTR, size_t));
395 #endif
396
397 #ifdef HAVE_STRERROR
398 # ifdef NEED_DECLARATION_STRERROR
399 #  ifndef strerror
400 extern char *strerror PARAMS ((int));
401 #  endif
402 # endif
403 #else /* ! HAVE_STRERROR */
404 extern int sys_nerr;
405 extern char *sys_errlist[];
406 #endif /* HAVE_STRERROR */
407
408 /* If the system doesn't provide strsignal, we get it defined in
409    libiberty but no declaration is supplied. */
410 #ifdef NEED_DECLARATION_STRSIGNAL
411 # ifndef strsignal
412 extern const char *strsignal PARAMS ((int));
413 # endif
414 #endif
415
416 #ifdef HAVE_GETRLIMIT
417 # ifdef NEED_DECLARATION_GETRLIMIT
418 #  ifndef getrlimit
419 #   ifdef ANSI_PROTOTYPES
420 struct rlimit;
421 #   endif
422 extern int getrlimit PARAMS ((int, struct rlimit *));
423 #  endif
424 # endif
425 #endif
426
427 #ifdef HAVE_SETRLIMIT
428 # ifdef NEED_DECLARATION_SETRLIMIT
429 #  ifndef setrlimit
430 #   ifdef ANSI_PROTOTYPES
431 struct rlimit;
432 #   endif
433 extern int setrlimit PARAMS ((int, const struct rlimit *));
434 #  endif
435 # endif
436 #endif
437
438 /* HAVE_VOLATILE only refers to the stage1 compiler.  We also check
439    __STDC__ and assume gcc sets it and has volatile in stage >=2. */
440 #if !defined(HAVE_VOLATILE) && !defined(__STDC__) && !defined(volatile)
441 #define volatile
442 #endif
443
444 #ifdef NEED_DECLARATION_ABORT
445 extern void abort PARAMS ((void));
446 #endif
447
448 /* Define a STRINGIFY macro that's right for ANSI or traditional C.
449    Note: if the argument passed to STRINGIFY is itself a macro, eg
450    #define foo bar, STRINGIFY(foo) will produce "foo", not "bar".
451    Although the __STDC__ case could be made to expand this via a layer
452    of indirection, the traditional C case can not do so.  Therefore
453    this behavior is not supported. */
454 #ifndef STRINGIFY
455 # ifdef HAVE_STRINGIZE
456 #  define STRINGIFY(STRING) #STRING
457 # else
458 #  define STRINGIFY(STRING) "STRING"
459 # endif
460 #endif /* ! STRINGIFY */
461
462 #if HAVE_SYS_STAT_H
463 # include <sys/stat.h>
464 #endif
465
466 /* Test if something is a normal file.  */
467 #ifndef S_ISREG
468 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
469 #endif
470
471 /* Test if something is a directory.  */
472 #ifndef S_ISDIR
473 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
474 #endif
475
476 /* Test if something is a character special file.  */
477 #ifndef S_ISCHR
478 #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
479 #endif
480
481 /* Test if something is a socket.  */
482 #ifndef S_ISSOCK
483 # ifdef S_IFSOCK
484 #   define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
485 # else
486 #   define S_ISSOCK(m) 0
487 # endif
488 #endif
489
490 /* Test if something is a FIFO.  */
491 #ifndef S_ISFIFO
492 # ifdef S_IFIFO
493 #  define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
494 # else
495 #  define S_ISFIFO(m) 0
496 # endif
497 #endif
498
499 /* Approximate O_NONBLOCK.  */
500 #ifndef O_NONBLOCK
501 #define O_NONBLOCK O_NDELAY
502 #endif
503
504 /* Approximate O_NOCTTY.  */
505 #ifndef O_NOCTTY
506 #define O_NOCTTY 0
507 #endif
508
509 /* Define well known filenos if the system does not define them.  */
510 #ifndef STDIN_FILENO
511 # define STDIN_FILENO   0
512 #endif
513 #ifndef STDOUT_FILENO
514 # define STDOUT_FILENO  1
515 #endif
516 #ifndef STDERR_FILENO
517 # define STDERR_FILENO  2
518 #endif
519
520 /* Some systems have mkdir that takes a single argument. */
521 #ifdef MKDIR_TAKES_ONE_ARG
522 # define mkdir(a,b) mkdir(a)
523 #endif
524
525 /* Provide a way to print an address via printf.  */
526 #ifndef HOST_PTR_PRINTF
527 # ifdef HAVE_PRINTF_PTR
528 #  define HOST_PTR_PRINTF "%p"
529 # else
530 #  define HOST_PTR_PRINTF \
531     (sizeof (int) == sizeof (char *) ? "%x" \
532      : sizeof (long) == sizeof (char *) ? "%lx" : "%llx")
533 # endif
534 #endif /* ! HOST_PTR_PRINTF */
535
536 /* By default, colon separates directories in a path.  */
537 #ifndef PATH_SEPARATOR
538 #define PATH_SEPARATOR ':'
539 #endif
540
541 #ifndef DIR_SEPARATOR
542 #define DIR_SEPARATOR '/'
543 #endif
544
545 /* Define IS_DIR_SEPARATOR.  */
546 #ifndef DIR_SEPARATOR_2
547 # define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
548 #else /* DIR_SEPARATOR_2 */
549 # define IS_DIR_SEPARATOR(ch) \
550         (((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
551 #endif /* DIR_SEPARATOR_2 */
552
553 /* Get libiberty declarations. */
554 #include "libiberty.h"
555
556 #endif /* __GCC_SYSTEM_H__ */