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 | #if __TIMESIZE == 64 |
275 | # define __nanosleep64 __nanosleep |
276 | #else |
277 | extern int __nanosleep64 (const struct __timespec64 *__requested_time, |
278 | struct __timespec64 *__remaining); |
279 | hidden_proto (__nanosleep64) |
280 | #endif |
281 | |
282 | |
283 | extern int __getdate_r (const char *__string, struct tm *__resbufp) |
284 | attribute_hidden; |
285 | |
286 | |
287 | /* Determine CLK_TCK value. */ |
288 | extern int __getclktck (void) attribute_hidden; |
289 | |
290 | |
291 | /* strptime support. */ |
292 | extern char * __strptime_internal (const char *rp, const char *fmt, |
293 | struct tm *tm, void *statep, |
294 | locale_t locparam) attribute_hidden; |
295 | |
296 | #if __TIMESIZE == 64 |
297 | # define __difftime64 __difftime |
298 | #else |
299 | extern double __difftime64 (__time64_t time1, __time64_t time0); |
300 | libc_hidden_proto (__difftime64) |
301 | #endif |
302 | |
303 | extern double __difftime (time_t time1, time_t time0); |
304 | |
305 | #if __TIMESIZE == 64 |
306 | # define __clock_nanosleep_time64 __clock_nanosleep |
307 | # define __clock_gettime64 __clock_gettime |
308 | # define __timespec_get64 __timespec_get |
309 | #else |
310 | extern int __clock_nanosleep_time64 (clockid_t clock_id, |
311 | int flags, const struct __timespec64 *req, |
312 | struct __timespec64 *rem); |
313 | libc_hidden_proto (__clock_nanosleep_time64) |
314 | extern int __clock_gettime64 (clockid_t clock_id, struct __timespec64 *tp); |
315 | libc_hidden_proto (__clock_gettime64) |
316 | extern int __timespec_get64 (struct __timespec64 *ts, int base); |
317 | libc_hidden_proto (__timespec_get64) |
318 | #endif |
319 | |
320 | #if __TIMESIZE == 64 |
321 | # define __time64 __time |
322 | #else |
323 | extern __time64_t __time64 (__time64_t *timer); |
324 | libc_hidden_proto (__time64) |
325 | #endif |
326 | |
327 | /* Use in the clock_* functions. Size of the field representing the |
328 | actual clock ID. */ |
329 | #define CLOCK_IDFIELD_SIZE 3 |
330 | |
331 | /* Check whether T fits in time_t. */ |
332 | static inline bool |
333 | in_time_t_range (__time64_t t) |
334 | { |
335 | time_t s = t; |
336 | return s == t; |
337 | } |
338 | |
339 | /* Convert a known valid struct timeval into a struct __timespec64. */ |
340 | static inline struct __timespec64 |
341 | valid_timeval_to_timespec64 (const struct timeval tv) |
342 | { |
343 | struct __timespec64 ts64; |
344 | |
345 | ts64.tv_sec = tv.tv_sec; |
346 | ts64.tv_nsec = tv.tv_usec * 1000; |
347 | |
348 | return ts64; |
349 | } |
350 | |
351 | /* Convert a known valid struct timeval into a struct __timeval64. */ |
352 | static inline struct __timeval64 |
353 | valid_timeval_to_timeval64 (const struct timeval tv) |
354 | { |
355 | struct __timeval64 tv64; |
356 | |
357 | tv64.tv_sec = tv.tv_sec; |
358 | tv64.tv_usec = tv.tv_usec; |
359 | |
360 | return tv64; |
361 | } |
362 | |
363 | /* Convert a valid and within range of struct timeval, struct |
364 | __timeval64 into a struct timeval. */ |
365 | static inline struct timeval |
366 | valid_timeval64_to_timeval (const struct __timeval64 tv64) |
367 | { |
368 | struct timeval tv; |
369 | |
370 | tv.tv_sec = (time_t) tv64.tv_sec; |
371 | tv.tv_usec = (suseconds_t) tv64.tv_usec; |
372 | |
373 | return tv; |
374 | } |
375 | |
376 | /* Convert a struct __timeval64 into a struct __timespec64. */ |
377 | static inline struct __timespec64 |
378 | timeval64_to_timespec64 (const struct __timeval64 tv64) |
379 | { |
380 | struct __timespec64 ts64; |
381 | |
382 | ts64.tv_sec = tv64.tv_sec; |
383 | ts64.tv_nsec = tv64.tv_usec * 1000; |
384 | |
385 | return ts64; |
386 | } |
387 | |
388 | /* Convert a known valid struct timespec into a struct __timespec64. */ |
389 | static inline struct __timespec64 |
390 | valid_timespec_to_timespec64 (const struct timespec ts) |
391 | { |
392 | struct __timespec64 ts64; |
393 | |
394 | ts64.tv_sec = ts.tv_sec; |
395 | ts64.tv_nsec = ts.tv_nsec; |
396 | |
397 | return ts64; |
398 | } |
399 | |
400 | /* Convert a valid and within range of struct timespec, struct |
401 | __timespec64 into a struct timespec. */ |
402 | static inline struct timespec |
403 | valid_timespec64_to_timespec (const struct __timespec64 ts64) |
404 | { |
405 | struct timespec ts; |
406 | |
407 | ts.tv_sec = (time_t) ts64.tv_sec; |
408 | ts.tv_nsec = ts64.tv_nsec; |
409 | |
410 | return ts; |
411 | } |
412 | |
413 | /* Convert a valid and within range of struct timeval struct |
414 | __timespec64 into a struct timeval. */ |
415 | static inline struct timeval |
416 | valid_timespec64_to_timeval (const struct __timespec64 ts64) |
417 | { |
418 | struct timeval tv; |
419 | |
420 | tv.tv_sec = (time_t) ts64.tv_sec; |
421 | tv.tv_usec = ts64.tv_nsec / 1000; |
422 | |
423 | return tv; |
424 | } |
425 | |
426 | /* Convert a struct __timespec64 into a struct __timeval64. */ |
427 | static inline struct __timeval64 |
428 | timespec64_to_timeval64 (const struct __timespec64 ts64) |
429 | { |
430 | struct __timeval64 tv64; |
431 | |
432 | tv64.tv_sec = ts64.tv_sec; |
433 | tv64.tv_usec = ts64.tv_nsec / 1000; |
434 | |
435 | return tv64; |
436 | } |
437 | |
438 | /* A version of 'struct timeval' with 32-bit time_t |
439 | and suseconds_t. */ |
440 | struct __timeval32 |
441 | { |
442 | __int32_t tv_sec; /* Seconds. */ |
443 | __int32_t tv_usec; /* Microseconds. */ |
444 | }; |
445 | |
446 | /* Conversion functions for converting to/from __timeval32 */ |
447 | static inline struct __timeval64 |
448 | valid_timeval32_to_timeval64 (const struct __timeval32 tv) |
449 | { |
450 | return (struct __timeval64) { tv.tv_sec, tv.tv_usec }; |
451 | } |
452 | |
453 | static inline struct __timeval32 |
454 | valid_timeval64_to_timeval32 (const struct __timeval64 tv64) |
455 | { |
456 | return (struct __timeval32) { tv64.tv_sec, tv64.tv_usec }; |
457 | } |
458 | |
459 | static inline struct timeval |
460 | valid_timeval32_to_timeval (const struct __timeval32 tv) |
461 | { |
462 | return (struct timeval) { tv.tv_sec, tv.tv_usec }; |
463 | } |
464 | |
465 | static inline struct __timeval32 |
466 | valid_timeval_to_timeval32 (const struct timeval tv) |
467 | { |
468 | return (struct __timeval32) { tv.tv_sec, tv.tv_usec }; |
469 | } |
470 | |
471 | static inline struct timespec |
472 | valid_timeval32_to_timespec (const struct __timeval32 tv) |
473 | { |
474 | return (struct timespec) { tv.tv_sec, tv.tv_usec * 1000 }; |
475 | } |
476 | |
477 | static inline struct __timeval32 |
478 | valid_timespec_to_timeval32 (const struct timespec ts) |
479 | { |
480 | return (struct __timeval32) { (time_t) ts.tv_sec, ts.tv_nsec / 1000 }; |
481 | } |
482 | |
483 | static inline struct __timeval64 |
484 | valid_timespec_to_timeval64 (const struct timespec ts) |
485 | { |
486 | return (struct __timeval64) { (time_t) ts.tv_sec, ts.tv_nsec / 1000 }; |
487 | } |
488 | |
489 | /* Check if a value is in the valid nanoseconds range. Return true if |
490 | it is, false otherwise. */ |
491 | static inline bool |
492 | valid_nanoseconds (__syscall_slong_t ns) |
493 | { |
494 | return __glibc_likely (0 <= ns && ns < 1000000000); |
495 | } |
496 | |
497 | /* Helper function to get time in seconds, similar to time. */ |
498 | static inline time_t |
499 | time_now (void) |
500 | { |
501 | struct timespec ts; |
502 | __clock_gettime (TIME_CLOCK_GETTIME_CLOCKID, &ts); |
503 | return ts.tv_sec; |
504 | } |
505 | #endif |
506 | |
507 | #endif |
508 | |