5 # include <bits/types/struct_timeval.h>
6 # include <struct___timespec64.h>
7 # include <bits/types/locale_t.h>
9 # include <time/mktime-internal.h>
10 # include <sys/time.h>
11 # include <time-clockid.h>
12 # include <sys/time.h>
14 extern __typeof (strftime_l
) __strftime_l
;
15 libc_hidden_proto (__strftime_l
)
16 extern __typeof (strptime_l
) __strptime_l
;
18 libc_hidden_proto (asctime
)
19 libc_hidden_proto (mktime
)
20 libc_hidden_proto (timelocal
)
21 libc_hidden_proto (localtime
)
22 libc_hidden_proto (strftime
)
23 libc_hidden_proto (strptime
)
25 extern __typeof (clock_gettime
) __clock_gettime
;
26 libc_hidden_proto (__clock_gettime
)
27 extern __typeof (clock_settime
) __clock_settime
;
28 libc_hidden_proto (__clock_settime
)
30 extern __typeof (clock_nanosleep
) __clock_nanosleep
;
31 libc_hidden_proto (__clock_nanosleep
);
34 extern __typeof (clock_adjtime
) __clock_adjtime
;
35 libc_hidden_proto (__clock_adjtime
);
38 /* Now define the internal interfaces. */
41 /* Defined in mktime.c. */
42 extern const unsigned short int __mon_yday
[2][13] attribute_hidden
;
44 /* Defined in localtime.c. */
45 extern struct tm _tmbuf attribute_hidden
;
47 /* Defined in tzset.c. */
48 extern char *__tzstring (const char *string
) attribute_hidden
;
50 extern int __use_tzfile attribute_hidden
;
52 extern void __tzfile_read (const char *file
, size_t extra
,
53 char **extrap
) attribute_hidden
;
54 extern void __tzfile_compute (__time64_t timer
, int use_localtime
,
55 long int *leap_correct
, int *leap_hit
,
56 struct tm
*tp
) attribute_hidden
;
57 extern void __tzfile_default (const char *std
, const char *dst
,
58 int stdoff
, int dstoff
)
60 extern void __tzset_parse_tz (const char *tz
) attribute_hidden
;
61 extern void __tz_compute (__time64_t timer
, struct tm
*tm
, int use_localtime
)
62 __THROW attribute_hidden
;
66 # define __itimerspec64 itimerspec
68 /* The glibc's internal representation of the struct itimerspec. */
71 struct __timespec64 it_interval
;
72 struct __timespec64 it_value
;
77 # define __timeval64 timeval
79 /* The glibc Y2038-proof struct __timeval64 structure for a time value.
80 This structure is NOT supposed to be passed to the Linux kernel.
81 Instead, it shall be converted to struct __timespec64 and time shall
82 be [sg]et via clock_[sg]ettime (which are now Y2038 safe). */
85 __time64_t tv_sec
; /* Seconds */
86 __suseconds64_t tv_usec
; /* Microseconds */
91 # define __utimbuf64 utimbuf
92 # define __itimerval64 itimerval
94 /* The glibc Y2038-proof struct __utimbuf64 structure for file's access
95 and modification time values. */
98 __time64_t actime
; /* Access time. */
99 __time64_t modtime
; /* Modification time. */
101 /* The glibc's internal representation of the struct itimerval. */
104 struct __timeval64 it_interval
;
105 struct __timeval64 it_value
;
110 # define __getitimer64 __getitimer
111 # define __setitimer64 __setitimer
113 extern int __getitimer64 (enum __itimer_which __which
,
114 struct __itimerval64
*__value
);
116 libc_hidden_proto (__getitimer64
)
117 extern int __setitimer64 (enum __itimer_which __which
,
118 const struct __itimerval64
*__restrict __new
,
119 struct __itimerval64
*__restrict __old
);
120 libc_hidden_proto (__setitimer64
)
124 # define __ctime64 ctime
126 extern char *__ctime64 (const __time64_t
*__timer
) __THROW
;
127 libc_hidden_proto (__ctime64
)
131 # define __ctime64_r ctime_r
133 extern char *__ctime64_r (const __time64_t
*__restrict __timer
,
134 char *__restrict __buf
) __THROW
;
135 libc_hidden_proto (__ctime64_r
)
139 # define __localtime64 localtime
141 extern struct tm
*__localtime64 (const __time64_t
*__timer
);
142 libc_hidden_proto (__localtime64
)
145 extern struct tm
*__localtime_r (const time_t *__timer
,
146 struct tm
*__tp
) attribute_hidden
;
148 extern struct tm
*__localtime64_r (const __time64_t
*__timer
,
150 libc_hidden_proto (__localtime64_r
)
152 extern __time64_t
__mktime64 (struct tm
*__tp
) __THROW
;
153 libc_hidden_proto (__mktime64
)
156 extern struct tm
*__gmtime_r (const time_t *__restrict __timer
,
157 struct tm
*__restrict __tp
);
158 libc_hidden_proto (__gmtime_r
)
161 # define __gmtime64 gmtime
163 extern struct tm
*__gmtime64 (const __time64_t
*__timer
);
164 libc_hidden_proto (__gmtime64
)
166 extern struct tm
*__gmtime64_r (const __time64_t
*__restrict __timer
,
167 struct tm
*__restrict __tp
);
168 libc_hidden_proto (__gmtime64_r
)
170 extern __time64_t
__timegm64 (struct tm
*__tp
) __THROW
;
171 libc_hidden_proto (__timegm64
)
175 # define __clock_settime64 __clock_settime
177 extern int __clock_settime64 (clockid_t clock_id
,
178 const struct __timespec64
*tp
);
179 libc_hidden_proto (__clock_settime64
)
183 # define __clock_getres64 __clock_getres
185 extern int __clock_getres64 (clockid_t clock_id
,
186 struct __timespec64
*tp
);
187 libc_hidden_proto (__clock_getres64
);
191 # define __utime64 __utime
192 # define __utimes64 __utimes
193 # define __utimensat64 __utimensat
195 extern int __utime64 (const char *file
, const struct __utimbuf64
*times
);
196 libc_hidden_proto (__utime64
)
197 extern int __utimes64 (const char *file
, const struct __timeval64 tvp
[2]);
198 libc_hidden_proto (__utimes64
)
199 extern int __utimensat64 (int fd
, const char *file
,
200 const struct __timespec64 tsp
[2], int flags
);
201 libc_hidden_proto (__utimensat64
);
204 extern int __utimensat64_helper (int fd
, const char *file
,
205 const struct __timespec64 tsp
[2], int flags
);
206 libc_hidden_proto (__utimensat64_helper
);
209 # define __futimes64 __futimes
210 # define __futimesat64 __futimesat
211 # define __lutimes64 __lutimes
212 # define __futimens64 __futimens
214 extern int __futimes64 (int fd
, const struct __timeval64 tvp64
[2]);
215 libc_hidden_proto (__futimes64
);
216 extern int __futimesat64 (int fd
, const char *file
,
217 const struct __timeval64 tvp
[2]);
218 libc_hidden_proto (__futimesat64
);
219 extern int __lutimes64 (const char *file
, const struct __timeval64 tvp64
[2]);
220 libc_hidden_proto (__lutimes64
);
221 extern int __futimens64 (int fd
, const struct __timespec64 tsp
[2]);
222 libc_hidden_proto (__futimens64
);
226 # define __timer_gettime64 __timer_gettime
227 # define __timerfd_gettime64 __timerfd_gettime
229 extern int __timer_gettime64 (timer_t timerid
, struct __itimerspec64
*value
);
230 extern int __timerfd_gettime64 (int fd
, struct __itimerspec64
*value
);
231 librt_hidden_proto (__timer_gettime64
);
232 libc_hidden_proto (__timerfd_gettime64
);
236 # define __timer_settime64 __timer_settime
237 # define __timerfd_settime64 __timerfd_settime
239 extern int __timer_settime64 (timer_t timerid
, int flags
,
240 const struct __itimerspec64
*value
,
241 struct __itimerspec64
*ovalue
);
242 extern int __timerfd_settime64 (int fd
, int flags
,
243 const struct __itimerspec64
*value
,
244 struct __itimerspec64
*ovalue
);
245 librt_hidden_proto (__timer_settime64
);
246 libc_hidden_proto (__timerfd_settime64
);
250 # define __sched_rr_get_interval64 __sched_rr_get_interval
252 extern int __sched_rr_get_interval64 (pid_t pid
, struct __timespec64
*tp
);
253 libc_hidden_proto (__sched_rr_get_interval64
);
257 # define __settimeofday64 __settimeofday
258 # define __gettimeofday64 __gettimeofday
260 extern int __settimeofday64 (const struct __timeval64
*tv
,
261 const struct timezone
*tz
);
262 libc_hidden_proto (__settimeofday64
)
263 extern int __gettimeofday64 (struct __timeval64
*restrict tv
,
265 libc_hidden_proto (__gettimeofday64
)
268 /* Compute the `struct tm' representation of T,
269 offset OFFSET seconds east of UTC,
270 and store year, yday, mon, mday, wday, hour, min, sec into *TP.
271 Return nonzero if successful. */
272 extern int __offtime (__time64_t __timer
,
274 struct tm
*__tp
) attribute_hidden
;
276 extern char *__asctime_r (const struct tm
*__tp
, char *__buf
)
278 extern void __tzset (void) attribute_hidden
;
280 /* Prototype for the internal function to get information based on TZ. */
281 extern struct tm
*__tz_convert (__time64_t timer
, int use_localtime
,
282 struct tm
*tp
) attribute_hidden
;
284 extern int __nanosleep (const struct timespec
*__requested_time
,
285 struct timespec
*__remaining
);
286 hidden_proto (__nanosleep
)
287 extern int __getdate_r (const char *__string
, struct tm
*__resbufp
)
291 /* Determine CLK_TCK value. */
292 extern int __getclktck (void) attribute_hidden
;
295 /* strptime support. */
296 extern char * __strptime_internal (const char *rp
, const char *fmt
,
297 struct tm
*tm
, void *statep
,
298 locale_t locparam
) attribute_hidden
;
301 # define __difftime64 __difftime
303 extern double __difftime64 (__time64_t time1
, __time64_t time0
);
304 libc_hidden_proto (__difftime64
)
307 extern double __difftime (time_t time1
, time_t time0
);
310 # define __clock_nanosleep_time64 __clock_nanosleep
311 # define __clock_gettime64 __clock_gettime
312 # define __timespec_get64 __timespec_get
314 extern int __clock_nanosleep_time64 (clockid_t clock_id
,
315 int flags
, const struct __timespec64
*req
,
316 struct __timespec64
*rem
);
317 libc_hidden_proto (__clock_nanosleep_time64
)
318 extern int __clock_gettime64 (clockid_t clock_id
, struct __timespec64
*tp
);
319 libc_hidden_proto (__clock_gettime64
)
320 extern int __timespec_get64 (struct __timespec64
*ts
, int base
);
321 libc_hidden_proto (__timespec_get64
)
324 /* Use in the clock_* functions. Size of the field representing the
326 #define CLOCK_IDFIELD_SIZE 3
328 /* Check whether T fits in time_t. */
330 in_time_t_range (__time64_t t
)
336 /* Convert a known valid struct timeval into a struct __timespec64. */
337 static inline struct __timespec64
338 valid_timeval_to_timespec64 (const struct timeval tv
)
340 struct __timespec64 ts64
;
342 ts64
.tv_sec
= tv
.tv_sec
;
343 ts64
.tv_nsec
= tv
.tv_usec
* 1000;
348 /* Convert a known valid struct timeval into a struct __timeval64. */
349 static inline struct __timeval64
350 valid_timeval_to_timeval64 (const struct timeval tv
)
352 struct __timeval64 tv64
;
354 tv64
.tv_sec
= tv
.tv_sec
;
355 tv64
.tv_usec
= tv
.tv_usec
;
360 /* Convert a valid and within range of struct timeval, struct
361 __timeval64 into a struct timeval. */
362 static inline struct timeval
363 valid_timeval64_to_timeval (const struct __timeval64 tv64
)
367 tv
.tv_sec
= (time_t) tv64
.tv_sec
;
368 tv
.tv_usec
= (suseconds_t
) tv64
.tv_usec
;
373 /* Convert a struct __timeval64 into a struct __timespec64. */
374 static inline struct __timespec64
375 timeval64_to_timespec64 (const struct __timeval64 tv64
)
377 struct __timespec64 ts64
;
379 ts64
.tv_sec
= tv64
.tv_sec
;
380 ts64
.tv_nsec
= tv64
.tv_usec
* 1000;
385 /* Convert a known valid struct timespec into a struct __timespec64. */
386 static inline struct __timespec64
387 valid_timespec_to_timespec64 (const struct timespec ts
)
389 struct __timespec64 ts64
;
391 ts64
.tv_sec
= ts
.tv_sec
;
392 ts64
.tv_nsec
= ts
.tv_nsec
;
397 /* Convert a valid and within range of struct timespec, struct
398 __timespec64 into a struct timespec. */
399 static inline struct timespec
400 valid_timespec64_to_timespec (const struct __timespec64 ts64
)
404 ts
.tv_sec
= (time_t) ts64
.tv_sec
;
405 ts
.tv_nsec
= ts64
.tv_nsec
;
410 /* Convert a valid and within range of struct timeval struct
411 __timespec64 into a struct timeval. */
412 static inline struct timeval
413 valid_timespec64_to_timeval (const struct __timespec64 ts64
)
417 tv
.tv_sec
= (time_t) ts64
.tv_sec
;
418 tv
.tv_usec
= ts64
.tv_nsec
/ 1000;
423 /* Convert a struct __timespec64 into a struct __timeval64. */
424 static inline struct __timeval64
425 timespec64_to_timeval64 (const struct __timespec64 ts64
)
427 struct __timeval64 tv64
;
429 tv64
.tv_sec
= ts64
.tv_sec
;
430 tv64
.tv_usec
= ts64
.tv_nsec
/ 1000;
435 /* A version of 'struct timeval' with 32-bit time_t
439 __int32_t tv_sec
; /* Seconds. */
440 __int32_t tv_usec
; /* Microseconds. */
443 /* Conversion functions for converting to/from __timeval32 */
444 static inline struct __timeval64
445 valid_timeval32_to_timeval64 (const struct __timeval32 tv
)
447 return (struct __timeval64
) { tv
.tv_sec
, tv
.tv_usec
};
450 static inline struct __timeval32
451 valid_timeval64_to_timeval32 (const struct __timeval64 tv64
)
453 return (struct __timeval32
) { tv64
.tv_sec
, tv64
.tv_usec
};
456 static inline struct timeval
457 valid_timeval32_to_timeval (const struct __timeval32 tv
)
459 return (struct timeval
) { tv
.tv_sec
, tv
.tv_usec
};
462 static inline struct __timeval32
463 valid_timeval_to_timeval32 (const struct timeval tv
)
465 return (struct __timeval32
) { tv
.tv_sec
, tv
.tv_usec
};
468 static inline struct timespec
469 valid_timeval32_to_timespec (const struct __timeval32 tv
)
471 return (struct timespec
) { tv
.tv_sec
, tv
.tv_usec
* 1000 };
474 static inline struct __timeval32
475 valid_timespec_to_timeval32 (const struct timespec ts
)
477 return (struct __timeval32
) { (time_t) ts
.tv_sec
, ts
.tv_nsec
/ 1000 };
480 /* Check if a value is in the valid nanoseconds range. Return true if
481 it is, false otherwise. */
483 valid_nanoseconds (__syscall_slong_t ns
)
485 return __glibc_likely (0 <= ns
&& ns
< 1000000000);
488 /* Helper function to get time in seconds, similar to time. */
493 __clock_gettime (TIME_CLOCK_GETTIME_CLOCKID
, &ts
);