OSDN Git Service

* system.h: Include stdarg.h/varargs.h, make sure they are ordered
[pf3gnuchains/gcc-fork.git] / gcc / system.h
1 /* system.h - Get common system includes and various definitions and
2    declarations based on autoconf macros.
3    Copyright (C) 1998 Free Software Foundation, Inc.
4
5  */
6
7 #ifndef __GCC_SYSTEM_H__
8 #define __GCC_SYSTEM_H__
9
10 /* We must include stdarg.h/varargs.h before stdio.h. */
11 #ifdef __STDC__
12 #include <stdarg.h>
13 #else
14 #include <varargs.h>
15 #endif
16
17 #include <stdio.h>
18
19 /* Define a generic NULL if one hasn't already been defined.  */
20 #ifndef NULL
21 #define NULL 0
22 #endif
23
24 #include <ctype.h>
25
26 /* Jim Meyering writes:
27
28    "... Some ctype macros are valid only for character codes that
29    isascii says are ASCII (SGI's IRIX-4.0.5 is one such system --when
30    using /bin/cc or gcc but without giving an ansi option).  So, all
31    ctype uses should be through macros like ISPRINT...  If
32    STDC_HEADERS is defined, then autoconf has verified that the ctype
33    macros don't need to be guarded with references to isascii. ...
34    Defining isascii to 1 should let any compiler worth its salt
35    eliminate the && through constant folding."
36
37    Bruno Haible adds:
38
39    "... Furthermore, isupper(c) etc. have an undefined result if c is
40    outside the range -1 <= c <= 255. One is tempted to write isupper(c)
41    with c being of type `char', but this is wrong if c is an 8-bit
42    character >= 128 which gets sign-extended to a negative value.
43    The macro ISUPPER protects against this as well."  */
44
45 #if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII))
46 # define IN_CTYPE_DOMAIN(c) 1
47 #else
48 # define IN_CTYPE_DOMAIN(c) isascii(c)
49 #endif
50
51 #ifdef isblank
52 # define ISBLANK(c) (IN_CTYPE_DOMAIN (c) && isblank (c))
53 #else
54 # define ISBLANK(c) ((c) == ' ' || (c) == '\t')
55 #endif
56 #ifdef isgraph
57 # define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isgraph (c))
58 #else
59 # define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isprint (c) && !isspace (c))
60 #endif
61
62 #define ISPRINT(c) (IN_CTYPE_DOMAIN (c) && isprint (c))
63 #define ISALNUM(c) (IN_CTYPE_DOMAIN (c) && isalnum (c))
64 #define ISALPHA(c) (IN_CTYPE_DOMAIN (c) && isalpha (c))
65 #define ISCNTRL(c) (IN_CTYPE_DOMAIN (c) && iscntrl (c))
66 #define ISLOWER(c) (IN_CTYPE_DOMAIN (c) && islower (c))
67 #define ISPUNCT(c) (IN_CTYPE_DOMAIN (c) && ispunct (c))
68 #define ISSPACE(c) (IN_CTYPE_DOMAIN (c) && isspace (c))
69 #define ISUPPER(c) (IN_CTYPE_DOMAIN (c) && isupper (c))
70 #define ISXDIGIT(c) (IN_CTYPE_DOMAIN (c) && isxdigit (c))
71 #define ISDIGIT_LOCALE(c) (IN_CTYPE_DOMAIN (c) && isdigit (c))
72
73 /* ISDIGIT differs from ISDIGIT_LOCALE, as follows:
74    - Its arg may be any int or unsigned int; it need not be an unsigned char.
75    - It's guaranteed to evaluate its argument exactly once.
76    - It's typically faster.
77    Posix 1003.2-1992 section 2.5.2.1 page 50 lines 1556-1558 says that
78    only '0' through '9' are digits.  Prefer ISDIGIT to ISDIGIT_LOCALE unless
79    it's important to use the locale's definition of `digit' even when the
80    host does not conform to Posix.  */
81 #define ISDIGIT(c) ((unsigned) (c) - '0' <= 9)
82
83
84 #include <sys/types.h>
85 #include <errno.h>
86
87 #ifndef errno
88 extern int errno;
89 #endif
90
91 #ifdef HAVE_STRING_H
92 # include <string.h>
93 #else
94 # ifdef HAVE_STRINGS_H
95 #  include <strings.h>
96 # endif
97 #endif
98
99 #ifdef HAVE_STDLIB_H
100 # include <stdlib.h>
101 #endif
102
103 #ifdef HAVE_UNISTD_H
104 # include <unistd.h>
105 #endif
106
107 #ifdef HAVE_SYS_PARAM_H
108 # include <sys/param.h>
109 #endif
110
111 #if HAVE_LIMITS_H
112 # include <limits.h>
113 #endif
114
115 #ifdef TIME_WITH_SYS_TIME
116 # include <sys/time.h>
117 # include <time.h>
118 #else
119 # if HAVE_SYS_TIME_H
120 #  include <sys/time.h>
121 # else
122 #  ifdef HAVE_TIME_H
123 #   include <time.h>
124 #  endif
125 # endif
126 #endif
127
128 #ifdef HAVE_FCNTL_H
129 # include <fcntl.h>
130 #else
131 # ifdef HAVE_SYS_FILE_H
132 #  include <sys/file.h>
133 # endif
134 #endif
135
136 #ifndef SEEK_SET
137 # define SEEK_SET 0
138 # define SEEK_CUR 1
139 # define SEEK_END 2
140 #endif
141 #ifndef F_OK
142 # define F_OK 0
143 # define X_OK 1
144 # define W_OK 2
145 # define R_OK 4
146 #endif
147 #ifndef O_RDONLY
148 # define O_RDONLY 0
149 #endif
150 #ifndef O_WRONLY
151 # define O_WRONLY 1
152 #endif
153
154
155
156 #ifndef bcopy
157 # ifdef HAVE_BCOPY
158 #  ifdef NEED_DECLARATION_BCOPY
159 extern void bcopy ();
160 #  endif
161 # else /* ! HAVE_BCOPY */
162 #  define bcopy(src,dst,len) memcpy ((dst),(src),(len))
163 # endif
164 #endif
165
166 #ifndef bcmp
167 # ifdef HAVE_BCMP
168 #  ifdef NEED_DECLARATION_BCMP
169 extern int bcmp ();
170 #  endif
171 # else /* ! HAVE_BCMP */
172 #  define bcmp(left,right,len) memcmp ((left),(right),(len))
173 # endif
174 #endif
175
176 #ifndef bzero
177 # ifdef HAVE_BZERO
178 #  ifdef NEED_DECLARATION_BZERO
179 extern void bzero ();
180 #  endif
181 # else /* ! HAVE_BZERO */
182 #  define bzero(dst,len) memset ((dst),0,(len))
183 # endif
184 #endif
185
186 #ifndef index
187 # ifdef HAVE_INDEX
188 #  ifdef NEED_DECLARATION_INDEX
189 extern char *index ();
190 #  endif
191 # else /* ! HAVE_INDEX */
192 #  define index strchr
193 # endif
194 #endif
195
196 #ifndef rindex
197 # ifdef HAVE_RINDEX
198 #  ifdef NEED_DECLARATION_RINDEX
199 extern char *rindex ();
200 #  endif
201 # else /* ! HAVE_RINDEX */
202 #  define rindex strrchr
203 # endif
204 #endif
205
206 #ifdef NEED_DECLARATION_ATOF
207 extern double atof ();
208 #endif
209
210 #ifdef NEED_DECLARATION_ATOL
211 extern long atol();
212 #endif
213
214 #ifdef NEED_DECLARATION_FREE
215 extern void free ();
216 #endif
217
218 #ifdef NEED_DECLARATION_GETCWD
219 extern char *getcwd ();
220 #endif
221
222 #ifdef NEED_DECLARATION_GETENV
223 extern char *getenv ();
224 #endif
225
226 #ifdef NEED_DECLARATION_GETWD
227 extern char *getwd ();
228 #endif
229
230 #ifdef NEED_DECLARATION_SBRK
231 extern char *sbrk ();
232 #endif
233
234 #ifdef HAVE_STRERROR
235 # ifdef NEED_DECLARATION_STRERROR
236 #  ifndef strerror
237 extern char *strerror ();
238 #  endif
239 # endif
240 #else /* ! HAVE_STRERROR */
241 extern int sys_nerr;
242 extern char *sys_errlist[];
243 #endif /* HAVE_STRERROR */
244
245 #ifdef HAVE_GETRLIMIT
246 # ifdef NEED_DECLARATION_GETRLIMIT
247 #  ifndef getrlimit
248 extern int getrlimit ();
249 #  endif
250 # endif
251 #endif
252
253 #ifdef HAVE_SETRLIMIT
254 # ifdef NEED_DECLARATION_SETRLIMIT
255 #  ifndef setrlimit
256 extern int setrlimit ();
257 #  endif
258 # endif
259 #endif
260
261 /* HAVE_VOLATILE only refers to the stage1 compiler.  We also check
262    __STDC__ and assume gcc sets it and has volatile in stage >=2. */
263 #if !defined(HAVE_VOLATILE) && !defined(__STDC__) && !defined(volatile)
264 #define volatile
265 #endif
266
267 /* Redefine abort to report an internal error w/o coredump, and reporting the
268    location of the error in the source file.  */
269 #ifndef abort
270 #ifndef __STDC__
271 #ifndef __GNUC__
272 #ifndef USE_SYSTEM_ABORT
273 #define USE_SYSTEM_ABORT
274 #endif /* !USE_SYSTEM_ABORT */
275 #endif /* !__GNUC__ */
276 #endif /* !__STDC__ */
277
278 #ifdef USE_SYSTEM_ABORT
279 # ifdef NEED_DECLARATION_ABORT
280 extern void abort ();
281 # endif
282 #else
283 #if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
284 #define abort()                                                         \
285 (fprintf (stderr,                                                       \
286           "%s:%d: Internal compiler error\n", __FILE__, __LINE__),      \
287  exit (FATAL_EXIT_CODE))
288
289 #else
290 #define abort()                                                         \
291 (fprintf (stderr,                                                       \
292           "%s:%d: Internal compiler error in function %s\n",            \
293           __FILE__, __LINE__, __PRETTY_FUNCTION__),                     \
294  exit (FATAL_EXIT_CODE))
295
296 #endif /* recent gcc */
297 #endif /* USE_SYSTEM_ABORT */
298 #endif /* !abort */
299
300
301 /* Define a STRINGIFY macro that's right for ANSI or traditional C.
302    HAVE_CPP_STRINGIFY only refers to the stage1 compiler.  Assume that
303    (non-traditional) gcc used in stage2 or later has this feature.
304
305    Note: if the argument passed to STRINGIFY is itself a macro, eg
306    #define foo bar, STRINGIFY(foo) will produce "foo", not "bar".
307    Although the __STDC__ case could be made to expand this via a layer
308    of indirection, the traditional C case can not do so.  Therefore
309    this behavior is not supported. */
310 #ifndef STRINGIFY
311 # if defined(HAVE_CPP_STRINGIFY) || (defined(__GNUC__) && defined(__STDC__))
312 #  define STRINGIFY(STRING) #STRING
313 # else
314 #  define STRINGIFY(STRING) "STRING"
315 # endif
316 #endif /* ! STRINGIFY */
317
318
319 /* These macros are here in preparation for the use of gettext in egcs.  */
320 #define _(String) String
321 #define N_(String) String
322
323 #endif /* __GCC_SYSTEM_H__ */