Merge branch 'bt/elisp'
[bpt/guile.git] / lib / time.in.h
CommitLineData
e65fc94b
LC
1/* A more-standard <time.h>.
2
f0007cad 3 Copyright (C) 2007-2012 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 \
3d458a81 31 || defined _@GUARD_PREFIX@_TIME_H)
e65fc94b
LC
32
33# @INCLUDE_NEXT@ @NEXT_TIME_H@
34
35#else
36
3d458a81 37# define _@GUARD_PREFIX@_TIME_H
e65fc94b
LC
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
69extern "C" {
70# endif
71
49114fd4
LC
72# if !GNULIB_defined_struct_timespec
73# undef timespec
74# define timespec rpl_timespec
e65fc94b
LC
75struct timespec
76{
77 time_t tv_sec;
78 long int tv_nsec;
79};
49114fd4
LC
80# define GNULIB_defined_struct_timespec 1
81# endif
e65fc94b 82
a927b6c1 83# ifdef __cplusplus
f4c79b3c 84}
a927b6c1
LC
85# endif
86
87# endif
f4c79b3c
LC
88# endif
89
49114fd4 90# if !GNULIB_defined_struct_time_t_must_be_integral
0f00f2c3
LC
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. */
96struct __time_t_must_be_integral {
97 unsigned int __floating_time_t_unsupported : (time_t) 1;
98};
49114fd4
LC
99# define GNULIB_defined_struct_time_t_must_be_integral 1
100# endif
0f00f2c3 101
e65fc94b
LC
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>. */
f4c79b3c
LC
105# if @GNULIB_NANOSLEEP@
106# if @REPLACE_NANOSLEEP@
107# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
108# define nanosleep rpl_nanosleep
109# endif
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));
115# else
a927b6c1
LC
116# if ! @HAVE_NANOSLEEP@
117_GL_FUNCDECL_SYS (nanosleep, int,
118 (struct timespec const *__rqtp, struct timespec *__rmtp)
119 _GL_ARG_NONNULL ((1)));
120# endif
f4c79b3c
LC
121_GL_CXXALIAS_SYS (nanosleep, int,
122 (struct timespec const *__rqtp, struct timespec *__rmtp));
123# endif
124_GL_CXXALIASWARN (nanosleep);
e65fc94b
LC
125# endif
126
25361e4b 127/* Return the 'time_t' representation of TP and normalize TP. */
f4c79b3c
LC
128# if @GNULIB_MKTIME@
129# if @REPLACE_MKTIME@
130# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
131# define mktime rpl_mktime
132# endif
133_GL_FUNCDECL_RPL (mktime, time_t, (struct tm *__tp) _GL_ARG_NONNULL ((1)));
134_GL_CXXALIAS_RPL (mktime, time_t, (struct tm *__tp));
135# else
136_GL_CXXALIAS_SYS (mktime, time_t, (struct tm *__tp));
137# endif
138_GL_CXXALIASWARN (mktime);
25361e4b
LC
139# endif
140
e65fc94b
LC
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>. */
f4c79b3c
LC
144# if @GNULIB_TIME_R@
145# if @REPLACE_LOCALTIME_R@
146# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
147# undef localtime_r
148# define localtime_r rpl_localtime_r
149# endif
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));
155# else
49114fd4 156# if ! @HAVE_DECL_LOCALTIME_R@
a927b6c1
LC
157_GL_FUNCDECL_SYS (localtime_r, struct tm *, (time_t const *restrict __timer,
158 struct tm *restrict __result)
159 _GL_ARG_NONNULL ((1, 2)));
160# endif
f4c79b3c
LC
161_GL_CXXALIAS_SYS (localtime_r, struct tm *, (time_t const *restrict __timer,
162 struct tm *restrict __result));
163# endif
49114fd4 164# if @HAVE_DECL_LOCALTIME_R@
f4c79b3c 165_GL_CXXALIASWARN (localtime_r);
49114fd4 166# endif
f4c79b3c
LC
167# if @REPLACE_LOCALTIME_R@
168# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
169# undef gmtime_r
170# define gmtime_r rpl_gmtime_r
171# endif
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));
177# else
49114fd4 178# if ! @HAVE_DECL_LOCALTIME_R@
a927b6c1
LC
179_GL_FUNCDECL_SYS (gmtime_r, struct tm *, (time_t const *restrict __timer,
180 struct tm *restrict __result)
181 _GL_ARG_NONNULL ((1, 2)));
182# endif
f4c79b3c
LC
183_GL_CXXALIAS_SYS (gmtime_r, struct tm *, (time_t const *restrict __timer,
184 struct tm *restrict __result));
185# endif
49114fd4 186# if @HAVE_DECL_LOCALTIME_R@
f4c79b3c 187_GL_CXXALIASWARN (gmtime_r);
49114fd4 188# endif
e65fc94b
LC
189# endif
190
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>. */
f4c79b3c 194# if @GNULIB_STRPTIME@
a927b6c1
LC
195# if ! @HAVE_STRPTIME@
196_GL_FUNCDECL_SYS (strptime, char *, (char const *restrict __buf,
f4c79b3c
LC
197 char const *restrict __format,
198 struct tm *restrict __tm)
199 _GL_ARG_NONNULL ((1, 2, 3)));
a927b6c1 200# endif
f4c79b3c
LC
201_GL_CXXALIAS_SYS (strptime, char *, (char const *restrict __buf,
202 char const *restrict __format,
203 struct tm *restrict __tm));
f4c79b3c 204_GL_CXXALIASWARN (strptime);
e65fc94b
LC
205# endif
206
207/* Convert TM to a time_t value, assuming UTC. */
f4c79b3c
LC
208# if @GNULIB_TIMEGM@
209# if @REPLACE_TIMEGM@
210# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
211# undef timegm
212# define timegm rpl_timegm
213# endif
214_GL_FUNCDECL_RPL (timegm, time_t, (struct tm *__tm) _GL_ARG_NONNULL ((1)));
215_GL_CXXALIAS_RPL (timegm, time_t, (struct tm *__tm));
216# else
a927b6c1
LC
217# if ! @HAVE_TIMEGM@
218_GL_FUNCDECL_SYS (timegm, time_t, (struct tm *__tm) _GL_ARG_NONNULL ((1)));
219# endif
f4c79b3c
LC
220_GL_CXXALIAS_SYS (timegm, time_t, (struct tm *__tm));
221# endif
222_GL_CXXALIASWARN (timegm);
e65fc94b
LC
223# endif
224
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. */
a927b6c1 228# if defined GNULIB_POSIXCHECK
e65fc94b 229# undef asctime
a927b6c1
LC
230_GL_WARN_ON_USE (asctime, "asctime can overrun buffers in some cases - "
231 "better use strftime (or even sprintf) instead");
232# endif
233# if defined GNULIB_POSIXCHECK
e65fc94b 234# undef asctime_r
a927b6c1
LC
235_GL_WARN_ON_USE (asctime, "asctime_r can overrun buffers in some cases - "
236 "better use strftime (or even sprintf) instead");
237# endif
238# if defined GNULIB_POSIXCHECK
e65fc94b 239# undef ctime
a927b6c1
LC
240_GL_WARN_ON_USE (asctime, "ctime can overrun buffers in some cases - "
241 "better use strftime (or even sprintf) instead");
242# endif
243# if defined GNULIB_POSIXCHECK
e65fc94b 244# undef ctime_r
a927b6c1
LC
245_GL_WARN_ON_USE (asctime, "ctime_r can overrun buffers in some cases - "
246 "better use strftime (or even sprintf) instead");
e65fc94b
LC
247# endif
248
e65fc94b 249#endif