|
| 1 | +/* |
| 2 | + * This calculates the platform-variable portion of the libc module. |
| 3 | + * Move code in here only as you discover it is platform-variable. |
| 4 | + * |
| 5 | + */ |
| 6 | + |
| 7 | + /* c95 */ |
| 8 | +#include <stddef.h> |
| 9 | +#include <time.h> |
| 10 | +#include <stdio.h> |
| 11 | +#include <stdlib.h> |
| 12 | +#include <limits.h> |
| 13 | + |
| 14 | +/* c99 */ |
| 15 | +#include <inttypes.h> |
| 16 | + |
| 17 | +/* posix */ |
| 18 | +#include <sys/types.h> |
| 19 | +#include <sys/stat.h> |
| 20 | +#include <fcntl.h> |
| 21 | +#include <unistd.h> |
| 22 | + |
| 23 | +#define S(T) ((((T)-1)<0) ? 'i' : 'u') |
| 24 | +#define B(T) (((int)sizeof(T)) * CHAR_BIT) |
| 25 | +#define put_type(N,T) \ |
| 26 | + printf(" type %s = %c%d;\n", N, S(T), B(T)) |
| 27 | + |
| 28 | +#define CT(T) ((((T)-1)<0) ? "int" : "uint") |
| 29 | +#define CS(T) ((((T)-1)<0) ? "" : "_u") |
| 30 | +#define put_const(N,T) \ |
| 31 | + printf(" const %s : %s = %d%s;\n", \ |
| 32 | + #N, CT(T), N, CS(T)) |
| 33 | + |
| 34 | +void c95_types() { |
| 35 | + printf(" mod c95 {\n"); |
| 36 | + |
| 37 | + put_type("c_char", char); |
| 38 | + put_type("c_schar", signed char); |
| 39 | + put_type("c_uchar", unsigned char); |
| 40 | + |
| 41 | + put_type("c_short", short); |
| 42 | + put_type("c_ushort", unsigned short); |
| 43 | + |
| 44 | + put_type("c_int", int); |
| 45 | + put_type("c_uint", unsigned int); |
| 46 | + |
| 47 | + put_type("c_long", long); |
| 48 | + put_type("c_ulong", unsigned long); |
| 49 | + |
| 50 | + put_type("size_t", size_t); |
| 51 | + put_type("ptrdiff_t", ptrdiff_t); |
| 52 | + |
| 53 | + put_type("clock_t", clock_t); |
| 54 | + put_type("time_t", time_t); |
| 55 | + |
| 56 | + printf(" }\n"); |
| 57 | +} |
| 58 | + |
| 59 | +void c99_types() { |
| 60 | + printf(" mod c99 {\n"); |
| 61 | + |
| 62 | + put_type("c_longlong", long long); |
| 63 | + put_type("c_ulonglong", unsigned long long); |
| 64 | + |
| 65 | + put_type("intptr_t", intptr_t); |
| 66 | + put_type("uintptr_t", uintptr_t); |
| 67 | + |
| 68 | + printf(" }\n"); |
| 69 | +} |
| 70 | + |
| 71 | +void posix88_types() { |
| 72 | + printf(" mod posix88 {\n"); |
| 73 | + |
| 74 | + put_type("off_t", off_t); |
| 75 | + put_type("dev_t", dev_t); |
| 76 | + put_type("ino_t", ino_t); |
| 77 | + put_type("pid_t", pid_t); |
| 78 | +#ifndef __WIN32__ |
| 79 | + put_type("uid_t", uid_t); |
| 80 | + put_type("gid_t", gid_t); |
| 81 | +#endif |
| 82 | + put_type("useconds_t", useconds_t); |
| 83 | + put_type("mode_t", mode_t); |
| 84 | + |
| 85 | + put_type("ssize_t", ssize_t); |
| 86 | + |
| 87 | + printf(" }\n"); |
| 88 | +} |
| 89 | + |
| 90 | +void extra_types() { |
| 91 | + printf(" mod extra {\n"); |
| 92 | + printf(" }\n"); |
| 93 | +} |
| 94 | + |
| 95 | + |
| 96 | +void c95_consts() { |
| 97 | + printf(" mod c95 {\n"); |
| 98 | + |
| 99 | + put_const(EXIT_FAILURE, int); |
| 100 | + put_const(EXIT_SUCCESS, int); |
| 101 | + put_const(RAND_MAX, int); |
| 102 | + |
| 103 | + put_const(EOF, int); |
| 104 | + put_const(SEEK_SET, int); |
| 105 | + put_const(SEEK_CUR, int); |
| 106 | + put_const(SEEK_END, int); |
| 107 | + |
| 108 | + put_const(_IOFBF, int); |
| 109 | + put_const(_IONBF, int); |
| 110 | + put_const(_IOLBF, int); |
| 111 | + |
| 112 | + put_const(BUFSIZ, size_t); |
| 113 | + put_const(FOPEN_MAX, size_t); |
| 114 | + put_const(FILENAME_MAX, size_t); |
| 115 | + put_const(L_tmpnam, size_t); |
| 116 | + put_const(TMP_MAX, size_t); |
| 117 | + |
| 118 | + printf(" }\n"); |
| 119 | +} |
| 120 | + |
| 121 | + |
| 122 | +void posix88_consts() { |
| 123 | + printf(" mod posix88 {\n"); |
| 124 | + put_const(O_RDONLY, int); |
| 125 | + put_const(O_WRONLY, int); |
| 126 | + put_const(O_RDWR, int); |
| 127 | + put_const(O_APPEND, int); |
| 128 | + put_const(O_CREAT, int); |
| 129 | + put_const(O_EXCL, int); |
| 130 | + put_const(O_TRUNC, int); |
| 131 | + |
| 132 | + put_const(S_IFIFO, int); |
| 133 | + put_const(S_IFCHR, int); |
| 134 | + put_const(S_IFBLK, int); |
| 135 | + put_const(S_IFDIR, int); |
| 136 | + put_const(S_IFREG, int); |
| 137 | + put_const(S_IFMT, int); |
| 138 | + |
| 139 | + put_const(S_IEXEC, int); |
| 140 | + put_const(S_IWRITE, int); |
| 141 | + put_const(S_IREAD, int); |
| 142 | + |
| 143 | + put_const(S_IRWXU, int); |
| 144 | + put_const(S_IXUSR, int); |
| 145 | + put_const(S_IWUSR, int); |
| 146 | + put_const(S_IRUSR, int); |
| 147 | + |
| 148 | +#ifdef F_OK |
| 149 | + put_const(F_OK, int); |
| 150 | +#endif |
| 151 | +#ifdef R_OK |
| 152 | + put_const(R_OK, int); |
| 153 | +#endif |
| 154 | +#ifdef W_OK |
| 155 | + put_const(W_OK, int); |
| 156 | +#endif |
| 157 | +#ifdef X_OK |
| 158 | + put_const(X_OK, int); |
| 159 | +#endif |
| 160 | + |
| 161 | +#ifdef STDERR_FILENO |
| 162 | + put_const(STDERR_FILENO, int); |
| 163 | +#endif |
| 164 | +#ifdef STDIN_FILENO |
| 165 | + put_const(STDIN_FILENO, int); |
| 166 | +#endif |
| 167 | +#ifdef STDOUT_FILENO |
| 168 | + put_const(STDOUT_FILENO, int); |
| 169 | +#endif |
| 170 | + |
| 171 | +#ifdef F_LOCK |
| 172 | + put_const(F_LOCK, int); |
| 173 | +#endif |
| 174 | + |
| 175 | +#ifdef F_TEST |
| 176 | + put_const(F_TEST, int); |
| 177 | +#endif |
| 178 | + |
| 179 | +#ifdef F_TLOCK |
| 180 | + put_const(F_TLOCK, int); |
| 181 | +#endif |
| 182 | + |
| 183 | +#ifdef F_ULOCK |
| 184 | + put_const(F_ULOCK, int); |
| 185 | +#endif |
| 186 | + |
| 187 | + printf(" }\n"); |
| 188 | +} |
| 189 | + |
| 190 | +void extra_consts() { |
| 191 | + printf(" mod extra {\n"); |
| 192 | +#ifdef O_RSYNC |
| 193 | + put_const(O_RSYNC, int); |
| 194 | +#endif |
| 195 | + |
| 196 | +#ifdef O_DSYNC |
| 197 | + put_const(O_DSYNC, int); |
| 198 | +#endif |
| 199 | + |
| 200 | +#ifdef O_SYNC |
| 201 | + put_const(O_SYNC, int); |
| 202 | +#endif |
| 203 | + |
| 204 | +#ifdef O_TEXT |
| 205 | + put_const(O_TEXT, int); |
| 206 | +#endif |
| 207 | + |
| 208 | +#ifdef O_BINARY |
| 209 | + put_const(O_BINARY, int); |
| 210 | +#endif |
| 211 | + |
| 212 | +#ifdef O_IRUSR |
| 213 | + put_const(O_IRUSR, int); |
| 214 | +#endif |
| 215 | + |
| 216 | +#ifdef O_IWUSR |
| 217 | + put_const(O_IWUSR, int); |
| 218 | +#endif |
| 219 | + |
| 220 | + printf(" }\n"); |
| 221 | +} |
| 222 | + |
| 223 | +int main() { |
| 224 | + printf("mod types {"); |
| 225 | + c95_types(); |
| 226 | + c99_types(); |
| 227 | + posix88_types(); |
| 228 | + extra_types(); |
| 229 | + printf("}\n"); |
| 230 | + |
| 231 | + printf("mod consts {\n"); |
| 232 | + c95_consts(); |
| 233 | + posix88_consts(); |
| 234 | + extra_consts(); |
| 235 | + printf("}\n"); |
| 236 | +} |
| 237 | + |
0 commit comments