system.h revision 72562
1193635Sedwin/* system.h - Get common system includes and various definitions and
2193635Sedwin   declarations based on autoconf macros.
3193635Sedwin   Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.
4193635Sedwin
5193635SedwinThis file is part of GNU CC.
6193635Sedwin
7193635SedwinGNU CC is free software; you can redistribute it and/or modify
8193635Sedwinit under the terms of the GNU General Public License as published by
9193635Sedwinthe Free Software Foundation; either version 2, or (at your option)
10193635Sedwinany later version.
11193635Sedwin
12193635SedwinGNU CC is distributed in the hope that it will be useful,
13193635Sedwinbut WITHOUT ANY WARRANTY; without even the implied warranty of
14193635SedwinMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15193635SedwinGNU General Public License for more details.
16195652Sdwmalone
17195652SdwmaloneYou should have received a copy of the GNU General Public License
18195652Sdwmalonealong with GNU CC; see the file COPYING.  If not, write to
19193635Sedwinthe Free Software Foundation, 59 Temple Place - Suite 330,
20259974SdelphijBoston, MA 02111-1307, USA.  */
21193635Sedwin
22239600Sdelphij#ifndef __GCC_SYSTEM_H__
23239600Sdelphij#define __GCC_SYSTEM_H__
24239600Sdelphij
25239600Sdelphij/* This is the location of the online document giving information how
26193635Sedwin   to report bugs. If you change this string, also check for strings
27193635Sedwin   not under control of the preprocessor.  */
28193635Sedwin#define GCCBUGURL "<URL:http://www.gnu.org/software/gcc/bugs.html>"
29193635Sedwin
30195652Sdwmalone/* We must include stdarg.h/varargs.h before stdio.h. */
31193635Sedwin#ifdef ANSI_PROTOTYPES
32193635Sedwin#include <stdarg.h>
33239600Sdelphij#else
34239600Sdelphij#include <varargs.h>
35239600Sdelphij#endif
36193635Sedwin
37193635Sedwin#include <stdio.h>
38259974Sdelphij
39193635Sedwin/* Define a generic NULL if one hasn't already been defined.  */
40259974Sdelphij#ifndef NULL
41259974Sdelphij#define NULL 0
42259974Sdelphij#endif
43259974Sdelphij
44259974Sdelphij/* The compiler is not a multi-threaded application and therefore we
45259974Sdelphij   do not have to use the locking functions.
46290001Sglebius
47290001Sglebius   NEED_DECLARATION_PUTC_UNLOCKED actually indicates whether or not
48259974Sdelphij   the IO code is multi-thread safe by default.  If it is not declared,
49259974Sdelphij   then do not worry about using the _unlocked functions.
50259974Sdelphij
51259974Sdelphij   fputs_unlocked is an extension and needs to be prototyped specially.  */
52259974Sdelphij
53259974Sdelphij#if defined HAVE_PUTC_UNLOCKED && !defined NEED_DECLARATION_PUTC_UNLOCKED
54259974Sdelphij# undef putc
55259974Sdelphij# define putc(C, Stream) putc_unlocked (C, Stream)
56259974Sdelphij#endif
57259974Sdelphij#if defined HAVE_FPUTC_UNLOCKED && !defined NEED_DECLARATION_PUTC_UNLOCKED
58193635Sedwin# undef fputc
59193635Sedwin# define fputc(C, Stream) fputc_unlocked (C, Stream)
60193635Sedwin#endif
61193635Sedwin#if defined HAVE_FPUTS_UNLOCKED && !defined NEED_DECLARATION_PUTC_UNLOCKED
62193635Sedwin# undef fputs
63193635Sedwin# define fputs(String, Stream) fputs_unlocked (String, Stream)
64259974Sdelphij# ifdef NEED_DECLARATION_FPUTS_UNLOCKED
65259974Sdelphijextern int fputs_unlocked PROTO ((const char *, FILE *));
66259974Sdelphij# endif
67259974Sdelphij#endif
68259974Sdelphij
69193635Sedwin#include <ctype.h>
70193635Sedwin
71195652Sdwmalone/* Jim Meyering writes:
72195652Sdwmalone
73195652Sdwmalone   "... Some ctype macros are valid only for character codes that
74195652Sdwmalone   isascii says are ASCII (SGI's IRIX-4.0.5 is one such system --when
75195652Sdwmalone   using /bin/cc or gcc but without giving an ansi option).  So, all
76195652Sdwmalone   ctype uses should be through macros like ISPRINT...  If
77193635Sedwin   STDC_HEADERS is defined, then autoconf has verified that the ctype
78195652Sdwmalone   macros don't need to be guarded with references to isascii. ...
79195652Sdwmalone   Defining isascii to 1 should let any compiler worth its salt
80   eliminate the && through constant folding."
81
82   Bruno Haible adds:
83
84   "... Furthermore, isupper(c) etc. have an undefined result if c is
85   outside the range -1 <= c <= 255. One is tempted to write isupper(c)
86   with c being of type `char', but this is wrong if c is an 8-bit
87   character >= 128 which gets sign-extended to a negative value.
88   The macro ISUPPER protects against this as well."  */
89
90#if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII))
91# define IN_CTYPE_DOMAIN(c) 1
92#else
93# define IN_CTYPE_DOMAIN(c) isascii(c)
94#endif
95
96#ifdef isblank
97# define ISBLANK(c) (IN_CTYPE_DOMAIN (c) && isblank (c))
98#else
99# define ISBLANK(c) ((c) == ' ' || (c) == '\t')
100#endif
101#ifdef isgraph
102# define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isgraph (c))
103#else
104# define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isprint (c) && !isspace (c))
105#endif
106
107#define ISPRINT(c) (IN_CTYPE_DOMAIN (c) && isprint (c))
108#define ISALNUM(c) (IN_CTYPE_DOMAIN (c) && isalnum (c))
109#define ISALPHA(c) (IN_CTYPE_DOMAIN (c) && isalpha (c))
110#define ISCNTRL(c) (IN_CTYPE_DOMAIN (c) && iscntrl (c))
111#define ISLOWER(c) (IN_CTYPE_DOMAIN (c) && islower (c))
112#define ISPUNCT(c) (IN_CTYPE_DOMAIN (c) && ispunct (c))
113#define ISSPACE(c) (IN_CTYPE_DOMAIN (c) && isspace (c))
114#define ISUPPER(c) (IN_CTYPE_DOMAIN (c) && isupper (c))
115#define ISXDIGIT(c) (IN_CTYPE_DOMAIN (c) && isxdigit (c))
116#define ISDIGIT_LOCALE(c) (IN_CTYPE_DOMAIN (c) && isdigit (c))
117
118/* ISDIGIT differs from ISDIGIT_LOCALE, as follows:
119   - Its arg may be any int or unsigned int; it need not be an unsigned char.
120   - It's guaranteed to evaluate its argument exactly once.
121   - It's typically faster.
122   Posix 1003.2-1992 section 2.5.2.1 page 50 lines 1556-1558 says that
123   only '0' through '9' are digits.  Prefer ISDIGIT to ISDIGIT_LOCALE unless
124   it's important to use the locale's definition of `digit' even when the
125   host does not conform to Posix.  */
126#define ISDIGIT(c) ((unsigned) (c) - '0' <= 9)
127
128
129#include <sys/types.h>
130#include <errno.h>
131
132#ifndef errno
133extern int errno;
134#endif
135
136#ifdef STRING_WITH_STRINGS
137# include <string.h>
138# include <strings.h>
139#else
140# ifdef HAVE_STRING_H
141#  include <string.h>
142# else
143#  ifdef HAVE_STRINGS_H
144#   include <strings.h>
145#  endif
146# endif
147#endif
148
149#ifdef HAVE_STDLIB_H
150# include <stdlib.h>
151#endif
152
153#ifdef HAVE_UNISTD_H
154# include <unistd.h>
155#endif
156
157#ifdef HAVE_SYS_PARAM_H
158# include <sys/param.h>
159#endif
160
161#if HAVE_LIMITS_H
162# include <limits.h>
163#endif
164
165/* Find HOST_WIDEST_INT and set its bit size, type and print macros.
166   It will be the largest integer mode supported by the host which may
167   (or may not) be larger than HOST_WIDE_INT.  This must appear after
168   <limits.h> since we only use `long long' if its bigger than a
169   `long' and also if it is supported by macros in limits.h.  For old
170   hosts which don't have a limits.h (and thus won't include it in
171   stage2 cause we don't rerun configure) we assume gcc supports long
172   long.)  Note, you won't get these defined if you don't include
173   {ht}config.h before this file to set the HOST_BITS_PER_* macros. */
174
175#ifndef HOST_WIDEST_INT
176# if defined (HOST_BITS_PER_LONG) && defined (HOST_BITS_PER_LONGLONG)
177#  if (HOST_BITS_PER_LONGLONG > HOST_BITS_PER_LONG) && (defined (LONG_LONG_MAX) || defined (LONGLONG_MAX) || defined (LLONG_MAX) || defined (__GNUC__))
178#   define HOST_BITS_PER_WIDEST_INT HOST_BITS_PER_LONGLONG
179#   define HOST_WIDEST_INT long long
180#   define HOST_WIDEST_INT_PRINT_DEC "%lld"
181#   define HOST_WIDEST_INT_PRINT_UNSIGNED "%llu"
182#   define HOST_WIDEST_INT_PRINT_HEX "0x%llx"
183#  else
184#   define HOST_BITS_PER_WIDEST_INT HOST_BITS_PER_LONG
185#   define HOST_WIDEST_INT long
186#   define HOST_WIDEST_INT_PRINT_DEC "%ld"
187#   define HOST_WIDEST_INT_PRINT_UNSIGNED "%lu"
188#   define HOST_WIDEST_INT_PRINT_HEX "0x%lx"
189#  endif /*(long long>long) && (LONG_LONG_MAX||LONGLONG_MAX||LLONG_MAX||GNUC)*/
190# endif /* defined(HOST_BITS_PER_LONG) && defined(HOST_BITS_PER_LONGLONG) */
191#endif /* ! HOST_WIDEST_INT */
192
193#ifdef TIME_WITH_SYS_TIME
194# include <sys/time.h>
195# include <time.h>
196#else
197# if HAVE_SYS_TIME_H
198#  include <sys/time.h>
199# else
200#  ifdef HAVE_TIME_H
201#   include <time.h>
202#  endif
203# endif
204#endif
205
206#ifdef HAVE_FCNTL_H
207# include <fcntl.h>
208#else
209# ifdef HAVE_SYS_FILE_H
210#  include <sys/file.h>
211# endif
212#endif
213
214#ifndef SEEK_SET
215# define SEEK_SET 0
216# define SEEK_CUR 1
217# define SEEK_END 2
218#endif
219#ifndef F_OK
220# define F_OK 0
221# define X_OK 1
222# define W_OK 2
223# define R_OK 4
224#endif
225#ifndef O_RDONLY
226# define O_RDONLY 0
227#endif
228#ifndef O_WRONLY
229# define O_WRONLY 1
230#endif
231
232/* Some systems define these in, e.g., param.h.  We undefine these names
233   here to avoid the warnings.  We prefer to use our definitions since we
234   know they are correct.  */
235
236#undef MIN
237#undef MAX
238#define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
239#define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
240
241#ifdef HAVE_SYS_WAIT_H
242#include <sys/wait.h>
243#endif
244
245#ifndef WIFSIGNALED
246#define WIFSIGNALED(S) (((S) & 0xff) != 0 && ((S) & 0xff) != 0x7f)
247#endif
248#ifndef WTERMSIG
249#define WTERMSIG(S) ((S) & 0x7f)
250#endif
251#ifndef WIFEXITED
252#define WIFEXITED(S) (((S) & 0xff) == 0)
253#endif
254#ifndef WEXITSTATUS
255#define WEXITSTATUS(S) (((S) & 0xff00) >> 8)
256#endif
257#ifndef WSTOPSIG
258#define WSTOPSIG WEXITSTATUS
259#endif
260
261
262
263#ifndef bcopy
264# ifdef HAVE_BCOPY
265#  ifdef NEED_DECLARATION_BCOPY
266extern void bcopy ();
267#  endif
268# else /* ! HAVE_BCOPY */
269#  define bcopy(src,dst,len) memmove((dst),(src),(len))
270# endif
271#endif
272
273#ifndef bcmp
274# ifdef HAVE_BCMP
275#  ifdef NEED_DECLARATION_BCMP
276extern int bcmp ();
277#  endif
278# else /* ! HAVE_BCMP */
279#  define bcmp(left,right,len) memcmp ((left),(right),(len))
280# endif
281#endif
282
283#ifndef bzero
284# ifdef HAVE_BZERO
285#  ifdef NEED_DECLARATION_BZERO
286extern void bzero ();
287#  endif
288# else /* ! HAVE_BZERO */
289#  define bzero(dst,len) memset ((dst),0,(len))
290# endif
291#endif
292
293#ifndef index
294# ifdef HAVE_INDEX
295#  ifdef NEED_DECLARATION_INDEX
296extern char *index ();
297#  endif
298# else /* ! HAVE_INDEX */
299#  define index strchr
300# endif
301#endif
302
303#ifndef rindex
304# ifdef HAVE_RINDEX
305#  ifdef NEED_DECLARATION_RINDEX
306extern char *rindex ();
307#  endif
308# else /* ! HAVE_RINDEX */
309#  define rindex strrchr
310# endif
311#endif
312
313#ifdef NEED_DECLARATION_ATOF
314extern double atof ();
315#endif
316
317#ifdef NEED_DECLARATION_ATOL
318extern long atol();
319#endif
320
321#ifdef NEED_DECLARATION_FREE
322extern void free ();
323#endif
324
325#ifdef NEED_DECLARATION_GETCWD
326extern char *getcwd ();
327#endif
328
329#ifdef NEED_DECLARATION_GETENV
330extern char *getenv ();
331#endif
332
333#ifdef NEED_DECLARATION_GETWD
334extern char *getwd ();
335#endif
336
337#ifdef NEED_DECLARATION_SBRK
338extern char *sbrk ();
339#endif
340
341#ifdef NEED_DECLARATION_STRSTR
342extern char *strstr ();
343#endif
344
345#ifdef HAVE_STRERROR
346# ifdef NEED_DECLARATION_STRERROR
347#  ifndef strerror
348extern char *strerror ();
349#  endif
350# endif
351#else /* ! HAVE_STRERROR */
352extern int sys_nerr;
353extern char *sys_errlist[];
354#endif /* HAVE_STRERROR */
355
356#ifdef HAVE_STRSIGNAL
357# ifdef NEED_DECLARATION_STRSIGNAL
358#  ifndef strsignal
359extern char * strsignal ();
360#  endif
361# endif
362#else /* ! HAVE_STRSIGNAL */
363# ifndef SYS_SIGLIST_DECLARED
364#  ifndef NO_SYS_SIGLIST
365extern char * sys_siglist[];
366#  endif
367# endif
368#endif /* HAVE_STRSIGNAL */
369
370#ifdef HAVE_GETRLIMIT
371# ifdef NEED_DECLARATION_GETRLIMIT
372#  ifndef getrlimit
373extern int getrlimit ();
374#  endif
375# endif
376#endif
377
378#ifdef HAVE_SETRLIMIT
379# ifdef NEED_DECLARATION_SETRLIMIT
380#  ifndef setrlimit
381extern int setrlimit ();
382#  endif
383# endif
384#endif
385
386/* HAVE_VOLATILE only refers to the stage1 compiler.  We also check
387   __STDC__ and assume gcc sets it and has volatile in stage >=2. */
388#if !defined(HAVE_VOLATILE) && !defined(__STDC__) && !defined(volatile)
389#define volatile
390#endif
391
392/* Redefine abort to report an internal error w/o coredump, and reporting the
393   location of the error in the source file.
394   Some files undefine abort again, so we must prototype the real thing
395   for their sake.  */
396#ifdef NEED_DECLARATION_ABORT
397extern void abort ();
398#endif
399extern void fatal PVPROTO((const char *, ...)) ATTRIBUTE_PRINTF_1 ATTRIBUTE_NORETURN;
400
401#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
402#define abort() fatal ("Internal compiler error at %s:%d\n", \
403		       trim_filename (__FILE__), __LINE__)
404#else
405#define abort() fatal ("Internal compiler error in `%s', at %s:%d\n"	\
406  "Please submit a full bug report.\n"	\
407  "See %s for instructions.", \
408  __PRETTY_FUNCTION__, trim_filename (__FILE__), __LINE__, GCCBUGURL)
409#endif /* recent gcc */
410
411/* trim_filename is in toplev.c.  Define a stub macro for files that
412   don't link toplev.c.  toplev.h will reset it to the real version.  */
413#define trim_filename(x) (x)
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__ */
499