]> gcc.gnu.org Git - gcc.git/blame - gcc/system.h
system.h (CTYPE_CONV, [...]): New macros.
[gcc.git] / gcc / system.h
CommitLineData
c5c76735
JL
1/* Get common system includes and various definitions and declarations based
2 on autoconf macros.
9de843ca 3 Copyright (C) 1998, 1999 Free Software Foundation, Inc.
aca69483 4
1b0c6de6
JL
5This file is part of GNU CC.
6
7GNU CC is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2, or (at your option)
10any later version.
11
12GNU CC is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU CC; see the file COPYING. If not, write to
19the Free Software Foundation, 59 Temple Place - Suite 330,
20Boston, MA 02111-1307, USA. */
aca69483 21
c5c76735 22
aca69483
KG
23#ifndef __GCC_SYSTEM_H__
24#define __GCC_SYSTEM_H__
25
789f983a 26/* We must include stdarg.h/varargs.h before stdio.h. */
5148a72b 27#ifdef ANSI_PROTOTYPES
789f983a
KG
28#include <stdarg.h>
29#else
30#include <varargs.h>
31#endif
32
aca69483 33#include <stdio.h>
51db713f
KG
34
35/* Define a generic NULL if one hasn't already been defined. */
36#ifndef NULL
37#define NULL 0
38#endif
39
54953b66 40/* The compiler is not a multi-threaded application and therefore we
9c30c0e7
ZW
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
54953b66
UD
50# undef putc
51# define putc(C, Stream) putc_unlocked (C, Stream)
52#endif
9c30c0e7 53#if defined HAVE_FPUTC_UNLOCKED && !defined NEED_DECLARATION_PUTC_UNLOCKED
54953b66
UD
54# undef fputc
55# define fputc(C, Stream) fputc_unlocked (C, Stream)
56#endif
9c30c0e7 57#if defined HAVE_FPUTS_UNLOCKED && !defined NEED_DECLARATION_PUTC_UNLOCKED
54953b66
UD
58# undef fputs
59# define fputs(String, Stream) fputs_unlocked (String, Stream)
9c30c0e7
ZW
60# ifdef NEED_DECLARATION_FPUTS_UNLOCKED
61extern int fputs_unlocked PROTO ((const char *, FILE *));
62# endif
54953b66
UD
63#endif
64
aca69483
KG
65#include <ctype.h>
66
67/* Jim Meyering writes:
9b91d8f4 68
aca69483
KG
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."
9b91d8f4 77
aca69483 78 Bruno Haible adds:
9b91d8f4 79
aca69483
KG
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." */
9b91d8f4 85
f3ad1f9c 86#if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII)) || defined(HOST_EBCDIC)
aca69483
KG
87# define IN_CTYPE_DOMAIN(c) 1
88#else
89# define IN_CTYPE_DOMAIN(c) isascii(c)
90#endif
9b91d8f4 91
92a438d1
KG
92/* The ctype functions are often implemented as macros which do
93 lookups in arrays using the parameter as the offset. If the ctype
94 function parameter is a char, then gcc will (appropriately) warn
95 that a "subscript has type char". Using a (signed) char as a subscript
96 is bad because you may get negative offsets and thus it is not 8-bit
97 safe. The CTYPE_CONV macro ensures that the parameter is cast to an
98 unsigned char when a char is passed in. When an int is passed in, the
99 parameter is left alone so we don't lose EOF.
100*/
101
102#define CTYPE_CONV(CH) \
103 (sizeof(CH) == sizeof(unsigned char) ? (int)(unsigned char)(CH) : (int)(CH))
104
105
106/* WARNING! The argument to the ctype replacement macros below is
107 evaluated more than once so it must not have side effects! */
108
aca69483 109#ifdef isblank
92a438d1 110# define ISBLANK(c) (IN_CTYPE_DOMAIN (c) && isblank (CTYPE_CONV(c)))
aca69483
KG
111#else
112# define ISBLANK(c) ((c) == ' ' || (c) == '\t')
113#endif
114#ifdef isgraph
92a438d1 115# define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isgraph (CTYPE_CONV(c)))
aca69483 116#else
92a438d1 117# define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isprint (CTYPE_CONV(c)) && !isspace (CTYPE_CONV(c)))
aca69483 118#endif
9b91d8f4 119
92a438d1
KG
120#define ISPRINT(c) (IN_CTYPE_DOMAIN (c) && isprint (CTYPE_CONV(c)))
121#define ISALNUM(c) (IN_CTYPE_DOMAIN (c) && isalnum (CTYPE_CONV(c)))
122#define ISALPHA(c) (IN_CTYPE_DOMAIN (c) && isalpha (CTYPE_CONV(c)))
123#define ISCNTRL(c) (IN_CTYPE_DOMAIN (c) && iscntrl (CTYPE_CONV(c)))
124#define ISLOWER(c) (IN_CTYPE_DOMAIN (c) && islower (CTYPE_CONV(c)))
125#define ISPUNCT(c) (IN_CTYPE_DOMAIN (c) && ispunct (CTYPE_CONV(c)))
126#define ISSPACE(c) (IN_CTYPE_DOMAIN (c) && isspace (CTYPE_CONV(c)))
127#define ISUPPER(c) (IN_CTYPE_DOMAIN (c) && isupper (CTYPE_CONV(c)))
128#define ISXDIGIT(c) (IN_CTYPE_DOMAIN (c) && isxdigit (CTYPE_CONV(c)))
129#define ISDIGIT_LOCALE(c) (IN_CTYPE_DOMAIN (c) && isdigit (CTYPE_CONV(c)))
130
131#if STDC_HEADERS
132# define TOLOWER(c) (tolower (CTYPE_CONV(c)))
133# define TOUPPER(c) (toupper (CTYPE_CONV(c)))
134#else
135# define TOLOWER(c) (ISUPPER (c) ? tolower (CTYPE_CONV(c)) : (c))
136# define TOUPPER(c) (ISLOWER (c) ? toupper (CTYPE_CONV(c)) : (c))
137#endif
9b91d8f4 138
aca69483
KG
139/* ISDIGIT differs from ISDIGIT_LOCALE, as follows:
140 - Its arg may be any int or unsigned int; it need not be an unsigned char.
141 - It's guaranteed to evaluate its argument exactly once.
142 - It's typically faster.
143 Posix 1003.2-1992 section 2.5.2.1 page 50 lines 1556-1558 says that
144 only '0' through '9' are digits. Prefer ISDIGIT to ISDIGIT_LOCALE unless
145 it's important to use the locale's definition of `digit' even when the
146 host does not conform to Posix. */
147#define ISDIGIT(c) ((unsigned) (c) - '0' <= 9)
148
64f8a718
RH
149/* Define a default escape character; its different for EBCDIC. */
150#ifndef TARGET_ESC
151#define TARGET_ESC 033
152#endif
153
c5c76735 154#ifdef HAVE_SYS_TYPES_H
aca69483 155#include <sys/types.h>
c5c76735
JL
156#endif
157
aca69483
KG
158#include <errno.h>
159
160#ifndef errno
161extern int errno;
162#endif
163
ccc7d11a 164#ifdef STRING_WITH_STRINGS
aca69483 165# include <string.h>
ccc7d11a 166# include <strings.h>
aca69483 167#else
ccc7d11a
KG
168# ifdef HAVE_STRING_H
169# include <string.h>
170# else
171# ifdef HAVE_STRINGS_H
172# include <strings.h>
173# endif
aca69483
KG
174# endif
175#endif
176
177#ifdef HAVE_STDLIB_H
178# include <stdlib.h>
179#endif
180
181#ifdef HAVE_UNISTD_H
182# include <unistd.h>
183#endif
184
185#ifdef HAVE_SYS_PARAM_H
186# include <sys/param.h>
187#endif
188
189#if HAVE_LIMITS_H
190# include <limits.h>
191#endif
192
f80d6fd7
KG
193/* Find HOST_WIDEST_INT and set its bit size, type and print macros.
194 It will be the largest integer mode supported by the host which may
195 (or may not) be larger than HOST_WIDE_INT. This must appear after
196 <limits.h> since we only use `long long' if its bigger than a
197 `long' and also if it is supported by macros in limits.h. For old
198 hosts which don't have a limits.h (and thus won't include it in
199 stage2 cause we don't rerun configure) we assume gcc supports long
200 long.) Note, you won't get these defined if you don't include
201 {ht}config.h before this file to set the HOST_BITS_PER_* macros. */
202
203#ifndef HOST_WIDEST_INT
204# if defined (HOST_BITS_PER_LONG) && defined (HOST_BITS_PER_LONGLONG)
205# if (HOST_BITS_PER_LONGLONG > HOST_BITS_PER_LONG) && (defined (LONG_LONG_MAX) || defined (LONGLONG_MAX) || defined (LLONG_MAX) || defined (__GNUC__))
206# define HOST_BITS_PER_WIDEST_INT HOST_BITS_PER_LONGLONG
207# define HOST_WIDEST_INT long long
208# define HOST_WIDEST_INT_PRINT_DEC "%lld"
209# define HOST_WIDEST_INT_PRINT_UNSIGNED "%llu"
210# define HOST_WIDEST_INT_PRINT_HEX "0x%llx"
211# else
212# define HOST_BITS_PER_WIDEST_INT HOST_BITS_PER_LONG
213# define HOST_WIDEST_INT long
214# define HOST_WIDEST_INT_PRINT_DEC "%ld"
215# define HOST_WIDEST_INT_PRINT_UNSIGNED "%lu"
216# define HOST_WIDEST_INT_PRINT_HEX "0x%lx"
217# endif /*(long long>long) && (LONG_LONG_MAX||LONGLONG_MAX||LLONG_MAX||GNUC)*/
218# endif /* defined(HOST_BITS_PER_LONG) && defined(HOST_BITS_PER_LONGLONG) */
219#endif /* ! HOST_WIDEST_INT */
220
aca69483
KG
221#ifdef TIME_WITH_SYS_TIME
222# include <sys/time.h>
223# include <time.h>
224#else
225# if HAVE_SYS_TIME_H
e572c0c6 226# include <sys/time.h>
aca69483 227# else
e572c0c6
KG
228# ifdef HAVE_TIME_H
229# include <time.h>
230# endif
231# endif
aca69483
KG
232#endif
233
234#ifdef HAVE_FCNTL_H
235# include <fcntl.h>
236#else
e572c0c6
KG
237# ifdef HAVE_SYS_FILE_H
238# include <sys/file.h>
239# endif
aca69483
KG
240#endif
241
242#ifndef SEEK_SET
243# define SEEK_SET 0
244# define SEEK_CUR 1
245# define SEEK_END 2
246#endif
247#ifndef F_OK
248# define F_OK 0
249# define X_OK 1
250# define W_OK 2
251# define R_OK 4
252#endif
e572c0c6
KG
253#ifndef O_RDONLY
254# define O_RDONLY 0
255#endif
256#ifndef O_WRONLY
257# define O_WRONLY 1
258#endif
aca69483 259
36b8337d
KG
260/* Some systems define these in, e.g., param.h. We undefine these names
261 here to avoid the warnings. We prefer to use our definitions since we
262 know they are correct. */
263
264#undef MIN
265#undef MAX
266#define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
267#define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
268
e9831ca0
KG
269#ifdef HAVE_SYS_WAIT_H
270#include <sys/wait.h>
271#endif
272
273#ifndef WIFSIGNALED
274#define WIFSIGNALED(S) (((S) & 0xff) != 0 && ((S) & 0xff) != 0x7f)
275#endif
276#ifndef WTERMSIG
277#define WTERMSIG(S) ((S) & 0x7f)
278#endif
279#ifndef WIFEXITED
280#define WIFEXITED(S) (((S) & 0xff) == 0)
281#endif
282#ifndef WEXITSTATUS
283#define WEXITSTATUS(S) (((S) & 0xff00) >> 8)
284#endif
8fa213ac
PDM
285#ifndef WSTOPSIG
286#define WSTOPSIG WEXITSTATUS
287#endif
e9831ca0 288
aca69483
KG
289
290
291#ifndef bcopy
292# ifdef HAVE_BCOPY
293# ifdef NEED_DECLARATION_BCOPY
79e11844 294extern void bcopy ();
aca69483
KG
295# endif
296# else /* ! HAVE_BCOPY */
b3c9dc1a 297# define bcopy(src,dst,len) memmove((dst),(src),(len))
aca69483
KG
298# endif
299#endif
300
301#ifndef bcmp
302# ifdef HAVE_BCMP
303# ifdef NEED_DECLARATION_BCMP
79e11844 304extern int bcmp ();
aca69483
KG
305# endif
306# else /* ! HAVE_BCMP */
307# define bcmp(left,right,len) memcmp ((left),(right),(len))
308# endif
309#endif
310
311#ifndef bzero
312# ifdef HAVE_BZERO
313# ifdef NEED_DECLARATION_BZERO
79e11844 314extern void bzero ();
aca69483
KG
315# endif
316# else /* ! HAVE_BZERO */
317# define bzero(dst,len) memset ((dst),0,(len))
318# endif
319#endif
320
321#ifndef index
322# ifdef HAVE_INDEX
323# ifdef NEED_DECLARATION_INDEX
324extern char *index ();
325# endif
326# else /* ! HAVE_INDEX */
327# define index strchr
328# endif
329#endif
330
331#ifndef rindex
332# ifdef HAVE_RINDEX
333# ifdef NEED_DECLARATION_RINDEX
334extern char *rindex ();
335# endif
336# else /* ! HAVE_RINDEX */
337# define rindex strrchr
338# endif
339#endif
340
8f81384f
KG
341#ifdef NEED_DECLARATION_ATOF
342extern double atof ();
343#endif
344
345#ifdef NEED_DECLARATION_ATOL
346extern long atol();
347#endif
348
aca69483
KG
349#ifdef NEED_DECLARATION_FREE
350extern void free ();
351#endif
352
6cd5dccd
KG
353#ifdef NEED_DECLARATION_GETCWD
354extern char *getcwd ();
355#endif
356
79e11844
KG
357#ifdef NEED_DECLARATION_GETENV
358extern char *getenv ();
359#endif
360
6cd5dccd
KG
361#ifdef NEED_DECLARATION_GETWD
362extern char *getwd ();
363#endif
364
8f81384f 365#ifdef NEED_DECLARATION_SBRK
ce3700e3 366extern PTR sbrk ();
8f81384f
KG
367#endif
368
d3d5cc97
JL
369#ifdef NEED_DECLARATION_STRSTR
370extern char *strstr ();
371#endif
372
c5c76735
JL
373#ifdef HAVE_MALLOC_H
374#include <malloc.h>
375#endif
376
377#ifdef NEED_DECLARATION_MALLOC
ce3700e3 378extern PTR malloc ();
c5c76735
JL
379#endif
380
381#ifdef NEED_DECLARATION_CALLOC
ce3700e3 382extern PTR calloc ();
c5c76735
JL
383#endif
384
ce3700e3
KG
385#ifdef NEED_DECLARATION_REALLOC
386extern PTR realloc ();
c5c76735
JL
387#endif
388
6cd5dccd
KG
389#ifdef HAVE_STRERROR
390# ifdef NEED_DECLARATION_STRERROR
391# ifndef strerror
392extern char *strerror ();
393# endif
394# endif
395#else /* ! HAVE_STRERROR */
396extern int sys_nerr;
397extern char *sys_errlist[];
398#endif /* HAVE_STRERROR */
399
007e8d2a
KG
400#ifdef HAVE_STRSIGNAL
401# ifdef NEED_DECLARATION_STRSIGNAL
402# ifndef strsignal
403extern char * strsignal ();
404# endif
405# endif
406#else /* ! HAVE_STRSIGNAL */
407# ifndef SYS_SIGLIST_DECLARED
408# ifndef NO_SYS_SIGLIST
409extern char * sys_siglist[];
410# endif
411# endif
412#endif /* HAVE_STRSIGNAL */
413
d2cabf16
KG
414#ifdef HAVE_GETRLIMIT
415# ifdef NEED_DECLARATION_GETRLIMIT
416# ifndef getrlimit
417extern int getrlimit ();
418# endif
419# endif
420#endif
421
422#ifdef HAVE_SETRLIMIT
423# ifdef NEED_DECLARATION_SETRLIMIT
424# ifndef setrlimit
425extern int setrlimit ();
426# endif
427# endif
428#endif
429
e9b4fabf
JL
430/* HAVE_VOLATILE only refers to the stage1 compiler. We also check
431 __STDC__ and assume gcc sets it and has volatile in stage >=2. */
432#if !defined(HAVE_VOLATILE) && !defined(__STDC__) && !defined(volatile)
433#define volatile
434#endif
435
2a611d21 436#ifdef NEED_DECLARATION_ABORT
6cd5dccd 437extern void abort ();
2a611d21 438#endif
d4ba0ead
KG
439
440/* Define a STRINGIFY macro that's right for ANSI or traditional C.
441 HAVE_CPP_STRINGIFY only refers to the stage1 compiler. Assume that
442 (non-traditional) gcc used in stage2 or later has this feature.
443
444 Note: if the argument passed to STRINGIFY is itself a macro, eg
445 #define foo bar, STRINGIFY(foo) will produce "foo", not "bar".
446 Although the __STDC__ case could be made to expand this via a layer
447 of indirection, the traditional C case can not do so. Therefore
448 this behavior is not supported. */
449#ifndef STRINGIFY
450# if defined(HAVE_CPP_STRINGIFY) || (defined(__GNUC__) && defined(__STDC__))
451# define STRINGIFY(STRING) #STRING
452# else
453# define STRINGIFY(STRING) "STRING"
454# endif
455#endif /* ! STRINGIFY */
456
a05e22b8
RH
457#if HAVE_SYS_STAT_H
458# include <sys/stat.h>
459#endif
9855b854
MN
460
461/* Test if something is a normal file. */
462#ifndef S_ISREG
463#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
464#endif
465
466/* Test if something is a directory. */
467#ifndef S_ISDIR
468#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
469#endif
470
6458033d
ZW
471/* Test if something is a character special file. */
472#ifndef S_ISCHR
473#define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
474#endif
475
476/* Test if something is a socket. */
477#ifndef S_ISSOCK
478# ifdef S_IFSOCK
479# define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
480# else
481# define S_ISSOCK(m) 0
482# endif
483#endif
484
485/* Test if something is a FIFO. */
486#ifndef S_ISFIFO
487# ifdef S_IFIFO
488# define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
489# else
490# define S_ISFIFO(m) 0
491# endif
492#endif
493
494/* Approximate O_NONBLOCK. */
495#ifndef O_NONBLOCK
496#define O_NONBLOCK O_NDELAY
497#endif
498
499/* Approximate O_NOCTTY. */
500#ifndef O_NOCTTY
501#define O_NOCTTY 0
502#endif
503
f3692274
ME
504/* Define well known filenos if the system does not define them. */
505#ifndef STDIN_FILENO
506# define STDIN_FILENO 0
507#endif
508#ifndef STDOUT_FILENO
509# define STDOUT_FILENO 1
510#endif
924d8a7c 511#ifndef STDERR_FILENO
f3692274
ME
512# define STDERR_FILENO 2
513#endif
514
75923b2f
MK
515/* Some systems have mkdir that takes a single argument. */
516#ifdef MKDIR_TAKES_ONE_ARG
517# define mkdir(a,b) mkdir(a)
518#endif
519
2778b98d
KG
520/* Get libiberty declarations. */
521#include "libiberty.h"
522
aca69483 523#endif /* __GCC_SYSTEM_H__ */
This page took 0.48957 seconds and 5 git commands to generate.