EXEEXT introduces to solve Cygwin problems
[fw/sdcc] / support / cpp2 / system.h
1 /* Get common system includes and various definitions and declarations based
2    on autoconf macros.
3    Copyright (C) 1998, 1999, 2000, 2001 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 /* This is the location of the online document giving information how
27    to report bugs. If you change this string, also check for strings
28    not under control of the preprocessor.  */
29 #define GCCBUGURL "<URL:http://www.gnu.org/software/gcc/bugs.html>"
30
31 #include "ansidecl.h"
32
33 /* We must include stdarg.h/varargs.h before stdio.h. */
34 #ifdef ANSI_PROTOTYPES
35 #include <stdarg.h>
36 #else
37 #include <varargs.h>
38 #endif
39
40 #ifndef va_copy
41 # ifdef __va_copy
42 #   define va_copy(d,s)  __va_copy((d),(s))
43 # else
44 #   define va_copy(d,s)  ((d) = (s))
45 # endif
46 #endif
47
48 #ifdef HAVE_STDDEF_H
49 # include <stddef.h>
50 #endif
51
52 #include <stdio.h>
53
54 #define CHAR_BIT 8
55
56 /* Define a generic NULL if one hasn't already been defined.  */
57 #ifndef NULL
58 #define NULL 0
59 #endif
60
61 /* There are an extraordinary number of issues with <ctype.h>.
62    The last straw is that it varies with the locale.  Use libiberty's
63    replacement instead.  */
64 #if defined(__APPLE__) && defined(__MACH__)
65 #include <libiberty/safe-ctype.h>
66 #else
67 #include <safe-ctype.h>
68 #endif
69
70 /* Define a default escape character; it's different for EBCDIC.  */
71 #ifndef TARGET_ESC
72 #define TARGET_ESC 033
73 #endif
74
75 #include <sys/types.h>
76
77 #include <errno.h>
78
79 #if !defined (errno) && defined (HAVE_DECL_ERRNO) && !HAVE_DECL_ERRNO
80 extern int errno;
81 #endif
82
83 #ifdef STRING_WITH_STRINGS
84 # include <string.h>
85 # include <strings.h>
86 #else
87 # ifdef HAVE_STRING_H
88 #  include <string.h>
89 # else
90 #  ifdef HAVE_STRINGS_H
91 #   include <strings.h>
92 #  endif
93 # endif
94 #endif
95
96 #ifdef HAVE_STDLIB_H
97 # include <stdlib.h>
98 #endif
99
100 /* If we don't have an overriding definition, set SUCCESS_EXIT_CODE and
101    FATAL_EXIT_CODE to EXIT_SUCCESS and EXIT_FAILURE respectively,
102    or 0 and 1 if those macros are not defined.  */
103 #ifndef SUCCESS_EXIT_CODE
104 # ifdef EXIT_SUCCESS
105 #  define SUCCESS_EXIT_CODE EXIT_SUCCESS
106 # else
107 #  define SUCCESS_EXIT_CODE 0
108 # endif
109 #endif
110
111 #ifndef FATAL_EXIT_CODE
112 # ifdef EXIT_FAILURE
113 #  define FATAL_EXIT_CODE EXIT_FAILURE
114 # else
115 #  define FATAL_EXIT_CODE 1
116 # endif
117 #endif
118
119 #ifdef HAVE_UNISTD_H
120 # include <unistd.h>
121 #endif
122
123 #ifdef HAVE_SYS_PARAM_H
124 # include <sys/param.h>
125 #endif
126
127 #if HAVE_LIMITS_H
128 # include <limits.h>
129 #endif
130
131 /* Get definitions of HOST_WIDE_INT and HOST_WIDEST_INT.  */
132 #include "hwint.h"
133
134 /* Infrastructure for defining missing _MAX and _MIN macros.  Note that
135    macros defined with these cannot be used in #if.  */
136
137 /* The extra casts work around common compiler bugs.  */
138 #define INTTYPE_SIGNED(t) (! ((t) 0 < (t) -1))
139 /* The outer cast is needed to work around a bug in Cray C 5.0.3.0.
140    It is necessary at least when t == time_t.  */
141 #define INTTYPE_MINIMUM(t) ((t) (INTTYPE_SIGNED (t) \
142                              ? ~ (t) 0 << (sizeof(t) * CHAR_BIT - 1) : (t) 0))
143 #define INTTYPE_MAXIMUM(t) ((t) (~ (t) 0 - INTTYPE_MINIMUM (t)))
144
145 /* Use that infrastructure to provide a few constants.  */
146 #ifndef UCHAR_MAX
147 # define UCHAR_MAX INTTYPE_MAXIMUM (unsigned char)
148 #endif
149
150 #ifdef TIME_WITH_SYS_TIME
151 # include <sys/time.h>
152 # include <time.h>
153 #else
154 # if HAVE_SYS_TIME_H
155 #  include <sys/time.h>
156 # else
157 #  ifdef HAVE_TIME_H
158 #   include <time.h>
159 #  endif
160 # endif
161 #endif
162
163 #ifdef HAVE_FCNTL_H
164 # include <fcntl.h>
165 #else
166 # ifdef HAVE_SYS_FILE_H
167 #  include <sys/file.h>
168 # endif
169 #endif
170
171 #ifndef SEEK_SET
172 # define SEEK_SET 0
173 # define SEEK_CUR 1
174 # define SEEK_END 2
175 #endif
176 #ifndef F_OK
177 # define F_OK 0
178 # define X_OK 1
179 # define W_OK 2
180 # define R_OK 4
181 #endif
182 #ifndef O_RDONLY
183 # define O_RDONLY 0
184 #endif
185 #ifndef O_WRONLY
186 # define O_WRONLY 1
187 #endif
188
189 /* Some systems define these in, e.g., param.h.  We undefine these names
190    here to avoid the warnings.  We prefer to use our definitions since we
191    know they are correct.  */
192
193 #undef MIN
194 #undef MAX
195 #define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
196 #define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
197
198 /* Returns the least number N such that N * Y >= X.  */
199 #define CEIL(x,y) (((x) + (y) - 1) / (y))
200
201 #ifdef HAVE_SYS_WAIT_H
202 #include <sys/wait.h>
203 #endif
204
205 #ifndef WIFSIGNALED
206 #define WIFSIGNALED(S) (((S) & 0xff) != 0 && ((S) & 0xff) != 0x7f)
207 #endif
208 #ifndef WTERMSIG
209 #define WTERMSIG(S) ((S) & 0x7f)
210 #endif
211 #ifndef WIFEXITED
212 #define WIFEXITED(S) (((S) & 0xff) == 0)
213 #endif
214 #ifndef WEXITSTATUS
215 #define WEXITSTATUS(S) (((S) & 0xff00) >> 8)
216 #endif
217 #ifndef WSTOPSIG
218 #define WSTOPSIG WEXITSTATUS
219 #endif
220
221 /* The HAVE_DECL_* macros are three-state, undefined, 0 or 1.  If they
222    are defined to 0 then we must provide the relevant declaration
223    here.  These checks will be in the undefined state while configure
224    is running so be careful to test "defined (HAVE_DECL_*)".  */
225
226 #if defined (HAVE_DECL_ATOF) && !HAVE_DECL_ATOF
227 extern double atof PARAMS ((const char *));
228 #endif
229
230 #if defined (HAVE_DECL_ATOL) && !HAVE_DECL_ATOL
231 extern long atol PARAMS ((const char *));
232 #endif
233
234 #if defined (HAVE_DECL_FREE) && !HAVE_DECL_FREE
235 extern void free PARAMS ((PTR));
236 #endif
237
238 #if defined (HAVE_DECL_GETENV) && !HAVE_DECL_GETENV
239 extern char *getenv PARAMS ((const char *));
240 #endif
241
242 #if defined (HAVE_DECL_STRSTR) && !HAVE_DECL_STRSTR
243 extern char *strstr PARAMS ((const char *, const char *));
244 #endif
245
246 #ifdef HAVE_MALLOC_H
247 #include <malloc.h>
248 #endif
249
250 #if defined (HAVE_DECL_MALLOC) && !HAVE_DECL_MALLOC
251 extern PTR malloc PARAMS ((size_t));
252 #endif
253
254 #if defined (HAVE_DECL_CALLOC) && !HAVE_DECL_CALLOC
255 extern PTR calloc PARAMS ((size_t, size_t));
256 #endif
257
258 #if defined (HAVE_DECL_REALLOC) && !HAVE_DECL_REALLOC
259 extern PTR realloc PARAMS ((PTR, size_t));
260 #endif
261
262 #if !defined(__STDC__) && !defined(volatile)
263 #define volatile
264 #endif
265
266 #if defined (HAVE_DECL_ABORT) && !HAVE_DECL_ABORT
267 extern void abort PARAMS ((void));
268 #endif
269
270 /* 1 if we have C99 designated initializers.  */
271 #if !defined(HAVE_DESIGNATED_INITIALIZERS)
272 #if defined(__APPLE__) && (__MACH__)
273 #define HAVE_DESIGNATED_INITIALIZERS 0
274 #else
275 #define HAVE_DESIGNATED_INITIALIZERS \
276   ((GCC_VERSION >= 2007) || (__STDC_VERSION__ >= 199901L))
277 #endif
278 #endif
279
280 #if HAVE_SYS_STAT_H
281 # include <sys/stat.h>
282 #endif
283
284 /* Test if something is a normal file.  */
285 #ifndef S_ISREG
286 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
287 #endif
288
289 /* Test if something is a directory.  */
290 #ifndef S_ISDIR
291 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
292 #endif
293
294 /* Test if something is a character special file.  */
295 #ifndef S_ISCHR
296 #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
297 #endif
298
299 /* Test if something is a block special file.  */
300 #ifndef S_ISBLK
301 #define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
302 #endif
303
304 /* Test if something is a socket.  */
305 #ifndef S_ISSOCK
306 # ifdef S_IFSOCK
307 #   define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
308 # else
309 #   define S_ISSOCK(m) 0
310 # endif
311 #endif
312
313 /* Test if something is a FIFO.  */
314 #ifndef S_ISFIFO
315 # ifdef S_IFIFO
316 #  define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
317 # else
318 #  define S_ISFIFO(m) 0
319 # endif
320 #endif
321
322 /* Approximate O_NONBLOCK.  */
323 #ifndef O_NONBLOCK
324 #define O_NONBLOCK O_NDELAY
325 #endif
326
327 /* Approximate O_NOCTTY.  */
328 #ifndef O_NOCTTY
329 #define O_NOCTTY 0
330 #endif
331
332 /* Define well known filenos if the system does not define them.  */
333 #ifndef STDIN_FILENO
334 # define STDIN_FILENO   0
335 #endif
336 #ifndef STDOUT_FILENO
337 # define STDOUT_FILENO  1
338 #endif
339 #ifndef STDERR_FILENO
340 # define STDERR_FILENO  2
341 #endif
342
343 /* Some systems have mkdir that takes a single argument. */
344 #ifdef MKDIR_TAKES_ONE_ARG
345 # define mkdir(a,b) mkdir(a)
346 #endif
347
348 /* Provide a way to print an address via printf.  */
349 #ifndef HOST_PTR_PRINTF
350 # ifdef HAVE_PRINTF_PTR
351 #  define HOST_PTR_PRINTF "%p"
352 # else
353 #  define HOST_PTR_PRINTF \
354     (sizeof (int) == sizeof (char *) ? "%x" \
355      : sizeof (long) == sizeof (char *) ? "%lx" : "%llx")
356 # endif
357 #endif /* ! HOST_PTR_PRINTF */
358
359 /* By default, colon separates directories in a path.  */
360 #ifndef PATH_SEPARATOR
361 #define PATH_SEPARATOR ':'
362 #endif
363
364 #ifndef DIR_SEPARATOR
365 #define DIR_SEPARATOR '/'
366 #endif
367
368 /* Define IS_DIR_SEPARATOR.  */
369 #ifndef DIR_SEPARATOR_2
370 # define IS_DIR_SEPARATOR(CH) ((CH) == DIR_SEPARATOR)
371 #else /* DIR_SEPARATOR_2 */
372 # define IS_DIR_SEPARATOR(CH) \
373         (((CH) == DIR_SEPARATOR) || ((CH) == DIR_SEPARATOR_2))
374 #endif /* DIR_SEPARATOR_2 */
375
376 /* Say how to test for an absolute pathname.  On Unix systems, this is if
377    it starts with a leading slash or a '$', the latter meaning the value of
378    an environment variable is to be used.  On machien with DOS-based
379    file systems, it is also absolute if it starts with a drive identifier.  */
380 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
381 #define IS_ABSOLUTE_PATHNAME(STR) \
382   (IS_DIR_SEPARATOR ((STR)[0]) || (STR)[0] == '$' \
383    || ((STR)[0] != '\0' && (STR)[1] == ':' && IS_DIR_SEPARATOR ((STR)[2])))
384 #else
385 #define IS_ABSOLUTE_PATHNAME(STR) \
386   (IS_DIR_SEPARATOR ((STR)[0]) || (STR)[0] == '$')
387 #endif
388
389 /* Get libiberty declarations. */
390 /* #include "libiberty.h" */
391 #include "sdcc.h"
392 #include "symcat.h"
393
394 /* Provide a default for the HOST_BIT_BUCKET.
395    This suffices for POSIX-like hosts.  */
396
397 #ifndef HOST_BIT_BUCKET
398 #define HOST_BIT_BUCKET "/dev/null"
399 #endif
400
401 /* Be conservative and only use enum bitfields with GCC.
402    FIXME: provide a complete autoconf test for buggy enum bitfields.  */
403
404 #if (GCC_VERSION > 2000)
405 #define ENUM_BITFIELD(TYPE) enum TYPE
406 #else
407 #define ENUM_BITFIELD(TYPE) unsigned int
408 #endif
409
410 #ifndef offsetof
411 #define offsetof(TYPE, MEMBER)  ((size_t) &((TYPE *)0)->MEMBER)
412 #endif
413
414 /* Traditional C cannot initialize union members of structs.  Provide
415    a macro which expands appropriately to handle it.  This only works
416    if you intend to initalize the union member to zero since it relies
417    on default initialization to zero in the traditional C case.  */
418 #ifdef __STDC__
419 #define UNION_INIT_ZERO , {0}
420 #else
421 #define UNION_INIT_ZERO
422 #endif
423
424 /* Various error reporting routines want to use __FUNCTION__.  */
425 #if (GCC_VERSION < 2007)
426 #ifndef __FUNCTION__
427 #define __FUNCTION__ "?"
428 #endif /* ! __FUNCTION__ */
429 #endif
430
431 /* As the last action in this file, we poison the identifiers that
432    shouldn't be used.  Note, luckily gcc-3.0's token-based integrated
433    preprocessor won't trip on poisoned identifiers that arrive from
434    the expansion of macros.  E.g. #define strrchr rindex, won't error
435    if rindex is poisoned after this directive is issued and later on
436    strrchr is called.
437
438    Note: We define bypass macros for the few cases where we really
439    want to use the libc memory allocation routines.  Otherwise we
440    insist you use the "x" versions from libiberty.  */
441
442 #define really_call_malloc malloc
443 #define really_call_calloc calloc
444 #define really_call_realloc realloc
445
446 #if (GCC_VERSION >= 3000)
447
448 /* Note autoconf checks for prototype declarations and includes
449    system.h while doing so.  Only poison these tokens if actually
450    compiling gcc, so that the autoconf declaration tests for malloc
451    etc don't spuriously fail.  */
452 #ifdef IN_GCC
453 #undef malloc
454 #undef realloc
455 #undef calloc
456 #undef strdup
457  #pragma GCC poison malloc realloc calloc strdup
458 #endif /* IN_GCC */
459
460 /* Note: not all uses of the `index' token (e.g. variable names and
461    structure members) have been eliminated.  */
462 #undef bcopy
463 #undef bzero
464 #undef bcmp
465 #undef rindex
466  #pragma GCC poison bcopy bzero bcmp rindex
467
468 #endif /* GCC >= 3.0 */
469
470 #endif /* ! GCC_SYSTEM_H */