Commit | Line | Data |
---|---|---|
e65fc94b LC |
1 | /* A more-standard <time.h>. |
2 | ||
61cd9dc9 | 3 | Copyright (C) 2007-2010 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 | |
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. */ | |
18 | ||
aa7a939c | 19 | #if __GNUC__ >= 3 |
e65fc94b | 20 | @PRAGMA_SYSTEM_HEADER@ |
aa7a939c | 21 | #endif |
0f00f2c3 | 22 | @PRAGMA_COLUMNS@ |
e65fc94b LC |
23 | |
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 _GL_TIME_H) | |
32 | ||
33 | # @INCLUDE_NEXT@ @NEXT_TIME_H@ | |
34 | ||
35 | #else | |
36 | ||
37 | # define _GL_TIME_H | |
38 | ||
39 | # @INCLUDE_NEXT@ @NEXT_TIME_H@ | |
40 | ||
8912421c | 41 | /* NetBSD 5.0 mis-defines NULL. */ |
a927b6c1 | 42 | # include <stddef.h> |
8912421c | 43 | |
f4c79b3c LC |
44 | /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ |
45 | ||
1cd4fffc LC |
46 | /* The definition of _GL_ARG_NONNULL is copied here. */ |
47 | ||
f4c79b3c LC |
48 | /* The definition of _GL_WARN_ON_USE is copied here. */ |
49 | ||
e65fc94b LC |
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> | |
6f32e5c7 LC |
52 | (e.g., FreeBSD circa 1997). Stock Mingw does not define it, but the |
53 | pthreads-win32 library defines it in <pthread.h>. */ | |
e65fc94b LC |
54 | # if ! @TIME_H_DEFINES_STRUCT_TIMESPEC@ |
55 | # if @SYS_TIME_H_DEFINES_STRUCT_TIMESPEC@ | |
56 | # include <sys/time.h> | |
6f32e5c7 LC |
57 | # elif @PTHREAD_H_DEFINES_STRUCT_TIMESPEC@ |
58 | # include <pthread.h> | |
59 | /* The pthreads-win32 <pthread.h> also defines a couple of broken macros. */ | |
60 | # undef asctime_r | |
61 | # undef ctime_r | |
62 | # undef gmtime_r | |
63 | # undef localtime_r | |
64 | # undef rand_r | |
65 | # undef strtok_r | |
e65fc94b | 66 | # else |
a927b6c1 LC |
67 | |
68 | # ifdef __cplusplus | |
69 | extern "C" { | |
70 | # endif | |
71 | ||
e65fc94b LC |
72 | # undef timespec |
73 | # define timespec rpl_timespec | |
74 | struct timespec | |
75 | { | |
76 | time_t tv_sec; | |
77 | long int tv_nsec; | |
78 | }; | |
e65fc94b | 79 | |
a927b6c1 | 80 | # ifdef __cplusplus |
f4c79b3c | 81 | } |
a927b6c1 LC |
82 | # endif |
83 | ||
84 | # endif | |
f4c79b3c LC |
85 | # endif |
86 | ||
0f00f2c3 LC |
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; | |
94 | }; | |
95 | ||
e65fc94b LC |
96 | /* Sleep for at least RQTP seconds unless interrupted, If interrupted, |
97 | return -1 and store the remaining time into RMTP. See | |
98 | <http://www.opengroup.org/susv3xsh/nanosleep.html>. */ | |
f4c79b3c LC |
99 | # if @GNULIB_NANOSLEEP@ |
100 | # if @REPLACE_NANOSLEEP@ | |
101 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | |
102 | # define nanosleep rpl_nanosleep | |
103 | # endif | |
104 | _GL_FUNCDECL_RPL (nanosleep, int, | |
105 | (struct timespec const *__rqtp, struct timespec *__rmtp) | |
106 | _GL_ARG_NONNULL ((1))); | |
107 | _GL_CXXALIAS_RPL (nanosleep, int, | |
108 | (struct timespec const *__rqtp, struct timespec *__rmtp)); | |
109 | # else | |
a927b6c1 LC |
110 | # if ! @HAVE_NANOSLEEP@ |
111 | _GL_FUNCDECL_SYS (nanosleep, int, | |
112 | (struct timespec const *__rqtp, struct timespec *__rmtp) | |
113 | _GL_ARG_NONNULL ((1))); | |
114 | # endif | |
f4c79b3c LC |
115 | _GL_CXXALIAS_SYS (nanosleep, int, |
116 | (struct timespec const *__rqtp, struct timespec *__rmtp)); | |
117 | # endif | |
118 | _GL_CXXALIASWARN (nanosleep); | |
e65fc94b LC |
119 | # endif |
120 | ||
25361e4b | 121 | /* Return the 'time_t' representation of TP and normalize TP. */ |
f4c79b3c LC |
122 | # if @GNULIB_MKTIME@ |
123 | # if @REPLACE_MKTIME@ | |
124 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | |
125 | # define mktime rpl_mktime | |
126 | # endif | |
127 | _GL_FUNCDECL_RPL (mktime, time_t, (struct tm *__tp) _GL_ARG_NONNULL ((1))); | |
128 | _GL_CXXALIAS_RPL (mktime, time_t, (struct tm *__tp)); | |
129 | # else | |
130 | _GL_CXXALIAS_SYS (mktime, time_t, (struct tm *__tp)); | |
131 | # endif | |
132 | _GL_CXXALIASWARN (mktime); | |
25361e4b LC |
133 | # endif |
134 | ||
e65fc94b LC |
135 | /* Convert TIMER to RESULT, assuming local time and UTC respectively. See |
136 | <http://www.opengroup.org/susv3xsh/localtime_r.html> and | |
137 | <http://www.opengroup.org/susv3xsh/gmtime_r.html>. */ | |
f4c79b3c LC |
138 | # if @GNULIB_TIME_R@ |
139 | # if @REPLACE_LOCALTIME_R@ | |
140 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | |
141 | # undef localtime_r | |
142 | # define localtime_r rpl_localtime_r | |
143 | # endif | |
144 | _GL_FUNCDECL_RPL (localtime_r, struct tm *, (time_t const *restrict __timer, | |
145 | struct tm *restrict __result) | |
146 | _GL_ARG_NONNULL ((1, 2))); | |
147 | _GL_CXXALIAS_RPL (localtime_r, struct tm *, (time_t const *restrict __timer, | |
148 | struct tm *restrict __result)); | |
149 | # else | |
a927b6c1 LC |
150 | # if ! @HAVE_LOCALTIME_R@ |
151 | _GL_FUNCDECL_SYS (localtime_r, struct tm *, (time_t const *restrict __timer, | |
152 | struct tm *restrict __result) | |
153 | _GL_ARG_NONNULL ((1, 2))); | |
154 | # endif | |
f4c79b3c LC |
155 | _GL_CXXALIAS_SYS (localtime_r, struct tm *, (time_t const *restrict __timer, |
156 | struct tm *restrict __result)); | |
157 | # endif | |
158 | _GL_CXXALIASWARN (localtime_r); | |
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 | |
a927b6c1 LC |
170 | # if ! @HAVE_LOCALTIME_R@ |
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 | |
178 | _GL_CXXALIASWARN (gmtime_r); | |
e65fc94b LC |
179 | # endif |
180 | ||
181 | /* Parse BUF as a time stamp, assuming FORMAT specifies its layout, and store | |
182 | the resulting broken-down time into TM. See | |
183 | <http://www.opengroup.org/susv3xsh/strptime.html>. */ | |
f4c79b3c | 184 | # if @GNULIB_STRPTIME@ |
a927b6c1 LC |
185 | # if ! @HAVE_STRPTIME@ |
186 | _GL_FUNCDECL_SYS (strptime, char *, (char const *restrict __buf, | |
f4c79b3c LC |
187 | char const *restrict __format, |
188 | struct tm *restrict __tm) | |
189 | _GL_ARG_NONNULL ((1, 2, 3))); | |
a927b6c1 | 190 | # endif |
f4c79b3c LC |
191 | _GL_CXXALIAS_SYS (strptime, char *, (char const *restrict __buf, |
192 | char const *restrict __format, | |
193 | struct tm *restrict __tm)); | |
f4c79b3c | 194 | _GL_CXXALIASWARN (strptime); |
e65fc94b LC |
195 | # endif |
196 | ||
197 | /* Convert TM to a time_t value, assuming UTC. */ | |
f4c79b3c LC |
198 | # if @GNULIB_TIMEGM@ |
199 | # if @REPLACE_TIMEGM@ | |
200 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | |
201 | # undef timegm | |
202 | # define timegm rpl_timegm | |
203 | # endif | |
204 | _GL_FUNCDECL_RPL (timegm, time_t, (struct tm *__tm) _GL_ARG_NONNULL ((1))); | |
205 | _GL_CXXALIAS_RPL (timegm, time_t, (struct tm *__tm)); | |
206 | # else | |
a927b6c1 LC |
207 | # if ! @HAVE_TIMEGM@ |
208 | _GL_FUNCDECL_SYS (timegm, time_t, (struct tm *__tm) _GL_ARG_NONNULL ((1))); | |
209 | # endif | |
f4c79b3c LC |
210 | _GL_CXXALIAS_SYS (timegm, time_t, (struct tm *__tm)); |
211 | # endif | |
212 | _GL_CXXALIASWARN (timegm); | |
e65fc94b LC |
213 | # endif |
214 | ||
215 | /* Encourage applications to avoid unsafe functions that can overrun | |
216 | buffers when given outlandish struct tm values. Portable | |
217 | applications should use strftime (or even sprintf) instead. */ | |
a927b6c1 | 218 | # if defined GNULIB_POSIXCHECK |
e65fc94b | 219 | # undef asctime |
a927b6c1 LC |
220 | _GL_WARN_ON_USE (asctime, "asctime can overrun buffers in some cases - " |
221 | "better use strftime (or even sprintf) instead"); | |
222 | # endif | |
223 | # if defined GNULIB_POSIXCHECK | |
e65fc94b | 224 | # undef asctime_r |
a927b6c1 LC |
225 | _GL_WARN_ON_USE (asctime, "asctime_r can overrun buffers in some cases - " |
226 | "better use strftime (or even sprintf) instead"); | |
227 | # endif | |
228 | # if defined GNULIB_POSIXCHECK | |
e65fc94b | 229 | # undef ctime |
a927b6c1 LC |
230 | _GL_WARN_ON_USE (asctime, "ctime can overrun buffers in some cases - " |
231 | "better use strftime (or even sprintf) instead"); | |
232 | # endif | |
233 | # if defined GNULIB_POSIXCHECK | |
e65fc94b | 234 | # undef ctime_r |
a927b6c1 LC |
235 | _GL_WARN_ON_USE (asctime, "ctime_r can overrun buffers in some cases - " |
236 | "better use strftime (or even sprintf) instead"); | |
e65fc94b LC |
237 | # endif |
238 | ||
e65fc94b | 239 | #endif |