Do not use ld.so to open statically linked programs in debugglibc.sh
[glibc.git] / include / time.h
blobd7800eb30f83a1834ade1a90796b30256a801c86
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>
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);
31 #ifdef __linux__
32 extern __typeof (clock_adjtime) __clock_adjtime;
33 libc_hidden_proto (__clock_adjtime);
34 #endif
36 /* Now define the internal interfaces. */
37 struct tm;
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)
57 attribute_hidden;
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;
62 #if __TIMESIZE == 64
63 # define __timespec64 timespec
64 #else
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
71 tv_nsec field. */
72 struct __timespec64
74 __time64_t tv_sec; /* Seconds */
75 # if BYTE_ORDER == BIG_ENDIAN
76 __int32_t :32; /* Padding */
77 __int32_t tv_nsec; /* Nanoseconds */
78 # else
79 __int32_t tv_nsec; /* Nanoseconds */
80 __int32_t :32; /* Padding */
81 # endif
83 #endif
85 #if __TIMESIZE == 64
86 # define __ctime64 ctime
87 #else
88 extern char *__ctime64 (const __time64_t *__timer) __THROW;
89 libc_hidden_proto (__ctime64)
90 #endif
92 #if __TIMESIZE == 64
93 # define __ctime64_r ctime_r
94 #else
95 extern char *__ctime64_r (const __time64_t *__restrict __timer,
96 char *__restrict __buf) __THROW;
97 libc_hidden_proto (__ctime64_r)
98 #endif
100 #if __TIMESIZE == 64
101 # define __localtime64 localtime
102 #else
103 extern struct tm *__localtime64 (const __time64_t *__timer);
104 libc_hidden_proto (__localtime64)
105 #endif
107 extern struct tm *__localtime_r (const time_t *__timer,
108 struct tm *__tp) attribute_hidden;
109 #if __TIMESIZE != 64
110 extern struct tm *__localtime64_r (const __time64_t *__timer,
111 struct tm *__tp);
112 libc_hidden_proto (__localtime64_r)
114 extern __time64_t __mktime64 (struct tm *__tp) __THROW;
115 libc_hidden_proto (__mktime64)
116 #endif
118 extern struct tm *__gmtime_r (const time_t *__restrict __timer,
119 struct tm *__restrict __tp);
120 libc_hidden_proto (__gmtime_r)
122 #if __TIMESIZE == 64
123 # define __gmtime64 gmtime
124 #else
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)
134 #endif
136 #if __TIMESIZE == 64
137 # define __clock_settime64 __clock_settime
138 #else
139 extern int __clock_settime64 (clockid_t clock_id,
140 const struct __timespec64 *tp);
141 libc_hidden_proto (__clock_settime64)
142 #endif
144 #if __TIMESIZE == 64
145 # define __clock_getres64 __clock_getres
146 #else
147 extern int __clock_getres64 (clockid_t clock_id,
148 struct __timespec64 *tp);
149 libc_hidden_proto (__clock_getres64);
150 #endif
152 #if __TIMESIZE == 64
153 # define __utimensat64 __utimensat
154 #else
155 extern int __utimensat64 (int fd, const char *file,
156 const struct __timespec64 tsp[2], int flags);
157 libc_hidden_proto (__utimensat64);
158 #endif
160 extern int __utimensat64_helper (int fd, const char *file,
161 const struct __timespec64 tsp[2], int flags);
162 libc_hidden_proto (__utimensat64_helper);
164 #if __TIMESIZE == 64
165 # define __futimens64 __futimens
166 #else
167 extern int __futimens64 (int fd, const struct __timespec64 tsp[2]);
168 libc_hidden_proto (__futimens64);
169 #endif
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,
176 long int __offset,
177 struct tm *__tp) attribute_hidden;
179 extern char *__asctime_r (const struct tm *__tp, char *__buf)
180 attribute_hidden;
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)
191 attribute_hidden;
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;
203 #if __TIMESIZE == 64
204 # define __difftime64 __difftime
205 #else
206 extern double __difftime64 (__time64_t time1, __time64_t time0);
207 libc_hidden_proto (__difftime64)
208 #endif
210 extern double __difftime (time_t time1, time_t time0);
212 #if __TIMESIZE == 64
213 # define __clock_nanosleep_time64 __clock_nanosleep
214 #else
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)
219 #endif
221 /* Use in the clock_* functions. Size of the field representing the
222 actual clock ID. */
223 #define CLOCK_IDFIELD_SIZE 3
225 /* Check whether T fits in time_t. */
226 static inline bool
227 in_time_t_range (__time64_t t)
229 time_t s = t;
230 return s == 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;
242 return ts64;
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;
254 return ts64;
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)
262 struct timespec ts;
264 ts.tv_sec = (time_t) ts64.tv_sec;
265 ts.tv_nsec = ts64.tv_nsec;
267 return ts;
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)
275 struct timeval tv;
277 tv.tv_sec = (time_t) ts64.tv_sec;
278 tv.tv_usec = ts64.tv_nsec / 1000;
280 return tv;
283 /* Check if a value is in the valid nanoseconds range. Return true if
284 it is, false otherwise. */
285 static inline bool
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. */
292 static inline time_t
293 time_now (void)
295 struct timespec ts;
296 __clock_gettime (TIME_CLOCK_GETTIME_CLOCKID, &ts);
297 return ts.tv_sec;
299 #endif
301 #endif