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