1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
12 * This calculates the platform-variable portion of the libc module.
13 * Move code in here only as you discover it is platform-variable.
29 #include <sys/types.h>
34 #define S(T) ((((T)-1)<0) ? 'i' : 'u')
35 #define B(T) (((int)sizeof(T)) * CHAR_BIT)
36 #define put_type(N,T) \
37 printf(" type %s = %c%d;\n", N, S(T), B(T))
39 #define put_ftype(N,T) \
40 printf(" type %s = f%d;\n", N, B(T))
42 #define CT(T) ((((T)-1)<0) ? "int" : "uint")
43 #define CS(T) ((((T)-1)<0) ? "" : "_u")
44 #define put_const(N,T) \
45 printf(" const %s : %s = %d%s;\n", \
49 printf(" mod c95 {\n");
51 put_type("c_char", char);
52 put_type("c_schar", signed char);
53 put_type("c_uchar", unsigned char);
55 put_type("c_short", short);
56 put_type("c_ushort", unsigned short);
58 put_type("c_int", int);
59 put_type("c_uint", unsigned int);
61 put_type("c_long", long);
62 put_type("c_ulong", unsigned long);
64 put_ftype("c_float", float);
65 put_ftype("c_double", double);
67 put_type("size_t", size_t);
68 put_type("ptrdiff_t", ptrdiff_t);
70 put_type("clock_t", clock_t);
71 put_type("time_t", time_t);
73 put_type("wchar_t", wchar_t);
79 printf(" mod c99 {\n");
81 put_type("c_longlong", long long);
82 put_type("c_ulonglong", unsigned long long);
84 put_type("intptr_t", intptr_t);
85 put_type("uintptr_t", uintptr_t);
90 void posix88_types() {
91 printf(" mod posix88 {\n");
93 put_type("off_t", off_t);
94 put_type("dev_t", dev_t);
95 put_type("ino_t", ino_t);
96 put_type("pid_t", pid_t);
98 put_type("uid_t", uid_t);
99 put_type("gid_t", gid_t);
101 put_type("useconds_t", useconds_t);
102 put_type("mode_t", mode_t);
104 put_type("ssize_t", ssize_t);
110 printf(" mod extra {\n");
116 printf(" mod c95 {\n");
118 put_const(EXIT_FAILURE, int);
119 put_const(EXIT_SUCCESS, int);
120 put_const(RAND_MAX, int);
123 put_const(SEEK_SET, int);
124 put_const(SEEK_CUR, int);
125 put_const(SEEK_END, int);
127 put_const(_IOFBF, int);
128 put_const(_IONBF, int);
129 put_const(_IOLBF, int);
131 put_const(BUFSIZ, size_t);
132 put_const(FOPEN_MAX, size_t);
133 put_const(FILENAME_MAX, size_t);
134 put_const(L_tmpnam, size_t);
135 put_const(TMP_MAX, size_t);
141 void posix88_consts() {
142 printf(" mod posix88 {\n");
143 put_const(O_RDONLY, int);
144 put_const(O_WRONLY, int);
145 put_const(O_RDWR, int);
146 put_const(O_APPEND, int);
147 put_const(O_CREAT, int);
148 put_const(O_EXCL, int);
149 put_const(O_TRUNC, int);
151 put_const(S_IFIFO, int);
152 put_const(S_IFCHR, int);
153 put_const(S_IFBLK, int);
154 put_const(S_IFDIR, int);
155 put_const(S_IFREG, int);
156 put_const(S_IFLNK, int);
157 put_const(S_IFMT, int);
159 put_const(S_IEXEC, int);
160 put_const(S_IWRITE, int);
161 put_const(S_IREAD, int);
163 put_const(S_IRWXU, int);
164 put_const(S_IXUSR, int);
165 put_const(S_IWUSR, int);
166 put_const(S_IRUSR, int);
169 put_const(F_OK, int);
172 put_const(R_OK, int);
175 put_const(W_OK, int);
178 put_const(X_OK, int);
182 put_const(STDIN_FILENO, int);
185 put_const(STDOUT_FILENO, int);
188 put_const(STDERR_FILENO, int);
192 put_const(F_LOCK, int);
196 put_const(F_TEST, int);
200 put_const(F_TLOCK, int);
204 put_const(F_ULOCK, int);
210 void extra_consts() {
211 printf(" mod extra {\n");
213 put_const(O_RSYNC, int);
217 put_const(O_DSYNC, int);
221 put_const(O_SYNC, int);
225 put_const(O_TEXT, int);
229 put_const(O_BINARY, int);
233 put_const(O_IRUSR, int);
237 put_const(O_IWUSR, int);
244 printf("mod types {");
251 printf("mod consts {\n");