]> gcc.gnu.org Git - gcc.git/blame - gcc/system.h
safe-ctype.h: New file.
[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
6f81b1ad
RH
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
aca69483 46#include <stdio.h>
51db713f
KG
47
48/* Define a generic NULL if one hasn't already been defined. */
49#ifndef NULL
50#define NULL 0
51#endif
52
54953b66 53/* The compiler is not a multi-threaded application and therefore we
9c30c0e7
ZW
54 do not have to use the locking functions.
55
f31e826b
KG
56 HAVE_DECL_PUTC_UNLOCKED actually indicates whether or not the IO
57 code is multi-thread safe by default. If it is set to 0, then do
58 not worry about using the _unlocked functions.
9c30c0e7
ZW
59
60 fputs_unlocked is an extension and needs to be prototyped specially. */
61
f31e826b 62#if defined HAVE_PUTC_UNLOCKED && (defined (HAVE_DECL_PUTC_UNLOCKED) && HAVE_DECL_PUTC_UNLOCKED)
54953b66
UD
63# undef putc
64# define putc(C, Stream) putc_unlocked (C, Stream)
65#endif
f31e826b 66#if defined HAVE_FPUTC_UNLOCKED && (defined (HAVE_DECL_PUTC_UNLOCKED) && HAVE_DECL_PUTC_UNLOCKED)
54953b66
UD
67# undef fputc
68# define fputc(C, Stream) fputc_unlocked (C, Stream)
69#endif
f31e826b 70#if defined HAVE_FPUTS_UNLOCKED && (defined (HAVE_DECL_PUTC_UNLOCKED) && HAVE_DECL_PUTC_UNLOCKED)
54953b66
UD
71# undef fputs
72# define fputs(String, Stream) fputs_unlocked (String, Stream)
f31e826b 73# if defined (HAVE_DECL_FPUTS_UNLOCKED) && !HAVE_DECL_FPUTS_UNLOCKED
cdadb1dd 74extern int fputs_unlocked PARAMS ((const char *, FILE *));
9c30c0e7 75# endif
54953b66
UD
76#endif
77
f6bbde28
ZW
78/* There are an extraordinary number of issues with <ctype.h>.
79 The last straw is that it varies with the locale. Use libiberty's
80 replacement instead. */
81#include <safe-ctype.h>
aca69483 82
f6bbde28 83/* Define a default escape character; it's different for EBCDIC. */
64f8a718
RH
84#ifndef TARGET_ESC
85#define TARGET_ESC 033
86#endif
87
aca69483 88#include <sys/types.h>
c5c76735 89
aca69483
KG
90#include <errno.h>
91
92#ifndef errno
93extern int errno;
94#endif
95
ccc7d11a 96#ifdef STRING_WITH_STRINGS
aca69483 97# include <string.h>
ccc7d11a 98# include <strings.h>
aca69483 99#else
ccc7d11a
KG
100# ifdef HAVE_STRING_H
101# include <string.h>
102# else
103# ifdef HAVE_STRINGS_H
104# include <strings.h>
105# endif
aca69483
KG
106# endif
107#endif
108
109#ifdef HAVE_STDLIB_H
110# include <stdlib.h>
512b62fb
JM
111# ifdef USE_C_ALLOCA
112/* Note that systems that use glibc have a <stdlib.h> that includes
113 <alloca.h> that defines alloca, so let USE_C_ALLOCA override this. */
114# undef alloca
115#endif
aca69483
KG
116#endif
117
118#ifdef HAVE_UNISTD_H
119# include <unistd.h>
120#endif
121
122#ifdef HAVE_SYS_PARAM_H
123# include <sys/param.h>
124#endif
125
126#if HAVE_LIMITS_H
127# include <limits.h>
128#endif
129
f80d6fd7
KG
130/* Find HOST_WIDEST_INT and set its bit size, type and print macros.
131 It will be the largest integer mode supported by the host which may
132 (or may not) be larger than HOST_WIDE_INT. This must appear after
133 <limits.h> since we only use `long long' if its bigger than a
134 `long' and also if it is supported by macros in limits.h. For old
135 hosts which don't have a limits.h (and thus won't include it in
136 stage2 cause we don't rerun configure) we assume gcc supports long
137 long.) Note, you won't get these defined if you don't include
138 {ht}config.h before this file to set the HOST_BITS_PER_* macros. */
139
140#ifndef HOST_WIDEST_INT
141# if defined (HOST_BITS_PER_LONG) && defined (HOST_BITS_PER_LONGLONG)
142# if (HOST_BITS_PER_LONGLONG > HOST_BITS_PER_LONG) && (defined (LONG_LONG_MAX) || defined (LONGLONG_MAX) || defined (LLONG_MAX) || defined (__GNUC__))
143# define HOST_BITS_PER_WIDEST_INT HOST_BITS_PER_LONGLONG
144# define HOST_WIDEST_INT long long
145# define HOST_WIDEST_INT_PRINT_DEC "%lld"
146# define HOST_WIDEST_INT_PRINT_UNSIGNED "%llu"
147# define HOST_WIDEST_INT_PRINT_HEX "0x%llx"
148# else
149# define HOST_BITS_PER_WIDEST_INT HOST_BITS_PER_LONG
150# define HOST_WIDEST_INT long
151# define HOST_WIDEST_INT_PRINT_DEC "%ld"
152# define HOST_WIDEST_INT_PRINT_UNSIGNED "%lu"
153# define HOST_WIDEST_INT_PRINT_HEX "0x%lx"
154# endif /*(long long>long) && (LONG_LONG_MAX||LONGLONG_MAX||LLONG_MAX||GNUC)*/
155# endif /* defined(HOST_BITS_PER_LONG) && defined(HOST_BITS_PER_LONGLONG) */
156#endif /* ! HOST_WIDEST_INT */
157
f12bc141
ZW
158/* Infrastructure for defining missing _MAX and _MIN macros. Note that
159 macros defined with these cannot be used in #if. */
160
161/* The extra casts work around common compiler bugs. */
162#define INTTYPE_SIGNED(t) (! ((t) 0 < (t) -1))
163/* The outer cast is needed to work around a bug in Cray C 5.0.3.0.
164 It is necessary at least when t == time_t. */
165#define INTTYPE_MINIMUM(t) ((t) (INTTYPE_SIGNED (t) \
166 ? ~ (t) 0 << (sizeof(t) * CHAR_BIT - 1) : (t) 0))
167#define INTTYPE_MAXIMUM(t) ((t) (~ (t) 0 - INTTYPE_MINIMUM (t)))
168
169/* Use that infrastructure to provide a few constants. */
170#ifndef UCHAR_MAX
171# define UCHAR_MAX INTTYPE_MAXIMUM (unsigned char)
172#endif
173
aca69483
KG
174#ifdef TIME_WITH_SYS_TIME
175# include <sys/time.h>
176# include <time.h>
177#else
178# if HAVE_SYS_TIME_H
e572c0c6 179# include <sys/time.h>
aca69483 180# else
e572c0c6
KG
181# ifdef HAVE_TIME_H
182# include <time.h>
183# endif
184# endif
aca69483
KG
185#endif
186
187#ifdef HAVE_FCNTL_H
188# include <fcntl.h>
189#else
e572c0c6
KG
190# ifdef HAVE_SYS_FILE_H
191# include <sys/file.h>
192# endif
aca69483
KG
193#endif
194
195#ifndef SEEK_SET
196# define SEEK_SET 0
197# define SEEK_CUR 1
198# define SEEK_END 2
199#endif
200#ifndef F_OK
201# define F_OK 0
202# define X_OK 1
203# define W_OK 2
204# define R_OK 4
205#endif
e572c0c6
KG
206#ifndef O_RDONLY
207# define O_RDONLY 0
208#endif
209#ifndef O_WRONLY
210# define O_WRONLY 1
211#endif
aca69483 212
36b8337d
KG
213/* Some systems define these in, e.g., param.h. We undefine these names
214 here to avoid the warnings. We prefer to use our definitions since we
215 know they are correct. */
216
217#undef MIN
218#undef MAX
219#define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
220#define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
221
13799af3
MM
222/* Returns the least number N such that N * Y >= X. */
223#define CEIL(x,y) (((x) + (y) - 1) / (y))
224
e9831ca0
KG
225#ifdef HAVE_SYS_WAIT_H
226#include <sys/wait.h>
227#endif
228
229#ifndef WIFSIGNALED
230#define WIFSIGNALED(S) (((S) & 0xff) != 0 && ((S) & 0xff) != 0x7f)
231#endif
232#ifndef WTERMSIG
233#define WTERMSIG(S) ((S) & 0x7f)
234#endif
235#ifndef WIFEXITED
236#define WIFEXITED(S) (((S) & 0xff) == 0)
237#endif
238#ifndef WEXITSTATUS
239#define WEXITSTATUS(S) (((S) & 0xff00) >> 8)
240#endif
8fa213ac
PDM
241#ifndef WSTOPSIG
242#define WSTOPSIG WEXITSTATUS
243#endif
e9831ca0 244
f31e826b
KG
245/* The HAVE_DECL_* macros are three-state, undefined, 0 or 1. If they
246 are defined to 0 then we must provide the relevant declaration
247 here. These checks will be in the undefined state while configure
248 is running so be careful to test "defined (HAVE_DECL_*)". */
aca69483
KG
249
250#ifndef bcopy
251# ifdef HAVE_BCOPY
f31e826b 252# if defined (HAVE_DECL_BCOPY) && !HAVE_DECL_BCOPY
d4d4ae5f 253extern void bcopy PARAMS ((const PTR, PTR, size_t));
aca69483
KG
254# endif
255# else /* ! HAVE_BCOPY */
b3c9dc1a 256# define bcopy(src,dst,len) memmove((dst),(src),(len))
aca69483
KG
257# endif
258#endif
259
f31e826b 260#if defined (HAVE_DECL_ATOF) && !HAVE_DECL_ATOF
d4d4ae5f 261extern double atof PARAMS ((const char *));
8f81384f
KG
262#endif
263
f31e826b 264#if defined (HAVE_DECL_ATOL) && !HAVE_DECL_ATOL
d4d4ae5f 265extern long atol PARAMS ((const char *));
8f81384f
KG
266#endif
267
f31e826b 268#if defined (HAVE_DECL_FREE) && !HAVE_DECL_FREE
d4d4ae5f 269extern void free PARAMS ((PTR));
aca69483
KG
270#endif
271
f31e826b 272#if defined (HAVE_DECL_GETCWD) && !HAVE_DECL_GETCWD
d4d4ae5f 273extern char *getcwd PARAMS ((char *, size_t));
6cd5dccd
KG
274#endif
275
f31e826b 276#if defined (HAVE_DECL_GETENV) && !HAVE_DECL_GETENV
d4d4ae5f 277extern char *getenv PARAMS ((const char *));
79e11844
KG
278#endif
279
ebb13e7e
RK
280#if defined (HAVE_DECL_GETOPT) && !HAVE_DECL_GETOPT
281extern int getopt PARAMS ((int, char **, char *));
282#endif
283
f31e826b 284#if defined (HAVE_DECL_GETWD) && !HAVE_DECL_GETWD
d4d4ae5f 285extern char *getwd PARAMS ((char *));
6cd5dccd
KG
286#endif
287
f31e826b 288#if defined (HAVE_DECL_SBRK) && !HAVE_DECL_SBRK
d4d4ae5f 289extern PTR sbrk PARAMS ((int));
8f81384f
KG
290#endif
291
f31e826b 292#if defined (HAVE_DECL_STRSTR) && !HAVE_DECL_STRSTR
d4d4ae5f 293extern char *strstr PARAMS ((const char *, const char *));
d3d5cc97
JL
294#endif
295
c5c76735
JL
296#ifdef HAVE_MALLOC_H
297#include <malloc.h>
298#endif
299
f31e826b 300#if defined (HAVE_DECL_MALLOC) && !HAVE_DECL_MALLOC
d4d4ae5f 301extern PTR malloc PARAMS ((size_t));
c5c76735
JL
302#endif
303
f31e826b 304#if defined (HAVE_DECL_CALLOC) && !HAVE_DECL_CALLOC
d4d4ae5f 305extern PTR calloc PARAMS ((size_t, size_t));
c5c76735
JL
306#endif
307
f31e826b 308#if defined (HAVE_DECL_REALLOC) && !HAVE_DECL_REALLOC
d4d4ae5f 309extern PTR realloc PARAMS ((PTR, size_t));
c5c76735
JL
310#endif
311
759af044
KG
312/* If the system doesn't provide strsignal, we get it defined in
313 libiberty but no declaration is supplied. */
317639a8 314#ifndef HAVE_STRSIGNAL
759af044
KG
315# ifndef strsignal
316extern const char *strsignal PARAMS ((int));
007e8d2a 317# endif
759af044 318#endif
007e8d2a 319
d2cabf16 320#ifdef HAVE_GETRLIMIT
f31e826b 321# if defined (HAVE_DECL_GETRLIMIT) && !HAVE_DECL_GETRLIMIT
d2cabf16 322# ifndef getrlimit
d4d4ae5f
KG
323# ifdef ANSI_PROTOTYPES
324struct rlimit;
325# endif
326extern int getrlimit PARAMS ((int, struct rlimit *));
d2cabf16
KG
327# endif
328# endif
329#endif
330
331#ifdef HAVE_SETRLIMIT
f31e826b 332# if defined (HAVE_DECL_SETRLIMIT) && !HAVE_DECL_SETRLIMIT
d2cabf16 333# ifndef setrlimit
d4d4ae5f
KG
334# ifdef ANSI_PROTOTYPES
335struct rlimit;
336# endif
337extern int setrlimit PARAMS ((int, const struct rlimit *));
d2cabf16
KG
338# endif
339# endif
340#endif
341
e9b4fabf
JL
342/* HAVE_VOLATILE only refers to the stage1 compiler. We also check
343 __STDC__ and assume gcc sets it and has volatile in stage >=2. */
344#if !defined(HAVE_VOLATILE) && !defined(__STDC__) && !defined(volatile)
345#define volatile
346#endif
347
f31e826b 348#if defined (HAVE_DECL_ABORT) && !HAVE_DECL_ABORT
d4d4ae5f 349extern void abort PARAMS ((void));
2a611d21 350#endif
d4ba0ead 351
61d0346d 352/* 1 if we have C99 designated initializers. */
18922061 353#if !defined(HAVE_DESIGNATED_INITIALIZERS)
61d0346d
NB
354#define HAVE_DESIGNATED_INITIALIZERS \
355 ((GCC_VERSION >= 2007) || (__STDC_VERSION__ >= 199901L))
18922061 356#endif
61d0346d 357
d4ba0ead 358/* Define a STRINGIFY macro that's right for ANSI or traditional C.
d4ba0ead
KG
359 Note: if the argument passed to STRINGIFY is itself a macro, eg
360 #define foo bar, STRINGIFY(foo) will produce "foo", not "bar".
361 Although the __STDC__ case could be made to expand this via a layer
362 of indirection, the traditional C case can not do so. Therefore
363 this behavior is not supported. */
364#ifndef STRINGIFY
890ad3ea 365# ifdef HAVE_STRINGIZE
d4ba0ead
KG
366# define STRINGIFY(STRING) #STRING
367# else
368# define STRINGIFY(STRING) "STRING"
369# endif
370#endif /* ! STRINGIFY */
371
a05e22b8
RH
372#if HAVE_SYS_STAT_H
373# include <sys/stat.h>
374#endif
9855b854
MN
375
376/* Test if something is a normal file. */
377#ifndef S_ISREG
378#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
379#endif
380
381/* Test if something is a directory. */
382#ifndef S_ISDIR
383#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
384#endif
385
6458033d
ZW
386/* Test if something is a character special file. */
387#ifndef S_ISCHR
388#define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
389#endif
390
be3dad6f
PDM
391/* Test if something is a block special file. */
392#ifndef S_ISBLK
393#define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
394#endif
395
6458033d
ZW
396/* Test if something is a socket. */
397#ifndef S_ISSOCK
398# ifdef S_IFSOCK
399# define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
400# else
401# define S_ISSOCK(m) 0
402# endif
403#endif
404
405/* Test if something is a FIFO. */
406#ifndef S_ISFIFO
407# ifdef S_IFIFO
408# define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
409# else
410# define S_ISFIFO(m) 0
411# endif
412#endif
413
414/* Approximate O_NONBLOCK. */
415#ifndef O_NONBLOCK
416#define O_NONBLOCK O_NDELAY
417#endif
418
419/* Approximate O_NOCTTY. */
420#ifndef O_NOCTTY
421#define O_NOCTTY 0
422#endif
423
f3692274
ME
424/* Define well known filenos if the system does not define them. */
425#ifndef STDIN_FILENO
426# define STDIN_FILENO 0
427#endif
428#ifndef STDOUT_FILENO
429# define STDOUT_FILENO 1
430#endif
924d8a7c 431#ifndef STDERR_FILENO
f3692274
ME
432# define STDERR_FILENO 2
433#endif
434
75923b2f
MK
435/* Some systems have mkdir that takes a single argument. */
436#ifdef MKDIR_TAKES_ONE_ARG
437# define mkdir(a,b) mkdir(a)
438#endif
439
1eb14644
KG
440/* Provide a way to print an address via printf. */
441#ifndef HOST_PTR_PRINTF
442# ifdef HAVE_PRINTF_PTR
443# define HOST_PTR_PRINTF "%p"
444# else
445# define HOST_PTR_PRINTF \
446 (sizeof (int) == sizeof (char *) ? "%x" \
447 : sizeof (long) == sizeof (char *) ? "%lx" : "%llx")
448# endif
449#endif /* ! HOST_PTR_PRINTF */
450
d5b6516d
MK
451/* By default, colon separates directories in a path. */
452#ifndef PATH_SEPARATOR
453#define PATH_SEPARATOR ':'
454#endif
455
456#ifndef DIR_SEPARATOR
457#define DIR_SEPARATOR '/'
458#endif
459
460/* Define IS_DIR_SEPARATOR. */
461#ifndef DIR_SEPARATOR_2
c5c0b3d9 462# define IS_DIR_SEPARATOR(CH) ((CH) == DIR_SEPARATOR)
d5b6516d 463#else /* DIR_SEPARATOR_2 */
c5c0b3d9
RK
464# define IS_DIR_SEPARATOR(CH) \
465 (((CH) == DIR_SEPARATOR) || ((CH) == DIR_SEPARATOR_2))
d5b6516d
MK
466#endif /* DIR_SEPARATOR_2 */
467
c5c0b3d9
RK
468/* Say how to test for an absolute pathname. On Unix systems, this is if
469 it starts with a leading slash or a '$', the latter meaning the value of
470 an environment variable is to be used. On machien with DOS-based
471 file systems, it is also absolute if it starts with a drive identifier. */
472#ifdef HAVE_DOS_BASED_FILE_SYSTEM
473#define IS_ABSOLUTE_PATHNAME(STR) \
474 (IS_DIR_SEPARATOR ((STR)[0]) || (STR)[0] == '$' \
475 || ((STR)[0] != '\0' && (STR)[1] == ':' && IS_DIR_SEPARATOR ((STR)[2])))
476#else
477#define IS_ABSOLUTE_PATHNAME(STR) \
478 (IS_DIR_SEPARATOR ((STR)[0]) || (STR)[0] == '$')
479#endif
480
2778b98d
KG
481/* Get libiberty declarations. */
482#include "libiberty.h"
483
f0e5eeeb
MM
484/* Make sure that ONLY_INT_FIELDS has an integral value. */
485#ifdef ONLY_INT_FIELDS
486#undef ONLY_INT_FIELDS
487#define ONLY_INT_FIELDS 1
488#else
489#define ONLY_INT_FIELDS 0
490#endif
491
49009afd
JL
492/* Provide a default for the HOST_BIT_BUCKET.
493 This suffices for POSIX-like hosts. */
494
495#ifndef HOST_BIT_BUCKET
496#define HOST_BIT_BUCKET "/dev/null"
497#endif
498
c149cc37 499/* Enumerated bitfields are safe to use unless we've been explictly told
ac79db28 500 otherwise or if they are signed. */
c149cc37 501
f0e5eeeb 502#define USE_ENUM_BITFIELDS (__GNUC__ || (!ONLY_INT_FIELDS && ENUM_BITFIELDS_ARE_UNSIGNED))
c149cc37
RL
503
504#if USE_ENUM_BITFIELDS
505#define ENUM_BITFIELD(TYPE) enum TYPE
506#else
507#define ENUM_BITFIELD(TYPE) unsigned int
508#endif
509
e0125cf3
KG
510#ifndef offsetof
511#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
512#endif
c149cc37 513
7de9cc38
KG
514/* Traditional C cannot initialize union members of structs. Provide
515 a macro which expands appropriately to handle it. This only works
516 if you intend to initalize the union member to zero since it relies
517 on default initialization to zero in the traditional C case. */
518#ifdef __STDC__
519#define UNION_INIT_ZERO , {0}
520#else
521#define UNION_INIT_ZERO
522#endif
523
2021c8d2
KG
524/* GCC now gives implicit declaration warnings for undeclared builtins. */
525#if defined(__GNUC__) && defined (__SIZE_TYPE__)
526extern void *alloca (__SIZE_TYPE__);
527#endif
528
fbfc1192
ZW
529/* Various error reporting routines want to use __FUNCTION__. */
530#if (GCC_VERSION < 2007)
791ef777 531#ifndef __FUNCTION__
fbfc1192 532#define __FUNCTION__ "?"
791ef777 533#endif /* ! __FUNCTION__ */
fbfc1192
ZW
534#endif
535
aca69483 536#endif /* __GCC_SYSTEM_H__ */
This page took 0.978931 seconds and 5 git commands to generate.