Some corrections in Elisp manual
[emacs.git] / lib / time.in.h
blob865c114119680ca398343cc32d0be2f1ad2b0e28
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)
8 any later version.
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/>. */
18 #if __GNUC__ >= 3
19 @PRAGMA_SYSTEM_HEADER@
20 #endif
21 @PRAGMA_COLUMNS@
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@
36 #else
38 # define _@GUARD_PREFIX@_TIME_H
40 # @INCLUDE_NEXT@ @NEXT_TIME_H@
42 /* NetBSD 5.0 mis-defines NULL. */
43 # include <stddef.h>
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@
59 # include <pthread.h>
60 # elif @UNISTD_H_DEFINES_STRUCT_TIMESPEC@
61 # include <unistd.h>
62 # else
64 # ifdef __cplusplus
65 extern "C" {
66 # endif
68 # if !GNULIB_defined_struct_timespec
69 # undef timespec
70 # define timespec rpl_timespec
71 struct timespec
73 time_t tv_sec;
74 long int tv_nsec;
76 # define GNULIB_defined_struct_timespec 1
77 # endif
79 # ifdef __cplusplus
81 # endif
83 # endif
84 # endif
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
96 # endif
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
105 # endif
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));
111 # else
112 # if ! @HAVE_NANOSLEEP@
113 _GL_FUNCDECL_SYS (nanosleep, int,
114 (struct timespec const *__rqtp, struct timespec *__rmtp)
115 _GL_ARG_NONNULL ((1)));
116 # endif
117 _GL_CXXALIAS_SYS (nanosleep, int,
118 (struct timespec const *__rqtp, struct timespec *__rmtp));
119 # endif
120 _GL_CXXALIASWARN (nanosleep);
121 # endif
123 /* Return the 'time_t' representation of TP and normalize TP. */
124 # if @GNULIB_MKTIME@
125 # if @REPLACE_MKTIME@
126 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
127 # define mktime rpl_mktime
128 # endif
129 _GL_FUNCDECL_RPL (mktime, time_t, (struct tm *__tp) _GL_ARG_NONNULL ((1)));
130 _GL_CXXALIAS_RPL (mktime, time_t, (struct tm *__tp));
131 # else
132 _GL_CXXALIAS_SYS (mktime, time_t, (struct tm *__tp));
133 # endif
134 _GL_CXXALIASWARN (mktime);
135 # endif
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>. */
140 # if @GNULIB_TIME_R@
141 # if @REPLACE_LOCALTIME_R@
142 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
143 # undef localtime_r
144 # define localtime_r rpl_localtime_r
145 # endif
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));
151 # else
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)));
156 # endif
157 _GL_CXXALIAS_SYS (localtime_r, struct tm *, (time_t const *restrict __timer,
158 struct tm *restrict __result));
159 # endif
160 # if @HAVE_DECL_LOCALTIME_R@
161 _GL_CXXALIASWARN (localtime_r);
162 # endif
163 # if @REPLACE_LOCALTIME_R@
164 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
165 # undef gmtime_r
166 # define gmtime_r rpl_gmtime_r
167 # endif
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));
173 # else
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)));
178 # endif
179 _GL_CXXALIAS_SYS (gmtime_r, struct tm *, (time_t const *restrict __timer,
180 struct tm *restrict __result));
181 # endif
182 # if @HAVE_DECL_LOCALTIME_R@
183 _GL_CXXALIASWARN (gmtime_r);
184 # endif
185 # endif
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)
193 # undef localtime
194 # define localtime rpl_localtime
195 # endif
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));
199 # else
200 _GL_CXXALIAS_SYS (localtime, struct tm *, (time_t const *__timer));
201 # endif
202 _GL_CXXALIASWARN (localtime);
203 # endif
205 # if @GNULIB_GETTIMEOFDAY@
206 # if @REPLACE_GMTIME@
207 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
208 # undef gmtime
209 # define gmtime rpl_gmtime
210 # endif
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));
214 # else
215 _GL_CXXALIAS_SYS (gmtime, struct tm *, (time_t const *__timer));
216 # endif
217 _GL_CXXALIASWARN (gmtime);
218 # endif
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)));
229 # endif
230 _GL_CXXALIAS_SYS (strptime, char *, (char const *restrict __buf,
231 char const *restrict __format,
232 struct tm *restrict __tm));
233 _GL_CXXALIASWARN (strptime);
234 # endif
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));
253 # endif
255 /* Convert TM to a time_t value, assuming UTC. */
256 # if @GNULIB_TIMEGM@
257 # if @REPLACE_TIMEGM@
258 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
259 # undef timegm
260 # define timegm rpl_timegm
261 # endif
262 _GL_FUNCDECL_RPL (timegm, time_t, (struct tm *__tm) _GL_ARG_NONNULL ((1)));
263 _GL_CXXALIAS_RPL (timegm, time_t, (struct tm *__tm));
264 # else
265 # if ! @HAVE_TIMEGM@
266 _GL_FUNCDECL_SYS (timegm, time_t, (struct tm *__tm) _GL_ARG_NONNULL ((1)));
267 # endif
268 _GL_CXXALIAS_SYS (timegm, time_t, (struct tm *__tm));
269 # endif
270 _GL_CXXALIASWARN (timegm);
271 # endif
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
277 # undef asctime
278 _GL_WARN_ON_USE (asctime, "asctime can overrun buffers in some cases - "
279 "better use strftime (or even sprintf) instead");
280 # endif
281 # if defined GNULIB_POSIXCHECK
282 # undef asctime_r
283 _GL_WARN_ON_USE (asctime, "asctime_r can overrun buffers in some cases - "
284 "better use strftime (or even sprintf) instead");
285 # endif
286 # if defined GNULIB_POSIXCHECK
287 # undef ctime
288 _GL_WARN_ON_USE (asctime, "ctime can overrun buffers in some cases - "
289 "better use strftime (or even sprintf) instead");
290 # endif
291 # if defined GNULIB_POSIXCHECK
292 # undef ctime_r
293 _GL_WARN_ON_USE (asctime, "ctime_r can overrun buffers in some cases - "
294 "better use strftime (or even sprintf) instead");
295 # endif
297 #endif