OSDN Git Service

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