]>
Commit | Line | Data |
---|---|---|
073609a4 | 1 | /* system.h - Get common system includes and various definitions and |
2 | declarations based on autoconf macros. | |
4a5355db | 3 | Copyright (C) 1998, 1999 Free Software Foundation, Inc. |
073609a4 | 4 | |
41e3445a | 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. */ | |
073609a4 | 21 | |
22 | #ifndef __GCC_SYSTEM_H__ | |
23 | #define __GCC_SYSTEM_H__ | |
24 | ||
32e0908a | 25 | /* We must include stdarg.h/varargs.h before stdio.h. */ |
7bca031c | 26 | #ifdef ANSI_PROTOTYPES |
32e0908a | 27 | #include <stdarg.h> |
28 | #else | |
29 | #include <varargs.h> | |
30 | #endif | |
31 | ||
073609a4 | 32 | #include <stdio.h> |
2e9695c1 | 33 | |
34 | /* Define a generic NULL if one hasn't already been defined. */ | |
35 | #ifndef NULL | |
36 | #define NULL 0 | |
37 | #endif | |
38 | ||
1bcf5ab8 | 39 | /* The compiler is not a multi-threaded application and therefore we |
40 | do not have to use the locking functions. */ | |
41 | #ifdef HAVE_PUTC_UNLOCKED | |
42 | # undef putc | |
43 | # define putc(C, Stream) putc_unlocked (C, Stream) | |
44 | #endif | |
45 | #ifdef HAVE_FPUTC_UNLOCKED | |
46 | # undef fputc | |
47 | # define fputc(C, Stream) fputc_unlocked (C, Stream) | |
48 | #endif | |
49 | #ifdef HAVE_FPUTS_UNLOCKED | |
50 | # undef fputs | |
51 | # define fputs(String, Stream) fputs_unlocked (String, Stream) | |
52 | #endif | |
53 | ||
073609a4 | 54 | #include <ctype.h> |
55 | ||
56 | /* Jim Meyering writes: | |
89f7f2db | 57 | |
073609a4 | 58 | "... Some ctype macros are valid only for character codes that |
59 | isascii says are ASCII (SGI's IRIX-4.0.5 is one such system --when | |
60 | using /bin/cc or gcc but without giving an ansi option). So, all | |
61 | ctype uses should be through macros like ISPRINT... If | |
62 | STDC_HEADERS is defined, then autoconf has verified that the ctype | |
63 | macros don't need to be guarded with references to isascii. ... | |
64 | Defining isascii to 1 should let any compiler worth its salt | |
65 | eliminate the && through constant folding." | |
89f7f2db | 66 | |
073609a4 | 67 | Bruno Haible adds: |
89f7f2db | 68 | |
073609a4 | 69 | "... Furthermore, isupper(c) etc. have an undefined result if c is |
70 | outside the range -1 <= c <= 255. One is tempted to write isupper(c) | |
71 | with c being of type `char', but this is wrong if c is an 8-bit | |
72 | character >= 128 which gets sign-extended to a negative value. | |
73 | The macro ISUPPER protects against this as well." */ | |
89f7f2db | 74 | |
073609a4 | 75 | #if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII)) |
76 | # define IN_CTYPE_DOMAIN(c) 1 | |
77 | #else | |
78 | # define IN_CTYPE_DOMAIN(c) isascii(c) | |
79 | #endif | |
89f7f2db | 80 | |
073609a4 | 81 | #ifdef isblank |
82 | # define ISBLANK(c) (IN_CTYPE_DOMAIN (c) && isblank (c)) | |
83 | #else | |
84 | # define ISBLANK(c) ((c) == ' ' || (c) == '\t') | |
85 | #endif | |
86 | #ifdef isgraph | |
87 | # define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isgraph (c)) | |
88 | #else | |
89 | # define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isprint (c) && !isspace (c)) | |
90 | #endif | |
89f7f2db | 91 | |
073609a4 | 92 | #define ISPRINT(c) (IN_CTYPE_DOMAIN (c) && isprint (c)) |
93 | #define ISALNUM(c) (IN_CTYPE_DOMAIN (c) && isalnum (c)) | |
94 | #define ISALPHA(c) (IN_CTYPE_DOMAIN (c) && isalpha (c)) | |
95 | #define ISCNTRL(c) (IN_CTYPE_DOMAIN (c) && iscntrl (c)) | |
96 | #define ISLOWER(c) (IN_CTYPE_DOMAIN (c) && islower (c)) | |
97 | #define ISPUNCT(c) (IN_CTYPE_DOMAIN (c) && ispunct (c)) | |
98 | #define ISSPACE(c) (IN_CTYPE_DOMAIN (c) && isspace (c)) | |
99 | #define ISUPPER(c) (IN_CTYPE_DOMAIN (c) && isupper (c)) | |
100 | #define ISXDIGIT(c) (IN_CTYPE_DOMAIN (c) && isxdigit (c)) | |
101 | #define ISDIGIT_LOCALE(c) (IN_CTYPE_DOMAIN (c) && isdigit (c)) | |
89f7f2db | 102 | |
073609a4 | 103 | /* ISDIGIT differs from ISDIGIT_LOCALE, as follows: |
104 | - Its arg may be any int or unsigned int; it need not be an unsigned char. | |
105 | - It's guaranteed to evaluate its argument exactly once. | |
106 | - It's typically faster. | |
107 | Posix 1003.2-1992 section 2.5.2.1 page 50 lines 1556-1558 says that | |
108 | only '0' through '9' are digits. Prefer ISDIGIT to ISDIGIT_LOCALE unless | |
109 | it's important to use the locale's definition of `digit' even when the | |
110 | host does not conform to Posix. */ | |
111 | #define ISDIGIT(c) ((unsigned) (c) - '0' <= 9) | |
112 | ||
113 | ||
114 | #include <sys/types.h> | |
073609a4 | 115 | #include <errno.h> |
116 | ||
117 | #ifndef errno | |
118 | extern int errno; | |
119 | #endif | |
120 | ||
259a120e | 121 | #ifdef STRING_WITH_STRINGS |
073609a4 | 122 | # include <string.h> |
259a120e | 123 | # include <strings.h> |
073609a4 | 124 | #else |
259a120e | 125 | # ifdef HAVE_STRING_H |
126 | # include <string.h> | |
127 | # else | |
128 | # ifdef HAVE_STRINGS_H | |
129 | # include <strings.h> | |
130 | # endif | |
073609a4 | 131 | # endif |
132 | #endif | |
133 | ||
134 | #ifdef HAVE_STDLIB_H | |
135 | # include <stdlib.h> | |
136 | #endif | |
137 | ||
138 | #ifdef HAVE_UNISTD_H | |
139 | # include <unistd.h> | |
140 | #endif | |
141 | ||
142 | #ifdef HAVE_SYS_PARAM_H | |
143 | # include <sys/param.h> | |
144 | #endif | |
145 | ||
146 | #if HAVE_LIMITS_H | |
147 | # include <limits.h> | |
148 | #endif | |
149 | ||
150 | #ifdef TIME_WITH_SYS_TIME | |
151 | # include <sys/time.h> | |
152 | # include <time.h> | |
153 | #else | |
154 | # if HAVE_SYS_TIME_H | |
f11c33a2 | 155 | # include <sys/time.h> |
073609a4 | 156 | # else |
f11c33a2 | 157 | # ifdef HAVE_TIME_H |
158 | # include <time.h> | |
159 | # endif | |
160 | # endif | |
073609a4 | 161 | #endif |
162 | ||
163 | #ifdef HAVE_FCNTL_H | |
164 | # include <fcntl.h> | |
165 | #else | |
f11c33a2 | 166 | # ifdef HAVE_SYS_FILE_H |
167 | # include <sys/file.h> | |
168 | # endif | |
073609a4 | 169 | #endif |
170 | ||
171 | #ifndef SEEK_SET | |
172 | # define SEEK_SET 0 | |
173 | # define SEEK_CUR 1 | |
174 | # define SEEK_END 2 | |
175 | #endif | |
176 | #ifndef F_OK | |
177 | # define F_OK 0 | |
178 | # define X_OK 1 | |
179 | # define W_OK 2 | |
180 | # define R_OK 4 | |
181 | #endif | |
f11c33a2 | 182 | #ifndef O_RDONLY |
183 | # define O_RDONLY 0 | |
184 | #endif | |
185 | #ifndef O_WRONLY | |
186 | # define O_WRONLY 1 | |
187 | #endif | |
073609a4 | 188 | |
65cee259 | 189 | /* Some systems define these in, e.g., param.h. We undefine these names |
190 | here to avoid the warnings. We prefer to use our definitions since we | |
191 | know they are correct. */ | |
192 | ||
193 | #undef MIN | |
194 | #undef MAX | |
195 | #define MIN(X,Y) ((X) < (Y) ? (X) : (Y)) | |
196 | #define MAX(X,Y) ((X) > (Y) ? (X) : (Y)) | |
197 | ||
5a3ee0b1 | 198 | #ifdef HAVE_SYS_WAIT_H |
199 | #include <sys/wait.h> | |
200 | #endif | |
201 | ||
202 | #ifndef WIFSIGNALED | |
203 | #define WIFSIGNALED(S) (((S) & 0xff) != 0 && ((S) & 0xff) != 0x7f) | |
204 | #endif | |
205 | #ifndef WTERMSIG | |
206 | #define WTERMSIG(S) ((S) & 0x7f) | |
207 | #endif | |
208 | #ifndef WIFEXITED | |
209 | #define WIFEXITED(S) (((S) & 0xff) == 0) | |
210 | #endif | |
211 | #ifndef WEXITSTATUS | |
212 | #define WEXITSTATUS(S) (((S) & 0xff00) >> 8) | |
213 | #endif | |
214 | ||
073609a4 | 215 | |
216 | ||
217 | #ifndef bcopy | |
218 | # ifdef HAVE_BCOPY | |
219 | # ifdef NEED_DECLARATION_BCOPY | |
fe879f7c | 220 | extern void bcopy (); |
073609a4 | 221 | # endif |
222 | # else /* ! HAVE_BCOPY */ | |
2f519eef | 223 | # define bcopy(src,dst,len) memmove((dst),(src),(len)) |
073609a4 | 224 | # endif |
225 | #endif | |
226 | ||
227 | #ifndef bcmp | |
228 | # ifdef HAVE_BCMP | |
229 | # ifdef NEED_DECLARATION_BCMP | |
fe879f7c | 230 | extern int bcmp (); |
073609a4 | 231 | # endif |
232 | # else /* ! HAVE_BCMP */ | |
233 | # define bcmp(left,right,len) memcmp ((left),(right),(len)) | |
234 | # endif | |
235 | #endif | |
236 | ||
237 | #ifndef bzero | |
238 | # ifdef HAVE_BZERO | |
239 | # ifdef NEED_DECLARATION_BZERO | |
fe879f7c | 240 | extern void bzero (); |
073609a4 | 241 | # endif |
242 | # else /* ! HAVE_BZERO */ | |
243 | # define bzero(dst,len) memset ((dst),0,(len)) | |
244 | # endif | |
245 | #endif | |
246 | ||
247 | #ifndef index | |
248 | # ifdef HAVE_INDEX | |
249 | # ifdef NEED_DECLARATION_INDEX | |
250 | extern char *index (); | |
251 | # endif | |
252 | # else /* ! HAVE_INDEX */ | |
253 | # define index strchr | |
254 | # endif | |
255 | #endif | |
256 | ||
257 | #ifndef rindex | |
258 | # ifdef HAVE_RINDEX | |
259 | # ifdef NEED_DECLARATION_RINDEX | |
260 | extern char *rindex (); | |
261 | # endif | |
262 | # else /* ! HAVE_RINDEX */ | |
263 | # define rindex strrchr | |
264 | # endif | |
265 | #endif | |
266 | ||
b3819e2e | 267 | #ifdef NEED_DECLARATION_ATOF |
268 | extern double atof (); | |
269 | #endif | |
270 | ||
271 | #ifdef NEED_DECLARATION_ATOL | |
272 | extern long atol(); | |
273 | #endif | |
274 | ||
073609a4 | 275 | #ifdef NEED_DECLARATION_FREE |
276 | extern void free (); | |
277 | #endif | |
278 | ||
ccb1060c | 279 | #ifdef NEED_DECLARATION_GETCWD |
280 | extern char *getcwd (); | |
281 | #endif | |
282 | ||
fe879f7c | 283 | #ifdef NEED_DECLARATION_GETENV |
284 | extern char *getenv (); | |
285 | #endif | |
286 | ||
ccb1060c | 287 | #ifdef NEED_DECLARATION_GETWD |
288 | extern char *getwd (); | |
289 | #endif | |
290 | ||
b3819e2e | 291 | #ifdef NEED_DECLARATION_SBRK |
292 | extern char *sbrk (); | |
293 | #endif | |
294 | ||
ccb1060c | 295 | #ifdef HAVE_STRERROR |
296 | # ifdef NEED_DECLARATION_STRERROR | |
297 | # ifndef strerror | |
298 | extern char *strerror (); | |
299 | # endif | |
300 | # endif | |
301 | #else /* ! HAVE_STRERROR */ | |
302 | extern int sys_nerr; | |
303 | extern char *sys_errlist[]; | |
304 | #endif /* HAVE_STRERROR */ | |
305 | ||
0b6ff5fb | 306 | #ifdef HAVE_STRSIGNAL |
307 | # ifdef NEED_DECLARATION_STRSIGNAL | |
308 | # ifndef strsignal | |
309 | extern char * strsignal (); | |
310 | # endif | |
311 | # endif | |
312 | #else /* ! HAVE_STRSIGNAL */ | |
313 | # ifndef SYS_SIGLIST_DECLARED | |
314 | # ifndef NO_SYS_SIGLIST | |
315 | extern char * sys_siglist[]; | |
316 | # endif | |
317 | # endif | |
318 | #endif /* HAVE_STRSIGNAL */ | |
319 | ||
436f5383 | 320 | #ifdef HAVE_GETRLIMIT |
321 | # ifdef NEED_DECLARATION_GETRLIMIT | |
322 | # ifndef getrlimit | |
323 | extern int getrlimit (); | |
324 | # endif | |
325 | # endif | |
326 | #endif | |
327 | ||
328 | #ifdef HAVE_SETRLIMIT | |
329 | # ifdef NEED_DECLARATION_SETRLIMIT | |
330 | # ifndef setrlimit | |
331 | extern int setrlimit (); | |
332 | # endif | |
333 | # endif | |
334 | #endif | |
335 | ||
8564ad21 | 336 | /* HAVE_VOLATILE only refers to the stage1 compiler. We also check |
337 | __STDC__ and assume gcc sets it and has volatile in stage >=2. */ | |
338 | #if !defined(HAVE_VOLATILE) && !defined(__STDC__) && !defined(volatile) | |
339 | #define volatile | |
340 | #endif | |
341 | ||
97fce000 | 342 | /* Redefine abort to report an internal error w/o coredump, and reporting the |
343 | location of the error in the source file. */ | |
344 | #ifndef abort | |
345 | #ifndef __STDC__ | |
346 | #ifndef __GNUC__ | |
347 | #ifndef USE_SYSTEM_ABORT | |
348 | #define USE_SYSTEM_ABORT | |
349 | #endif /* !USE_SYSTEM_ABORT */ | |
350 | #endif /* !__GNUC__ */ | |
351 | #endif /* !__STDC__ */ | |
352 | ||
b3819e2e | 353 | #ifdef USE_SYSTEM_ABORT |
354 | # ifdef NEED_DECLARATION_ABORT | |
ccb1060c | 355 | extern void abort (); |
b3819e2e | 356 | # endif |
357 | #else | |
97fce000 | 358 | #if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) |
359 | #define abort() \ | |
360 | (fprintf (stderr, \ | |
361 | "%s:%d: Internal compiler error\n", __FILE__, __LINE__), \ | |
362 | exit (FATAL_EXIT_CODE)) | |
363 | ||
364 | #else | |
365 | #define abort() \ | |
366 | (fprintf (stderr, \ | |
4a5355db | 367 | "%s:%d: Internal compiler error in function %s\n" \ |
368 | "Please submit a full bug report to `egcs-bugs@cygnus.com'.\n" \ | |
369 | "See <URL:http://egcs.cygnus.com/faq.html#bugreport> for details.\n", \ | |
97fce000 | 370 | __FILE__, __LINE__, __PRETTY_FUNCTION__), \ |
371 | exit (FATAL_EXIT_CODE)) | |
372 | ||
373 | #endif /* recent gcc */ | |
b3819e2e | 374 | #endif /* USE_SYSTEM_ABORT */ |
97fce000 | 375 | #endif /* !abort */ |
376 | ||
42aaf0b7 | 377 | |
378 | /* Define a STRINGIFY macro that's right for ANSI or traditional C. | |
379 | HAVE_CPP_STRINGIFY only refers to the stage1 compiler. Assume that | |
380 | (non-traditional) gcc used in stage2 or later has this feature. | |
381 | ||
382 | Note: if the argument passed to STRINGIFY is itself a macro, eg | |
383 | #define foo bar, STRINGIFY(foo) will produce "foo", not "bar". | |
384 | Although the __STDC__ case could be made to expand this via a layer | |
385 | of indirection, the traditional C case can not do so. Therefore | |
386 | this behavior is not supported. */ | |
387 | #ifndef STRINGIFY | |
388 | # if defined(HAVE_CPP_STRINGIFY) || (defined(__GNUC__) && defined(__STDC__)) | |
389 | # define STRINGIFY(STRING) #STRING | |
390 | # else | |
391 | # define STRINGIFY(STRING) "STRING" | |
392 | # endif | |
393 | #endif /* ! STRINGIFY */ | |
394 | ||
89f7f2db | 395 | |
396 | /* These macros are here in preparation for the use of gettext in egcs. */ | |
397 | #define _(String) String | |
398 | #define N_(String) String | |
399 | ||
8be93a1c | 400 | #if HAVE_SYS_STAT_H |
401 | # include <sys/stat.h> | |
402 | #endif | |
d128acff | 403 | |
404 | /* Test if something is a normal file. */ | |
405 | #ifndef S_ISREG | |
406 | #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) | |
407 | #endif | |
408 | ||
409 | /* Test if something is a directory. */ | |
410 | #ifndef S_ISDIR | |
411 | #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) | |
412 | #endif | |
413 | ||
ac7eca71 | 414 | /* Get libiberty declarations. */ |
415 | #include "libiberty.h" | |
416 | ||
be2828ce | 417 | #if defined (ANSI_PROTOTYPES) |
418 | # define PRINTF_PROTO(ARGS, m, n) PVPROTO (ARGS) ATTRIBUTE_PRINTF(m, n) | |
419 | #else | |
420 | # define PRINTF_PROTO(ARGS, m, n) () ATTRIBUTE_PRINTF(m, n) | |
421 | #endif | |
422 | #define PRINTF_PROTO_1(ARGS) PRINTF_PROTO(ARGS, 1, 2) | |
423 | #define PRINTF_PROTO_2(ARGS) PRINTF_PROTO(ARGS, 2, 3) | |
424 | #define PRINTF_PROTO_3(ARGS) PRINTF_PROTO(ARGS, 3, 4) | |
425 | #define PRINTF_PROTO_4(ARGS) PRINTF_PROTO(ARGS, 4, 5) | |
426 | ||
427 | ||
073609a4 | 428 | #endif /* __GCC_SYSTEM_H__ */ |