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

source code of glibc/include/time.h