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>
12 extern __typeof (strftime_l
) __strftime_l
;
13 libc_hidden_proto (__strftime_l
)
14 extern __typeof (strptime_l
) __strptime_l
;
16 libc_hidden_proto (asctime
)
17 libc_hidden_proto (mktime
)
18 libc_hidden_proto (timelocal
)
19 libc_hidden_proto (localtime
)
20 libc_hidden_proto (strftime
)
21 libc_hidden_proto (strptime
)
23 extern __typeof (clock_gettime
) __clock_gettime
;
24 libc_hidden_proto (__clock_gettime
)
25 extern __typeof (clock_settime
) __clock_settime
;
26 libc_hidden_proto (__clock_settime
)
28 extern __typeof (clock_nanosleep
) __clock_nanosleep
;
29 libc_hidden_proto (__clock_nanosleep
);
32 extern __typeof (clock_adjtime
) __clock_adjtime
;
33 libc_hidden_proto (__clock_adjtime
);
36 /* Now define the internal interfaces. */
39 /* Defined in mktime.c. */
40 extern const unsigned short int __mon_yday
[2][13] attribute_hidden
;
42 /* Defined in localtime.c. */
43 extern struct tm _tmbuf attribute_hidden
;
45 /* Defined in tzset.c. */
46 extern char *__tzstring (const char *string
) attribute_hidden
;
48 extern int __use_tzfile attribute_hidden
;
50 extern void __tzfile_read (const char *file
, size_t extra
,
51 char **extrap
) attribute_hidden
;
52 extern void __tzfile_compute (__time64_t timer
, int use_localtime
,
53 long int *leap_correct
, int *leap_hit
,
54 struct tm
*tp
) attribute_hidden
;
55 extern void __tzfile_default (const char *std
, const char *dst
,
56 int stdoff
, int dstoff
)
58 extern void __tzset_parse_tz (const char *tz
) attribute_hidden
;
59 extern void __tz_compute (__time64_t timer
, struct tm
*tm
, int use_localtime
)
60 __THROW attribute_hidden
;
63 # define __timespec64 timespec
65 /* The glibc Y2038-proof struct __timespec64 structure for a time value.
66 To keep things Posix-ish, we keep the nanoseconds field a 32-bit
67 signed long, but since the Linux field is a 64-bit signed int, we
68 pad our tv_nsec with a 32-bit unnamed bit-field padding.
70 As a general rule the Linux kernel is ignoring upper 32 bits of
74 __time64_t tv_sec
; /* Seconds */
75 # if BYTE_ORDER == BIG_ENDIAN
76 __int32_t
:32; /* Padding */
77 __int32_t tv_nsec
; /* Nanoseconds */
79 __int32_t tv_nsec
; /* Nanoseconds */
80 __int32_t
:32; /* Padding */
86 # define __ctime64 ctime
88 extern char *__ctime64 (const __time64_t
*__timer
) __THROW
;
89 libc_hidden_proto (__ctime64
)
93 # define __ctime64_r ctime_r
95 extern char *__ctime64_r (const __time64_t
*__restrict __timer
,
96 char *__restrict __buf
) __THROW
;
97 libc_hidden_proto (__ctime64_r
)
101 # define __localtime64 localtime
103 extern struct tm
*__localtime64 (const __time64_t
*__timer
);
104 libc_hidden_proto (__localtime64
)
107 extern struct tm
*__localtime_r (const time_t *__timer
,
108 struct tm
*__tp
) attribute_hidden
;
110 extern struct tm
*__localtime64_r (const __time64_t
*__timer
,
112 libc_hidden_proto (__localtime64_r
)
114 extern __time64_t
__mktime64 (struct tm
*__tp
) __THROW
;
115 libc_hidden_proto (__mktime64
)
118 extern struct tm
*__gmtime_r (const time_t *__restrict __timer
,
119 struct tm
*__restrict __tp
);
120 libc_hidden_proto (__gmtime_r
)
123 # define __gmtime64 gmtime
125 extern struct tm
*__gmtime64 (const __time64_t
*__timer
);
126 libc_hidden_proto (__gmtime64
)
128 extern struct tm
*__gmtime64_r (const __time64_t
*__restrict __timer
,
129 struct tm
*__restrict __tp
);
130 libc_hidden_proto (__gmtime64_r
)
132 extern __time64_t
__timegm64 (struct tm
*__tp
) __THROW
;
133 libc_hidden_proto (__timegm64
)
137 # define __clock_settime64 __clock_settime
139 extern int __clock_settime64 (clockid_t clock_id
,
140 const struct __timespec64
*tp
);
141 libc_hidden_proto (__clock_settime64
)
145 # define __clock_getres64 __clock_getres
147 extern int __clock_getres64 (clockid_t clock_id
,
148 struct __timespec64
*tp
);
149 libc_hidden_proto (__clock_getres64
);
153 # define __utimensat64 __utimensat
155 extern int __utimensat64 (int fd
, const char *file
,
156 const struct __timespec64 tsp
[2], int flags
);
157 libc_hidden_proto (__utimensat64
);
160 extern int __utimensat64_helper (int fd
, const char *file
,
161 const struct __timespec64 tsp
[2], int flags
);
162 libc_hidden_proto (__utimensat64_helper
);
165 # define __futimens64 __futimens
167 extern int __futimens64 (int fd
, const struct __timespec64 tsp
[2]);
168 libc_hidden_proto (__futimens64
);
171 /* Compute the `struct tm' representation of T,
172 offset OFFSET seconds east of UTC,
173 and store year, yday, mon, mday, wday, hour, min, sec into *TP.
174 Return nonzero if successful. */
175 extern int __offtime (__time64_t __timer
,
177 struct tm
*__tp
) attribute_hidden
;
179 extern char *__asctime_r (const struct tm
*__tp
, char *__buf
)
181 extern void __tzset (void) attribute_hidden
;
183 /* Prototype for the internal function to get information based on TZ. */
184 extern struct tm
*__tz_convert (__time64_t timer
, int use_localtime
,
185 struct tm
*tp
) attribute_hidden
;
187 extern int __nanosleep (const struct timespec
*__requested_time
,
188 struct timespec
*__remaining
);
189 hidden_proto (__nanosleep
)
190 extern int __getdate_r (const char *__string
, struct tm
*__resbufp
)
194 /* Determine CLK_TCK value. */
195 extern int __getclktck (void) attribute_hidden
;
198 /* strptime support. */
199 extern char * __strptime_internal (const char *rp
, const char *fmt
,
200 struct tm
*tm
, void *statep
,
201 locale_t locparam
) attribute_hidden
;
204 # define __difftime64 __difftime
206 extern double __difftime64 (__time64_t time1
, __time64_t time0
);
207 libc_hidden_proto (__difftime64
)
210 extern double __difftime (time_t time1
, time_t time0
);
213 # define __clock_nanosleep_time64 __clock_nanosleep
215 extern int __clock_nanosleep_time64 (clockid_t clock_id
,
216 int flags
, const struct __timespec64
*req
,
217 struct __timespec64
*rem
);
218 libc_hidden_proto (__clock_nanosleep_time64
)
221 /* Use in the clock_* functions. Size of the field representing the
223 #define CLOCK_IDFIELD_SIZE 3
225 /* Check whether T fits in time_t. */
227 in_time_t_range (__time64_t t
)
233 /* Convert a known valid struct timeval into a struct __timespec64. */
234 static inline struct __timespec64
235 valid_timeval_to_timespec64 (const struct timeval tv
)
237 struct __timespec64 ts64
;
239 ts64
.tv_sec
= tv
.tv_sec
;
240 ts64
.tv_nsec
= tv
.tv_usec
* 1000;
245 /* Convert a known valid struct timespec into a struct __timespec64. */
246 static inline struct __timespec64
247 valid_timespec_to_timespec64 (const struct timespec ts
)
249 struct __timespec64 ts64
;
251 ts64
.tv_sec
= ts
.tv_sec
;
252 ts64
.tv_nsec
= ts
.tv_nsec
;
257 /* Convert a valid and within range of struct timespec, struct
258 __timespec64 into a struct timespec. */
259 static inline struct timespec
260 valid_timespec64_to_timespec (const struct __timespec64 ts64
)
264 ts
.tv_sec
= (time_t) ts64
.tv_sec
;
265 ts
.tv_nsec
= ts64
.tv_nsec
;
270 /* Convert a valid and within range of struct timeval struct
271 __timespec64 into a struct timeval. */
272 static inline struct timeval
273 valid_timespec64_to_timeval (const struct __timespec64 ts64
)
277 tv
.tv_sec
= (time_t) ts64
.tv_sec
;
278 tv
.tv_usec
= ts64
.tv_nsec
/ 1000;
283 /* Check if a value is in the valid nanoseconds range. Return true if
284 it is, false otherwise. */
286 valid_nanoseconds (__syscall_slong_t ns
)
288 return __glibc_likely (0 <= ns
&& ns
< 1000000000);
291 /* Helper function to get time in seconds, similar to time. */
296 __clock_gettime (TIME_CLOCK_GETTIME_CLOCKID
, &ts
);