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