system.h revision 50397
150397Sobrien/* system.h - Get common system includes and various definitions and 250397Sobrien declarations based on autoconf macros. 350397Sobrien Copyright (C) 1998 Free Software Foundation, Inc. 450397Sobrien 550397Sobrien */ 650397Sobrien 750397Sobrien#ifndef __GCC_SYSTEM_H__ 850397Sobrien#define __GCC_SYSTEM_H__ 950397Sobrien 1050397Sobrien#include <stdio.h> 1150397Sobrien 1250397Sobrien/* Define a generic NULL if one hasn't already been defined. */ 1350397Sobrien#ifndef NULL 1450397Sobrien#define NULL 0 1550397Sobrien#endif 1650397Sobrien 1750397Sobrien#include <ctype.h> 1850397Sobrien 1950397Sobrien/* Jim Meyering writes: 2050397Sobrien 2150397Sobrien "... Some ctype macros are valid only for character codes that 2250397Sobrien isascii says are ASCII (SGI's IRIX-4.0.5 is one such system --when 2350397Sobrien using /bin/cc or gcc but without giving an ansi option). So, all 2450397Sobrien ctype uses should be through macros like ISPRINT... If 2550397Sobrien STDC_HEADERS is defined, then autoconf has verified that the ctype 2650397Sobrien macros don't need to be guarded with references to isascii. ... 2750397Sobrien Defining isascii to 1 should let any compiler worth its salt 2850397Sobrien eliminate the && through constant folding." 2950397Sobrien 3050397Sobrien Bruno Haible adds: 3150397Sobrien 3250397Sobrien "... Furthermore, isupper(c) etc. have an undefined result if c is 3350397Sobrien outside the range -1 <= c <= 255. One is tempted to write isupper(c) 3450397Sobrien with c being of type `char', but this is wrong if c is an 8-bit 3550397Sobrien character >= 128 which gets sign-extended to a negative value. 3650397Sobrien The macro ISUPPER protects against this as well." */ 3750397Sobrien 3850397Sobrien#if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII)) 3950397Sobrien# define IN_CTYPE_DOMAIN(c) 1 4050397Sobrien#else 4150397Sobrien# define IN_CTYPE_DOMAIN(c) isascii(c) 4250397Sobrien#endif 4350397Sobrien 4450397Sobrien#ifdef isblank 4550397Sobrien# define ISBLANK(c) (IN_CTYPE_DOMAIN (c) && isblank (c)) 4650397Sobrien#else 4750397Sobrien# define ISBLANK(c) ((c) == ' ' || (c) == '\t') 4850397Sobrien#endif 4950397Sobrien#ifdef isgraph 5050397Sobrien# define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isgraph (c)) 5150397Sobrien#else 5250397Sobrien# define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isprint (c) && !isspace (c)) 5350397Sobrien#endif 5450397Sobrien 5550397Sobrien#define ISPRINT(c) (IN_CTYPE_DOMAIN (c) && isprint (c)) 5650397Sobrien#define ISALNUM(c) (IN_CTYPE_DOMAIN (c) && isalnum (c)) 5750397Sobrien#define ISALPHA(c) (IN_CTYPE_DOMAIN (c) && isalpha (c)) 5850397Sobrien#define ISCNTRL(c) (IN_CTYPE_DOMAIN (c) && iscntrl (c)) 5950397Sobrien#define ISLOWER(c) (IN_CTYPE_DOMAIN (c) && islower (c)) 6050397Sobrien#define ISPUNCT(c) (IN_CTYPE_DOMAIN (c) && ispunct (c)) 6150397Sobrien#define ISSPACE(c) (IN_CTYPE_DOMAIN (c) && isspace (c)) 6250397Sobrien#define ISUPPER(c) (IN_CTYPE_DOMAIN (c) && isupper (c)) 6350397Sobrien#define ISXDIGIT(c) (IN_CTYPE_DOMAIN (c) && isxdigit (c)) 6450397Sobrien#define ISDIGIT_LOCALE(c) (IN_CTYPE_DOMAIN (c) && isdigit (c)) 6550397Sobrien 6650397Sobrien/* ISDIGIT differs from ISDIGIT_LOCALE, as follows: 6750397Sobrien - Its arg may be any int or unsigned int; it need not be an unsigned char. 6850397Sobrien - It's guaranteed to evaluate its argument exactly once. 6950397Sobrien - It's typically faster. 7050397Sobrien Posix 1003.2-1992 section 2.5.2.1 page 50 lines 1556-1558 says that 7150397Sobrien only '0' through '9' are digits. Prefer ISDIGIT to ISDIGIT_LOCALE unless 7250397Sobrien it's important to use the locale's definition of `digit' even when the 7350397Sobrien host does not conform to Posix. */ 7450397Sobrien#define ISDIGIT(c) ((unsigned) (c) - '0' <= 9) 7550397Sobrien 7650397Sobrien 7750397Sobrien#include <sys/types.h> 7850397Sobrien#include <errno.h> 7950397Sobrien 8050397Sobrien#ifndef errno 8150397Sobrienextern int errno; 8250397Sobrien#endif 8350397Sobrien 8450397Sobrien#ifdef HAVE_STRING_H 8550397Sobrien# include <string.h> 8650397Sobrien#else 8750397Sobrien# ifdef HAVE_STRINGS_H 8850397Sobrien# include <strings.h> 8950397Sobrien# endif 9050397Sobrien#endif 9150397Sobrien 9250397Sobrien#ifdef HAVE_STDLIB_H 9350397Sobrien# include <stdlib.h> 9450397Sobrien#endif 9550397Sobrien 9650397Sobrien#ifdef HAVE_UNISTD_H 9750397Sobrien# include <unistd.h> 9850397Sobrien#endif 9950397Sobrien 10050397Sobrien#ifdef HAVE_SYS_PARAM_H 10150397Sobrien# include <sys/param.h> 10250397Sobrien#endif 10350397Sobrien 10450397Sobrien#if HAVE_LIMITS_H 10550397Sobrien# include <limits.h> 10650397Sobrien#endif 10750397Sobrien 10850397Sobrien#ifdef TIME_WITH_SYS_TIME 10950397Sobrien# include <sys/time.h> 11050397Sobrien# include <time.h> 11150397Sobrien#else 11250397Sobrien# if HAVE_SYS_TIME_H 11350397Sobrien# include <sys/time.h> 11450397Sobrien# else 11550397Sobrien# ifdef HAVE_TIME_H 11650397Sobrien# include <time.h> 11750397Sobrien# endif 11850397Sobrien# endif 11950397Sobrien#endif 12050397Sobrien 12150397Sobrien#ifdef HAVE_FCNTL_H 12250397Sobrien# include <fcntl.h> 12350397Sobrien#else 12450397Sobrien# ifdef HAVE_SYS_FILE_H 12550397Sobrien# include <sys/file.h> 12650397Sobrien# endif 12750397Sobrien#endif 12850397Sobrien 12950397Sobrien#ifndef SEEK_SET 13050397Sobrien# define SEEK_SET 0 13150397Sobrien# define SEEK_CUR 1 13250397Sobrien# define SEEK_END 2 13350397Sobrien#endif 13450397Sobrien#ifndef F_OK 13550397Sobrien# define F_OK 0 13650397Sobrien# define X_OK 1 13750397Sobrien# define W_OK 2 13850397Sobrien# define R_OK 4 13950397Sobrien#endif 14050397Sobrien#ifndef O_RDONLY 14150397Sobrien# define O_RDONLY 0 14250397Sobrien#endif 14350397Sobrien#ifndef O_WRONLY 14450397Sobrien# define O_WRONLY 1 14550397Sobrien#endif 14650397Sobrien 14750397Sobrien 14850397Sobrien 14950397Sobrien#ifndef bcopy 15050397Sobrien# ifdef HAVE_BCOPY 15150397Sobrien# ifdef NEED_DECLARATION_BCOPY 15250397Sobrienextern void bcopy (); 15350397Sobrien# endif 15450397Sobrien# else /* ! HAVE_BCOPY */ 15550397Sobrien# define bcopy(src,dst,len) memcpy ((dst),(src),(len)) 15650397Sobrien# endif 15750397Sobrien#endif 15850397Sobrien 15950397Sobrien#ifndef bcmp 16050397Sobrien# ifdef HAVE_BCMP 16150397Sobrien# ifdef NEED_DECLARATION_BCMP 16250397Sobrienextern int bcmp (); 16350397Sobrien# endif 16450397Sobrien# else /* ! HAVE_BCMP */ 16550397Sobrien# define bcmp(left,right,len) memcmp ((left),(right),(len)) 16650397Sobrien# endif 16750397Sobrien#endif 16850397Sobrien 16950397Sobrien#ifndef bzero 17050397Sobrien# ifdef HAVE_BZERO 17150397Sobrien# ifdef NEED_DECLARATION_BZERO 17250397Sobrienextern void bzero (); 17350397Sobrien# endif 17450397Sobrien# else /* ! HAVE_BZERO */ 17550397Sobrien# define bzero(dst,len) memset ((dst),0,(len)) 17650397Sobrien# endif 17750397Sobrien#endif 17850397Sobrien 17950397Sobrien#ifndef index 18050397Sobrien# ifdef HAVE_INDEX 18150397Sobrien# ifdef NEED_DECLARATION_INDEX 18250397Sobrienextern char *index (); 18350397Sobrien# endif 18450397Sobrien# else /* ! HAVE_INDEX */ 18550397Sobrien# define index strchr 18650397Sobrien# endif 18750397Sobrien#endif 18850397Sobrien 18950397Sobrien#ifndef rindex 19050397Sobrien# ifdef HAVE_RINDEX 19150397Sobrien# ifdef NEED_DECLARATION_RINDEX 19250397Sobrienextern char *rindex (); 19350397Sobrien# endif 19450397Sobrien# else /* ! HAVE_RINDEX */ 19550397Sobrien# define rindex strrchr 19650397Sobrien# endif 19750397Sobrien#endif 19850397Sobrien 19950397Sobrien#ifdef NEED_DECLARATION_ATOF 20050397Sobrienextern double atof (); 20150397Sobrien#endif 20250397Sobrien 20350397Sobrien#ifdef NEED_DECLARATION_ATOL 20450397Sobrienextern long atol(); 20550397Sobrien#endif 20650397Sobrien 20750397Sobrien#ifdef NEED_DECLARATION_FREE 20850397Sobrienextern void free (); 20950397Sobrien#endif 21050397Sobrien 21150397Sobrien#ifdef NEED_DECLARATION_GETCWD 21250397Sobrienextern char *getcwd (); 21350397Sobrien#endif 21450397Sobrien 21550397Sobrien#ifdef NEED_DECLARATION_GETENV 21650397Sobrienextern char *getenv (); 21750397Sobrien#endif 21850397Sobrien 21950397Sobrien#ifdef NEED_DECLARATION_GETWD 22050397Sobrienextern char *getwd (); 22150397Sobrien#endif 22250397Sobrien 22350397Sobrien#ifdef NEED_DECLARATION_SBRK 22450397Sobrienextern char *sbrk (); 22550397Sobrien#endif 22650397Sobrien 22750397Sobrien#ifdef HAVE_STRERROR 22850397Sobrien# ifdef NEED_DECLARATION_STRERROR 22950397Sobrien# ifndef strerror 23050397Sobrienextern char *strerror (); 23150397Sobrien# endif 23250397Sobrien# endif 23350397Sobrien#else /* ! HAVE_STRERROR */ 23450397Sobrienextern int sys_nerr; 23550397Sobrienextern char *sys_errlist[]; 23650397Sobrien#endif /* HAVE_STRERROR */ 23750397Sobrien 23850397Sobrien#ifdef HAVE_GETRLIMIT 23950397Sobrien# ifdef NEED_DECLARATION_GETRLIMIT 24050397Sobrien# ifndef getrlimit 24150397Sobrienextern int getrlimit (); 24250397Sobrien# endif 24350397Sobrien# endif 24450397Sobrien#endif 24550397Sobrien 24650397Sobrien#ifdef HAVE_SETRLIMIT 24750397Sobrien# ifdef NEED_DECLARATION_SETRLIMIT 24850397Sobrien# ifndef setrlimit 24950397Sobrienextern int setrlimit (); 25050397Sobrien# endif 25150397Sobrien# endif 25250397Sobrien#endif 25350397Sobrien 25450397Sobrien/* HAVE_VOLATILE only refers to the stage1 compiler. We also check 25550397Sobrien __STDC__ and assume gcc sets it and has volatile in stage >=2. */ 25650397Sobrien#if !defined(HAVE_VOLATILE) && !defined(__STDC__) && !defined(volatile) 25750397Sobrien#define volatile 25850397Sobrien#endif 25950397Sobrien 26050397Sobrien/* Redefine abort to report an internal error w/o coredump, and reporting the 26150397Sobrien location of the error in the source file. */ 26250397Sobrien#ifndef abort 26350397Sobrien#ifndef __STDC__ 26450397Sobrien#ifndef __GNUC__ 26550397Sobrien#ifndef USE_SYSTEM_ABORT 26650397Sobrien#define USE_SYSTEM_ABORT 26750397Sobrien#endif /* !USE_SYSTEM_ABORT */ 26850397Sobrien#endif /* !__GNUC__ */ 26950397Sobrien#endif /* !__STDC__ */ 27050397Sobrien 27150397Sobrien#ifdef USE_SYSTEM_ABORT 27250397Sobrien# ifdef NEED_DECLARATION_ABORT 27350397Sobrienextern void abort (); 27450397Sobrien# endif 27550397Sobrien#else 27650397Sobrien#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) 27750397Sobrien#define abort() \ 27850397Sobrien(fprintf (stderr, \ 27950397Sobrien "%s:%d: Internal compiler error\n", __FILE__, __LINE__), \ 28050397Sobrien exit (FATAL_EXIT_CODE)) 28150397Sobrien 28250397Sobrien#else 28350397Sobrien#define abort() \ 28450397Sobrien(fprintf (stderr, \ 28550397Sobrien "%s:%d: Internal compiler error in function %s\n", \ 28650397Sobrien __FILE__, __LINE__, __PRETTY_FUNCTION__), \ 28750397Sobrien exit (FATAL_EXIT_CODE)) 28850397Sobrien 28950397Sobrien#endif /* recent gcc */ 29050397Sobrien#endif /* USE_SYSTEM_ABORT */ 29150397Sobrien#endif /* !abort */ 29250397Sobrien 29350397Sobrien 29450397Sobrien/* Define a STRINGIFY macro that's right for ANSI or traditional C. 29550397Sobrien HAVE_CPP_STRINGIFY only refers to the stage1 compiler. Assume that 29650397Sobrien (non-traditional) gcc used in stage2 or later has this feature. 29750397Sobrien 29850397Sobrien Note: if the argument passed to STRINGIFY is itself a macro, eg 29950397Sobrien #define foo bar, STRINGIFY(foo) will produce "foo", not "bar". 30050397Sobrien Although the __STDC__ case could be made to expand this via a layer 30150397Sobrien of indirection, the traditional C case can not do so. Therefore 30250397Sobrien this behavior is not supported. */ 30350397Sobrien#ifndef STRINGIFY 30450397Sobrien# if defined(HAVE_CPP_STRINGIFY) || (defined(__GNUC__) && defined(__STDC__)) 30550397Sobrien# define STRINGIFY(STRING) #STRING 30650397Sobrien# else 30750397Sobrien# define STRINGIFY(STRING) "STRING" 30850397Sobrien# endif 30950397Sobrien#endif /* ! STRINGIFY */ 31050397Sobrien 31150397Sobrien 31250397Sobrien/* These macros are here in preparation for the use of gettext in egcs. */ 31350397Sobrien#define _(String) String 31450397Sobrien#define N_(String) String 31550397Sobrien 31650397Sobrien#endif /* __GCC_SYSTEM_H__ */ 317