1 /* A more-standard <time.h>.
3 Copyright (C) 2007-2010 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 2, 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@
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 \
30 || defined _GL_TIME_H)
32 # @INCLUDE_NEXT@ @NEXT_TIME_H@
38 # @INCLUDE_NEXT@ @NEXT_TIME_H@
40 /* NetBSD 5.0 mis-defines NULL. */
43 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
45 /* The definition of _GL_ARG_NONNULL is copied here. */
47 /* The definition of _GL_WARN_ON_USE is copied here. */
53 /* Some systems don't define struct timespec (e.g., AIX 4.1, Ultrix 4.3).
54 Or they define it with the wrong member names or define it in <sys/time.h>
55 (e.g., FreeBSD circa 1997). */
56 # if ! @TIME_H_DEFINES_STRUCT_TIMESPEC@
57 # if @SYS_TIME_H_DEFINES_STRUCT_TIMESPEC@
58 # include <sys/time.h>
61 # define timespec rpl_timespec
74 /* Sleep for at least RQTP seconds unless interrupted, If interrupted,
75 return -1 and store the remaining time into RMTP. See
76 <http://www.opengroup.org/susv3xsh/nanosleep.html>. */
77 # if @GNULIB_NANOSLEEP@
78 # if @REPLACE_NANOSLEEP@
79 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
80 # define nanosleep rpl_nanosleep
82 _GL_FUNCDECL_RPL (nanosleep, int,
83 (struct timespec const *__rqtp, struct timespec *__rmtp)
84 _GL_ARG_NONNULL ((1)));
85 _GL_CXXALIAS_RPL (nanosleep, int,
86 (struct timespec const *__rqtp, struct timespec *__rmtp));
88 _GL_CXXALIAS_SYS (nanosleep, int,
89 (struct timespec const *__rqtp, struct timespec *__rmtp));
91 _GL_CXXALIASWARN (nanosleep);
94 /* Return the 'time_t' representation of TP and normalize TP. */
97 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
98 # define mktime rpl_mktime
100 _GL_FUNCDECL_RPL (mktime, time_t, (struct tm *__tp) _GL_ARG_NONNULL ((1)));
101 _GL_CXXALIAS_RPL (mktime, time_t, (struct tm *__tp));
103 _GL_CXXALIAS_SYS (mktime, time_t, (struct tm *__tp));
105 _GL_CXXALIASWARN (mktime);
108 /* Convert TIMER to RESULT, assuming local time and UTC respectively. See
109 <http://www.opengroup.org/susv3xsh/localtime_r.html> and
110 <http://www.opengroup.org/susv3xsh/gmtime_r.html>. */
111 # if @REPLACE_LOCALTIME_R@
112 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
114 # define localtime_r rpl_localtime_r
116 _GL_FUNCDECL_RPL (localtime_r, struct tm *, (time_t const *restrict __timer,
117 struct tm *restrict __result)
118 _GL_ARG_NONNULL ((1, 2)));
119 _GL_CXXALIAS_RPL (localtime_r, struct tm *, (time_t const *restrict __timer,
120 struct tm *restrict __result));
122 _GL_CXXALIAS_SYS (localtime_r, struct tm *, (time_t const *restrict __timer,
123 struct tm *restrict __result));
125 _GL_CXXALIASWARN (localtime_r);
126 # if @REPLACE_LOCALTIME_R@
127 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
129 # define gmtime_r rpl_gmtime_r
131 _GL_FUNCDECL_RPL (gmtime_r, struct tm *, (time_t const *restrict __timer,
132 struct tm *restrict __result)
133 _GL_ARG_NONNULL ((1, 2)));
134 _GL_CXXALIAS_RPL (gmtime_r, struct tm *, (time_t const *restrict __timer,
135 struct tm *restrict __result));
137 _GL_CXXALIAS_SYS (gmtime_r, struct tm *, (time_t const *restrict __timer,
138 struct tm *restrict __result));
140 _GL_CXXALIASWARN (gmtime_r);
142 /* Parse BUF as a time stamp, assuming FORMAT specifies its layout, and store
143 the resulting broken-down time into TM. See
144 <http://www.opengroup.org/susv3xsh/strptime.html>. */
145 # if @GNULIB_STRPTIME@
146 # if @REPLACE_STRPTIME@
147 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
149 # define strptime rpl_strptime
151 _GL_FUNCDECL_RPL (strptime, char *, (char const *restrict __buf,
152 char const *restrict __format,
153 struct tm *restrict __tm)
154 _GL_ARG_NONNULL ((1, 2, 3)));
155 _GL_CXXALIAS_RPL (strptime, char *, (char const *restrict __buf,
156 char const *restrict __format,
157 struct tm *restrict __tm));
159 _GL_CXXALIAS_SYS (strptime, char *, (char const *restrict __buf,
160 char const *restrict __format,
161 struct tm *restrict __tm));
163 _GL_CXXALIASWARN (strptime);
166 /* Convert TM to a time_t value, assuming UTC. */
168 # if @REPLACE_TIMEGM@
169 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
171 # define timegm rpl_timegm
173 _GL_FUNCDECL_RPL (timegm, time_t, (struct tm *__tm) _GL_ARG_NONNULL ((1)));
174 _GL_CXXALIAS_RPL (timegm, time_t, (struct tm *__tm));
176 _GL_CXXALIAS_SYS (timegm, time_t, (struct tm *__tm));
178 _GL_CXXALIASWARN (timegm);
181 /* Encourage applications to avoid unsafe functions that can overrun
182 buffers when given outlandish struct tm values. Portable
183 applications should use strftime (or even sprintf) instead. */
184 # if GNULIB_PORTCHECK
186 # define asctime eschew_asctime
188 # define asctime_r eschew_asctime_r
190 # define ctime eschew_ctime
192 # define ctime_r eschew_ctime_r