1 /* A more-standard <time.h>.
3 Copyright (C) 2007-2016 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3, or (at your option)
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 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, see <http://www.gnu.org/licenses/>. */
19 @PRAGMA_SYSTEM_HEADER@
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. (However, skip this for MinGW as it treats __need_time_t
26 incompatibly.) Also, Solaris 8 <time.h> eventually includes itself
27 recursively; if that is happening, just include the system <time.h>
28 without adding our own declarations. */
29 #if (((defined __need_time_t || defined __need_clock_t \
30 || defined __need_timespec) \
31 && !defined __MINGW32__) \
32 || defined _@GUARD_PREFIX@_TIME_H)
34 # @INCLUDE_NEXT@ @NEXT_TIME_H@
38 # define _@GUARD_PREFIX@_TIME_H
40 # @INCLUDE_NEXT@ @NEXT_TIME_H@
42 /* NetBSD 5.0 mis-defines NULL. */
45 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
47 /* The definition of _GL_ARG_NONNULL is copied here. */
49 /* The definition of _GL_WARN_ON_USE is copied here. */
51 /* Some systems don't define struct timespec (e.g., AIX 4.1, Ultrix 4.3).
52 Or they define it with the wrong member names or define it in <sys/time.h>
53 (e.g., FreeBSD circa 1997). Stock Mingw prior to 3.0 does not define it,
54 but the pthreads-win32 library defines it in <pthread.h>. */
55 # if ! @TIME_H_DEFINES_STRUCT_TIMESPEC@
56 # if @SYS_TIME_H_DEFINES_STRUCT_TIMESPEC@
57 # include <sys/time.h>
58 # elif @PTHREAD_H_DEFINES_STRUCT_TIMESPEC@
60 # elif @UNISTD_H_DEFINES_STRUCT_TIMESPEC@
68 # if !GNULIB_defined_struct_timespec
70 # define timespec rpl_timespec
76 # define GNULIB_defined_struct_timespec 1
86 # if !GNULIB_defined_struct_time_t_must_be_integral
87 /* Per http://austingroupbugs.net/view.php?id=327, POSIX requires
88 time_t to be an integer type, even though C99 permits floating
89 point. We don't know of any implementation that uses floating
90 point, and it is much easier to write code that doesn't have to
91 worry about that corner case, so we force the issue. */
92 struct __time_t_must_be_integral
{
93 unsigned int __floating_time_t_unsupported
: (time_t) 1;
95 # define GNULIB_defined_struct_time_t_must_be_integral 1
98 /* Sleep for at least RQTP seconds unless interrupted, If interrupted,
99 return -1 and store the remaining time into RMTP. See
100 <http://www.opengroup.org/susv3xsh/nanosleep.html>. */
101 # if @GNULIB_NANOSLEEP@
102 # if @REPLACE_NANOSLEEP@
103 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
104 # define nanosleep rpl_nanosleep
106 _GL_FUNCDECL_RPL (nanosleep
, int,
107 (struct timespec
const *__rqtp
, struct timespec
*__rmtp
)
108 _GL_ARG_NONNULL ((1)));
109 _GL_CXXALIAS_RPL (nanosleep
, int,
110 (struct timespec
const *__rqtp
, struct timespec
*__rmtp
));
112 # if ! @HAVE_NANOSLEEP@
113 _GL_FUNCDECL_SYS (nanosleep
, int,
114 (struct timespec
const *__rqtp
, struct timespec
*__rmtp
)
115 _GL_ARG_NONNULL ((1)));
117 _GL_CXXALIAS_SYS (nanosleep
, int,
118 (struct timespec
const *__rqtp
, struct timespec
*__rmtp
));
120 _GL_CXXALIASWARN (nanosleep
);
123 /* Return the 'time_t' representation of TP and normalize TP. */
125 # if @REPLACE_MKTIME@
126 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
127 # define mktime rpl_mktime
129 _GL_FUNCDECL_RPL (mktime
, time_t, (struct tm
*__tp
) _GL_ARG_NONNULL ((1)));
130 _GL_CXXALIAS_RPL (mktime
, time_t, (struct tm
*__tp
));
132 _GL_CXXALIAS_SYS (mktime
, time_t, (struct tm
*__tp
));
134 _GL_CXXALIASWARN (mktime
);
137 /* Convert TIMER to RESULT, assuming local time and UTC respectively. See
138 <http://www.opengroup.org/susv3xsh/localtime_r.html> and
139 <http://www.opengroup.org/susv3xsh/gmtime_r.html>. */
141 # if @REPLACE_LOCALTIME_R@
142 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
144 # define localtime_r rpl_localtime_r
146 _GL_FUNCDECL_RPL (localtime_r
, struct tm
*, (time_t const *restrict __timer
,
147 struct tm
*restrict __result
)
148 _GL_ARG_NONNULL ((1, 2)));
149 _GL_CXXALIAS_RPL (localtime_r
, struct tm
*, (time_t const *restrict __timer
,
150 struct tm
*restrict __result
));
152 # if ! @HAVE_DECL_LOCALTIME_R@
153 _GL_FUNCDECL_SYS (localtime_r
, struct tm
*, (time_t const *restrict __timer
,
154 struct tm
*restrict __result
)
155 _GL_ARG_NONNULL ((1, 2)));
157 _GL_CXXALIAS_SYS (localtime_r
, struct tm
*, (time_t const *restrict __timer
,
158 struct tm
*restrict __result
));
160 # if @HAVE_DECL_LOCALTIME_R@
161 _GL_CXXALIASWARN (localtime_r
);
163 # if @REPLACE_LOCALTIME_R@
164 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
166 # define gmtime_r rpl_gmtime_r
168 _GL_FUNCDECL_RPL (gmtime_r
, struct tm
*, (time_t const *restrict __timer
,
169 struct tm
*restrict __result
)
170 _GL_ARG_NONNULL ((1, 2)));
171 _GL_CXXALIAS_RPL (gmtime_r
, struct tm
*, (time_t const *restrict __timer
,
172 struct tm
*restrict __result
));
174 # if ! @HAVE_DECL_LOCALTIME_R@
175 _GL_FUNCDECL_SYS (gmtime_r
, struct tm
*, (time_t const *restrict __timer
,
176 struct tm
*restrict __result
)
177 _GL_ARG_NONNULL ((1, 2)));
179 _GL_CXXALIAS_SYS (gmtime_r
, struct tm
*, (time_t const *restrict __timer
,
180 struct tm
*restrict __result
));
182 # if @HAVE_DECL_LOCALTIME_R@
183 _GL_CXXALIASWARN (gmtime_r
);
187 /* Convert TIMER to RESULT, assuming local time and UTC respectively. See
188 <http://www.opengroup.org/susv3xsh/localtime.html> and
189 <http://www.opengroup.org/susv3xsh/gmtime.html>. */
190 # if @GNULIB_GETTIMEOFDAY@
191 # if @REPLACE_LOCALTIME@
192 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
194 # define localtime rpl_localtime
196 _GL_FUNCDECL_RPL (localtime
, struct tm
*, (time_t const *__timer
)
197 _GL_ARG_NONNULL ((1)));
198 _GL_CXXALIAS_RPL (localtime
, struct tm
*, (time_t const *__timer
));
200 _GL_CXXALIAS_SYS (localtime
, struct tm
*, (time_t const *__timer
));
202 _GL_CXXALIASWARN (localtime
);
205 # if @GNULIB_GETTIMEOFDAY@
206 # if @REPLACE_GMTIME@
207 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
209 # define gmtime rpl_gmtime
211 _GL_FUNCDECL_RPL (gmtime
, struct tm
*, (time_t const *__timer
)
212 _GL_ARG_NONNULL ((1)));
213 _GL_CXXALIAS_RPL (gmtime
, struct tm
*, (time_t const *__timer
));
215 _GL_CXXALIAS_SYS (gmtime
, struct tm
*, (time_t const *__timer
));
217 _GL_CXXALIASWARN (gmtime
);
220 /* Parse BUF as a time stamp, assuming FORMAT specifies its layout, and store
221 the resulting broken-down time into TM. See
222 <http://www.opengroup.org/susv3xsh/strptime.html>. */
223 # if @GNULIB_STRPTIME@
224 # if ! @HAVE_STRPTIME@
225 _GL_FUNCDECL_SYS (strptime
, char *, (char const *restrict __buf
,
226 char const *restrict __format
,
227 struct tm
*restrict __tm
)
228 _GL_ARG_NONNULL ((1, 2, 3)));
230 _GL_CXXALIAS_SYS (strptime
, char *, (char const *restrict __buf
,
231 char const *restrict __format
,
232 struct tm
*restrict __tm
));
233 _GL_CXXALIASWARN (strptime
);
236 # if defined _GNU_SOURCE && @GNULIB_TIME_RZ@ && ! @HAVE_TIMEZONE_T@
237 typedef struct tm_zone
*timezone_t
;
238 _GL_FUNCDECL_SYS (tzalloc
, timezone_t
, (char const *__name
));
239 _GL_CXXALIAS_SYS (tzalloc
, timezone_t
, (char const *__name
));
240 _GL_FUNCDECL_SYS (tzfree
, void, (timezone_t __tz
));
241 _GL_CXXALIAS_SYS (tzfree
, void, (timezone_t __tz
));
242 _GL_FUNCDECL_SYS (localtime_rz
, struct tm
*,
243 (timezone_t __tz
, time_t const *restrict __timer
,
244 struct tm
*restrict __result
) _GL_ARG_NONNULL ((2, 3)));
245 _GL_CXXALIAS_SYS (localtime_rz
, struct tm
*,
246 (timezone_t __tz
, time_t const *restrict __timer
,
247 struct tm
*restrict __result
));
248 _GL_FUNCDECL_SYS (mktime_z
, time_t,
249 (timezone_t __tz
, struct tm
*restrict __result
)
250 _GL_ARG_NONNULL ((2)));
251 _GL_CXXALIAS_SYS (mktime_z
, time_t,
252 (timezone_t __tz
, struct tm
*restrict __result
));
255 /* Convert TM to a time_t value, assuming UTC. */
257 # if @REPLACE_TIMEGM@
258 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
260 # define timegm rpl_timegm
262 _GL_FUNCDECL_RPL (timegm
, time_t, (struct tm
*__tm
) _GL_ARG_NONNULL ((1)));
263 _GL_CXXALIAS_RPL (timegm
, time_t, (struct tm
*__tm
));
266 _GL_FUNCDECL_SYS (timegm
, time_t, (struct tm
*__tm
) _GL_ARG_NONNULL ((1)));
268 _GL_CXXALIAS_SYS (timegm
, time_t, (struct tm
*__tm
));
270 _GL_CXXALIASWARN (timegm
);
273 /* Encourage applications to avoid unsafe functions that can overrun
274 buffers when given outlandish struct tm values. Portable
275 applications should use strftime (or even sprintf) instead. */
276 # if defined GNULIB_POSIXCHECK
278 _GL_WARN_ON_USE (asctime
, "asctime can overrun buffers in some cases - "
279 "better use strftime (or even sprintf) instead");
281 # if defined GNULIB_POSIXCHECK
283 _GL_WARN_ON_USE (asctime
, "asctime_r can overrun buffers in some cases - "
284 "better use strftime (or even sprintf) instead");
286 # if defined GNULIB_POSIXCHECK
288 _GL_WARN_ON_USE (asctime
, "ctime can overrun buffers in some cases - "
289 "better use strftime (or even sprintf) instead");
291 # if defined GNULIB_POSIXCHECK
293 _GL_WARN_ON_USE (asctime
, "ctime_r can overrun buffers in some cases - "
294 "better use strftime (or even sprintf) instead");