Commit | Line | Data |
---|---|---|
a3209dfc WJ |
1 | /* std.h - automagically adapt to old and new compilers. |
2 | In the Public Domain; written by Mike Haertel. */ | |
3 | ||
4 | #if __STDC__ | |
5 | ||
6 | #include <stddef.h> | |
7 | #include <limits.h> | |
8 | ||
9 | typedef void *PTR; | |
10 | typedef const void *PTRCONST; | |
11 | ||
12 | #define AND , | |
13 | #define DEFUN(F, L, P) F(P) | |
14 | #define EXFUN(F, P) F P | |
15 | ||
16 | #else | |
17 | ||
18 | #define const | |
19 | #define volatile | |
20 | ||
21 | /* The following approximations of <stddef.h> and <limits.h> are appropriate | |
22 | for most machines. */ | |
23 | typedef int ptrdiff_t; | |
24 | typedef unsigned int size_t; | |
25 | #define NULL 0 | |
26 | #define offsetof(T, M) ((size_t)&((T *) 0)->(M)) | |
27 | ||
28 | #define CHAR_BIT 8 | |
29 | #define SCHAR_MIN -128 | |
30 | #define SCHAR_MAX 127 | |
31 | #define UCHAR_MAX 255 | |
32 | #define CHAR_MIN ((char) UCHAR_MAX < 0 ? SCHAR_MIN : 0) | |
33 | #define CHAR_MAX ((char) UCHAR_MAX < 0 ? SCHAR_MAX : UCHAR_MAX) | |
34 | #define SHRT_MIN -32768 | |
35 | #define SHRT_MAX 32767 | |
36 | #define USHRT_MAX 65535 | |
37 | #define INT_MIN (sizeof (int) == 2 ? -32768 : -2147483648) | |
38 | #define INT_MAX (sizeof (int) == 2 ? 32767 : 2147483647) | |
39 | #define UINT_MAX (sizeof (int) == 2 ? 65535 : 4294967295) | |
40 | #define LONG_MIN -2147483648L | |
41 | #define LONG_MAX 2147483647L | |
42 | #define ULONG_MAX 4294967295 | |
43 | ||
44 | typedef char *PTR; | |
45 | typedef const char *PTRCONST; | |
46 | ||
47 | #define AND ; | |
48 | #define DEFUN(F, L, P) F L P ; | |
49 | #define EXFUN(F, P) F() | |
50 | ||
51 | #endif | |
52 | ||
53 | /* Deal with <ctype.h> lossage. */ | |
54 | #include <ctype.h> | |
55 | ||
56 | #ifndef isascii | |
57 | ||
58 | #define ISALNUM(C) isalnum(C) | |
59 | #define ISALPHA(C) isalpha(C) | |
60 | #define ISCNTRL(C) iscntrl(C) | |
61 | #define ISDIGIT(C) isdigit(C) | |
62 | #define ISGRAPH(C) isgraph(C) | |
63 | #define ISLOWER(C) islower(C) | |
64 | #define ISPRINT(C) isprint(C) | |
65 | #define ISPUNCT(C) ispunct(C) | |
66 | #define ISSPACE(C) isspace(C) | |
67 | #define ISUPPER(C) isupper(C) | |
68 | #define ISXDIGIT(C) isxdigit(C) | |
69 | #define TOLOWER(C) tolower(C) | |
70 | #define TOUPPER(C) toupper(C) | |
71 | ||
72 | #else | |
73 | ||
74 | #define ISALNUM(C) (isascii(C) && isalnum(C)) | |
75 | #define ISALPHA(C) (isascii(C) && isalpha(C)) | |
76 | #define ISCNTRL(C) (isascii(C) && iscntrl(C)) | |
77 | #define ISDIGIT(C) (isascii(C) && isdigit(C)) | |
78 | #define ISGRAPH(C) (isascii(C) && isgraph(C)) | |
79 | #define ISLOWER(C) (isascii(C) && islower(C)) | |
80 | #define ISPRINT(C) (isascii(C) && isprint(C)) | |
81 | #define ISPUNCT(C) (isascii(C) && ispunct(C)) | |
82 | #define ISSPACE(C) (isascii(C) && isspace(C)) | |
83 | #define ISUPPER(C) (isascii(C) && isupper(C)) | |
84 | #define ISXDIGIT(C) (isascii(C) && isxdigit(C)) | |
85 | #define TOLOWER(C) (ISUPPER(C) ? tolower(C) : (C)) | |
86 | #define TOUPPER(C) (ISLOWER(C) ? toupper(C) : (C)) | |
87 | ||
88 | #endif | |
89 | ||
90 | /* Declaring this here should be safe. Some losing <errno.h>'s don't. */ | |
91 | extern int errno; | |
92 | ||
93 | /* Adapt variable arguments to new implementations (with <stdarg.h>) | |
94 | or old (which are assumed to have <varargs.h>). */ | |
95 | ||
96 | #if __STDC__ | |
97 | ||
98 | #include <stdarg.h> | |
99 | ||
100 | #define VA_ALIST ... | |
101 | #define VA_DCL ... | |
102 | #define VA_LIST va_list | |
103 | #define VA_START(AP, LASTARG) va_start(AP, LASTARG) | |
104 | #define VA_ARG(AP, TYPE) va_arg(AP, TYPE) | |
105 | #define VA_END(AP) va_end(AP) | |
106 | ||
107 | #define VA_DEFUN(F, L, P) F(P) | |
108 | ||
109 | #else | |
110 | ||
111 | #include <varargs.h> | |
112 | ||
113 | #define VA_ALIST va_alist | |
114 | #define VA_DCL va_dcl | |
115 | #define VA_LIST va_list | |
116 | #define VA_START(AP, LASTARG) va_start(AP) | |
117 | #define VA_ARG(AP, TYPE) va_arg(AP, TYPE) | |
118 | #define VA_END(AP) va_end(AP) | |
119 | ||
120 | #define VA_DEFUN(F, L, P) F L P | |
121 | ||
122 | #endif | |
123 | ||
124 | /* Declarations of traditional library routines. */ | |
125 | extern double EXFUN(atof, (const char *)); | |
126 | extern int EXFUN(atoi, (const char *)); | |
127 | extern long int EXFUN(atol, (const char *)); | |
128 | extern int EXFUN(rand, (void)); | |
129 | extern void EXFUN(srand, (int)); | |
130 | extern PTR EXFUN(calloc, (size_t, size_t)); | |
131 | extern void EXFUN(free, (PTR)); | |
132 | extern PTR EXFUN(malloc, (size_t)); | |
133 | extern PTR EXFUN(realloc, (PTR, size_t)); | |
134 | extern void EXFUN(abort, (void)); | |
135 | extern void EXFUN(exit, (int)); | |
136 | extern char *EXFUN(getenv, (const char *)); | |
137 | extern int EXFUN(system, (const char *)); | |
138 | extern void EXFUN(qsort, (PTR, size_t, size_t, | |
139 | int EXFUN((*), (PTRCONST, PTRCONST)))); | |
140 | extern int EXFUN(abs, (int)); | |
141 | extern long int EXFUN(labs, (long int)); | |
142 | ||
143 | #ifdef X_strerror | |
144 | extern char *EXFUN(strerror, (int)); | |
145 | #endif |