]> git.ipfire.org Git - thirdparty/glibc.git/blame - include/time.h
y2038: linux: Provide __futimens64 implementation
[thirdparty/glibc.git] / include / time.h
CommitLineData
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 12extern __typeof (strftime_l) __strftime_l;
ee2a5ae8 13libc_hidden_proto (__strftime_l)
da4cfe38
RM
14extern __typeof (strptime_l) __strptime_l;
15
c5598d47
RM
16libc_hidden_proto (asctime)
17libc_hidden_proto (mktime)
18libc_hidden_proto (timelocal)
19libc_hidden_proto (localtime)
20libc_hidden_proto (strftime)
21libc_hidden_proto (strptime)
22
6e6249d0 23extern __typeof (clock_gettime) __clock_gettime;
89fb6835 24libc_hidden_proto (__clock_gettime)
6e6249d0 25extern __typeof (clock_settime) __clock_settime;
7b5af2d8 26libc_hidden_proto (__clock_settime)
a9564ae9 27
c81aa64e
AZ
28#ifdef __linux__
29extern __typeof (clock_adjtime) __clock_adjtime;
30libc_hidden_proto (__clock_adjtime);
31#endif
32
bdbf022d
UD
33/* Now define the internal interfaces. */
34struct tm;
35
8632b240 36/* Defined in mktime.c. */
ab26a24a 37extern const unsigned short int __mon_yday[2][13] attribute_hidden;
8632b240
UD
38
39/* Defined in localtime.c. */
418f1701 40extern struct tm _tmbuf attribute_hidden;
8632b240
UD
41
42/* Defined in tzset.c. */
b0f56784 43extern char *__tzstring (const char *string) attribute_hidden;
8632b240 44
418f1701 45extern int __use_tzfile attribute_hidden;
8632b240 46
fe559c5e 47extern void __tzfile_read (const char *file, size_t extra,
b0f56784 48 char **extrap) attribute_hidden;
d51f99ce 49extern 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 52extern void __tzfile_default (const char *std, const char *dst,
77c7d55e 53 int stdoff, int dstoff)
b0f56784
L
54 attribute_hidden;
55extern void __tzset_parse_tz (const char *tz) attribute_hidden;
72b8692d 56extern 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. */
69struct __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
85extern char *__ctime64 (const __time64_t *__timer) __THROW;
20aa5819 86libc_hidden_proto (__ctime64)
7755e504
AA
87#endif
88
c4c2836a
AA
89#if __TIMESIZE == 64
90# define __ctime64_r ctime_r
91#else
92extern char *__ctime64_r (const __time64_t *__restrict __timer,
93 char *__restrict __buf) __THROW;
20aa5819 94libc_hidden_proto (__ctime64_r)
c4c2836a
AA
95#endif
96
6e15f3e2
AA
97#if __TIMESIZE == 64
98# define __localtime64 localtime
99#else
100extern struct tm *__localtime64 (const __time64_t *__timer);
101libc_hidden_proto (__localtime64)
102#endif
103
a784e502 104extern struct tm *__localtime_r (const time_t *__timer,
dff07c4b 105 struct tm *__tp) attribute_hidden;
20aa5819 106#if __TIMESIZE != 64
64c2277d
AA
107extern struct tm *__localtime64_r (const __time64_t *__timer,
108 struct tm *__tp);
109libc_hidden_proto (__localtime64_r)
20aa5819
PE
110
111extern __time64_t __mktime64 (struct tm *__tp) __THROW;
112libc_hidden_proto (__mktime64)
64c2277d
AA
113#endif
114
a784e502 115extern struct tm *__gmtime_r (const time_t *__restrict __timer,
c19559b0 116 struct tm *__restrict __tp);
230491f0 117libc_hidden_proto (__gmtime_r)
811ba236 118
131db8b0
AA
119#if __TIMESIZE == 64
120# define __gmtime64 gmtime
121#else
122extern struct tm *__gmtime64 (const __time64_t *__timer);
123libc_hidden_proto (__gmtime64)
131db8b0 124
a1d346ce
AA
125extern struct tm *__gmtime64_r (const __time64_t *__restrict __timer,
126 struct tm *__restrict __tp);
20aa5819
PE
127libc_hidden_proto (__gmtime64_r)
128
129extern __time64_t __timegm64 (struct tm *__tp) __THROW;
130libc_hidden_proto (__timegm64)
a1d346ce
AA
131#endif
132
7ce198e1
LM
133#if __TIMESIZE == 64
134# define __clock_settime64 __clock_settime
135#else
136extern int __clock_settime64 (clockid_t clock_id,
137 const struct __timespec64 *tp);
138libc_hidden_proto (__clock_settime64)
139#endif
140
177a3d48
LM
141#if __TIMESIZE == 64
142# define __clock_getres64 __clock_getres
143#else
144extern int __clock_getres64 (clockid_t clock_id,
145 struct __timespec64 *tp);
146libc_hidden_proto (__clock_getres64);
147#endif
148
f5b6fd25
LM
149#if __TIMESIZE == 64
150# define __utimensat64 __utimensat
151#else
152extern int __utimensat64 (int fd, const char *file,
153 const struct __timespec64 tsp[2], int flags);
154libc_hidden_proto (__utimensat64);
155#endif
156
157extern int __utimensat64_helper (int fd, const char *file,
158 const struct __timespec64 tsp[2], int flags);
159libc_hidden_proto (__utimensat64_helper);
160
42893aa3
LM
161#if __TIMESIZE == 64
162# define __futimens64 __futimens
163#else
164extern int __futimens64 (int fd, const struct __timespec64 tsp[2]);
165libc_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 172extern int __offtime (__time64_t __timer,
fe559c5e 173 long int __offset,
b0f56784 174 struct tm *__tp) attribute_hidden;
bdbf022d 175
b0f56784
L
176extern char *__asctime_r (const struct tm *__tp, char *__buf)
177 attribute_hidden;
178extern void __tzset (void) attribute_hidden;
bdbf022d 179
8632b240 180/* Prototype for the internal function to get information based on TZ. */
72b8692d 181extern struct tm *__tz_convert (__time64_t timer, int use_localtime,
b0f56784 182 struct tm *tp) attribute_hidden;
8632b240 183
a784e502 184extern int __nanosleep (const struct timespec *__requested_time,
c19559b0 185 struct timespec *__remaining);
fa872e1b 186hidden_proto (__nanosleep)
b0f56784
L
187extern int __getdate_r (const char *__string, struct tm *__resbufp)
188 attribute_hidden;
25b3dd49
UD
189
190
191/* Determine CLK_TCK value. */
b0f56784 192extern int __getclktck (void) attribute_hidden;
4165d44d
UD
193
194
ccadf7b5 195/* strptime support. */
ccadf7b5 196extern 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
203extern double __difftime64 (__time64_t time1, __time64_t time0);
204libc_hidden_proto (__difftime64)
205#endif
206
abca9f7f 207extern 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. */
215static inline bool
216in_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. */
223static inline struct __timespec64
224valid_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. */
235static inline struct __timespec64
236valid_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. */
248static inline struct timespec
249valid_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. */
261static inline struct timeval
262valid_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. */
274static inline bool
275valid_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. */
281static inline time_t
282time_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