]>
Commit | Line | Data |
---|---|---|
6796bc80 | 1 | #ifndef _TIME_H |
05b68e14 ZW |
2 | #include <time/time.h> |
3 | ||
4 | #ifndef _ISOMAC | |
4973abcb | 5 | # include <bits/types/struct_timeval.h> |
f0be25b6 | 6 | # include <bits/types/locale_t.h> |
20aa5819 PE |
7 | # include <stdbool.h> |
8 | # include <time/mktime-internal.h> | |
464cd3a9 | 9 | # include <endian.h> |
f9a75540 | 10 | # include <time-clockid.h> |
bdbf022d | 11 | |
da4cfe38 | 12 | extern __typeof (strftime_l) __strftime_l; |
ee2a5ae8 | 13 | libc_hidden_proto (__strftime_l) |
da4cfe38 RM |
14 | extern __typeof (strptime_l) __strptime_l; |
15 | ||
c5598d47 RM |
16 | libc_hidden_proto (asctime) |
17 | libc_hidden_proto (mktime) | |
18 | libc_hidden_proto (timelocal) | |
19 | libc_hidden_proto (localtime) | |
20 | libc_hidden_proto (strftime) | |
21 | libc_hidden_proto (strptime) | |
22 | ||
6e6249d0 | 23 | extern __typeof (clock_gettime) __clock_gettime; |
89fb6835 | 24 | libc_hidden_proto (__clock_gettime) |
6e6249d0 | 25 | extern __typeof (clock_settime) __clock_settime; |
7b5af2d8 | 26 | libc_hidden_proto (__clock_settime) |
a9564ae9 | 27 | |
3537ecb4 AZ |
28 | extern __typeof (clock_nanosleep) __clock_nanosleep; |
29 | libc_hidden_proto (__clock_nanosleep); | |
30 | ||
c81aa64e AZ |
31 | #ifdef __linux__ |
32 | extern __typeof (clock_adjtime) __clock_adjtime; | |
33 | libc_hidden_proto (__clock_adjtime); | |
34 | #endif | |
35 | ||
bdbf022d UD |
36 | /* Now define the internal interfaces. */ |
37 | struct tm; | |
38 | ||
8632b240 | 39 | /* Defined in mktime.c. */ |
ab26a24a | 40 | extern const unsigned short int __mon_yday[2][13] attribute_hidden; |
8632b240 UD |
41 | |
42 | /* Defined in localtime.c. */ | |
418f1701 | 43 | extern struct tm _tmbuf attribute_hidden; |
8632b240 UD |
44 | |
45 | /* Defined in tzset.c. */ | |
b0f56784 | 46 | extern char *__tzstring (const char *string) attribute_hidden; |
8632b240 | 47 | |
418f1701 | 48 | extern int __use_tzfile attribute_hidden; |
8632b240 | 49 | |
fe559c5e | 50 | extern void __tzfile_read (const char *file, size_t extra, |
b0f56784 | 51 | char **extrap) attribute_hidden; |
d51f99ce | 52 | extern void __tzfile_compute (__time64_t timer, int use_localtime, |
38e68573 | 53 | long int *leap_correct, int *leap_hit, |
b0f56784 | 54 | struct tm *tp) attribute_hidden; |
fe559c5e | 55 | extern void __tzfile_default (const char *std, const char *dst, |
77c7d55e | 56 | int stdoff, int dstoff) |
b0f56784 L |
57 | attribute_hidden; |
58 | extern void __tzset_parse_tz (const char *tz) attribute_hidden; | |
72b8692d | 59 | extern void __tz_compute (__time64_t timer, struct tm *tm, int use_localtime) |
8bcdb7e0 | 60 | __THROW attribute_hidden; |
8632b240 | 61 | |
464cd3a9 LM |
62 | #if __TIMESIZE == 64 |
63 | # define __timespec64 timespec | |
64 | #else | |
65 | /* The glibc Y2038-proof struct __timespec64 structure for a time value. | |
66 | To keep things Posix-ish, we keep the nanoseconds field a 32-bit | |
67 | signed long, but since the Linux field is a 64-bit signed int, we | |
68 | pad our tv_nsec with a 32-bit unnamed bit-field padding. | |
69 | ||
70 | As a general rule the Linux kernel is ignoring upper 32 bits of | |
71 | tv_nsec field. */ | |
72 | struct __timespec64 | |
73 | { | |
74 | __time64_t tv_sec; /* Seconds */ | |
75 | # if BYTE_ORDER == BIG_ENDIAN | |
76 | __int32_t :32; /* Padding */ | |
77 | __int32_t tv_nsec; /* Nanoseconds */ | |
78 | # else | |
79 | __int32_t tv_nsec; /* Nanoseconds */ | |
80 | __int32_t :32; /* Padding */ | |
81 | # endif | |
82 | }; | |
83 | #endif | |
84 | ||
7755e504 AA |
85 | #if __TIMESIZE == 64 |
86 | # define __ctime64 ctime | |
87 | #else | |
88 | extern char *__ctime64 (const __time64_t *__timer) __THROW; | |
20aa5819 | 89 | libc_hidden_proto (__ctime64) |
7755e504 AA |
90 | #endif |
91 | ||
c4c2836a AA |
92 | #if __TIMESIZE == 64 |
93 | # define __ctime64_r ctime_r | |
94 | #else | |
95 | extern char *__ctime64_r (const __time64_t *__restrict __timer, | |
96 | char *__restrict __buf) __THROW; | |
20aa5819 | 97 | libc_hidden_proto (__ctime64_r) |
c4c2836a AA |
98 | #endif |
99 | ||
6e15f3e2 AA |
100 | #if __TIMESIZE == 64 |
101 | # define __localtime64 localtime | |
102 | #else | |
103 | extern struct tm *__localtime64 (const __time64_t *__timer); | |
104 | libc_hidden_proto (__localtime64) | |
105 | #endif | |
106 | ||
a784e502 | 107 | extern struct tm *__localtime_r (const time_t *__timer, |
dff07c4b | 108 | struct tm *__tp) attribute_hidden; |
20aa5819 | 109 | #if __TIMESIZE != 64 |
64c2277d AA |
110 | extern struct tm *__localtime64_r (const __time64_t *__timer, |
111 | struct tm *__tp); | |
112 | libc_hidden_proto (__localtime64_r) | |
20aa5819 PE |
113 | |
114 | extern __time64_t __mktime64 (struct tm *__tp) __THROW; | |
115 | libc_hidden_proto (__mktime64) | |
64c2277d AA |
116 | #endif |
117 | ||
a784e502 | 118 | extern struct tm *__gmtime_r (const time_t *__restrict __timer, |
c19559b0 | 119 | struct tm *__restrict __tp); |
230491f0 | 120 | libc_hidden_proto (__gmtime_r) |
811ba236 | 121 | |
131db8b0 AA |
122 | #if __TIMESIZE == 64 |
123 | # define __gmtime64 gmtime | |
124 | #else | |
125 | extern struct tm *__gmtime64 (const __time64_t *__timer); | |
126 | libc_hidden_proto (__gmtime64) | |
131db8b0 | 127 | |
a1d346ce AA |
128 | extern struct tm *__gmtime64_r (const __time64_t *__restrict __timer, |
129 | struct tm *__restrict __tp); | |
20aa5819 PE |
130 | libc_hidden_proto (__gmtime64_r) |
131 | ||
132 | extern __time64_t __timegm64 (struct tm *__tp) __THROW; | |
133 | libc_hidden_proto (__timegm64) | |
a1d346ce AA |
134 | #endif |
135 | ||
7ce198e1 LM |
136 | #if __TIMESIZE == 64 |
137 | # define __clock_settime64 __clock_settime | |
138 | #else | |
139 | extern int __clock_settime64 (clockid_t clock_id, | |
140 | const struct __timespec64 *tp); | |
141 | libc_hidden_proto (__clock_settime64) | |
142 | #endif | |
143 | ||
177a3d48 LM |
144 | #if __TIMESIZE == 64 |
145 | # define __clock_getres64 __clock_getres | |
146 | #else | |
147 | extern int __clock_getres64 (clockid_t clock_id, | |
148 | struct __timespec64 *tp); | |
149 | libc_hidden_proto (__clock_getres64); | |
150 | #endif | |
151 | ||
f5b6fd25 LM |
152 | #if __TIMESIZE == 64 |
153 | # define __utimensat64 __utimensat | |
154 | #else | |
155 | extern int __utimensat64 (int fd, const char *file, | |
156 | const struct __timespec64 tsp[2], int flags); | |
157 | libc_hidden_proto (__utimensat64); | |
158 | #endif | |
159 | ||
160 | extern int __utimensat64_helper (int fd, const char *file, | |
161 | const struct __timespec64 tsp[2], int flags); | |
162 | libc_hidden_proto (__utimensat64_helper); | |
163 | ||
42893aa3 LM |
164 | #if __TIMESIZE == 64 |
165 | # define __futimens64 __futimens | |
166 | #else | |
167 | extern int __futimens64 (int fd, const struct __timespec64 tsp[2]); | |
168 | libc_hidden_proto (__futimens64); | |
169 | #endif | |
170 | ||
72b8692d | 171 | /* Compute the `struct tm' representation of T, |
bdbf022d UD |
172 | offset OFFSET seconds east of UTC, |
173 | and store year, yday, mon, mday, wday, hour, min, sec into *TP. | |
174 | Return nonzero if successful. */ | |
72b8692d | 175 | extern int __offtime (__time64_t __timer, |
fe559c5e | 176 | long int __offset, |
b0f56784 | 177 | struct tm *__tp) attribute_hidden; |
bdbf022d | 178 | |
b0f56784 L |
179 | extern char *__asctime_r (const struct tm *__tp, char *__buf) |
180 | attribute_hidden; | |
181 | extern void __tzset (void) attribute_hidden; | |
bdbf022d | 182 | |
8632b240 | 183 | /* Prototype for the internal function to get information based on TZ. */ |
72b8692d | 184 | extern struct tm *__tz_convert (__time64_t timer, int use_localtime, |
b0f56784 | 185 | struct tm *tp) attribute_hidden; |
8632b240 | 186 | |
a784e502 | 187 | extern int __nanosleep (const struct timespec *__requested_time, |
c19559b0 | 188 | struct timespec *__remaining); |
fa872e1b | 189 | hidden_proto (__nanosleep) |
b0f56784 L |
190 | extern int __getdate_r (const char *__string, struct tm *__resbufp) |
191 | attribute_hidden; | |
25b3dd49 UD |
192 | |
193 | ||
194 | /* Determine CLK_TCK value. */ | |
b0f56784 | 195 | extern int __getclktck (void) attribute_hidden; |
4165d44d UD |
196 | |
197 | ||
ccadf7b5 | 198 | /* strptime support. */ |
ccadf7b5 | 199 | extern char * __strptime_internal (const char *rp, const char *fmt, |
fa69dc9c | 200 | struct tm *tm, void *statep, |
8bcdb7e0 | 201 | locale_t locparam) attribute_hidden; |
ccadf7b5 | 202 | |
ac253355 AA |
203 | #if __TIMESIZE == 64 |
204 | # define __difftime64 __difftime | |
205 | #else | |
206 | extern double __difftime64 (__time64_t time1, __time64_t time0); | |
207 | libc_hidden_proto (__difftime64) | |
208 | #endif | |
209 | ||
abca9f7f | 210 | extern double __difftime (time_t time1, time_t time0); |
ccadf7b5 | 211 | |
2e44b10b AF |
212 | #if __TIMESIZE == 64 |
213 | # define __clock_nanosleep_time64 __clock_nanosleep | |
ec138c67 | 214 | # define __clock_gettime64 __clock_gettime |
2e44b10b AF |
215 | #else |
216 | extern int __clock_nanosleep_time64 (clockid_t clock_id, | |
217 | int flags, const struct __timespec64 *req, | |
218 | struct __timespec64 *rem); | |
219 | libc_hidden_proto (__clock_nanosleep_time64) | |
ec138c67 AF |
220 | extern int __clock_gettime64 (clockid_t clock_id, struct __timespec64 *tp); |
221 | libc_hidden_proto (__clock_gettime64) | |
2e44b10b | 222 | #endif |
ccadf7b5 | 223 | |
4165d44d UD |
224 | /* Use in the clock_* functions. Size of the field representing the |
225 | actual clock ID. */ | |
31341567 | 226 | #define CLOCK_IDFIELD_SIZE 3 |
7735afa2 | 227 | |
20aa5819 PE |
228 | /* Check whether T fits in time_t. */ |
229 | static inline bool | |
230 | in_time_t_range (__time64_t t) | |
231 | { | |
232 | time_t s = t; | |
233 | return s == t; | |
234 | } | |
235 | ||
9c44c6a9 LM |
236 | /* Convert a known valid struct timeval into a struct __timespec64. */ |
237 | static inline struct __timespec64 | |
238 | valid_timeval_to_timespec64 (const struct timeval tv) | |
239 | { | |
240 | struct __timespec64 ts64; | |
241 | ||
242 | ts64.tv_sec = tv.tv_sec; | |
243 | ts64.tv_nsec = tv.tv_usec * 1000; | |
244 | ||
245 | return ts64; | |
246 | } | |
247 | ||
248 | /* Convert a known valid struct timespec into a struct __timespec64. */ | |
249 | static inline struct __timespec64 | |
250 | valid_timespec_to_timespec64 (const struct timespec ts) | |
251 | { | |
252 | struct __timespec64 ts64; | |
253 | ||
254 | ts64.tv_sec = ts.tv_sec; | |
255 | ts64.tv_nsec = ts.tv_nsec; | |
256 | ||
257 | return ts64; | |
258 | } | |
259 | ||
260 | /* Convert a valid and within range of struct timespec, struct | |
261 | __timespec64 into a struct timespec. */ | |
262 | static inline struct timespec | |
263 | valid_timespec64_to_timespec (const struct __timespec64 ts64) | |
264 | { | |
265 | struct timespec ts; | |
266 | ||
267 | ts.tv_sec = (time_t) ts64.tv_sec; | |
268 | ts.tv_nsec = ts64.tv_nsec; | |
269 | ||
270 | return ts; | |
271 | } | |
272 | ||
273 | /* Convert a valid and within range of struct timeval struct | |
274 | __timespec64 into a struct timeval. */ | |
275 | static inline struct timeval | |
276 | valid_timespec64_to_timeval (const struct __timespec64 ts64) | |
277 | { | |
278 | struct timeval tv; | |
279 | ||
280 | tv.tv_sec = (time_t) ts64.tv_sec; | |
281 | tv.tv_usec = ts64.tv_nsec / 1000; | |
282 | ||
283 | return tv; | |
284 | } | |
48123656 LM |
285 | |
286 | /* Check if a value is in the valid nanoseconds range. Return true if | |
287 | it is, false otherwise. */ | |
288 | static inline bool | |
289 | valid_nanoseconds (__syscall_slong_t ns) | |
290 | { | |
291 | return __glibc_likely (0 <= ns && ns < 1000000000); | |
292 | } | |
f9a75540 AZ |
293 | |
294 | /* Helper function to get time in seconds, similar to time. */ | |
295 | static inline time_t | |
296 | time_now (void) | |
297 | { | |
298 | struct timespec ts; | |
299 | __clock_gettime (TIME_CLOCK_GETTIME_CLOCKID, &ts); | |
300 | return ts.tv_sec; | |
301 | } | |
bdbf022d | 302 | #endif |
f9a75540 | 303 | |
6796bc80 | 304 | #endif |