1 | #ifndef _TIME_H |
2 | #include <time/time.h> |
3 | |
4 | #ifndef _ISOMAC |
5 | # include <bits/types/struct_timeval.h> |
6 | # include <struct___timespec64.h> |
7 | # include <struct___timeval64.h> |
8 | # include <bits/types/locale_t.h> |
9 | # include <stdbool.h> |
10 | # include <time/mktime-internal.h> |
11 | # include <sys/time.h> |
12 | # include <time-clockid.h> |
13 | # include <sys/time.h> |
14 | |
15 | extern __typeof (strftime_l) __strftime_l; |
16 | libc_hidden_proto (__strftime_l) |
17 | extern __typeof (strptime_l) __strptime_l; |
18 | |
19 | libc_hidden_proto (asctime) |
20 | libc_hidden_proto (mktime) |
21 | libc_hidden_proto (timelocal) |
22 | libc_hidden_proto (localtime) |
23 | libc_hidden_proto (strftime) |
24 | libc_hidden_proto (strptime) |
25 | |
26 | extern __typeof (clock_gettime) __clock_gettime; |
27 | libc_hidden_proto (__clock_gettime) |
28 | extern __typeof (clock_settime) __clock_settime; |
29 | libc_hidden_proto (__clock_settime) |
30 | |
31 | extern __typeof (clock_nanosleep) __clock_nanosleep; |
32 | libc_hidden_proto (__clock_nanosleep); |
33 | |
34 | #ifdef __linux__ |
35 | extern __typeof (clock_adjtime) __clock_adjtime; |
36 | libc_hidden_proto (__clock_adjtime); |
37 | #endif |
38 | |
39 | /* Now define the internal interfaces. */ |
40 | struct tm; |
41 | |
42 | /* Defined in mktime.c. */ |
43 | extern const unsigned short int __mon_yday[2][13] attribute_hidden; |
44 | |
45 | /* Defined in localtime.c. */ |
46 | extern struct tm _tmbuf attribute_hidden; |
47 | |
48 | /* Defined in tzset.c. */ |
49 | extern char *__tzstring (const char *string) attribute_hidden; |
50 | |
51 | extern int __use_tzfile attribute_hidden; |
52 | |
53 | extern void __tzfile_read (const char *file, size_t , |
54 | char **) attribute_hidden; |
55 | extern void __tzfile_compute (__time64_t timer, int use_localtime, |
56 | long int *leap_correct, int *leap_hit, |
57 | struct tm *tp) attribute_hidden; |
58 | extern void __tzfile_default (const char *std, const char *dst, |
59 | int stdoff, int dstoff) |
60 | attribute_hidden; |
61 | extern void __tzset_parse_tz (const char *tz) attribute_hidden; |
62 | extern void __tz_compute (__time64_t timer, struct tm *tm, int use_localtime) |
63 | __THROW attribute_hidden; |
64 | |
65 | |
66 | #if __TIMESIZE == 64 |
67 | # define __itimerspec64 itimerspec |
68 | #else |
69 | /* The glibc's internal representation of the struct itimerspec. */ |
70 | struct __itimerspec64 |
71 | { |
72 | struct __timespec64 it_interval; |
73 | struct __timespec64 it_value; |
74 | }; |
75 | #endif |
76 | |
77 | #if __TIMESIZE == 64 |
78 | # define __utimbuf64 utimbuf |
79 | # define __itimerval64 itimerval |
80 | #else |
81 | /* The glibc Y2038-proof struct __utimbuf64 structure for file's access |
82 | and modification time values. */ |
83 | struct __utimbuf64 |
84 | { |
85 | __time64_t actime; /* Access time. */ |
86 | __time64_t modtime; /* Modification time. */ |
87 | }; |
88 | /* The glibc's internal representation of the struct itimerval. */ |
89 | struct __itimerval64 |
90 | { |
91 | struct __timeval64 it_interval; |
92 | struct __timeval64 it_value; |
93 | }; |
94 | #endif |
95 | |
96 | #if __TIMESIZE == 64 |
97 | # define __getitimer64 __getitimer |
98 | # define __setitimer64 __setitimer |
99 | #else |
100 | extern int __getitimer64 (enum __itimer_which __which, |
101 | struct __itimerval64 *__value); |
102 | |
103 | libc_hidden_proto (__getitimer64) |
104 | extern int __setitimer64 (enum __itimer_which __which, |
105 | const struct __itimerval64 *__restrict __new, |
106 | struct __itimerval64 *__restrict __old); |
107 | libc_hidden_proto (__setitimer64) |
108 | #endif |
109 | |
110 | #if __TIMESIZE == 64 |
111 | # define __ctime64 ctime |
112 | #else |
113 | extern char *__ctime64 (const __time64_t *__timer) __THROW; |
114 | libc_hidden_proto (__ctime64) |
115 | #endif |
116 | |
117 | #if __TIMESIZE == 64 |
118 | # define __ctime64_r ctime_r |
119 | #else |
120 | extern char *__ctime64_r (const __time64_t *__restrict __timer, |
121 | char *__restrict __buf) __THROW; |
122 | libc_hidden_proto (__ctime64_r) |
123 | #endif |
124 | |
125 | #if __TIMESIZE == 64 |
126 | # define __localtime64 localtime |
127 | #else |
128 | extern struct tm *__localtime64 (const __time64_t *__timer); |
129 | libc_hidden_proto (__localtime64) |
130 | #endif |
131 | |
132 | extern struct tm *__localtime_r (const time_t *__timer, |
133 | struct tm *__tp) attribute_hidden; |
134 | #if __TIMESIZE != 64 |
135 | extern struct tm *__localtime64_r (const __time64_t *__timer, |
136 | struct tm *__tp); |
137 | libc_hidden_proto (__localtime64_r) |
138 | |
139 | extern __time64_t __mktime64 (struct tm *__tp) __THROW; |
140 | libc_hidden_proto (__mktime64) |
141 | #endif |
142 | |
143 | extern struct tm *__gmtime_r (const time_t *__restrict __timer, |
144 | struct tm *__restrict __tp); |
145 | libc_hidden_proto (__gmtime_r) |
146 | |
147 | #if __TIMESIZE == 64 |
148 | # define __gmtime64 gmtime |
149 | #else |
150 | extern struct tm *__gmtime64 (const __time64_t *__timer); |
151 | libc_hidden_proto (__gmtime64) |
152 | |
153 | extern struct tm *__gmtime64_r (const __time64_t *__restrict __timer, |
154 | struct tm *__restrict __tp); |
155 | libc_hidden_proto (__gmtime64_r) |
156 | |
157 | extern __time64_t __timegm64 (struct tm *__tp) __THROW; |
158 | libc_hidden_proto (__timegm64) |
159 | #endif |
160 | |
161 | #if __TIMESIZE == 64 |
162 | # define __clock_settime64 __clock_settime |
163 | #else |
164 | extern int __clock_settime64 (clockid_t clock_id, |
165 | const struct __timespec64 *tp); |
166 | libc_hidden_proto (__clock_settime64) |
167 | #endif |
168 | |
169 | #if __TIMESIZE == 64 |
170 | # define __clock_getres64 __clock_getres |
171 | #else |
172 | extern int __clock_getres64 (clockid_t clock_id, |
173 | struct __timespec64 *tp); |
174 | libc_hidden_proto (__clock_getres64); |
175 | #endif |
176 | |
177 | #if __TIMESIZE == 64 |
178 | # define __utime64 __utime |
179 | # define __utimes64 __utimes |
180 | # define __utimensat64 __utimensat |
181 | #else |
182 | extern int __utime64 (const char *file, const struct __utimbuf64 *times); |
183 | libc_hidden_proto (__utime64) |
184 | extern int __utimes64 (const char *file, const struct __timeval64 tvp[2]); |
185 | libc_hidden_proto (__utimes64) |
186 | extern int __utimensat64 (int fd, const char *file, |
187 | const struct __timespec64 tsp[2], int flags); |
188 | libc_hidden_proto (__utimensat64); |
189 | #endif |
190 | |
191 | extern int __utimensat64_helper (int fd, const char *file, |
192 | const struct __timespec64 tsp[2], int flags); |
193 | libc_hidden_proto (__utimensat64_helper); |
194 | |
195 | #if __TIMESIZE == 64 |
196 | # define __futimes64 __futimes |
197 | # define __futimesat64 __futimesat |
198 | # define __lutimes64 __lutimes |
199 | # define __futimens64 __futimens |
200 | #else |
201 | extern int __futimes64 (int fd, const struct __timeval64 tvp64[2]); |
202 | libc_hidden_proto (__futimes64); |
203 | extern int __futimesat64 (int fd, const char *file, |
204 | const struct __timeval64 tvp[2]); |
205 | libc_hidden_proto (__futimesat64); |
206 | extern int __lutimes64 (const char *file, const struct __timeval64 tvp64[2]); |
207 | libc_hidden_proto (__lutimes64); |
208 | extern int __futimens64 (int fd, const struct __timespec64 tsp[2]); |
209 | libc_hidden_proto (__futimens64); |
210 | #endif |
211 | |
212 | #if __TIMESIZE == 64 |
213 | # define __timer_gettime64 __timer_gettime |
214 | # define __timerfd_gettime64 __timerfd_gettime |
215 | #else |
216 | extern int __timer_gettime64 (timer_t timerid, struct __itimerspec64 *value); |
217 | extern int __timerfd_gettime64 (int fd, struct __itimerspec64 *value); |
218 | librt_hidden_proto (__timer_gettime64); |
219 | libc_hidden_proto (__timerfd_gettime64); |
220 | #endif |
221 | |
222 | #if __TIMESIZE == 64 |
223 | # define __timer_settime64 __timer_settime |
224 | # define __timerfd_settime64 __timerfd_settime |
225 | #else |
226 | extern int __timer_settime64 (timer_t timerid, int flags, |
227 | const struct __itimerspec64 *value, |
228 | struct __itimerspec64 *ovalue); |
229 | extern int __timerfd_settime64 (int fd, int flags, |
230 | const struct __itimerspec64 *value, |
231 | struct __itimerspec64 *ovalue); |
232 | librt_hidden_proto (__timer_settime64); |
233 | libc_hidden_proto (__timerfd_settime64); |
234 | #endif |
235 | |
236 | #if __TIMESIZE == 64 |
237 | # define __sched_rr_get_interval64 __sched_rr_get_interval |
238 | #else |
239 | extern int __sched_rr_get_interval64 (pid_t pid, struct __timespec64 *tp); |
240 | libc_hidden_proto (__sched_rr_get_interval64); |
241 | #endif |
242 | |
243 | #if __TIMESIZE == 64 |
244 | # define __settimeofday64 __settimeofday |
245 | # define __gettimeofday64 __gettimeofday |
246 | #else |
247 | extern int __settimeofday64 (const struct __timeval64 *tv, |
248 | const struct timezone *tz); |
249 | libc_hidden_proto (__settimeofday64) |
250 | extern int __gettimeofday64 (struct __timeval64 *restrict tv, |
251 | void *restrict tz); |
252 | libc_hidden_proto (__gettimeofday64) |
253 | #endif |
254 | |
255 | /* Compute the `struct tm' representation of T, |
256 | offset OFFSET seconds east of UTC, |
257 | and store year, yday, mon, mday, wday, hour, min, sec into *TP. |
258 | Return nonzero if successful. */ |
259 | extern int __offtime (__time64_t __timer, |
260 | long int __offset, |
261 | struct tm *__tp) attribute_hidden; |
262 | |
263 | extern char *__asctime_r (const struct tm *__tp, char *__buf) |
264 | attribute_hidden; |
265 | extern void __tzset (void) attribute_hidden; |
266 | |
267 | /* Prototype for the internal function to get information based on TZ. */ |
268 | extern struct tm *__tz_convert (__time64_t timer, int use_localtime, |
269 | struct tm *tp) attribute_hidden; |
270 | |
271 | extern int __nanosleep (const struct timespec *__requested_time, |
272 | struct timespec *__remaining); |
273 | hidden_proto (__nanosleep) |
274 | extern int __getdate_r (const char *__string, struct tm *__resbufp) |
275 | attribute_hidden; |
276 | |
277 | |
278 | /* Determine CLK_TCK value. */ |
279 | extern int __getclktck (void) attribute_hidden; |
280 | |
281 | |
282 | /* strptime support. */ |
283 | extern char * __strptime_internal (const char *rp, const char *fmt, |
284 | struct tm *tm, void *statep, |
285 | locale_t locparam) attribute_hidden; |
286 | |
287 | #if __TIMESIZE == 64 |
288 | # define __difftime64 __difftime |
289 | #else |
290 | extern double __difftime64 (__time64_t time1, __time64_t time0); |
291 | libc_hidden_proto (__difftime64) |
292 | #endif |
293 | |
294 | extern double __difftime (time_t time1, time_t time0); |
295 | |
296 | #if __TIMESIZE == 64 |
297 | # define __clock_nanosleep_time64 __clock_nanosleep |
298 | # define __clock_gettime64 __clock_gettime |
299 | # define __timespec_get64 __timespec_get |
300 | #else |
301 | extern int __clock_nanosleep_time64 (clockid_t clock_id, |
302 | int flags, const struct __timespec64 *req, |
303 | struct __timespec64 *rem); |
304 | libc_hidden_proto (__clock_nanosleep_time64) |
305 | extern int __clock_gettime64 (clockid_t clock_id, struct __timespec64 *tp); |
306 | libc_hidden_proto (__clock_gettime64) |
307 | extern int __timespec_get64 (struct __timespec64 *ts, int base); |
308 | libc_hidden_proto (__timespec_get64) |
309 | #endif |
310 | |
311 | /* Use in the clock_* functions. Size of the field representing the |
312 | actual clock ID. */ |
313 | #define CLOCK_IDFIELD_SIZE 3 |
314 | |
315 | /* Check whether T fits in time_t. */ |
316 | static inline bool |
317 | in_time_t_range (__time64_t t) |
318 | { |
319 | time_t s = t; |
320 | return s == t; |
321 | } |
322 | |
323 | /* Convert a known valid struct timeval into a struct __timespec64. */ |
324 | static inline struct __timespec64 |
325 | valid_timeval_to_timespec64 (const struct timeval tv) |
326 | { |
327 | struct __timespec64 ts64; |
328 | |
329 | ts64.tv_sec = tv.tv_sec; |
330 | ts64.tv_nsec = tv.tv_usec * 1000; |
331 | |
332 | return ts64; |
333 | } |
334 | |
335 | /* Convert a known valid struct timeval into a struct __timeval64. */ |
336 | static inline struct __timeval64 |
337 | valid_timeval_to_timeval64 (const struct timeval tv) |
338 | { |
339 | struct __timeval64 tv64; |
340 | |
341 | tv64.tv_sec = tv.tv_sec; |
342 | tv64.tv_usec = tv.tv_usec; |
343 | |
344 | return tv64; |
345 | } |
346 | |
347 | /* Convert a valid and within range of struct timeval, struct |
348 | __timeval64 into a struct timeval. */ |
349 | static inline struct timeval |
350 | valid_timeval64_to_timeval (const struct __timeval64 tv64) |
351 | { |
352 | struct timeval tv; |
353 | |
354 | tv.tv_sec = (time_t) tv64.tv_sec; |
355 | tv.tv_usec = (suseconds_t) tv64.tv_usec; |
356 | |
357 | return tv; |
358 | } |
359 | |
360 | /* Convert a struct __timeval64 into a struct __timespec64. */ |
361 | static inline struct __timespec64 |
362 | timeval64_to_timespec64 (const struct __timeval64 tv64) |
363 | { |
364 | struct __timespec64 ts64; |
365 | |
366 | ts64.tv_sec = tv64.tv_sec; |
367 | ts64.tv_nsec = tv64.tv_usec * 1000; |
368 | |
369 | return ts64; |
370 | } |
371 | |
372 | /* Convert a known valid struct timespec into a struct __timespec64. */ |
373 | static inline struct __timespec64 |
374 | valid_timespec_to_timespec64 (const struct timespec ts) |
375 | { |
376 | struct __timespec64 ts64; |
377 | |
378 | ts64.tv_sec = ts.tv_sec; |
379 | ts64.tv_nsec = ts.tv_nsec; |
380 | |
381 | return ts64; |
382 | } |
383 | |
384 | /* Convert a valid and within range of struct timespec, struct |
385 | __timespec64 into a struct timespec. */ |
386 | static inline struct timespec |
387 | valid_timespec64_to_timespec (const struct __timespec64 ts64) |
388 | { |
389 | struct timespec ts; |
390 | |
391 | ts.tv_sec = (time_t) ts64.tv_sec; |
392 | ts.tv_nsec = ts64.tv_nsec; |
393 | |
394 | return ts; |
395 | } |
396 | |
397 | /* Convert a valid and within range of struct timeval struct |
398 | __timespec64 into a struct timeval. */ |
399 | static inline struct timeval |
400 | valid_timespec64_to_timeval (const struct __timespec64 ts64) |
401 | { |
402 | struct timeval tv; |
403 | |
404 | tv.tv_sec = (time_t) ts64.tv_sec; |
405 | tv.tv_usec = ts64.tv_nsec / 1000; |
406 | |
407 | return tv; |
408 | } |
409 | |
410 | /* Convert a struct __timespec64 into a struct __timeval64. */ |
411 | static inline struct __timeval64 |
412 | timespec64_to_timeval64 (const struct __timespec64 ts64) |
413 | { |
414 | struct __timeval64 tv64; |
415 | |
416 | tv64.tv_sec = ts64.tv_sec; |
417 | tv64.tv_usec = ts64.tv_nsec / 1000; |
418 | |
419 | return tv64; |
420 | } |
421 | |
422 | /* A version of 'struct timeval' with 32-bit time_t |
423 | and suseconds_t. */ |
424 | struct __timeval32 |
425 | { |
426 | __int32_t tv_sec; /* Seconds. */ |
427 | __int32_t tv_usec; /* Microseconds. */ |
428 | }; |
429 | |
430 | /* Conversion functions for converting to/from __timeval32 */ |
431 | static inline struct __timeval64 |
432 | valid_timeval32_to_timeval64 (const struct __timeval32 tv) |
433 | { |
434 | return (struct __timeval64) { tv.tv_sec, tv.tv_usec }; |
435 | } |
436 | |
437 | static inline struct __timeval32 |
438 | valid_timeval64_to_timeval32 (const struct __timeval64 tv64) |
439 | { |
440 | return (struct __timeval32) { tv64.tv_sec, tv64.tv_usec }; |
441 | } |
442 | |
443 | static inline struct timeval |
444 | valid_timeval32_to_timeval (const struct __timeval32 tv) |
445 | { |
446 | return (struct timeval) { tv.tv_sec, tv.tv_usec }; |
447 | } |
448 | |
449 | static inline struct __timeval32 |
450 | valid_timeval_to_timeval32 (const struct timeval tv) |
451 | { |
452 | return (struct __timeval32) { tv.tv_sec, tv.tv_usec }; |
453 | } |
454 | |
455 | static inline struct timespec |
456 | valid_timeval32_to_timespec (const struct __timeval32 tv) |
457 | { |
458 | return (struct timespec) { tv.tv_sec, tv.tv_usec * 1000 }; |
459 | } |
460 | |
461 | static inline struct __timeval32 |
462 | valid_timespec_to_timeval32 (const struct timespec ts) |
463 | { |
464 | return (struct __timeval32) { (time_t) ts.tv_sec, ts.tv_nsec / 1000 }; |
465 | } |
466 | |
467 | /* Check if a value is in the valid nanoseconds range. Return true if |
468 | it is, false otherwise. */ |
469 | static inline bool |
470 | valid_nanoseconds (__syscall_slong_t ns) |
471 | { |
472 | return __glibc_likely (0 <= ns && ns < 1000000000); |
473 | } |
474 | |
475 | /* Helper function to get time in seconds, similar to time. */ |
476 | static inline time_t |
477 | time_now (void) |
478 | { |
479 | struct timespec ts; |
480 | __clock_gettime (TIME_CLOCK_GETTIME_CLOCKID, &ts); |
481 | return ts.tv_sec; |
482 | } |
483 | #endif |
484 | |
485 | #endif |
486 | |