OSDN Git Service

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