5 # include <bits/types/struct_timeval.h>
6 # include <struct___timespec64.h>
7 # include <struct___timeval64.h>
8 # include <bits/types/locale_t.h>
10 # include <time/mktime-internal.h>
11 # include <sys/time.h>
12 # include <time-clockid.h>
13 # include <sys/time.h>
15 extern __typeof (strftime_l
) __strftime_l
;
16 libc_hidden_proto (__strftime_l
)
17 extern __typeof (strptime_l
) __strptime_l
;
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
)
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
)
31 extern __typeof (clock_getres
) __clock_getres
;
32 libc_hidden_proto (__clock_getres
)
34 extern __typeof (clock_nanosleep
) __clock_nanosleep
;
35 libc_hidden_proto (__clock_nanosleep
);
38 extern __typeof (clock_adjtime
) __clock_adjtime
;
39 libc_hidden_proto (__clock_adjtime
);
42 /* Now define the internal interfaces. */
45 /* Defined in mktime.c. */
46 extern const unsigned short int __mon_yday
[2][13] attribute_hidden
;
48 /* Defined in localtime.c. */
49 extern struct tm _tmbuf attribute_hidden
;
51 /* Defined in tzset.c. */
52 extern char *__tzstring (const char *string
) attribute_hidden
;
54 extern int __use_tzfile attribute_hidden
;
56 extern void __tzfile_read (const char *file
, size_t extra
,
57 char **extrap
) attribute_hidden
;
58 extern void __tzfile_compute (__time64_t timer
, int use_localtime
,
59 long int *leap_correct
, int *leap_hit
,
60 struct tm
*tp
) attribute_hidden
;
61 extern void __tzfile_default (const char *std
, const char *dst
,
62 int stdoff
, int dstoff
)
64 extern void __tzset_parse_tz (const char *tz
) attribute_hidden
;
65 extern void __tz_compute (__time64_t timer
, struct tm
*tm
, int use_localtime
)
66 __THROW attribute_hidden
;
70 # define __itimerspec64 itimerspec
72 /* The glibc's internal representation of the struct itimerspec. */
75 struct __timespec64 it_interval
;
76 struct __timespec64 it_value
;
81 # define __utimbuf64 utimbuf
82 # define __itimerval64 itimerval
84 /* The glibc Y2038-proof struct __utimbuf64 structure for file's access
85 and modification time values. */
88 __time64_t actime
; /* Access time. */
89 __time64_t modtime
; /* Modification time. */
91 /* The glibc's internal representation of the struct itimerval. */
94 struct __timeval64 it_interval
;
95 struct __timeval64 it_value
;
100 # define __getitimer64 __getitimer
101 # define __setitimer64 __setitimer
103 extern int __getitimer64 (enum __itimer_which __which
,
104 struct __itimerval64
*__value
);
106 libc_hidden_proto (__getitimer64
)
107 extern int __setitimer64 (enum __itimer_which __which
,
108 const struct __itimerval64
*__restrict __new
,
109 struct __itimerval64
*__restrict __old
);
110 libc_hidden_proto (__setitimer64
)
114 # define __ctime64 ctime
116 extern char *__ctime64 (const __time64_t
*__timer
) __THROW
;
117 libc_hidden_proto (__ctime64
)
121 # define __ctime64_r ctime_r
123 extern char *__ctime64_r (const __time64_t
*__restrict __timer
,
124 char *__restrict __buf
) __THROW
;
125 libc_hidden_proto (__ctime64_r
)
129 # define __localtime64 localtime
131 extern struct tm
*__localtime64 (const __time64_t
*__timer
);
132 libc_hidden_proto (__localtime64
)
135 extern struct tm
*__localtime_r (const time_t *__timer
,
136 struct tm
*__tp
) attribute_hidden
;
138 extern struct tm
*__localtime64_r (const __time64_t
*__timer
,
140 libc_hidden_proto (__localtime64_r
)
142 extern __time64_t
__mktime64 (struct tm
*__tp
) __THROW
;
143 libc_hidden_proto (__mktime64
)
146 extern struct tm
*__gmtime_r (const time_t *__restrict __timer
,
147 struct tm
*__restrict __tp
);
148 libc_hidden_proto (__gmtime_r
)
151 # define __gmtime64 gmtime
153 extern struct tm
*__gmtime64 (const __time64_t
*__timer
);
154 libc_hidden_proto (__gmtime64
)
156 extern struct tm
*__gmtime64_r (const __time64_t
*__restrict __timer
,
157 struct tm
*__restrict __tp
);
158 libc_hidden_proto (__gmtime64_r
)
160 extern __time64_t
__timegm64 (struct tm
*__tp
) __THROW
;
161 libc_hidden_proto (__timegm64
)
165 # define __clock_settime64 __clock_settime
167 extern int __clock_settime64 (clockid_t clock_id
,
168 const struct __timespec64
*tp
);
169 libc_hidden_proto (__clock_settime64
)
173 # define __clock_getres64 __clock_getres
175 extern int __clock_getres64 (clockid_t clock_id
,
176 struct __timespec64
*tp
);
177 libc_hidden_proto (__clock_getres64
);
181 # define __utime64 __utime
182 # define __utimes64 __utimes
183 # define __utimensat64 __utimensat
185 extern int __utime64 (const char *file
, const struct __utimbuf64
*times
);
186 libc_hidden_proto (__utime64
)
187 extern int __utimes64 (const char *file
, const struct __timeval64 tvp
[2]);
188 libc_hidden_proto (__utimes64
)
189 extern int __utimensat64 (int fd
, const char *file
,
190 const struct __timespec64 tsp
[2], int flags
);
191 libc_hidden_proto (__utimensat64
);
194 extern int __utimensat64_helper (int fd
, const char *file
,
195 const struct __timespec64 tsp
[2], int flags
);
196 libc_hidden_proto (__utimensat64_helper
);
199 # define __futimes64 __futimes
200 # define __futimesat64 __futimesat
201 # define __lutimes64 __lutimes
202 # define __futimens64 __futimens
204 extern int __futimes64 (int fd
, const struct __timeval64 tvp64
[2]);
205 libc_hidden_proto (__futimes64
);
206 extern int __futimesat64 (int fd
, const char *file
,
207 const struct __timeval64 tvp
[2]);
208 libc_hidden_proto (__futimesat64
);
209 extern int __lutimes64 (const char *file
, const struct __timeval64 tvp64
[2]);
210 libc_hidden_proto (__lutimes64
);
211 extern int __futimens64 (int fd
, const struct __timespec64 tsp
[2]);
212 libc_hidden_proto (__futimens64
);
216 # define __timer_gettime64 __timer_gettime
217 # define __timerfd_gettime64 __timerfd_gettime
219 extern int __timer_gettime64 (timer_t timerid
, struct __itimerspec64
*value
);
220 extern int __timerfd_gettime64 (int fd
, struct __itimerspec64
*value
);
222 libc_hidden_proto (__timer_gettime64
)
224 librt_hidden_proto (__timer_gettime64
)
226 libc_hidden_proto (__timerfd_gettime64
);
230 # define __timer_settime64 __timer_settime
231 # define __timerfd_settime64 __timerfd_settime
233 extern int __timer_settime64 (timer_t timerid
, int flags
,
234 const struct __itimerspec64
*value
,
235 struct __itimerspec64
*ovalue
);
236 extern int __timerfd_settime64 (int fd
, int flags
,
237 const struct __itimerspec64
*value
,
238 struct __itimerspec64
*ovalue
);
240 libc_hidden_proto (__timer_settime64
)
242 librt_hidden_proto (__timer_settime64
)
244 libc_hidden_proto (__timerfd_settime64
);
248 # define __sched_rr_get_interval64 __sched_rr_get_interval
250 extern int __sched_rr_get_interval64 (pid_t pid
, struct __timespec64
*tp
);
251 libc_hidden_proto (__sched_rr_get_interval64
);
255 # define __settimeofday64 __settimeofday
256 # define __gettimeofday64 __gettimeofday
258 extern int __settimeofday64 (const struct __timeval64
*tv
,
259 const struct timezone
*tz
);
260 libc_hidden_proto (__settimeofday64
)
261 extern int __gettimeofday64 (struct __timeval64
*restrict tv
,
263 libc_hidden_proto (__gettimeofday64
)
266 /* Compute the `struct tm' representation of T,
267 offset OFFSET seconds east of UTC,
268 and store year, yday, mon, mday, wday, hour, min, sec into *TP.
269 Return nonzero if successful. */
270 extern int __offtime (__time64_t __timer
,
272 struct tm
*__tp
) attribute_hidden
;
274 extern char *__asctime_r (const struct tm
*__tp
, char *__buf
)
276 extern void __tzset (void) attribute_hidden
;
278 /* Prototype for the internal function to get information based on TZ. */
279 extern struct tm
*__tz_convert (__time64_t timer
, int use_localtime
,
280 struct tm
*tp
) attribute_hidden
;
282 extern int __nanosleep (const struct timespec
*__requested_time
,
283 struct timespec
*__remaining
);
284 hidden_proto (__nanosleep
)
286 # define __nanosleep64 __nanosleep
288 extern int __nanosleep64 (const struct __timespec64
*__requested_time
,
289 struct __timespec64
*__remaining
);
290 hidden_proto (__nanosleep64
)
294 extern int __getdate_r (const char *__string
, struct tm
*__resbufp
);
295 libc_hidden_proto (__getdate_r
);
298 /* Determine CLK_TCK value. */
299 extern int __getclktck (void) attribute_hidden
;
302 /* strptime support. */
303 extern char * __strptime_internal (const char *rp
, const char *fmt
,
304 struct tm
*tm
, void *statep
,
305 locale_t locparam
) attribute_hidden
;
308 # define __difftime64 __difftime
310 extern double __difftime64 (__time64_t time1
, __time64_t time0
);
311 libc_hidden_proto (__difftime64
)
314 extern double __difftime (time_t time1
, time_t time0
);
317 # define __clock_nanosleep_time64 __clock_nanosleep
318 # define __clock_gettime64 __clock_gettime
319 # define __timespec_get64 __timespec_get
320 # define __timespec_getres64 __timespec_getres
322 extern int __clock_nanosleep_time64 (clockid_t clock_id
,
323 int flags
, const struct __timespec64
*req
,
324 struct __timespec64
*rem
);
325 libc_hidden_proto (__clock_nanosleep_time64
)
326 extern int __clock_gettime64 (clockid_t clock_id
, struct __timespec64
*tp
);
327 libc_hidden_proto (__clock_gettime64
)
328 extern int __timespec_get64 (struct __timespec64
*ts
, int base
);
329 libc_hidden_proto (__timespec_get64
)
330 extern int __timespec_getres64 (struct __timespec64
*ts
, int base
);
331 libc_hidden_proto (__timespec_getres64
)
335 # define __time64 __time
337 extern __time64_t
__time64 (__time64_t
*timer
);
338 libc_hidden_proto (__time64
)
341 /* Use in the clock_* functions. Size of the field representing the
343 #define CLOCK_IDFIELD_SIZE 3
345 /* Check whether T fits in time_t. */
347 in_time_t_range (__time64_t t
)
353 /* Convert a known valid struct timeval into a struct __timespec64. */
354 static inline struct __timespec64
355 valid_timeval_to_timespec64 (const struct timeval tv
)
357 struct __timespec64 ts64
;
359 ts64
.tv_sec
= tv
.tv_sec
;
360 ts64
.tv_nsec
= tv
.tv_usec
* 1000;
365 /* Convert a known valid struct timeval into a struct __timeval64. */
366 static inline struct __timeval64
367 valid_timeval_to_timeval64 (const struct timeval tv
)
369 struct __timeval64 tv64
;
371 tv64
.tv_sec
= tv
.tv_sec
;
372 tv64
.tv_usec
= tv
.tv_usec
;
377 /* Convert a valid and within range of struct timeval, struct
378 __timeval64 into a struct timeval. */
379 static inline struct timeval
380 valid_timeval64_to_timeval (const struct __timeval64 tv64
)
384 tv
.tv_sec
= (time_t) tv64
.tv_sec
;
385 tv
.tv_usec
= (suseconds_t
) tv64
.tv_usec
;
390 /* Convert a struct __timeval64 into a struct __timespec64. */
391 static inline struct __timespec64
392 timeval64_to_timespec64 (const struct __timeval64 tv64
)
394 struct __timespec64 ts64
;
396 ts64
.tv_sec
= tv64
.tv_sec
;
397 ts64
.tv_nsec
= tv64
.tv_usec
* 1000;
402 /* Convert a known valid struct timespec into a struct __timespec64. */
403 static inline struct __timespec64
404 valid_timespec_to_timespec64 (const struct timespec ts
)
406 struct __timespec64 ts64
;
408 ts64
.tv_sec
= ts
.tv_sec
;
409 ts64
.tv_nsec
= ts
.tv_nsec
;
414 /* Convert a valid and within range of struct timespec, struct
415 __timespec64 into a struct timespec. */
416 static inline struct timespec
417 valid_timespec64_to_timespec (const struct __timespec64 ts64
)
421 ts
.tv_sec
= (time_t) ts64
.tv_sec
;
422 ts
.tv_nsec
= ts64
.tv_nsec
;
427 /* Convert a valid and within range of struct timeval struct
428 __timespec64 into a struct timeval. */
429 static inline struct timeval
430 valid_timespec64_to_timeval (const struct __timespec64 ts64
)
434 tv
.tv_sec
= (time_t) ts64
.tv_sec
;
435 tv
.tv_usec
= ts64
.tv_nsec
/ 1000;
440 /* Convert a struct __timespec64 into a struct __timeval64. */
441 static inline struct __timeval64
442 timespec64_to_timeval64 (const struct __timespec64 ts64
)
444 struct __timeval64 tv64
;
446 tv64
.tv_sec
= ts64
.tv_sec
;
447 tv64
.tv_usec
= ts64
.tv_nsec
/ 1000;
452 /* A version of 'struct timeval' with 32-bit time_t
456 __int32_t tv_sec
; /* Seconds. */
457 __int32_t tv_usec
; /* Microseconds. */
460 /* Conversion functions for converting to/from __timeval32 */
461 static inline struct __timeval64
462 valid_timeval32_to_timeval64 (const struct __timeval32 tv
)
464 return (struct __timeval64
) { tv
.tv_sec
, tv
.tv_usec
};
467 static inline struct __timeval32
468 valid_timeval64_to_timeval32 (const struct __timeval64 tv64
)
470 return (struct __timeval32
) { tv64
.tv_sec
, tv64
.tv_usec
};
473 static inline struct timeval
474 valid_timeval32_to_timeval (const struct __timeval32 tv
)
476 return (struct timeval
) { tv
.tv_sec
, tv
.tv_usec
};
479 static inline struct __timeval32
480 valid_timeval_to_timeval32 (const struct timeval tv
)
482 return (struct __timeval32
) { tv
.tv_sec
, tv
.tv_usec
};
485 static inline struct timespec
486 valid_timeval32_to_timespec (const struct __timeval32 tv
)
488 return (struct timespec
) { tv
.tv_sec
, tv
.tv_usec
* 1000 };
491 static inline struct __timeval32
492 valid_timespec_to_timeval32 (const struct timespec ts
)
494 return (struct __timeval32
) { (time_t) ts
.tv_sec
, ts
.tv_nsec
/ 1000 };
497 static inline struct __timeval64
498 valid_timespec_to_timeval64 (const struct timespec ts
)
500 return (struct __timeval64
) { (time_t) ts
.tv_sec
, ts
.tv_nsec
/ 1000 };
503 /* Check if a value is in the valid nanoseconds range. Return true if
504 it is, false otherwise. */
506 valid_nanoseconds (__syscall_slong_t ns
)
508 return __glibc_likely (0 <= ns
&& ns
< 1000000000);
511 /* Helper function to get time in seconds, similar to time. */
516 __clock_gettime (TIME_CLOCK_GETTIME_CLOCKID
, &ts
);
520 static inline __time64_t
523 struct __timespec64 ts
;
524 __clock_gettime64 (TIME_CLOCK_GETTIME_CLOCKID
, &ts
);
528 #define NSEC_PER_SEC 1000000000L /* Nanoseconds per second. */
529 #define USEC_PER_SEC 1000000L /* Microseconds per second. */
530 #define NSEC_PER_USEC 1000L /* Nanoseconds per microsecond. */