Rename __LONG_DOUBLE_USES_FLOAT128 to __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI
[glibc.git] / include / time.h
blob1c103a4cb281c752a91f26895457ba8f1cefc180
1 #ifndef _TIME_H
2 #include <time/time.h>
4 #ifndef _ISOMAC
5 # include <bits/types/struct_timeval.h>
6 # include <struct___timespec64.h>
7 # include <bits/types/locale_t.h>
8 # include <stdbool.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);
33 #ifdef __linux__
34 extern __typeof (clock_adjtime) __clock_adjtime;
35 libc_hidden_proto (__clock_adjtime);
36 #endif
38 /* Now define the internal interfaces. */
39 struct tm;
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)
59 attribute_hidden;
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;
65 #if __TIMESIZE == 64
66 # define __itimerspec64 itimerspec
67 #else
68 /* The glibc's internal representation of the struct itimerspec. */
69 struct __itimerspec64
71 struct __timespec64 it_interval;
72 struct __timespec64 it_value;
74 #endif
76 #if __TIMESIZE == 64
77 # define __timeval64 timeval
78 #else
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). */
83 struct __timeval64
85 __time64_t tv_sec; /* Seconds */
86 __suseconds64_t tv_usec; /* Microseconds */
88 #endif
90 #if __TIMESIZE == 64
91 # define __utimbuf64 utimbuf
92 # define __itimerval64 itimerval
93 #else
94 /* The glibc Y2038-proof struct __utimbuf64 structure for file's access
95 and modification time values. */
96 struct __utimbuf64
98 __time64_t actime; /* Access time. */
99 __time64_t modtime; /* Modification time. */
101 /* The glibc's internal representation of the struct itimerval. */
102 struct __itimerval64
104 struct __timeval64 it_interval;
105 struct __timeval64 it_value;
107 #endif
109 #if __TIMESIZE == 64
110 # define __getitimer64 __getitimer
111 # define __setitimer64 __setitimer
112 #else
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)
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 /* A version of 'struct timeval' with 32-bit time_t
436 and suseconds_t. */
437 struct __timeval32
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. */
482 static inline bool
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. */
489 static inline time_t
490 time_now (void)
492 struct timespec ts;
493 __clock_gettime (TIME_CLOCK_GETTIME_CLOCKID, &ts);
494 return ts.tv_sec;
496 #endif
498 #endif