]> git.ipfire.org Git - thirdparty/glibc.git/blob - include/time.h
9878c2b2cac23931a6b3800a58e2f06ec0ac8316
[thirdparty/glibc.git] / include / time.h
1 #ifndef _TIME_H
2 #include <time/time.h>
3
4 #ifndef _ISOMAC
5 # include <bits/types/locale_t.h>
6 # include <stdbool.h>
7 # include <time/mktime-internal.h>
8 # include <endian.h>
9
10 extern __typeof (strftime_l) __strftime_l;
11 libc_hidden_proto (__strftime_l)
12 extern __typeof (strptime_l) __strptime_l;
13
14 libc_hidden_proto (time)
15 libc_hidden_proto (asctime)
16 libc_hidden_proto (mktime)
17 libc_hidden_proto (timelocal)
18 libc_hidden_proto (localtime)
19 libc_hidden_proto (strftime)
20 libc_hidden_proto (strptime)
21
22 extern __typeof (clock_gettime) __clock_gettime;
23 libc_hidden_proto (__clock_gettime)
24 extern __typeof (clock_settime) __clock_settime;
25 libc_hidden_proto (__clock_settime)
26
27 /* Now define the internal interfaces. */
28 struct tm;
29
30 /* Defined in mktime.c. */
31 extern const unsigned short int __mon_yday[2][13] attribute_hidden;
32
33 /* Defined in localtime.c. */
34 extern struct tm _tmbuf attribute_hidden;
35
36 /* Defined in tzset.c. */
37 extern char *__tzstring (const char *string) attribute_hidden;
38
39 extern int __use_tzfile attribute_hidden;
40
41 extern void __tzfile_read (const char *file, size_t extra,
42 char **extrap) attribute_hidden;
43 extern void __tzfile_compute (__time64_t timer, int use_localtime,
44 long int *leap_correct, int *leap_hit,
45 struct tm *tp) attribute_hidden;
46 extern void __tzfile_default (const char *std, const char *dst,
47 int stdoff, int dstoff)
48 attribute_hidden;
49 extern void __tzset_parse_tz (const char *tz) attribute_hidden;
50 extern void __tz_compute (__time64_t timer, struct tm *tm, int use_localtime)
51 __THROW attribute_hidden;
52
53 #if __TIMESIZE == 64
54 # define __timespec64 timespec
55 #else
56 /* The glibc Y2038-proof struct __timespec64 structure for a time value.
57 To keep things Posix-ish, we keep the nanoseconds field a 32-bit
58 signed long, but since the Linux field is a 64-bit signed int, we
59 pad our tv_nsec with a 32-bit unnamed bit-field padding.
60
61 As a general rule the Linux kernel is ignoring upper 32 bits of
62 tv_nsec field. */
63 struct __timespec64
64 {
65 __time64_t tv_sec; /* Seconds */
66 # if BYTE_ORDER == BIG_ENDIAN
67 __int32_t :32; /* Padding */
68 __int32_t tv_nsec; /* Nanoseconds */
69 # else
70 __int32_t tv_nsec; /* Nanoseconds */
71 __int32_t :32; /* Padding */
72 # endif
73 };
74 #endif
75
76 #if __TIMESIZE == 64
77 # define __ctime64 ctime
78 #else
79 extern char *__ctime64 (const __time64_t *__timer) __THROW;
80 libc_hidden_proto (__ctime64)
81 #endif
82
83 #if __TIMESIZE == 64
84 # define __ctime64_r ctime_r
85 #else
86 extern char *__ctime64_r (const __time64_t *__restrict __timer,
87 char *__restrict __buf) __THROW;
88 libc_hidden_proto (__ctime64_r)
89 #endif
90
91 #if __TIMESIZE == 64
92 # define __localtime64 localtime
93 #else
94 extern struct tm *__localtime64 (const __time64_t *__timer);
95 libc_hidden_proto (__localtime64)
96 #endif
97
98 extern struct tm *__localtime_r (const time_t *__timer,
99 struct tm *__tp) attribute_hidden;
100 #if __TIMESIZE != 64
101 extern struct tm *__localtime64_r (const __time64_t *__timer,
102 struct tm *__tp);
103 libc_hidden_proto (__localtime64_r)
104
105 extern __time64_t __mktime64 (struct tm *__tp) __THROW;
106 libc_hidden_proto (__mktime64)
107 #endif
108
109 extern struct tm *__gmtime_r (const time_t *__restrict __timer,
110 struct tm *__restrict __tp);
111 libc_hidden_proto (__gmtime_r)
112
113 #if __TIMESIZE == 64
114 # define __gmtime64 gmtime
115 #else
116 extern struct tm *__gmtime64 (const __time64_t *__timer);
117 libc_hidden_proto (__gmtime64)
118
119 extern struct tm *__gmtime64_r (const __time64_t *__restrict __timer,
120 struct tm *__restrict __tp);
121 libc_hidden_proto (__gmtime64_r)
122
123 extern __time64_t __timegm64 (struct tm *__tp) __THROW;
124 libc_hidden_proto (__timegm64)
125 #endif
126
127 /* Compute the `struct tm' representation of T,
128 offset OFFSET seconds east of UTC,
129 and store year, yday, mon, mday, wday, hour, min, sec into *TP.
130 Return nonzero if successful. */
131 extern int __offtime (__time64_t __timer,
132 long int __offset,
133 struct tm *__tp) attribute_hidden;
134
135 extern char *__asctime_r (const struct tm *__tp, char *__buf)
136 attribute_hidden;
137 extern void __tzset (void) attribute_hidden;
138
139 /* Prototype for the internal function to get information based on TZ. */
140 extern struct tm *__tz_convert (__time64_t timer, int use_localtime,
141 struct tm *tp) attribute_hidden;
142
143 extern int __nanosleep (const struct timespec *__requested_time,
144 struct timespec *__remaining);
145 hidden_proto (__nanosleep)
146 extern int __getdate_r (const char *__string, struct tm *__resbufp)
147 attribute_hidden;
148
149
150 /* Determine CLK_TCK value. */
151 extern int __getclktck (void) attribute_hidden;
152
153
154 /* strptime support. */
155 extern char * __strptime_internal (const char *rp, const char *fmt,
156 struct tm *tm, void *statep,
157 locale_t locparam) attribute_hidden;
158
159 #if __TIMESIZE == 64
160 # define __difftime64 __difftime
161 #else
162 extern double __difftime64 (__time64_t time1, __time64_t time0);
163 libc_hidden_proto (__difftime64)
164 #endif
165
166 extern double __difftime (time_t time1, time_t time0);
167
168
169 /* Use in the clock_* functions. Size of the field representing the
170 actual clock ID. */
171 #define CLOCK_IDFIELD_SIZE 3
172
173 /* Check whether T fits in time_t. */
174 static inline bool
175 in_time_t_range (__time64_t t)
176 {
177 time_t s = t;
178 return s == t;
179 }
180
181 /* Convert a known valid struct timeval into a struct __timespec64. */
182 static inline struct __timespec64
183 valid_timeval_to_timespec64 (const struct timeval tv)
184 {
185 struct __timespec64 ts64;
186
187 ts64.tv_sec = tv.tv_sec;
188 ts64.tv_nsec = tv.tv_usec * 1000;
189
190 return ts64;
191 }
192
193 /* Convert a known valid struct timespec into a struct __timespec64. */
194 static inline struct __timespec64
195 valid_timespec_to_timespec64 (const struct timespec ts)
196 {
197 struct __timespec64 ts64;
198
199 ts64.tv_sec = ts.tv_sec;
200 ts64.tv_nsec = ts.tv_nsec;
201
202 return ts64;
203 }
204
205 /* Convert a valid and within range of struct timespec, struct
206 __timespec64 into a struct timespec. */
207 static inline struct timespec
208 valid_timespec64_to_timespec (const struct __timespec64 ts64)
209 {
210 struct timespec ts;
211
212 ts.tv_sec = (time_t) ts64.tv_sec;
213 ts.tv_nsec = ts64.tv_nsec;
214
215 return ts;
216 }
217
218 /* Convert a valid and within range of struct timeval struct
219 __timespec64 into a struct timeval. */
220 static inline struct timeval
221 valid_timespec64_to_timeval (const struct __timespec64 ts64)
222 {
223 struct timeval tv;
224
225 tv.tv_sec = (time_t) ts64.tv_sec;
226 tv.tv_usec = ts64.tv_nsec / 1000;
227
228 return tv;
229 }
230 #endif
231 #endif