OSDN Git Service

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