1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/* <time.h> — date and time (C99 7.23).
*
* `struct tm` is laid out the way glibc and Apple's library lay it out: the
* nine standard members followed by the two BSD ones, which both libraries
* have and which a program that passes a `struct tm` by address would corrupt
* if they were missing. The Microsoft library has only the nine, and the `#if`
* below follows it.
*
* `_WIN32` is the *target's*, from the model cinrs was told to translate for.
* `time_t` is `long` on the Unix platforms, which makes it 32 bits wide on a
* 32-bit target — glibc's own default without `_TIME_BITS=64` — and `long
* long` on Windows.
*
* `struct timespec` (C11 7.27.1) is `{ time_t; long; }` on all three, which is
* eight bytes on a 32-bit Unix and sixteen everywhere else. It is here rather
* than in `<threads.h>` alone because C puts it here, and `thrd_sleep`,
* `mtx_timedlock` and `cnd_timedwait` all take one.
*
* # Coexisting with the platform's own headers
*
* With `#pragma cinrs system_include` this header wins over the platform's
* `<time.h>`, but the platform's *other* headers are still in play — and
* glibc's `<pthread.h>`, `<sys/stat.h>`, `<fcntl.h>`, `<sys/time.h>` and
* `<sys/wait.h>` all reach `bits/types/struct_timespec.h`,
* `bits/types/struct_tm.h` and the `time_t`/`clock_t` files behind them. Each
* of those is wrapped in a per-type guard macro, so every definition here
* *tests and then claims* the guards glibc, musl and mingw-w64 use for the same
* type. Claiming one is a promise that the layout below is that platform's own,
* which is what the differential tests in `tests/system_headers.rs` check.
*
* type / macro glibc musl mingw-w64
* time_t __time_t_defined __DEFINED_time_t _TIME_T_DEFINED
* clock_t __clock_t_defined __DEFINED_clock_t _CLOCK_T_DEFINED
* clockid_t __clockid_t_defined __DEFINED_clockid_t —
* timer_t __timer_t_defined __DEFINED_timer_t —
* struct timespec _STRUCT_TIMESPEC __DEFINED_struct_timespec _TIMESPEC_DEFINED
* struct tm __struct_tm_defined __DEFINED_struct_tm —
* struct itimerspec __itimerspec_defined __DEFINED_struct_itimerspec —
*
* `_STRUCT_TIMESPEC` is also what `<linux/time.h>` tests, so claiming it keeps
* the kernel's UAPI headers quiet as well — glibc's own file says so.
*
* `CLOCKS_PER_SEC` and `TIME_UTC` have no per-type guard in glibc at all:
* `bits/time.h` defines `CLOCKS_PER_SEC` as `((__clock_t) 1000000)` behind
* nothing but its file guard. The two spellings mean the same number, and the
* preprocessor takes the platform's own as the authoritative one when a bundled
* header and a platform header disagree about a macro; see `Pp::define`.
*/
/* ---- time_t, clock_t --------------------------------------------------- */
/* `__extension__`: `long long` is C99's, and a header may use it whatever the
* entry point is. */
__extension__ typedef long long time_t;
typedef long time_t;
typedef long clock_t;
/* ---- struct timespec -------------------------------------------------- */
/* C11 7.27.1p3. `tv_nsec` is `long` on glibc, musl, Apple's library and the
* Microsoft one alike — glibc spells it `__syscall_slong_t`, which is `long`
* on every target this crate models. */
;
/* The one time base C requires, and the value all four libraries give it. */
/* ---- struct tm -------------------------------------------------------- */
;
time_t ;
clock_t ;
double ;
time_t ;
struct tm *;
struct tm *;
char *;
char *;
size_t ;
/* C11 7.27.2.5. glibc has had it since 2.16, musl since 1.1.5, Apple since
* macOS 10.15 and the Microsoft UCRT since Visual Studio 2015. */
int ;
/* _CINRS_TIME_H */