Commit | Line | Data |
---|---|---|
e65fc94b LC |
1 | /* A more-standard <time.h>. |
2 | ||
5e69ceb7 | 3 | Copyright (C) 2007-2014 Free Software Foundation, Inc. |
e65fc94b LC |
4 | |
5 | This program is free software; you can redistribute it and/or modify | |
6 | it under the terms of the GNU Lesser General Public License as published by | |
7 | the Free Software Foundation; either version 2, or (at your option) | |
8 | any later version. | |
9 | ||
10 | This program is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | GNU Lesser General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU Lesser General Public License | |
005de2e8 | 16 | along with this program; if not, see <http://www.gnu.org/licenses/>. */ |
e65fc94b | 17 | |
aa7a939c | 18 | #if __GNUC__ >= 3 |
e65fc94b | 19 | @PRAGMA_SYSTEM_HEADER@ |
aa7a939c | 20 | #endif |
0f00f2c3 | 21 | @PRAGMA_COLUMNS@ |
e65fc94b LC |
22 | |
23 | /* Don't get in the way of glibc when it includes time.h merely to | |
24 | declare a few standard symbols, rather than to declare all the | |
25 | symbols. Also, Solaris 8 <time.h> eventually includes itself | |
26 | recursively; if that is happening, just include the system <time.h> | |
27 | without adding our own declarations. */ | |
28 | #if (defined __need_time_t || defined __need_clock_t \ | |
29 | || defined __need_timespec \ | |
3d458a81 | 30 | || defined _@GUARD_PREFIX@_TIME_H) |
e65fc94b LC |
31 | |
32 | # @INCLUDE_NEXT@ @NEXT_TIME_H@ | |
33 | ||
34 | #else | |
35 | ||
3d458a81 | 36 | # define _@GUARD_PREFIX@_TIME_H |
e65fc94b LC |
37 | |
38 | # @INCLUDE_NEXT@ @NEXT_TIME_H@ | |
39 | ||
8912421c | 40 | /* NetBSD 5.0 mis-defines NULL. */ |
a927b6c1 | 41 | # include <stddef.h> |
8912421c | 42 | |
f4c79b3c LC |
43 | /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ |
44 | ||
1cd4fffc LC |
45 | /* The definition of _GL_ARG_NONNULL is copied here. */ |
46 | ||
f4c79b3c LC |
47 | /* The definition of _GL_WARN_ON_USE is copied here. */ |
48 | ||
e65fc94b LC |
49 | /* Some systems don't define struct timespec (e.g., AIX 4.1, Ultrix 4.3). |
50 | Or they define it with the wrong member names or define it in <sys/time.h> | |
5e69ceb7 MW |
51 | (e.g., FreeBSD circa 1997). Stock Mingw prior to 3.0 does not define it, |
52 | but the pthreads-win32 library defines it in <pthread.h>. */ | |
e65fc94b LC |
53 | # if ! @TIME_H_DEFINES_STRUCT_TIMESPEC@ |
54 | # if @SYS_TIME_H_DEFINES_STRUCT_TIMESPEC@ | |
55 | # include <sys/time.h> | |
6f32e5c7 LC |
56 | # elif @PTHREAD_H_DEFINES_STRUCT_TIMESPEC@ |
57 | # include <pthread.h> | |
e65fc94b | 58 | # else |
a927b6c1 LC |
59 | |
60 | # ifdef __cplusplus | |
61 | extern "C" { | |
62 | # endif | |
63 | ||
49114fd4 LC |
64 | # if !GNULIB_defined_struct_timespec |
65 | # undef timespec | |
66 | # define timespec rpl_timespec | |
e65fc94b LC |
67 | struct timespec |
68 | { | |
69 | time_t tv_sec; | |
70 | long int tv_nsec; | |
71 | }; | |
49114fd4 LC |
72 | # define GNULIB_defined_struct_timespec 1 |
73 | # endif | |
e65fc94b | 74 | |
a927b6c1 | 75 | # ifdef __cplusplus |
f4c79b3c | 76 | } |
a927b6c1 LC |
77 | # endif |
78 | ||
79 | # endif | |
f4c79b3c LC |
80 | # endif |
81 | ||
49114fd4 | 82 | # if !GNULIB_defined_struct_time_t_must_be_integral |
0f00f2c3 LC |
83 | /* Per http://austingroupbugs.net/view.php?id=327, POSIX requires |
84 | time_t to be an integer type, even though C99 permits floating | |
85 | point. We don't know of any implementation that uses floating | |
86 | point, and it is much easier to write code that doesn't have to | |
87 | worry about that corner case, so we force the issue. */ | |
88 | struct __time_t_must_be_integral { | |
89 | unsigned int __floating_time_t_unsupported : (time_t) 1; | |
90 | }; | |
49114fd4 LC |
91 | # define GNULIB_defined_struct_time_t_must_be_integral 1 |
92 | # endif | |
0f00f2c3 | 93 | |
e65fc94b LC |
94 | /* Sleep for at least RQTP seconds unless interrupted, If interrupted, |
95 | return -1 and store the remaining time into RMTP. See | |
96 | <http://www.opengroup.org/susv3xsh/nanosleep.html>. */ | |
f4c79b3c LC |
97 | # if @GNULIB_NANOSLEEP@ |
98 | # if @REPLACE_NANOSLEEP@ | |
99 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | |
100 | # define nanosleep rpl_nanosleep | |
101 | # endif | |
102 | _GL_FUNCDECL_RPL (nanosleep, int, | |
103 | (struct timespec const *__rqtp, struct timespec *__rmtp) | |
104 | _GL_ARG_NONNULL ((1))); | |
105 | _GL_CXXALIAS_RPL (nanosleep, int, | |
106 | (struct timespec const *__rqtp, struct timespec *__rmtp)); | |
107 | # else | |
a927b6c1 LC |
108 | # if ! @HAVE_NANOSLEEP@ |
109 | _GL_FUNCDECL_SYS (nanosleep, int, | |
110 | (struct timespec const *__rqtp, struct timespec *__rmtp) | |
111 | _GL_ARG_NONNULL ((1))); | |
112 | # endif | |
f4c79b3c LC |
113 | _GL_CXXALIAS_SYS (nanosleep, int, |
114 | (struct timespec const *__rqtp, struct timespec *__rmtp)); | |
115 | # endif | |
116 | _GL_CXXALIASWARN (nanosleep); | |
e65fc94b LC |
117 | # endif |
118 | ||
25361e4b | 119 | /* Return the 'time_t' representation of TP and normalize TP. */ |
f4c79b3c LC |
120 | # if @GNULIB_MKTIME@ |
121 | # if @REPLACE_MKTIME@ | |
122 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | |
123 | # define mktime rpl_mktime | |
124 | # endif | |
125 | _GL_FUNCDECL_RPL (mktime, time_t, (struct tm *__tp) _GL_ARG_NONNULL ((1))); | |
126 | _GL_CXXALIAS_RPL (mktime, time_t, (struct tm *__tp)); | |
127 | # else | |
128 | _GL_CXXALIAS_SYS (mktime, time_t, (struct tm *__tp)); | |
129 | # endif | |
130 | _GL_CXXALIASWARN (mktime); | |
25361e4b LC |
131 | # endif |
132 | ||
e65fc94b LC |
133 | /* Convert TIMER to RESULT, assuming local time and UTC respectively. See |
134 | <http://www.opengroup.org/susv3xsh/localtime_r.html> and | |
135 | <http://www.opengroup.org/susv3xsh/gmtime_r.html>. */ | |
f4c79b3c LC |
136 | # if @GNULIB_TIME_R@ |
137 | # if @REPLACE_LOCALTIME_R@ | |
138 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | |
139 | # undef localtime_r | |
140 | # define localtime_r rpl_localtime_r | |
141 | # endif | |
142 | _GL_FUNCDECL_RPL (localtime_r, struct tm *, (time_t const *restrict __timer, | |
143 | struct tm *restrict __result) | |
144 | _GL_ARG_NONNULL ((1, 2))); | |
145 | _GL_CXXALIAS_RPL (localtime_r, struct tm *, (time_t const *restrict __timer, | |
146 | struct tm *restrict __result)); | |
147 | # else | |
49114fd4 | 148 | # if ! @HAVE_DECL_LOCALTIME_R@ |
a927b6c1 LC |
149 | _GL_FUNCDECL_SYS (localtime_r, struct tm *, (time_t const *restrict __timer, |
150 | struct tm *restrict __result) | |
151 | _GL_ARG_NONNULL ((1, 2))); | |
152 | # endif | |
f4c79b3c LC |
153 | _GL_CXXALIAS_SYS (localtime_r, struct tm *, (time_t const *restrict __timer, |
154 | struct tm *restrict __result)); | |
155 | # endif | |
49114fd4 | 156 | # if @HAVE_DECL_LOCALTIME_R@ |
f4c79b3c | 157 | _GL_CXXALIASWARN (localtime_r); |
49114fd4 | 158 | # endif |
f4c79b3c LC |
159 | # if @REPLACE_LOCALTIME_R@ |
160 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | |
161 | # undef gmtime_r | |
162 | # define gmtime_r rpl_gmtime_r | |
163 | # endif | |
164 | _GL_FUNCDECL_RPL (gmtime_r, struct tm *, (time_t const *restrict __timer, | |
165 | struct tm *restrict __result) | |
166 | _GL_ARG_NONNULL ((1, 2))); | |
167 | _GL_CXXALIAS_RPL (gmtime_r, struct tm *, (time_t const *restrict __timer, | |
168 | struct tm *restrict __result)); | |
169 | # else | |
49114fd4 | 170 | # if ! @HAVE_DECL_LOCALTIME_R@ |
a927b6c1 LC |
171 | _GL_FUNCDECL_SYS (gmtime_r, struct tm *, (time_t const *restrict __timer, |
172 | struct tm *restrict __result) | |
173 | _GL_ARG_NONNULL ((1, 2))); | |
174 | # endif | |
f4c79b3c LC |
175 | _GL_CXXALIAS_SYS (gmtime_r, struct tm *, (time_t const *restrict __timer, |
176 | struct tm *restrict __result)); | |
177 | # endif | |
49114fd4 | 178 | # if @HAVE_DECL_LOCALTIME_R@ |
f4c79b3c | 179 | _GL_CXXALIASWARN (gmtime_r); |
49114fd4 | 180 | # endif |
e65fc94b LC |
181 | # endif |
182 | ||
5e69ceb7 MW |
183 | /* Convert TIMER to RESULT, assuming local time and UTC respectively. See |
184 | <http://www.opengroup.org/susv3xsh/localtime.html> and | |
185 | <http://www.opengroup.org/susv3xsh/gmtime.html>. */ | |
186 | # if @GNULIB_GETTIMEOFDAY@ | |
187 | # if @REPLACE_LOCALTIME@ | |
188 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | |
189 | # undef localtime | |
190 | # define localtime rpl_localtime | |
191 | # endif | |
192 | _GL_FUNCDECL_RPL (localtime, struct tm *, (time_t const *__timer) | |
193 | _GL_ARG_NONNULL ((1))); | |
194 | _GL_CXXALIAS_RPL (localtime, struct tm *, (time_t const *__timer)); | |
195 | # else | |
196 | _GL_CXXALIAS_SYS (localtime, struct tm *, (time_t const *__timer)); | |
197 | # endif | |
198 | _GL_CXXALIASWARN (localtime); | |
199 | # endif | |
200 | ||
201 | # if @GNULIB_GETTIMEOFDAY@ | |
202 | # if @REPLACE_GMTIME@ | |
203 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | |
204 | # undef gmtime | |
205 | # define gmtime rpl_gmtime | |
206 | # endif | |
207 | _GL_FUNCDECL_RPL (gmtime, struct tm *, (time_t const *__timer) | |
208 | _GL_ARG_NONNULL ((1))); | |
209 | _GL_CXXALIAS_RPL (gmtime, struct tm *, (time_t const *__timer)); | |
210 | # else | |
211 | _GL_CXXALIAS_SYS (gmtime, struct tm *, (time_t const *__timer)); | |
212 | # endif | |
213 | _GL_CXXALIASWARN (gmtime); | |
214 | # endif | |
215 | ||
e65fc94b LC |
216 | /* Parse BUF as a time stamp, assuming FORMAT specifies its layout, and store |
217 | the resulting broken-down time into TM. See | |
218 | <http://www.opengroup.org/susv3xsh/strptime.html>. */ | |
f4c79b3c | 219 | # if @GNULIB_STRPTIME@ |
a927b6c1 LC |
220 | # if ! @HAVE_STRPTIME@ |
221 | _GL_FUNCDECL_SYS (strptime, char *, (char const *restrict __buf, | |
f4c79b3c LC |
222 | char const *restrict __format, |
223 | struct tm *restrict __tm) | |
224 | _GL_ARG_NONNULL ((1, 2, 3))); | |
a927b6c1 | 225 | # endif |
f4c79b3c LC |
226 | _GL_CXXALIAS_SYS (strptime, char *, (char const *restrict __buf, |
227 | char const *restrict __format, | |
228 | struct tm *restrict __tm)); | |
f4c79b3c | 229 | _GL_CXXALIASWARN (strptime); |
e65fc94b LC |
230 | # endif |
231 | ||
232 | /* Convert TM to a time_t value, assuming UTC. */ | |
f4c79b3c LC |
233 | # if @GNULIB_TIMEGM@ |
234 | # if @REPLACE_TIMEGM@ | |
235 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | |
236 | # undef timegm | |
237 | # define timegm rpl_timegm | |
238 | # endif | |
239 | _GL_FUNCDECL_RPL (timegm, time_t, (struct tm *__tm) _GL_ARG_NONNULL ((1))); | |
240 | _GL_CXXALIAS_RPL (timegm, time_t, (struct tm *__tm)); | |
241 | # else | |
a927b6c1 LC |
242 | # if ! @HAVE_TIMEGM@ |
243 | _GL_FUNCDECL_SYS (timegm, time_t, (struct tm *__tm) _GL_ARG_NONNULL ((1))); | |
244 | # endif | |
f4c79b3c LC |
245 | _GL_CXXALIAS_SYS (timegm, time_t, (struct tm *__tm)); |
246 | # endif | |
247 | _GL_CXXALIASWARN (timegm); | |
e65fc94b LC |
248 | # endif |
249 | ||
250 | /* Encourage applications to avoid unsafe functions that can overrun | |
251 | buffers when given outlandish struct tm values. Portable | |
252 | applications should use strftime (or even sprintf) instead. */ | |
a927b6c1 | 253 | # if defined GNULIB_POSIXCHECK |
e65fc94b | 254 | # undef asctime |
a927b6c1 LC |
255 | _GL_WARN_ON_USE (asctime, "asctime can overrun buffers in some cases - " |
256 | "better use strftime (or even sprintf) instead"); | |
257 | # endif | |
258 | # if defined GNULIB_POSIXCHECK | |
e65fc94b | 259 | # undef asctime_r |
a927b6c1 LC |
260 | _GL_WARN_ON_USE (asctime, "asctime_r can overrun buffers in some cases - " |
261 | "better use strftime (or even sprintf) instead"); | |
262 | # endif | |
263 | # if defined GNULIB_POSIXCHECK | |
e65fc94b | 264 | # undef ctime |
a927b6c1 LC |
265 | _GL_WARN_ON_USE (asctime, "ctime can overrun buffers in some cases - " |
266 | "better use strftime (or even sprintf) instead"); | |
267 | # endif | |
268 | # if defined GNULIB_POSIXCHECK | |
e65fc94b | 269 | # undef ctime_r |
a927b6c1 LC |
270 | _GL_WARN_ON_USE (asctime, "ctime_r can overrun buffers in some cases - " |
271 | "better use strftime (or even sprintf) instead"); | |
e65fc94b LC |
272 | # endif |
273 | ||
e65fc94b | 274 | #endif |