OSDN Git Service

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