Fix tests which expose ldbl -> _Float128 redirects
[glibc.git] / include / time.h
blob00b80eef003625798c30e4581a4e55c189d15b2a
1 #ifndef _TIME_H
2 #include <time/time.h>
4 #ifndef _ISOMAC
5 # include <bits/types/struct_timeval.h>
6 # include <bits/types/locale_t.h>
7 # include <stdbool.h>
8 # include <time/mktime-internal.h>
9 # include <endian.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);
32 #ifdef __linux__
33 extern __typeof (clock_adjtime) __clock_adjtime;
34 libc_hidden_proto (__clock_adjtime);
35 #endif
37 /* Now define the internal interfaces. */
38 struct tm;
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)
58 attribute_hidden;
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;
63 #if __TIMESIZE == 64
64 # define __timespec64 timespec
65 #else
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
72 tv_nsec field. */
73 struct __timespec64
75 __time64_t tv_sec; /* Seconds */
76 # if BYTE_ORDER == BIG_ENDIAN
77 __int32_t :32; /* Padding */
78 __int32_t tv_nsec; /* Nanoseconds */
79 # else
80 __int32_t tv_nsec; /* Nanoseconds */
81 __int32_t :32; /* Padding */
82 # endif
84 #endif
86 #if __TIMESIZE == 64
87 # define __itimerspec64 itimerspec
88 #else
89 /* The glibc's internal representation of the struct itimerspec. */
90 struct __itimerspec64
92 struct __timespec64 it_interval;
93 struct __timespec64 it_value;
95 #endif
97 #if __TIMESIZE == 64
98 # define __timeval64 timeval
99 #else
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). */
104 struct __timeval64
106 __time64_t tv_sec; /* Seconds */
107 __suseconds64_t tv_usec; /* Microseconds */
109 #endif
111 #if __TIMESIZE == 64
112 # define __utimbuf64 utimbuf
113 #else
114 /* The glibc Y2038-proof struct __utimbuf64 structure for file's access
115 and modification time values. */
116 struct __utimbuf64
118 __time64_t actime; /* Access time. */
119 __time64_t modtime; /* Modification time. */
121 #endif
123 #if __TIMESIZE == 64
124 # define __ctime64 ctime
125 #else
126 extern char *__ctime64 (const __time64_t *__timer) __THROW;
127 libc_hidden_proto (__ctime64)
128 #endif
130 #if __TIMESIZE == 64
131 # define __ctime64_r ctime_r
132 #else
133 extern char *__ctime64_r (const __time64_t *__restrict __timer,
134 char *__restrict __buf) __THROW;
135 libc_hidden_proto (__ctime64_r)
136 #endif
138 #if __TIMESIZE == 64
139 # define __localtime64 localtime
140 #else
141 extern struct tm *__localtime64 (const __time64_t *__timer);
142 libc_hidden_proto (__localtime64)
143 #endif
145 extern struct tm *__localtime_r (const time_t *__timer,
146 struct tm *__tp) attribute_hidden;
147 #if __TIMESIZE != 64
148 extern struct tm *__localtime64_r (const __time64_t *__timer,
149 struct tm *__tp);
150 libc_hidden_proto (__localtime64_r)
152 extern __time64_t __mktime64 (struct tm *__tp) __THROW;
153 libc_hidden_proto (__mktime64)
154 #endif
156 extern struct tm *__gmtime_r (const time_t *__restrict __timer,
157 struct tm *__restrict __tp);
158 libc_hidden_proto (__gmtime_r)
160 #if __TIMESIZE == 64
161 # define __gmtime64 gmtime
162 #else
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)
172 #endif
174 #if __TIMESIZE == 64
175 # define __clock_settime64 __clock_settime
176 #else
177 extern int __clock_settime64 (clockid_t clock_id,
178 const struct __timespec64 *tp);
179 libc_hidden_proto (__clock_settime64)
180 #endif
182 #if __TIMESIZE == 64
183 # define __clock_getres64 __clock_getres
184 #else
185 extern int __clock_getres64 (clockid_t clock_id,
186 struct __timespec64 *tp);
187 libc_hidden_proto (__clock_getres64);
188 #endif
190 #if __TIMESIZE == 64
191 # define __utime64 __utime
192 # define __utimes64 __utimes
193 # define __utimensat64 __utimensat
194 #else
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);
202 #endif
204 extern int __utimensat64_helper (int fd, const char *file,
205 const struct __timespec64 tsp[2], int flags);
206 libc_hidden_proto (__utimensat64_helper);
208 #if __TIMESIZE == 64
209 # define __futimes64 __futimes
210 # define __futimesat64 __futimesat
211 # define __lutimes64 __lutimes
212 # define __futimens64 __futimens
213 #else
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);
223 #endif
225 #if __TIMESIZE == 64
226 # define __timer_gettime64 __timer_gettime
227 # define __timerfd_gettime64 __timerfd_gettime
228 #else
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);
233 #endif
235 #if __TIMESIZE == 64
236 # define __timer_settime64 __timer_settime
237 # define __timerfd_settime64 __timerfd_settime
238 #else
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);
247 #endif
249 #if __TIMESIZE == 64
250 # define __sched_rr_get_interval64 __sched_rr_get_interval
251 #else
252 extern int __sched_rr_get_interval64 (pid_t pid, struct __timespec64 *tp);
253 libc_hidden_proto (__sched_rr_get_interval64);
254 #endif
256 #if __TIMESIZE == 64
257 # define __settimeofday64 __settimeofday
258 # define __gettimeofday64 __gettimeofday
259 #else
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,
264 void *restrict tz);
265 libc_hidden_proto (__gettimeofday64)
266 #endif
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,
273 long int __offset,
274 struct tm *__tp) attribute_hidden;
276 extern char *__asctime_r (const struct tm *__tp, char *__buf)
277 attribute_hidden;
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)
288 attribute_hidden;
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;
300 #if __TIMESIZE == 64
301 # define __difftime64 __difftime
302 #else
303 extern double __difftime64 (__time64_t time1, __time64_t time0);
304 libc_hidden_proto (__difftime64)
305 #endif
307 extern double __difftime (time_t time1, time_t time0);
309 #if __TIMESIZE == 64
310 # define __clock_nanosleep_time64 __clock_nanosleep
311 # define __clock_gettime64 __clock_gettime
312 # define __timespec_get64 __timespec_get
313 #else
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)
322 #endif
324 /* Use in the clock_* functions. Size of the field representing the
325 actual clock ID. */
326 #define CLOCK_IDFIELD_SIZE 3
328 /* Check whether T fits in time_t. */
329 static inline bool
330 in_time_t_range (__time64_t t)
332 time_t s = t;
333 return s == 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;
345 return ts64;
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;
357 return tv64;
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)
365 struct timeval tv;
367 tv.tv_sec = (time_t) tv64.tv_sec;
368 tv.tv_usec = (suseconds_t) tv64.tv_usec;
370 return tv;
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;
382 return ts64;
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;
394 return ts64;
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)
402 struct timespec ts;
404 ts.tv_sec = (time_t) ts64.tv_sec;
405 ts.tv_nsec = ts64.tv_nsec;
407 return ts;
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)
415 struct timeval tv;
417 tv.tv_sec = (time_t) ts64.tv_sec;
418 tv.tv_usec = ts64.tv_nsec / 1000;
420 return tv;
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;
432 return tv64;
435 /* Check if a value is in the valid nanoseconds range. Return true if
436 it is, false otherwise. */
437 static inline bool
438 valid_nanoseconds (__syscall_slong_t ns)
440 return __glibc_likely (0 <= ns && ns < 1000000000);
443 /* Helper function to get time in seconds, similar to time. */
444 static inline time_t
445 time_now (void)
447 struct timespec ts;
448 __clock_gettime (TIME_CLOCK_GETTIME_CLOCKID, &ts);
449 return ts.tv_sec;
451 #endif
453 #endif