5 # include <bits/types/struct_timeval.h>
6 # include <bits/types/locale_t.h>
8 # include <time/mktime-internal.h>
10 # include <time-clockid.h>
11 # include <sys/time.h>
13 extern __typeof (strftime_l
) __strftime_l
;
14 libc_hidden_proto (__strftime_l
)
15 extern __typeof (strptime_l
) __strptime_l
;
17 libc_hidden_proto (asctime
)
18 libc_hidden_proto (mktime
)
19 libc_hidden_proto (timelocal
)
20 libc_hidden_proto (localtime
)
21 libc_hidden_proto (strftime
)
22 libc_hidden_proto (strptime
)
24 extern __typeof (clock_gettime
) __clock_gettime
;
25 libc_hidden_proto (__clock_gettime
)
26 extern __typeof (clock_settime
) __clock_settime
;
27 libc_hidden_proto (__clock_settime
)
29 extern __typeof (clock_nanosleep
) __clock_nanosleep
;
30 libc_hidden_proto (__clock_nanosleep
);
33 extern __typeof (clock_adjtime
) __clock_adjtime
;
34 libc_hidden_proto (__clock_adjtime
);
37 /* Now define the internal interfaces. */
40 /* Defined in mktime.c. */
41 extern const unsigned short int __mon_yday
[2][13] attribute_hidden
;
43 /* Defined in localtime.c. */
44 extern struct tm _tmbuf attribute_hidden
;
46 /* Defined in tzset.c. */
47 extern char *__tzstring (const char *string
) attribute_hidden
;
49 extern int __use_tzfile attribute_hidden
;
51 extern void __tzfile_read (const char *file
, size_t extra
,
52 char **extrap
) attribute_hidden
;
53 extern void __tzfile_compute (__time64_t timer
, int use_localtime
,
54 long int *leap_correct
, int *leap_hit
,
55 struct tm
*tp
) attribute_hidden
;
56 extern void __tzfile_default (const char *std
, const char *dst
,
57 int stdoff
, int dstoff
)
59 extern void __tzset_parse_tz (const char *tz
) attribute_hidden
;
60 extern void __tz_compute (__time64_t timer
, struct tm
*tm
, int use_localtime
)
61 __THROW attribute_hidden
;
64 # define __timespec64 timespec
66 /* The glibc Y2038-proof struct __timespec64 structure for a time value.
67 To keep things Posix-ish, we keep the nanoseconds field a 32-bit
68 signed long, but since the Linux field is a 64-bit signed int, we
69 pad our tv_nsec with a 32-bit unnamed bit-field padding.
71 As a general rule the Linux kernel is ignoring upper 32 bits of
75 __time64_t tv_sec
; /* Seconds */
76 # if BYTE_ORDER == BIG_ENDIAN
77 __int32_t
:32; /* Padding */
78 __int32_t tv_nsec
; /* Nanoseconds */
80 __int32_t tv_nsec
; /* Nanoseconds */
81 __int32_t
:32; /* Padding */
87 # define __itimerspec64 itimerspec
89 /* The glibc's internal representation of the struct itimerspec. */
92 struct __timespec64 it_interval
;
93 struct __timespec64 it_value
;
98 # define __timeval64 timeval
100 /* The glibc Y2038-proof struct __timeval64 structure for a time value.
101 This structure is NOT supposed to be passed to the Linux kernel.
102 Instead, it shall be converted to struct __timespec64 and time shall
103 be [sg]et via clock_[sg]ettime (which are now Y2038 safe). */
106 __time64_t tv_sec
; /* Seconds */
107 __suseconds64_t tv_usec
; /* Microseconds */
112 # define __ctime64 ctime
114 extern char *__ctime64 (const __time64_t
*__timer
) __THROW
;
115 libc_hidden_proto (__ctime64
)
119 # define __ctime64_r ctime_r
121 extern char *__ctime64_r (const __time64_t
*__restrict __timer
,
122 char *__restrict __buf
) __THROW
;
123 libc_hidden_proto (__ctime64_r
)
127 # define __localtime64 localtime
129 extern struct tm
*__localtime64 (const __time64_t
*__timer
);
130 libc_hidden_proto (__localtime64
)
133 extern struct tm
*__localtime_r (const time_t *__timer
,
134 struct tm
*__tp
) attribute_hidden
;
136 extern struct tm
*__localtime64_r (const __time64_t
*__timer
,
138 libc_hidden_proto (__localtime64_r
)
140 extern __time64_t
__mktime64 (struct tm
*__tp
) __THROW
;
141 libc_hidden_proto (__mktime64
)
144 extern struct tm
*__gmtime_r (const time_t *__restrict __timer
,
145 struct tm
*__restrict __tp
);
146 libc_hidden_proto (__gmtime_r
)
149 # define __gmtime64 gmtime
151 extern struct tm
*__gmtime64 (const __time64_t
*__timer
);
152 libc_hidden_proto (__gmtime64
)
154 extern struct tm
*__gmtime64_r (const __time64_t
*__restrict __timer
,
155 struct tm
*__restrict __tp
);
156 libc_hidden_proto (__gmtime64_r
)
158 extern __time64_t
__timegm64 (struct tm
*__tp
) __THROW
;
159 libc_hidden_proto (__timegm64
)
163 # define __clock_settime64 __clock_settime
165 extern int __clock_settime64 (clockid_t clock_id
,
166 const struct __timespec64
*tp
);
167 libc_hidden_proto (__clock_settime64
)
171 # define __clock_getres64 __clock_getres
173 extern int __clock_getres64 (clockid_t clock_id
,
174 struct __timespec64
*tp
);
175 libc_hidden_proto (__clock_getres64
);
179 # define __utimensat64 __utimensat
181 extern int __utimensat64 (int fd
, const char *file
,
182 const struct __timespec64 tsp
[2], int flags
);
183 libc_hidden_proto (__utimensat64
);
186 extern int __utimensat64_helper (int fd
, const char *file
,
187 const struct __timespec64 tsp
[2], int flags
);
188 libc_hidden_proto (__utimensat64_helper
);
191 # define __futimens64 __futimens
193 extern int __futimens64 (int fd
, const struct __timespec64 tsp
[2]);
194 libc_hidden_proto (__futimens64
);
198 # define __timer_gettime64 __timer_gettime
199 # define __timerfd_gettime64 __timerfd_gettime
201 extern int __timer_gettime64 (timer_t timerid
, struct __itimerspec64
*value
);
202 extern int __timerfd_gettime64 (int fd
, struct __itimerspec64
*value
);
203 librt_hidden_proto (__timer_gettime64
);
204 libc_hidden_proto (__timerfd_gettime64
);
208 # define __timer_settime64 __timer_settime
209 # define __timerfd_settime64 __timerfd_settime
211 extern int __timer_settime64 (timer_t timerid
, int flags
,
212 const struct __itimerspec64
*value
,
213 struct __itimerspec64
*ovalue
);
214 extern int __timerfd_settime64 (int fd
, int flags
,
215 const struct __itimerspec64
*value
,
216 struct __itimerspec64
*ovalue
);
217 librt_hidden_proto (__timer_settime64
);
218 libc_hidden_proto (__timerfd_settime64
);
222 # define __sched_rr_get_interval64 __sched_rr_get_interval
224 extern int __sched_rr_get_interval64 (pid_t pid
, struct __timespec64
*tp
);
225 libc_hidden_proto (__sched_rr_get_interval64
);
229 # define __settimeofday64 __settimeofday
230 # define __gettimeofday64 __gettimeofday
232 extern int __settimeofday64 (const struct __timeval64
*tv
,
233 const struct timezone
*tz
);
234 libc_hidden_proto (__settimeofday64
)
235 extern int __gettimeofday64 (struct __timeval64
*restrict tv
,
237 libc_hidden_proto (__gettimeofday64
)
240 /* Compute the `struct tm' representation of T,
241 offset OFFSET seconds east of UTC,
242 and store year, yday, mon, mday, wday, hour, min, sec into *TP.
243 Return nonzero if successful. */
244 extern int __offtime (__time64_t __timer
,
246 struct tm
*__tp
) attribute_hidden
;
248 extern char *__asctime_r (const struct tm
*__tp
, char *__buf
)
250 extern void __tzset (void) attribute_hidden
;
252 /* Prototype for the internal function to get information based on TZ. */
253 extern struct tm
*__tz_convert (__time64_t timer
, int use_localtime
,
254 struct tm
*tp
) attribute_hidden
;
256 extern int __nanosleep (const struct timespec
*__requested_time
,
257 struct timespec
*__remaining
);
258 hidden_proto (__nanosleep
)
259 extern int __getdate_r (const char *__string
, struct tm
*__resbufp
)
263 /* Determine CLK_TCK value. */
264 extern int __getclktck (void) attribute_hidden
;
267 /* strptime support. */
268 extern char * __strptime_internal (const char *rp
, const char *fmt
,
269 struct tm
*tm
, void *statep
,
270 locale_t locparam
) attribute_hidden
;
273 # define __difftime64 __difftime
275 extern double __difftime64 (__time64_t time1
, __time64_t time0
);
276 libc_hidden_proto (__difftime64
)
279 extern double __difftime (time_t time1
, time_t time0
);
282 # define __clock_nanosleep_time64 __clock_nanosleep
283 # define __clock_gettime64 __clock_gettime
284 # define __timespec_get64 __timespec_get
286 extern int __clock_nanosleep_time64 (clockid_t clock_id
,
287 int flags
, const struct __timespec64
*req
,
288 struct __timespec64
*rem
);
289 libc_hidden_proto (__clock_nanosleep_time64
)
290 extern int __clock_gettime64 (clockid_t clock_id
, struct __timespec64
*tp
);
291 libc_hidden_proto (__clock_gettime64
)
292 extern int __timespec_get64 (struct __timespec64
*ts
, int base
);
293 libc_hidden_proto (__timespec_get64
)
296 /* Use in the clock_* functions. Size of the field representing the
298 #define CLOCK_IDFIELD_SIZE 3
300 /* Check whether T fits in time_t. */
302 in_time_t_range (__time64_t t
)
308 /* Convert a known valid struct timeval into a struct __timespec64. */
309 static inline struct __timespec64
310 valid_timeval_to_timespec64 (const struct timeval tv
)
312 struct __timespec64 ts64
;
314 ts64
.tv_sec
= tv
.tv_sec
;
315 ts64
.tv_nsec
= tv
.tv_usec
* 1000;
320 /* Convert a known valid struct timeval into a struct __timeval64. */
321 static inline struct __timeval64
322 valid_timeval_to_timeval64 (const struct timeval tv
)
324 struct __timeval64 tv64
;
326 tv64
.tv_sec
= tv
.tv_sec
;
327 tv64
.tv_usec
= tv
.tv_usec
;
332 /* Convert a valid and within range of struct timeval, struct
333 __timeval64 into a struct timeval. */
334 static inline struct timeval
335 valid_timeval64_to_timeval (const struct __timeval64 tv64
)
339 tv
.tv_sec
= (time_t) tv64
.tv_sec
;
340 tv
.tv_usec
= (suseconds_t
) tv64
.tv_usec
;
345 /* Convert a struct __timeval64 into a struct __timespec64. */
346 static inline struct __timespec64
347 timeval64_to_timespec64 (const struct __timeval64 tv64
)
349 struct __timespec64 ts64
;
351 ts64
.tv_sec
= tv64
.tv_sec
;
352 ts64
.tv_nsec
= tv64
.tv_usec
* 1000;
357 /* Convert a known valid struct timespec into a struct __timespec64. */
358 static inline struct __timespec64
359 valid_timespec_to_timespec64 (const struct timespec ts
)
361 struct __timespec64 ts64
;
363 ts64
.tv_sec
= ts
.tv_sec
;
364 ts64
.tv_nsec
= ts
.tv_nsec
;
369 /* Convert a valid and within range of struct timespec, struct
370 __timespec64 into a struct timespec. */
371 static inline struct timespec
372 valid_timespec64_to_timespec (const struct __timespec64 ts64
)
376 ts
.tv_sec
= (time_t) ts64
.tv_sec
;
377 ts
.tv_nsec
= ts64
.tv_nsec
;
382 /* Convert a valid and within range of struct timeval struct
383 __timespec64 into a struct timeval. */
384 static inline struct timeval
385 valid_timespec64_to_timeval (const struct __timespec64 ts64
)
389 tv
.tv_sec
= (time_t) ts64
.tv_sec
;
390 tv
.tv_usec
= ts64
.tv_nsec
/ 1000;
395 /* Convert a struct __timespec64 into a struct __timeval64. */
396 static inline struct __timeval64
397 timespec64_to_timeval64 (const struct __timespec64 ts64
)
399 struct __timeval64 tv64
;
401 tv64
.tv_sec
= ts64
.tv_sec
;
402 tv64
.tv_usec
= ts64
.tv_nsec
/ 1000;
407 /* Check if a value is in the valid nanoseconds range. Return true if
408 it is, false otherwise. */
410 valid_nanoseconds (__syscall_slong_t ns
)
412 return __glibc_likely (0 <= ns
&& ns
< 1000000000);
415 /* Helper function to get time in seconds, similar to time. */
420 __clock_gettime (TIME_CLOCK_GETTIME_CLOCKID
, &ts
);