1 /* A more-standard <time.h>.
3 Copyright (C) 2007-2011 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, write to the Free Software Foundation,
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
20 @PRAGMA_SYSTEM_HEADER@
24 /* Don't get in the way of glibc when it includes time.h merely to
25 declare a few standard symbols, rather than to declare all the
26 symbols. 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 _@GUARD_PREFIX@_TIME_H)
33 # @INCLUDE_NEXT@ @NEXT_TIME_H@
37 # define _@GUARD_PREFIX@_TIME_H
39 # @INCLUDE_NEXT@ @NEXT_TIME_H@
41 /* NetBSD 5.0 mis-defines NULL. */
44 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
46 /* The definition of _GL_ARG_NONNULL is copied here. */
48 /* The definition of _GL_WARN_ON_USE is copied here. */
50 /* Some systems don't define struct timespec (e.g., AIX 4.1, Ultrix 4.3).
51 Or they define it with the wrong member names or define it in <sys/time.h>
52 (e.g., FreeBSD circa 1997). Stock Mingw does not define it, but the
53 pthreads-win32 library defines it in <pthread.h>. */
54 # if ! @TIME_H_DEFINES_STRUCT_TIMESPEC@
55 # if @SYS_TIME_H_DEFINES_STRUCT_TIMESPEC@
56 # include <sys/time.h>
57 # elif @PTHREAD_H_DEFINES_STRUCT_TIMESPEC@
59 /* The pthreads-win32 <pthread.h> also defines a couple of broken macros. */
72 # if !GNULIB_defined_struct_timespec
74 # define timespec rpl_timespec
80 # define GNULIB_defined_struct_timespec 1
90 # if !GNULIB_defined_struct_time_t_must_be_integral
91 /* Per http://austingroupbugs.net/view.php?id=327, POSIX requires
92 time_t to be an integer type, even though C99 permits floating
93 point. We don't know of any implementation that uses floating
94 point, and it is much easier to write code that doesn't have to
95 worry about that corner case, so we force the issue. */
96 struct __time_t_must_be_integral
{
97 unsigned int __floating_time_t_unsupported
: (time_t) 1;
99 # define GNULIB_defined_struct_time_t_must_be_integral 1
102 /* Sleep for at least RQTP seconds unless interrupted, If interrupted,
103 return -1 and store the remaining time into RMTP. See
104 <http://www.opengroup.org/susv3xsh/nanosleep.html>. */
105 # if @GNULIB_NANOSLEEP@
106 # if @REPLACE_NANOSLEEP@
107 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
108 # define nanosleep rpl_nanosleep
110 _GL_FUNCDECL_RPL (nanosleep
, int,
111 (struct timespec
const *__rqtp
, struct timespec
*__rmtp
)
112 _GL_ARG_NONNULL ((1)));
113 _GL_CXXALIAS_RPL (nanosleep
, int,
114 (struct timespec
const *__rqtp
, struct timespec
*__rmtp
));
116 # if ! @HAVE_NANOSLEEP@
117 _GL_FUNCDECL_SYS (nanosleep
, int,
118 (struct timespec
const *__rqtp
, struct timespec
*__rmtp
)
119 _GL_ARG_NONNULL ((1)));
121 _GL_CXXALIAS_SYS (nanosleep
, int,
122 (struct timespec
const *__rqtp
, struct timespec
*__rmtp
));
124 _GL_CXXALIASWARN (nanosleep
);
127 /* Return the 'time_t' representation of TP and normalize TP. */
129 # if @REPLACE_MKTIME@
130 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
131 # define mktime rpl_mktime
133 _GL_FUNCDECL_RPL (mktime
, time_t, (struct tm
*__tp
) _GL_ARG_NONNULL ((1)));
134 _GL_CXXALIAS_RPL (mktime
, time_t, (struct tm
*__tp
));
136 _GL_CXXALIAS_SYS (mktime
, time_t, (struct tm
*__tp
));
138 _GL_CXXALIASWARN (mktime
);
141 /* Convert TIMER to RESULT, assuming local time and UTC respectively. See
142 <http://www.opengroup.org/susv3xsh/localtime_r.html> and
143 <http://www.opengroup.org/susv3xsh/gmtime_r.html>. */
145 # if @REPLACE_LOCALTIME_R@
146 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
148 # define localtime_r rpl_localtime_r
150 _GL_FUNCDECL_RPL (localtime_r
, struct tm
*, (time_t const *restrict __timer
,
151 struct tm
*restrict __result
)
152 _GL_ARG_NONNULL ((1, 2)));
153 _GL_CXXALIAS_RPL (localtime_r
, struct tm
*, (time_t const *restrict __timer
,
154 struct tm
*restrict __result
));
156 # if ! @HAVE_DECL_LOCALTIME_R@
157 _GL_FUNCDECL_SYS (localtime_r
, struct tm
*, (time_t const *restrict __timer
,
158 struct tm
*restrict __result
)
159 _GL_ARG_NONNULL ((1, 2)));
161 _GL_CXXALIAS_SYS (localtime_r
, struct tm
*, (time_t const *restrict __timer
,
162 struct tm
*restrict __result
));
164 # if @HAVE_DECL_LOCALTIME_R@
165 _GL_CXXALIASWARN (localtime_r
);
167 # if @REPLACE_LOCALTIME_R@
168 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
170 # define gmtime_r rpl_gmtime_r
172 _GL_FUNCDECL_RPL (gmtime_r
, struct tm
*, (time_t const *restrict __timer
,
173 struct tm
*restrict __result
)
174 _GL_ARG_NONNULL ((1, 2)));
175 _GL_CXXALIAS_RPL (gmtime_r
, struct tm
*, (time_t const *restrict __timer
,
176 struct tm
*restrict __result
));
178 # if ! @HAVE_DECL_LOCALTIME_R@
179 _GL_FUNCDECL_SYS (gmtime_r
, struct tm
*, (time_t const *restrict __timer
,
180 struct tm
*restrict __result
)
181 _GL_ARG_NONNULL ((1, 2)));
183 _GL_CXXALIAS_SYS (gmtime_r
, struct tm
*, (time_t const *restrict __timer
,
184 struct tm
*restrict __result
));
186 # if @HAVE_DECL_LOCALTIME_R@
187 _GL_CXXALIASWARN (gmtime_r
);
191 /* Parse BUF as a time stamp, assuming FORMAT specifies its layout, and store
192 the resulting broken-down time into TM. See
193 <http://www.opengroup.org/susv3xsh/strptime.html>. */
194 # if @GNULIB_STRPTIME@
195 # if ! @HAVE_STRPTIME@
196 _GL_FUNCDECL_SYS (strptime
, char *, (char const *restrict __buf
,
197 char const *restrict __format
,
198 struct tm
*restrict __tm
)
199 _GL_ARG_NONNULL ((1, 2, 3)));
201 _GL_CXXALIAS_SYS (strptime
, char *, (char const *restrict __buf
,
202 char const *restrict __format
,
203 struct tm
*restrict __tm
));
204 _GL_CXXALIASWARN (strptime
);
207 /* Convert TM to a time_t value, assuming UTC. */
209 # if @REPLACE_TIMEGM@
210 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
212 # define timegm rpl_timegm
214 _GL_FUNCDECL_RPL (timegm
, time_t, (struct tm
*__tm
) _GL_ARG_NONNULL ((1)));
215 _GL_CXXALIAS_RPL (timegm
, time_t, (struct tm
*__tm
));
218 _GL_FUNCDECL_SYS (timegm
, time_t, (struct tm
*__tm
) _GL_ARG_NONNULL ((1)));
220 _GL_CXXALIAS_SYS (timegm
, time_t, (struct tm
*__tm
));
222 _GL_CXXALIASWARN (timegm
);
225 /* Encourage applications to avoid unsafe functions that can overrun
226 buffers when given outlandish struct tm values. Portable
227 applications should use strftime (or even sprintf) instead. */
228 # if defined GNULIB_POSIXCHECK
230 _GL_WARN_ON_USE (asctime
, "asctime can overrun buffers in some cases - "
231 "better use strftime (or even sprintf) instead");
233 # if defined GNULIB_POSIXCHECK
235 _GL_WARN_ON_USE (asctime
, "asctime_r can overrun buffers in some cases - "
236 "better use strftime (or even sprintf) instead");
238 # if defined GNULIB_POSIXCHECK
240 _GL_WARN_ON_USE (asctime
, "ctime can overrun buffers in some cases - "
241 "better use strftime (or even sprintf) instead");
243 # if defined GNULIB_POSIXCHECK
245 _GL_WARN_ON_USE (asctime
, "ctime_r can overrun buffers in some cases - "
246 "better use strftime (or even sprintf) instead");