]>
Commit | Line | Data |
---|---|---|
6796bc80 | 1 | #ifndef _TIME_H |
05b68e14 ZW |
2 | #include <time/time.h> |
3 | ||
4 | #ifndef _ISOMAC | |
4973abcb | 5 | # include <bits/types/struct_timeval.h> |
f0be25b6 | 6 | # include <bits/types/locale_t.h> |
20aa5819 PE |
7 | # include <stdbool.h> |
8 | # include <time/mktime-internal.h> | |
464cd3a9 | 9 | # include <endian.h> |
f9a75540 | 10 | # include <time-clockid.h> |
bdbf022d | 11 | |
da4cfe38 | 12 | extern __typeof (strftime_l) __strftime_l; |
ee2a5ae8 | 13 | libc_hidden_proto (__strftime_l) |
da4cfe38 RM |
14 | extern __typeof (strptime_l) __strptime_l; |
15 | ||
c5598d47 RM |
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) | |
22 | ||
6e6249d0 | 23 | extern __typeof (clock_gettime) __clock_gettime; |
89fb6835 | 24 | libc_hidden_proto (__clock_gettime) |
6e6249d0 | 25 | extern __typeof (clock_settime) __clock_settime; |
7b5af2d8 | 26 | libc_hidden_proto (__clock_settime) |
a9564ae9 | 27 | |
c81aa64e AZ |
28 | #ifdef __linux__ |
29 | extern __typeof (clock_adjtime) __clock_adjtime; | |
30 | libc_hidden_proto (__clock_adjtime); | |
31 | #endif | |
32 | ||
bdbf022d UD |
33 | /* Now define the internal interfaces. */ |
34 | struct tm; | |
35 | ||
8632b240 | 36 | /* Defined in mktime.c. */ |
ab26a24a | 37 | extern const unsigned short int __mon_yday[2][13] attribute_hidden; |
8632b240 UD |
38 | |
39 | /* Defined in localtime.c. */ | |
418f1701 | 40 | extern struct tm _tmbuf attribute_hidden; |
8632b240 UD |
41 | |
42 | /* Defined in tzset.c. */ | |
b0f56784 | 43 | extern char *__tzstring (const char *string) attribute_hidden; |
8632b240 | 44 | |
418f1701 | 45 | extern int __use_tzfile attribute_hidden; |
8632b240 | 46 | |
fe559c5e | 47 | extern void __tzfile_read (const char *file, size_t extra, |
b0f56784 | 48 | char **extrap) attribute_hidden; |
d51f99ce | 49 | extern void __tzfile_compute (__time64_t timer, int use_localtime, |
38e68573 | 50 | long int *leap_correct, int *leap_hit, |
b0f56784 | 51 | struct tm *tp) attribute_hidden; |
fe559c5e | 52 | extern void __tzfile_default (const char *std, const char *dst, |
77c7d55e | 53 | int stdoff, int dstoff) |
b0f56784 L |
54 | attribute_hidden; |
55 | extern void __tzset_parse_tz (const char *tz) attribute_hidden; | |
72b8692d | 56 | extern void __tz_compute (__time64_t timer, struct tm *tm, int use_localtime) |
8bcdb7e0 | 57 | __THROW attribute_hidden; |
8632b240 | 58 | |
464cd3a9 LM |
59 | #if __TIMESIZE == 64 |
60 | # define __timespec64 timespec | |
61 | #else | |
62 | /* The glibc Y2038-proof struct __timespec64 structure for a time value. | |
63 | To keep things Posix-ish, we keep the nanoseconds field a 32-bit | |
64 | signed long, but since the Linux field is a 64-bit signed int, we | |
65 | pad our tv_nsec with a 32-bit unnamed bit-field padding. | |
66 | ||
67 | As a general rule the Linux kernel is ignoring upper 32 bits of | |
68 | tv_nsec field. */ | |
69 | struct __timespec64 | |
70 | { | |
71 | __time64_t tv_sec; /* Seconds */ | |
72 | # if BYTE_ORDER == BIG_ENDIAN | |
73 | __int32_t :32; /* Padding */ | |
74 | __int32_t tv_nsec; /* Nanoseconds */ | |
75 | # else | |
76 | __int32_t tv_nsec; /* Nanoseconds */ | |
77 | __int32_t :32; /* Padding */ | |
78 | # endif | |
79 | }; | |
80 | #endif | |
81 | ||
7755e504 AA |
82 | #if __TIMESIZE == 64 |
83 | # define __ctime64 ctime | |
84 | #else | |
85 | extern char *__ctime64 (const __time64_t *__timer) __THROW; | |
20aa5819 | 86 | libc_hidden_proto (__ctime64) |
7755e504 AA |
87 | #endif |
88 | ||
c4c2836a AA |
89 | #if __TIMESIZE == 64 |
90 | # define __ctime64_r ctime_r | |
91 | #else | |
92 | extern char *__ctime64_r (const __time64_t *__restrict __timer, | |
93 | char *__restrict __buf) __THROW; | |
20aa5819 | 94 | libc_hidden_proto (__ctime64_r) |
c4c2836a AA |
95 | #endif |
96 | ||
6e15f3e2 AA |
97 | #if __TIMESIZE == 64 |
98 | # define __localtime64 localtime | |
99 | #else | |
100 | extern struct tm *__localtime64 (const __time64_t *__timer); | |
101 | libc_hidden_proto (__localtime64) | |
102 | #endif | |
103 | ||
a784e502 | 104 | extern struct tm *__localtime_r (const time_t *__timer, |
dff07c4b | 105 | struct tm *__tp) attribute_hidden; |
20aa5819 | 106 | #if __TIMESIZE != 64 |
64c2277d AA |
107 | extern struct tm *__localtime64_r (const __time64_t *__timer, |
108 | struct tm *__tp); | |
109 | libc_hidden_proto (__localtime64_r) | |
20aa5819 PE |
110 | |
111 | extern __time64_t __mktime64 (struct tm *__tp) __THROW; | |
112 | libc_hidden_proto (__mktime64) | |
64c2277d AA |
113 | #endif |
114 | ||
a784e502 | 115 | extern struct tm *__gmtime_r (const time_t *__restrict __timer, |
c19559b0 | 116 | struct tm *__restrict __tp); |
230491f0 | 117 | libc_hidden_proto (__gmtime_r) |
811ba236 | 118 | |
131db8b0 AA |
119 | #if __TIMESIZE == 64 |
120 | # define __gmtime64 gmtime | |
121 | #else | |
122 | extern struct tm *__gmtime64 (const __time64_t *__timer); | |
123 | libc_hidden_proto (__gmtime64) | |
131db8b0 | 124 | |
a1d346ce AA |
125 | extern struct tm *__gmtime64_r (const __time64_t *__restrict __timer, |
126 | struct tm *__restrict __tp); | |
20aa5819 PE |
127 | libc_hidden_proto (__gmtime64_r) |
128 | ||
129 | extern __time64_t __timegm64 (struct tm *__tp) __THROW; | |
130 | libc_hidden_proto (__timegm64) | |
a1d346ce AA |
131 | #endif |
132 | ||
7ce198e1 LM |
133 | #if __TIMESIZE == 64 |
134 | # define __clock_settime64 __clock_settime | |
135 | #else | |
136 | extern int __clock_settime64 (clockid_t clock_id, | |
137 | const struct __timespec64 *tp); | |
138 | libc_hidden_proto (__clock_settime64) | |
139 | #endif | |
140 | ||
177a3d48 LM |
141 | #if __TIMESIZE == 64 |
142 | # define __clock_getres64 __clock_getres | |
143 | #else | |
144 | extern int __clock_getres64 (clockid_t clock_id, | |
145 | struct __timespec64 *tp); | |
146 | libc_hidden_proto (__clock_getres64); | |
147 | #endif | |
148 | ||
f5b6fd25 LM |
149 | #if __TIMESIZE == 64 |
150 | # define __utimensat64 __utimensat | |
151 | #else | |
152 | extern int __utimensat64 (int fd, const char *file, | |
153 | const struct __timespec64 tsp[2], int flags); | |
154 | libc_hidden_proto (__utimensat64); | |
155 | #endif | |
156 | ||
157 | extern int __utimensat64_helper (int fd, const char *file, | |
158 | const struct __timespec64 tsp[2], int flags); | |
159 | libc_hidden_proto (__utimensat64_helper); | |
160 | ||
42893aa3 LM |
161 | #if __TIMESIZE == 64 |
162 | # define __futimens64 __futimens | |
163 | #else | |
164 | extern int __futimens64 (int fd, const struct __timespec64 tsp[2]); | |
165 | libc_hidden_proto (__futimens64); | |
166 | #endif | |
167 | ||
72b8692d | 168 | /* Compute the `struct tm' representation of T, |
bdbf022d UD |
169 | offset OFFSET seconds east of UTC, |
170 | and store year, yday, mon, mday, wday, hour, min, sec into *TP. | |
171 | Return nonzero if successful. */ | |
72b8692d | 172 | extern int __offtime (__time64_t __timer, |
fe559c5e | 173 | long int __offset, |
b0f56784 | 174 | struct tm *__tp) attribute_hidden; |
bdbf022d | 175 | |
b0f56784 L |
176 | extern char *__asctime_r (const struct tm *__tp, char *__buf) |
177 | attribute_hidden; | |
178 | extern void __tzset (void) attribute_hidden; | |
bdbf022d | 179 | |
8632b240 | 180 | /* Prototype for the internal function to get information based on TZ. */ |
72b8692d | 181 | extern struct tm *__tz_convert (__time64_t timer, int use_localtime, |
b0f56784 | 182 | struct tm *tp) attribute_hidden; |
8632b240 | 183 | |
a784e502 | 184 | extern int __nanosleep (const struct timespec *__requested_time, |
c19559b0 | 185 | struct timespec *__remaining); |
fa872e1b | 186 | hidden_proto (__nanosleep) |
b0f56784 L |
187 | extern int __getdate_r (const char *__string, struct tm *__resbufp) |
188 | attribute_hidden; | |
25b3dd49 UD |
189 | |
190 | ||
191 | /* Determine CLK_TCK value. */ | |
b0f56784 | 192 | extern int __getclktck (void) attribute_hidden; |
4165d44d UD |
193 | |
194 | ||
ccadf7b5 | 195 | /* strptime support. */ |
ccadf7b5 | 196 | extern char * __strptime_internal (const char *rp, const char *fmt, |
fa69dc9c | 197 | struct tm *tm, void *statep, |
8bcdb7e0 | 198 | locale_t locparam) attribute_hidden; |
ccadf7b5 | 199 | |
ac253355 AA |
200 | #if __TIMESIZE == 64 |
201 | # define __difftime64 __difftime | |
202 | #else | |
203 | extern double __difftime64 (__time64_t time1, __time64_t time0); | |
204 | libc_hidden_proto (__difftime64) | |
205 | #endif | |
206 | ||
abca9f7f | 207 | extern double __difftime (time_t time1, time_t time0); |
ccadf7b5 UD |
208 | |
209 | ||
4165d44d UD |
210 | /* Use in the clock_* functions. Size of the field representing the |
211 | actual clock ID. */ | |
31341567 | 212 | #define CLOCK_IDFIELD_SIZE 3 |
7735afa2 | 213 | |
20aa5819 PE |
214 | /* Check whether T fits in time_t. */ |
215 | static inline bool | |
216 | in_time_t_range (__time64_t t) | |
217 | { | |
218 | time_t s = t; | |
219 | return s == t; | |
220 | } | |
221 | ||
9c44c6a9 LM |
222 | /* Convert a known valid struct timeval into a struct __timespec64. */ |
223 | static inline struct __timespec64 | |
224 | valid_timeval_to_timespec64 (const struct timeval tv) | |
225 | { | |
226 | struct __timespec64 ts64; | |
227 | ||
228 | ts64.tv_sec = tv.tv_sec; | |
229 | ts64.tv_nsec = tv.tv_usec * 1000; | |
230 | ||
231 | return ts64; | |
232 | } | |
233 | ||
234 | /* Convert a known valid struct timespec into a struct __timespec64. */ | |
235 | static inline struct __timespec64 | |
236 | valid_timespec_to_timespec64 (const struct timespec ts) | |
237 | { | |
238 | struct __timespec64 ts64; | |
239 | ||
240 | ts64.tv_sec = ts.tv_sec; | |
241 | ts64.tv_nsec = ts.tv_nsec; | |
242 | ||
243 | return ts64; | |
244 | } | |
245 | ||
246 | /* Convert a valid and within range of struct timespec, struct | |
247 | __timespec64 into a struct timespec. */ | |
248 | static inline struct timespec | |
249 | valid_timespec64_to_timespec (const struct __timespec64 ts64) | |
250 | { | |
251 | struct timespec ts; | |
252 | ||
253 | ts.tv_sec = (time_t) ts64.tv_sec; | |
254 | ts.tv_nsec = ts64.tv_nsec; | |
255 | ||
256 | return ts; | |
257 | } | |
258 | ||
259 | /* Convert a valid and within range of struct timeval struct | |
260 | __timespec64 into a struct timeval. */ | |
261 | static inline struct timeval | |
262 | valid_timespec64_to_timeval (const struct __timespec64 ts64) | |
263 | { | |
264 | struct timeval tv; | |
265 | ||
266 | tv.tv_sec = (time_t) ts64.tv_sec; | |
267 | tv.tv_usec = ts64.tv_nsec / 1000; | |
268 | ||
269 | return tv; | |
270 | } | |
48123656 LM |
271 | |
272 | /* Check if a value is in the valid nanoseconds range. Return true if | |
273 | it is, false otherwise. */ | |
274 | static inline bool | |
275 | valid_nanoseconds (__syscall_slong_t ns) | |
276 | { | |
277 | return __glibc_likely (0 <= ns && ns < 1000000000); | |
278 | } | |
f9a75540 AZ |
279 | |
280 | /* Helper function to get time in seconds, similar to time. */ | |
281 | static inline time_t | |
282 | time_now (void) | |
283 | { | |
284 | struct timespec ts; | |
285 | __clock_gettime (TIME_CLOCK_GETTIME_CLOCKID, &ts); | |
286 | return ts.tv_sec; | |
287 | } | |
bdbf022d | 288 | #endif |
f9a75540 | 289 | |
6796bc80 | 290 | #endif |