OSDN Git Service

Fix comment
[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 /* This is the location of the online document giving information how
27    to report bugs. If you change this string, also check for strings
28    not under control of the preprocessor.  */
29 #define GCCBUGURL "<URL:http://www.gnu.org/software/gcc/bugs.html>"
30
31 /* We must include stdarg.h/varargs.h before stdio.h. */
32 #ifdef ANSI_PROTOTYPES
33 #include <stdarg.h>
34 #else
35 #include <varargs.h>
36 #endif
37
38 #ifndef va_copy
39 # ifdef __va_copy
40 #   define va_copy(d,s)  __va_copy((d),(s))
41 # else
42 #   define va_copy(d,s)  ((d) = (s))
43 # endif
44 #endif
45
46 #include <stdio.h>
47
48 /* Define a generic NULL if one hasn't already been defined.  */
49 #ifndef NULL
50 #define NULL 0
51 #endif
52
53 /* The compiler is not a multi-threaded application and therefore we
54    do not have to use the locking functions.
55
56    NEED_DECLARATION_PUTC_UNLOCKED actually indicates whether or not
57    the IO code is multi-thread safe by default.  If it is not declared,
58    then do not worry about using the _unlocked functions.
59    
60    fputs_unlocked is an extension and needs to be prototyped specially.  */
61
62 #if defined HAVE_PUTC_UNLOCKED && !defined NEED_DECLARATION_PUTC_UNLOCKED
63 # undef putc
64 # define putc(C, Stream) putc_unlocked (C, Stream)
65 #endif
66 #if defined HAVE_FPUTC_UNLOCKED && !defined NEED_DECLARATION_PUTC_UNLOCKED
67 # undef fputc
68 # define fputc(C, Stream) fputc_unlocked (C, Stream)
69 #endif
70 #if defined HAVE_FPUTS_UNLOCKED && !defined NEED_DECLARATION_PUTC_UNLOCKED
71 # undef fputs
72 # define fputs(String, Stream) fputs_unlocked (String, Stream)
73 # ifdef NEED_DECLARATION_FPUTS_UNLOCKED
74 extern int fputs_unlocked PARAMS ((const char *, FILE *));
75 # endif
76 #endif
77
78 #include <ctype.h>
79
80 /* Jim Meyering writes:
81
82    "... Some ctype macros are valid only for character codes that
83    isascii says are ASCII (SGI's IRIX-4.0.5 is one such system --when
84    using /bin/cc or gcc but without giving an ansi option).  So, all
85    ctype uses should be through macros like ISPRINT...  If
86    STDC_HEADERS is defined, then autoconf has verified that the ctype
87    macros don't need to be guarded with references to isascii. ...
88    Defining isascii to 1 should let any compiler worth its salt
89    eliminate the && through constant folding."
90
91    Bruno Haible adds:
92
93    "... Furthermore, isupper(c) etc. have an undefined result if c is
94    outside the range -1 <= c <= 255. One is tempted to write isupper(c)
95    with c being of type `char', but this is wrong if c is an 8-bit
96    character >= 128 which gets sign-extended to a negative value.
97    The macro ISUPPER protects against this as well."  */
98
99 #if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII)) || defined(HOST_EBCDIC)
100 # define IN_CTYPE_DOMAIN(c) 1
101 #else
102 # define IN_CTYPE_DOMAIN(c) isascii(c)
103 #endif
104
105 /* The ctype functions are often implemented as macros which do
106    lookups in arrays using the parameter as the offset.  If the ctype
107    function parameter is a char, then gcc will (appropriately) warn
108    that a "subscript has type char".  Using a (signed) char as a subscript
109    is bad because you may get negative offsets and thus it is not 8-bit
110    safe.  The CTYPE_CONV macro ensures that the parameter is cast to an
111    unsigned char when a char is passed in.  When an int is passed in, the
112    parameter is left alone so we don't lose EOF.
113 */
114
115 #define CTYPE_CONV(CH) \
116   (sizeof(CH) == sizeof(unsigned char) ? (int)(unsigned char)(CH) : (int)(CH))
117
118
119 /* WARNING!  The argument to the ctype replacement macros below is
120    evaluated more than once so it must not have side effects!  */
121
122 #ifdef isblank
123 # define ISBLANK(c) (IN_CTYPE_DOMAIN (c) && isblank (CTYPE_CONV(c)))
124 #else
125 # define ISBLANK(c) ((c) == ' ' || (c) == '\t')
126 #endif
127 #ifdef isgraph
128 # define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isgraph (CTYPE_CONV(c)))
129 #else
130 # define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isprint (CTYPE_CONV(c)) && !isspace (CTYPE_CONV(c)))
131 #endif
132
133 #define ISPRINT(c) (IN_CTYPE_DOMAIN (c) && isprint (CTYPE_CONV(c)))
134 #define ISALNUM(c) (IN_CTYPE_DOMAIN (c) && isalnum (CTYPE_CONV(c)))
135 #define ISALPHA(c) (IN_CTYPE_DOMAIN (c) && isalpha (CTYPE_CONV(c)))
136 #define ISCNTRL(c) (IN_CTYPE_DOMAIN (c) && iscntrl (CTYPE_CONV(c)))
137 #define ISLOWER(c) (IN_CTYPE_DOMAIN (c) && islower (CTYPE_CONV(c)))
138 #define ISPUNCT(c) (IN_CTYPE_DOMAIN (c) && ispunct (CTYPE_CONV(c)))
139 #define ISSPACE(c) (IN_CTYPE_DOMAIN (c) && isspace (CTYPE_CONV(c)))
140 #define ISUPPER(c) (IN_CTYPE_DOMAIN (c) && isupper (CTYPE_CONV(c)))
141 #define ISXDIGIT(c) (IN_CTYPE_DOMAIN (c) && isxdigit (CTYPE_CONV(c)))
142 #define ISDIGIT_LOCALE(c) (IN_CTYPE_DOMAIN (c) && isdigit (CTYPE_CONV(c)))
143
144 #if STDC_HEADERS
145 # define TOLOWER(c) (tolower (CTYPE_CONV(c)))
146 # define TOUPPER(c) (toupper (CTYPE_CONV(c)))
147 #else
148 # define TOLOWER(c) (ISUPPER (c) ? tolower (CTYPE_CONV(c)) : (c))
149 # define TOUPPER(c) (ISLOWER (c) ? toupper (CTYPE_CONV(c)) : (c))
150 #endif
151
152 /* ISDIGIT differs from ISDIGIT_LOCALE, as follows:
153    - Its arg may be any int or unsigned int; it need not be an unsigned char.
154    - It's guaranteed to evaluate its argument exactly once.
155    - It's typically faster.
156    Posix 1003.2-1992 section 2.5.2.1 page 50 lines 1556-1558 says that
157    only '0' through '9' are digits.  Prefer ISDIGIT to ISDIGIT_LOCALE unless
158    it's important to use the locale's definition of `digit' even when the
159    host does not conform to Posix.  */
160 #define ISDIGIT(c) ((unsigned) (c) - '0' <= 9)
161
162 /* Define a default escape character; its different for EBCDIC.  */
163 #ifndef TARGET_ESC
164 #define TARGET_ESC 033
165 #endif
166
167 #ifdef HAVE_SYS_TYPES_H
168 #include <sys/types.h>
169 #endif
170
171 #include <errno.h>
172
173 #ifndef errno
174 extern int errno;
175 #endif
176
177 #ifdef STRING_WITH_STRINGS
178 # include <string.h>
179 # include <strings.h>
180 #else
181 # ifdef HAVE_STRING_H
182 #  include <string.h>
183 # else
184 #  ifdef HAVE_STRINGS_H
185 #   include <strings.h>
186 #  endif
187 # endif
188 #endif
189
190 #ifdef HAVE_STDLIB_H
191 # include <stdlib.h>
192 # ifdef USE_C_ALLOCA
193 /* Note that systems that use glibc have a <stdlib.h> that includes
194    <alloca.h> that defines alloca, so let USE_C_ALLOCA override this. */
195 # undef alloca
196 #endif
197 #endif
198
199 #ifdef HAVE_UNISTD_H
200 # include <unistd.h>
201 #endif
202
203 #ifdef HAVE_SYS_PARAM_H
204 # include <sys/param.h>
205 #endif
206
207 #if HAVE_LIMITS_H
208 # include <limits.h>
209 #endif
210
211 /* Find HOST_WIDEST_INT and set its bit size, type and print macros.
212    It will be the largest integer mode supported by the host which may
213    (or may not) be larger than HOST_WIDE_INT.  This must appear after
214    <limits.h> since we only use `long long' if its bigger than a
215    `long' and also if it is supported by macros in limits.h.  For old
216    hosts which don't have a limits.h (and thus won't include it in
217    stage2 cause we don't rerun configure) we assume gcc supports long
218    long.)  Note, you won't get these defined if you don't include
219    {ht}config.h before this file to set the HOST_BITS_PER_* macros. */
220
221 #ifndef HOST_WIDEST_INT
222 # if defined (HOST_BITS_PER_LONG) && defined (HOST_BITS_PER_LONGLONG)
223 #  if (HOST_BITS_PER_LONGLONG > HOST_BITS_PER_LONG) && (defined (LONG_LONG_MAX) || defined (LONGLONG_MAX) || defined (LLONG_MAX) || defined (__GNUC__))
224 #   define HOST_BITS_PER_WIDEST_INT HOST_BITS_PER_LONGLONG
225 #   define HOST_WIDEST_INT long long
226 #   define HOST_WIDEST_INT_PRINT_DEC "%lld"
227 #   define HOST_WIDEST_INT_PRINT_UNSIGNED "%llu"
228 #   define HOST_WIDEST_INT_PRINT_HEX "0x%llx"
229 #  else
230 #   define HOST_BITS_PER_WIDEST_INT HOST_BITS_PER_LONG
231 #   define HOST_WIDEST_INT long
232 #   define HOST_WIDEST_INT_PRINT_DEC "%ld"
233 #   define HOST_WIDEST_INT_PRINT_UNSIGNED "%lu"
234 #   define HOST_WIDEST_INT_PRINT_HEX "0x%lx"
235 #  endif /*(long long>long) && (LONG_LONG_MAX||LONGLONG_MAX||LLONG_MAX||GNUC)*/
236 # endif /* defined(HOST_BITS_PER_LONG) && defined(HOST_BITS_PER_LONGLONG) */
237 #endif /* ! HOST_WIDEST_INT */
238
239 #ifdef TIME_WITH_SYS_TIME
240 # include <sys/time.h>
241 # include <time.h>
242 #else
243 # if HAVE_SYS_TIME_H
244 #  include <sys/time.h>
245 # else
246 #  ifdef HAVE_TIME_H
247 #   include <time.h>
248 #  endif
249 # endif
250 #endif
251
252 #ifdef HAVE_FCNTL_H
253 # include <fcntl.h>
254 #else
255 # ifdef HAVE_SYS_FILE_H
256 #  include <sys/file.h>
257 # endif
258 #endif
259
260 #ifndef SEEK_SET
261 # define SEEK_SET 0
262 # define SEEK_CUR 1
263 # define SEEK_END 2
264 #endif
265 #ifndef F_OK
266 # define F_OK 0
267 # define X_OK 1
268 # define W_OK 2
269 # define R_OK 4
270 #endif
271 #ifndef O_RDONLY
272 # define O_RDONLY 0
273 #endif
274 #ifndef O_WRONLY
275 # define O_WRONLY 1
276 #endif
277
278 /* Some systems define these in, e.g., param.h.  We undefine these names
279    here to avoid the warnings.  We prefer to use our definitions since we
280    know they are correct.  */
281
282 #undef MIN
283 #undef MAX
284 #define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
285 #define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
286
287 /* Returns the least number N such that N * Y >= X.  */
288 #define CEIL(x,y) (((x) + (y) - 1) / (y))
289
290 #ifdef HAVE_SYS_WAIT_H
291 #include <sys/wait.h>
292 #endif
293
294 #ifndef WIFSIGNALED
295 #define WIFSIGNALED(S) (((S) & 0xff) != 0 && ((S) & 0xff) != 0x7f)
296 #endif
297 #ifndef WTERMSIG
298 #define WTERMSIG(S) ((S) & 0x7f)
299 #endif
300 #ifndef WIFEXITED
301 #define WIFEXITED(S) (((S) & 0xff) == 0)
302 #endif
303 #ifndef WEXITSTATUS
304 #define WEXITSTATUS(S) (((S) & 0xff00) >> 8)
305 #endif
306 #ifndef WSTOPSIG
307 #define WSTOPSIG WEXITSTATUS
308 #endif
309
310
311
312 #ifndef bcopy
313 # ifdef HAVE_BCOPY
314 #  ifdef NEED_DECLARATION_BCOPY
315 extern void bcopy PARAMS ((const PTR, PTR, size_t));
316 #  endif
317 # else /* ! HAVE_BCOPY */
318 #  define bcopy(src,dst,len) memmove((dst),(src),(len))
319 # endif
320 #endif
321
322 #ifndef bcmp
323 # ifdef HAVE_BCMP
324 #  ifdef NEED_DECLARATION_BCMP
325 extern int bcmp PARAMS ((const PTR, const PTR, size_t));
326 #  endif
327 # else /* ! HAVE_BCMP */
328 #  define bcmp(left,right,len) memcmp ((left),(right),(len))
329 # endif
330 #endif
331
332 #ifndef bzero
333 # ifdef HAVE_BZERO
334 #  ifdef NEED_DECLARATION_BZERO
335 extern void bzero PARAMS ((PTR, size_t));
336 #  endif
337 # else /* ! HAVE_BZERO */
338 #  define bzero(dst,len) memset ((dst),0,(len))
339 # endif
340 #endif
341
342 #ifndef index
343 # ifdef HAVE_INDEX
344 #  ifdef NEED_DECLARATION_INDEX
345 extern char *index PARAMS ((const char *, int));
346 #  endif
347 # else /* ! HAVE_INDEX */
348 #  define index strchr
349 # endif
350 #endif
351
352 #ifndef rindex
353 # ifdef HAVE_RINDEX
354 #  ifdef NEED_DECLARATION_RINDEX
355 extern char *rindex PARAMS ((const char *, int));
356 #  endif
357 # else /* ! HAVE_RINDEX */
358 #  define rindex strrchr
359 # endif
360 #endif
361
362 #ifdef NEED_DECLARATION_ATOF
363 extern double atof PARAMS ((const char *));
364 #endif
365
366 #ifdef NEED_DECLARATION_ATOL
367 extern long atol PARAMS ((const char *));
368 #endif
369
370 #ifdef NEED_DECLARATION_FREE
371 extern void free PARAMS ((PTR));
372 #endif
373
374 #ifdef NEED_DECLARATION_GETCWD
375 extern char *getcwd PARAMS ((char *, size_t));
376 #endif
377
378 #ifdef NEED_DECLARATION_GETENV
379 extern char *getenv PARAMS ((const char *));
380 #endif
381
382 #ifdef NEED_DECLARATION_GETWD
383 extern char *getwd PARAMS ((char *));
384 #endif
385
386 #ifdef NEED_DECLARATION_SBRK
387 extern PTR sbrk PARAMS ((int));
388 #endif
389
390 #ifdef NEED_DECLARATION_STRSTR
391 extern char *strstr PARAMS ((const char *, const char *));
392 #endif
393
394 #ifdef HAVE_MALLOC_H
395 #include <malloc.h>
396 #endif
397
398 #ifdef NEED_DECLARATION_MALLOC
399 extern PTR malloc PARAMS ((size_t));
400 #endif
401
402 #ifdef NEED_DECLARATION_CALLOC
403 extern PTR calloc PARAMS ((size_t, size_t));
404 #endif
405
406 #ifdef NEED_DECLARATION_REALLOC
407 extern PTR realloc PARAMS ((PTR, size_t));
408 #endif
409
410 /* If the system doesn't provide strsignal, we get it defined in
411    libiberty but no declaration is supplied. */
412 #ifdef NEED_DECLARATION_STRSIGNAL
413 # ifndef strsignal
414 extern const char *strsignal PARAMS ((int));
415 # endif
416 #endif
417
418 #ifdef HAVE_GETRLIMIT
419 # ifdef NEED_DECLARATION_GETRLIMIT
420 #  ifndef getrlimit
421 #   ifdef ANSI_PROTOTYPES
422 struct rlimit;
423 #   endif
424 extern int getrlimit PARAMS ((int, struct rlimit *));
425 #  endif
426 # endif
427 #endif
428
429 #ifdef HAVE_SETRLIMIT
430 # ifdef NEED_DECLARATION_SETRLIMIT
431 #  ifndef setrlimit
432 #   ifdef ANSI_PROTOTYPES
433 struct rlimit;
434 #   endif
435 extern int setrlimit PARAMS ((int, const struct rlimit *));
436 #  endif
437 # endif
438 #endif
439
440 /* HAVE_VOLATILE only refers to the stage1 compiler.  We also check
441    __STDC__ and assume gcc sets it and has volatile in stage >=2. */
442 #if !defined(HAVE_VOLATILE) && !defined(__STDC__) && !defined(volatile)
443 #define volatile
444 #endif
445
446 #ifdef NEED_DECLARATION_ABORT
447 extern void abort PARAMS ((void));
448 #endif
449
450 /* Define a STRINGIFY macro that's right for ANSI or traditional C.
451    Note: if the argument passed to STRINGIFY is itself a macro, eg
452    #define foo bar, STRINGIFY(foo) will produce "foo", not "bar".
453    Although the __STDC__ case could be made to expand this via a layer
454    of indirection, the traditional C case can not do so.  Therefore
455    this behavior is not supported. */
456 #ifndef STRINGIFY
457 # ifdef HAVE_STRINGIZE
458 #  define STRINGIFY(STRING) #STRING
459 # else
460 #  define STRINGIFY(STRING) "STRING"
461 # endif
462 #endif /* ! STRINGIFY */
463
464 #if HAVE_SYS_STAT_H
465 # include <sys/stat.h>
466 #endif
467
468 /* Test if something is a normal file.  */
469 #ifndef S_ISREG
470 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
471 #endif
472
473 /* Test if something is a directory.  */
474 #ifndef S_ISDIR
475 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
476 #endif
477
478 /* Test if something is a character special file.  */
479 #ifndef S_ISCHR
480 #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
481 #endif
482
483 /* Test if something is a socket.  */
484 #ifndef S_ISSOCK
485 # ifdef S_IFSOCK
486 #   define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
487 # else
488 #   define S_ISSOCK(m) 0
489 # endif
490 #endif
491
492 /* Test if something is a FIFO.  */
493 #ifndef S_ISFIFO
494 # ifdef S_IFIFO
495 #  define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
496 # else
497 #  define S_ISFIFO(m) 0
498 # endif
499 #endif
500
501 /* Approximate O_NONBLOCK.  */
502 #ifndef O_NONBLOCK
503 #define O_NONBLOCK O_NDELAY
504 #endif
505
506 /* Approximate O_NOCTTY.  */
507 #ifndef O_NOCTTY
508 #define O_NOCTTY 0
509 #endif
510
511 /* Define well known filenos if the system does not define them.  */
512 #ifndef STDIN_FILENO
513 # define STDIN_FILENO   0
514 #endif
515 #ifndef STDOUT_FILENO
516 # define STDOUT_FILENO  1
517 #endif
518 #ifndef STDERR_FILENO
519 # define STDERR_FILENO  2
520 #endif
521
522 /* Some systems have mkdir that takes a single argument. */
523 #ifdef MKDIR_TAKES_ONE_ARG
524 # define mkdir(a,b) mkdir(a)
525 #endif
526
527 /* Provide a way to print an address via printf.  */
528 #ifndef HOST_PTR_PRINTF
529 # ifdef HAVE_PRINTF_PTR
530 #  define HOST_PTR_PRINTF "%p"
531 # else
532 #  define HOST_PTR_PRINTF \
533     (sizeof (int) == sizeof (char *) ? "%x" \
534      : sizeof (long) == sizeof (char *) ? "%lx" : "%llx")
535 # endif
536 #endif /* ! HOST_PTR_PRINTF */
537
538 /* By default, colon separates directories in a path.  */
539 #ifndef PATH_SEPARATOR
540 #define PATH_SEPARATOR ':'
541 #endif
542
543 #ifndef DIR_SEPARATOR
544 #define DIR_SEPARATOR '/'
545 #endif
546
547 /* Define IS_DIR_SEPARATOR.  */
548 #ifndef DIR_SEPARATOR_2
549 # define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
550 #else /* DIR_SEPARATOR_2 */
551 # define IS_DIR_SEPARATOR(ch) \
552         (((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
553 #endif /* DIR_SEPARATOR_2 */
554
555 /* Get libiberty declarations. */
556 #include "libiberty.h"
557
558 /* Make sure that ONLY_INT_FIELDS has an integral value.  */
559 #ifdef ONLY_INT_FIELDS
560 #undef ONLY_INT_FIELDS
561 #define ONLY_INT_FIELDS 1
562 #else
563 #define ONLY_INT_FIELDS 0
564 #endif 
565
566 /* Enumerated bitfields are safe to use unless we've been explictly told
567    otherwise or if they are signed. */
568  
569 #define USE_ENUM_BITFIELDS (__GNUC__ || (!ONLY_INT_FIELDS && ENUM_BITFIELDS_ARE_UNSIGNED))
570
571 #if USE_ENUM_BITFIELDS
572 #define ENUM_BITFIELD(TYPE) enum TYPE
573 #else
574 #define ENUM_BITFIELD(TYPE) unsigned int
575 #endif
576
577
578 #endif /* __GCC_SYSTEM_H__ */