OSDN Git Service

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