Make libc symbols hidden in static PIE
[glibc.git] / include / time.h
blobcaf2af5e74ed6179e182e0ab7ce2012b2c421a10
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 <struct___timeval64.h>
8 # include <bits/types/locale_t.h>
9 # include <stdbool.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_nanosleep) __clock_nanosleep;
32 libc_hidden_proto (__clock_nanosleep);
34 #ifdef __linux__
35 extern __typeof (clock_adjtime) __clock_adjtime;
36 libc_hidden_proto (__clock_adjtime);
37 #endif
39 /* Now define the internal interfaces. */
40 struct tm;
42 /* Defined in mktime.c. */
43 extern const unsigned short int __mon_yday[2][13] attribute_hidden;
45 /* Defined in localtime.c. */
46 extern struct tm _tmbuf attribute_hidden;
48 /* Defined in tzset.c. */
49 extern char *__tzstring (const char *string) attribute_hidden;
51 extern int __use_tzfile attribute_hidden;
53 extern void __tzfile_read (const char *file, size_t extra,
54 char **extrap) attribute_hidden;
55 extern void __tzfile_compute (__time64_t timer, int use_localtime,
56 long int *leap_correct, int *leap_hit,
57 struct tm *tp) attribute_hidden;
58 extern void __tzfile_default (const char *std, const char *dst,
59 int stdoff, int dstoff)
60 attribute_hidden;
61 extern void __tzset_parse_tz (const char *tz) attribute_hidden;
62 extern void __tz_compute (__time64_t timer, struct tm *tm, int use_localtime)
63 __THROW attribute_hidden;
66 #if __TIMESIZE == 64
67 # define __itimerspec64 itimerspec
68 #else
69 /* The glibc's internal representation of the struct itimerspec. */
70 struct __itimerspec64
72 struct __timespec64 it_interval;
73 struct __timespec64 it_value;
75 #endif
77 #if __TIMESIZE == 64
78 # define __utimbuf64 utimbuf
79 # define __itimerval64 itimerval
80 #else
81 /* The glibc Y2038-proof struct __utimbuf64 structure for file's access
82 and modification time values. */
83 struct __utimbuf64
85 __time64_t actime; /* Access time. */
86 __time64_t modtime; /* Modification time. */
88 /* The glibc's internal representation of the struct itimerval. */
89 struct __itimerval64
91 struct __timeval64 it_interval;
92 struct __timeval64 it_value;
94 #endif
96 #if __TIMESIZE == 64
97 # define __getitimer64 __getitimer
98 # define __setitimer64 __setitimer
99 #else
100 extern int __getitimer64 (enum __itimer_which __which,
101 struct __itimerval64 *__value);
103 libc_hidden_proto (__getitimer64)
104 extern int __setitimer64 (enum __itimer_which __which,
105 const struct __itimerval64 *__restrict __new,
106 struct __itimerval64 *__restrict __old);
107 libc_hidden_proto (__setitimer64)
108 #endif
110 #if __TIMESIZE == 64
111 # define __ctime64 ctime
112 #else
113 extern char *__ctime64 (const __time64_t *__timer) __THROW;
114 libc_hidden_proto (__ctime64)
115 #endif
117 #if __TIMESIZE == 64
118 # define __ctime64_r ctime_r
119 #else
120 extern char *__ctime64_r (const __time64_t *__restrict __timer,
121 char *__restrict __buf) __THROW;
122 libc_hidden_proto (__ctime64_r)
123 #endif
125 #if __TIMESIZE == 64
126 # define __localtime64 localtime
127 #else
128 extern struct tm *__localtime64 (const __time64_t *__timer);
129 libc_hidden_proto (__localtime64)
130 #endif
132 extern struct tm *__localtime_r (const time_t *__timer,
133 struct tm *__tp) attribute_hidden;
134 #if __TIMESIZE != 64
135 extern struct tm *__localtime64_r (const __time64_t *__timer,
136 struct tm *__tp);
137 libc_hidden_proto (__localtime64_r)
139 extern __time64_t __mktime64 (struct tm *__tp) __THROW;
140 libc_hidden_proto (__mktime64)
141 #endif
143 extern struct tm *__gmtime_r (const time_t *__restrict __timer,
144 struct tm *__restrict __tp);
145 libc_hidden_proto (__gmtime_r)
147 #if __TIMESIZE == 64
148 # define __gmtime64 gmtime
149 #else
150 extern struct tm *__gmtime64 (const __time64_t *__timer);
151 libc_hidden_proto (__gmtime64)
153 extern struct tm *__gmtime64_r (const __time64_t *__restrict __timer,
154 struct tm *__restrict __tp);
155 libc_hidden_proto (__gmtime64_r)
157 extern __time64_t __timegm64 (struct tm *__tp) __THROW;
158 libc_hidden_proto (__timegm64)
159 #endif
161 #if __TIMESIZE == 64
162 # define __clock_settime64 __clock_settime
163 #else
164 extern int __clock_settime64 (clockid_t clock_id,
165 const struct __timespec64 *tp);
166 libc_hidden_proto (__clock_settime64)
167 #endif
169 #if __TIMESIZE == 64
170 # define __clock_getres64 __clock_getres
171 #else
172 extern int __clock_getres64 (clockid_t clock_id,
173 struct __timespec64 *tp);
174 libc_hidden_proto (__clock_getres64);
175 #endif
177 #if __TIMESIZE == 64
178 # define __utime64 __utime
179 # define __utimes64 __utimes
180 # define __utimensat64 __utimensat
181 #else
182 extern int __utime64 (const char *file, const struct __utimbuf64 *times);
183 libc_hidden_proto (__utime64)
184 extern int __utimes64 (const char *file, const struct __timeval64 tvp[2]);
185 libc_hidden_proto (__utimes64)
186 extern int __utimensat64 (int fd, const char *file,
187 const struct __timespec64 tsp[2], int flags);
188 libc_hidden_proto (__utimensat64);
189 #endif
191 extern int __utimensat64_helper (int fd, const char *file,
192 const struct __timespec64 tsp[2], int flags);
193 libc_hidden_proto (__utimensat64_helper);
195 #if __TIMESIZE == 64
196 # define __futimes64 __futimes
197 # define __futimesat64 __futimesat
198 # define __lutimes64 __lutimes
199 # define __futimens64 __futimens
200 #else
201 extern int __futimes64 (int fd, const struct __timeval64 tvp64[2]);
202 libc_hidden_proto (__futimes64);
203 extern int __futimesat64 (int fd, const char *file,
204 const struct __timeval64 tvp[2]);
205 libc_hidden_proto (__futimesat64);
206 extern int __lutimes64 (const char *file, const struct __timeval64 tvp64[2]);
207 libc_hidden_proto (__lutimes64);
208 extern int __futimens64 (int fd, const struct __timespec64 tsp[2]);
209 libc_hidden_proto (__futimens64);
210 #endif
212 #if __TIMESIZE == 64
213 # define __timer_gettime64 __timer_gettime
214 # define __timerfd_gettime64 __timerfd_gettime
215 #else
216 extern int __timer_gettime64 (timer_t timerid, struct __itimerspec64 *value);
217 extern int __timerfd_gettime64 (int fd, struct __itimerspec64 *value);
218 librt_hidden_proto (__timer_gettime64);
219 libc_hidden_proto (__timerfd_gettime64);
220 #endif
222 #if __TIMESIZE == 64
223 # define __timer_settime64 __timer_settime
224 # define __timerfd_settime64 __timerfd_settime
225 #else
226 extern int __timer_settime64 (timer_t timerid, int flags,
227 const struct __itimerspec64 *value,
228 struct __itimerspec64 *ovalue);
229 extern int __timerfd_settime64 (int fd, int flags,
230 const struct __itimerspec64 *value,
231 struct __itimerspec64 *ovalue);
232 librt_hidden_proto (__timer_settime64);
233 libc_hidden_proto (__timerfd_settime64);
234 #endif
236 #if __TIMESIZE == 64
237 # define __sched_rr_get_interval64 __sched_rr_get_interval
238 #else
239 extern int __sched_rr_get_interval64 (pid_t pid, struct __timespec64 *tp);
240 libc_hidden_proto (__sched_rr_get_interval64);
241 #endif
243 #if __TIMESIZE == 64
244 # define __settimeofday64 __settimeofday
245 # define __gettimeofday64 __gettimeofday
246 #else
247 extern int __settimeofday64 (const struct __timeval64 *tv,
248 const struct timezone *tz);
249 libc_hidden_proto (__settimeofday64)
250 extern int __gettimeofday64 (struct __timeval64 *restrict tv,
251 void *restrict tz);
252 libc_hidden_proto (__gettimeofday64)
253 #endif
255 /* Compute the `struct tm' representation of T,
256 offset OFFSET seconds east of UTC,
257 and store year, yday, mon, mday, wday, hour, min, sec into *TP.
258 Return nonzero if successful. */
259 extern int __offtime (__time64_t __timer,
260 long int __offset,
261 struct tm *__tp) attribute_hidden;
263 extern char *__asctime_r (const struct tm *__tp, char *__buf)
264 attribute_hidden;
265 extern void __tzset (void) attribute_hidden;
267 /* Prototype for the internal function to get information based on TZ. */
268 extern struct tm *__tz_convert (__time64_t timer, int use_localtime,
269 struct tm *tp) attribute_hidden;
271 extern int __nanosleep (const struct timespec *__requested_time,
272 struct timespec *__remaining);
273 hidden_proto (__nanosleep)
274 #if __TIMESIZE == 64
275 # define __nanosleep64 __nanosleep
276 #else
277 extern int __nanosleep64 (const struct __timespec64 *__requested_time,
278 struct __timespec64 *__remaining);
279 hidden_proto (__nanosleep64)
280 #endif
283 extern int __getdate_r (const char *__string, struct tm *__resbufp)
284 attribute_hidden;
287 /* Determine CLK_TCK value. */
288 extern int __getclktck (void) attribute_hidden;
291 /* strptime support. */
292 extern char * __strptime_internal (const char *rp, const char *fmt,
293 struct tm *tm, void *statep,
294 locale_t locparam) attribute_hidden;
296 #if __TIMESIZE == 64
297 # define __difftime64 __difftime
298 #else
299 extern double __difftime64 (__time64_t time1, __time64_t time0);
300 libc_hidden_proto (__difftime64)
301 #endif
303 extern double __difftime (time_t time1, time_t time0);
305 #if __TIMESIZE == 64
306 # define __clock_nanosleep_time64 __clock_nanosleep
307 # define __clock_gettime64 __clock_gettime
308 # define __timespec_get64 __timespec_get
309 #else
310 extern int __clock_nanosleep_time64 (clockid_t clock_id,
311 int flags, const struct __timespec64 *req,
312 struct __timespec64 *rem);
313 libc_hidden_proto (__clock_nanosleep_time64)
314 extern int __clock_gettime64 (clockid_t clock_id, struct __timespec64 *tp);
315 libc_hidden_proto (__clock_gettime64)
316 extern int __timespec_get64 (struct __timespec64 *ts, int base);
317 libc_hidden_proto (__timespec_get64)
318 #endif
320 #if __TIMESIZE == 64
321 # define __time64 __time
322 #else
323 extern __time64_t __time64 (__time64_t *timer);
324 libc_hidden_proto (__time64)
325 #endif
327 /* Use in the clock_* functions. Size of the field representing the
328 actual clock ID. */
329 #define CLOCK_IDFIELD_SIZE 3
331 /* Check whether T fits in time_t. */
332 static inline bool
333 in_time_t_range (__time64_t t)
335 time_t s = t;
336 return s == t;
339 /* Convert a known valid struct timeval into a struct __timespec64. */
340 static inline struct __timespec64
341 valid_timeval_to_timespec64 (const struct timeval tv)
343 struct __timespec64 ts64;
345 ts64.tv_sec = tv.tv_sec;
346 ts64.tv_nsec = tv.tv_usec * 1000;
348 return ts64;
351 /* Convert a known valid struct timeval into a struct __timeval64. */
352 static inline struct __timeval64
353 valid_timeval_to_timeval64 (const struct timeval tv)
355 struct __timeval64 tv64;
357 tv64.tv_sec = tv.tv_sec;
358 tv64.tv_usec = tv.tv_usec;
360 return tv64;
363 /* Convert a valid and within range of struct timeval, struct
364 __timeval64 into a struct timeval. */
365 static inline struct timeval
366 valid_timeval64_to_timeval (const struct __timeval64 tv64)
368 struct timeval tv;
370 tv.tv_sec = (time_t) tv64.tv_sec;
371 tv.tv_usec = (suseconds_t) tv64.tv_usec;
373 return tv;
376 /* Convert a struct __timeval64 into a struct __timespec64. */
377 static inline struct __timespec64
378 timeval64_to_timespec64 (const struct __timeval64 tv64)
380 struct __timespec64 ts64;
382 ts64.tv_sec = tv64.tv_sec;
383 ts64.tv_nsec = tv64.tv_usec * 1000;
385 return ts64;
388 /* Convert a known valid struct timespec into a struct __timespec64. */
389 static inline struct __timespec64
390 valid_timespec_to_timespec64 (const struct timespec ts)
392 struct __timespec64 ts64;
394 ts64.tv_sec = ts.tv_sec;
395 ts64.tv_nsec = ts.tv_nsec;
397 return ts64;
400 /* Convert a valid and within range of struct timespec, struct
401 __timespec64 into a struct timespec. */
402 static inline struct timespec
403 valid_timespec64_to_timespec (const struct __timespec64 ts64)
405 struct timespec ts;
407 ts.tv_sec = (time_t) ts64.tv_sec;
408 ts.tv_nsec = ts64.tv_nsec;
410 return ts;
413 /* Convert a valid and within range of struct timeval struct
414 __timespec64 into a struct timeval. */
415 static inline struct timeval
416 valid_timespec64_to_timeval (const struct __timespec64 ts64)
418 struct timeval tv;
420 tv.tv_sec = (time_t) ts64.tv_sec;
421 tv.tv_usec = ts64.tv_nsec / 1000;
423 return tv;
426 /* Convert a struct __timespec64 into a struct __timeval64. */
427 static inline struct __timeval64
428 timespec64_to_timeval64 (const struct __timespec64 ts64)
430 struct __timeval64 tv64;
432 tv64.tv_sec = ts64.tv_sec;
433 tv64.tv_usec = ts64.tv_nsec / 1000;
435 return tv64;
438 /* A version of 'struct timeval' with 32-bit time_t
439 and suseconds_t. */
440 struct __timeval32
442 __int32_t tv_sec; /* Seconds. */
443 __int32_t tv_usec; /* Microseconds. */
446 /* Conversion functions for converting to/from __timeval32 */
447 static inline struct __timeval64
448 valid_timeval32_to_timeval64 (const struct __timeval32 tv)
450 return (struct __timeval64) { tv.tv_sec, tv.tv_usec };
453 static inline struct __timeval32
454 valid_timeval64_to_timeval32 (const struct __timeval64 tv64)
456 return (struct __timeval32) { tv64.tv_sec, tv64.tv_usec };
459 static inline struct timeval
460 valid_timeval32_to_timeval (const struct __timeval32 tv)
462 return (struct timeval) { tv.tv_sec, tv.tv_usec };
465 static inline struct __timeval32
466 valid_timeval_to_timeval32 (const struct timeval tv)
468 return (struct __timeval32) { tv.tv_sec, tv.tv_usec };
471 static inline struct timespec
472 valid_timeval32_to_timespec (const struct __timeval32 tv)
474 return (struct timespec) { tv.tv_sec, tv.tv_usec * 1000 };
477 static inline struct __timeval32
478 valid_timespec_to_timeval32 (const struct timespec ts)
480 return (struct __timeval32) { (time_t) ts.tv_sec, ts.tv_nsec / 1000 };
483 static inline struct __timeval64
484 valid_timespec_to_timeval64 (const struct timespec ts)
486 return (struct __timeval64) { (time_t) ts.tv_sec, ts.tv_nsec / 1000 };
489 /* Check if a value is in the valid nanoseconds range. Return true if
490 it is, false otherwise. */
491 static inline bool
492 valid_nanoseconds (__syscall_slong_t ns)
494 return __glibc_likely (0 <= ns && ns < 1000000000);
497 /* Helper function to get time in seconds, similar to time. */
498 static inline time_t
499 time_now (void)
501 struct timespec ts;
502 __clock_gettime (TIME_CLOCK_GETTIME_CLOCKID, &ts);
503 return ts.tv_sec;
505 #endif
507 #endif