]> git.lizzy.rs Git - rust.git/blob - src/etc/libc.c
Auto merge of #31077 - nagisa:mir-temp-promotion, r=dotdash
[rust.git] / src / etc / libc.c
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.
4 //
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.
10
11 /*
12  * This calculates the platform-variable portion of the libc module.
13  * Move code in here only as you discover it is platform-variable.
14  *
15  */
16
17  /* c95 */
18 #include <stddef.h>
19 #include <time.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <limits.h>
23 #include <wchar.h>
24
25 /* c99 */
26 #include <inttypes.h>
27
28 /* posix */
29 #include <sys/types.h>
30 #include <sys/stat.h>
31 #include <fcntl.h>
32 #include <unistd.h>
33
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))
38
39 #define put_ftype(N,T) \
40         printf("        type %s = f%d;\n", N, B(T))
41
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", \
46                #N, CT(T), N, CS(T))
47
48 void c95_types() {
49   printf("    mod c95 {\n");
50
51   put_type("c_char", char);
52   put_type("c_schar", signed char);
53   put_type("c_uchar", unsigned char);
54
55   put_type("c_short", short);
56   put_type("c_ushort", unsigned short);
57
58   put_type("c_int", int);
59   put_type("c_uint", unsigned int);
60
61   put_type("c_long", long);
62   put_type("c_ulong", unsigned long);
63
64   put_ftype("c_float", float);
65   put_ftype("c_double", double);
66
67   put_type("size_t", size_t);
68   put_type("ptrdiff_t", ptrdiff_t);
69
70   put_type("clock_t", clock_t);
71   put_type("time_t", time_t);
72
73   put_type("wchar_t", wchar_t);
74
75   printf("    }\n");
76 }
77
78 void c99_types() {
79   printf("    mod c99 {\n");
80
81   put_type("c_longlong", long long);
82   put_type("c_ulonglong", unsigned long long);
83
84   put_type("intptr_t", intptr_t);
85   put_type("uintptr_t", uintptr_t);
86
87   printf("    }\n");
88 }
89
90 void posix88_types() {
91   printf("    mod posix88 {\n");
92
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);
97 #ifndef __WIN32__
98   put_type("uid_t", uid_t);
99   put_type("gid_t", gid_t);
100 #endif
101   put_type("useconds_t", useconds_t);
102   put_type("mode_t", mode_t);
103
104   put_type("ssize_t", ssize_t);
105
106   printf("    }\n");
107 }
108
109 void extra_types() {
110   printf("    mod extra {\n");
111   printf("    }\n");
112 }
113
114
115 void c95_consts() {
116   printf("    mod c95 {\n");
117
118   put_const(EXIT_FAILURE, int);
119   put_const(EXIT_SUCCESS, int);
120   put_const(RAND_MAX, int);
121
122   put_const(EOF, int);
123   put_const(SEEK_SET, int);
124   put_const(SEEK_CUR, int);
125   put_const(SEEK_END, int);
126
127   put_const(_IOFBF, int);
128   put_const(_IONBF, int);
129   put_const(_IOLBF, int);
130
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);
136
137   printf("    }\n");
138 }
139
140
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);
150
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);
158
159   put_const(S_IEXEC, int);
160   put_const(S_IWRITE, int);
161   put_const(S_IREAD, int);
162
163   put_const(S_IRWXU, int);
164   put_const(S_IXUSR, int);
165   put_const(S_IWUSR, int);
166   put_const(S_IRUSR, int);
167
168   put_const(S_IRWXG, int);
169   put_const(S_IXGRP, int);
170   put_const(S_IWGRP, int);
171   put_const(S_IRGRP, int);
172
173   put_const(S_IRWXO, int);
174   put_const(S_IXOTH, int);
175   put_const(S_IWOTH, int);
176   put_const(S_IROTH, int);
177
178 #ifdef F_OK
179   put_const(F_OK, int);
180 #endif
181 #ifdef R_OK
182   put_const(R_OK, int);
183 #endif
184 #ifdef W_OK
185   put_const(W_OK, int);
186 #endif
187 #ifdef X_OK
188   put_const(X_OK, int);
189 #endif
190
191 #ifdef STDIN_FILENO
192   put_const(STDIN_FILENO, int);
193 #endif
194 #ifdef STDOUT_FILENO
195   put_const(STDOUT_FILENO, int);
196 #endif
197 #ifdef STDERR_FILENO
198   put_const(STDERR_FILENO, int);
199 #endif
200
201 #ifdef F_LOCK
202   put_const(F_LOCK, int);
203 #endif
204
205 #ifdef F_TEST
206   put_const(F_TEST, int);
207 #endif
208
209 #ifdef F_TLOCK
210   put_const(F_TLOCK, int);
211 #endif
212
213 #ifdef F_ULOCK
214   put_const(F_ULOCK, int);
215 #endif
216
217   printf("    }\n");
218 }
219
220 void extra_consts() {
221   printf("    mod extra {\n");
222 #ifdef O_RSYNC
223   put_const(O_RSYNC, int);
224 #endif
225
226 #ifdef O_DSYNC
227   put_const(O_DSYNC, int);
228 #endif
229
230 #ifdef O_SYNC
231   put_const(O_SYNC, int);
232 #endif
233
234 #ifdef O_TEXT
235   put_const(O_TEXT, int);
236 #endif
237
238 #ifdef O_BINARY
239   put_const(O_BINARY, int);
240 #endif
241
242 #ifdef O_IRUSR
243   put_const(O_IRUSR, int);
244 #endif
245
246 #ifdef O_IWUSR
247   put_const(O_IWUSR, int);
248 #endif
249
250   printf("    }\n");
251 }
252
253 int main() {
254   printf("mod types {");
255   c95_types();
256   c99_types();
257   posix88_types();
258   extra_types();
259   printf("}\n");
260
261   printf("mod consts {\n");
262   c95_consts();
263   posix88_consts();
264   extra_consts();
265   printf("}\n");
266 }