Update to gnulib 0.0.7865-a828.
[bpt/guile.git] / lib / time.in.h
CommitLineData
e65fc94b
LC
1/* A more-standard <time.h>.
2
af07e104 3 Copyright (C) 2007-2013 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
005de2e8 16 along with this program; if not, see <http://www.gnu.org/licenses/>. */
e65fc94b 17
aa7a939c 18#if __GNUC__ >= 3
e65fc94b 19@PRAGMA_SYSTEM_HEADER@
aa7a939c 20#endif
0f00f2c3 21@PRAGMA_COLUMNS@
e65fc94b
LC
22
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 \
3d458a81 30 || defined _@GUARD_PREFIX@_TIME_H)
e65fc94b
LC
31
32# @INCLUDE_NEXT@ @NEXT_TIME_H@
33
34#else
35
3d458a81 36# define _@GUARD_PREFIX@_TIME_H
e65fc94b
LC
37
38# @INCLUDE_NEXT@ @NEXT_TIME_H@
39
8912421c 40/* NetBSD 5.0 mis-defines NULL. */
a927b6c1 41# include <stddef.h>
8912421c 42
f4c79b3c
LC
43/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
44
1cd4fffc
LC
45/* The definition of _GL_ARG_NONNULL is copied here. */
46
f4c79b3c
LC
47/* The definition of _GL_WARN_ON_USE is copied here. */
48
e65fc94b
LC
49/* Some systems don't define struct timespec (e.g., AIX 4.1, Ultrix 4.3).
50 Or they define it with the wrong member names or define it in <sys/time.h>
6f32e5c7
LC
51 (e.g., FreeBSD circa 1997). Stock Mingw does not define it, but the
52 pthreads-win32 library defines it in <pthread.h>. */
e65fc94b
LC
53# if ! @TIME_H_DEFINES_STRUCT_TIMESPEC@
54# if @SYS_TIME_H_DEFINES_STRUCT_TIMESPEC@
55# include <sys/time.h>
6f32e5c7
LC
56# elif @PTHREAD_H_DEFINES_STRUCT_TIMESPEC@
57# include <pthread.h>
58/* The pthreads-win32 <pthread.h> also defines a couple of broken macros. */
59# undef asctime_r
60# undef ctime_r
61# undef gmtime_r
62# undef localtime_r
63# undef rand_r
64# undef strtok_r
e65fc94b 65# else
a927b6c1
LC
66
67# ifdef __cplusplus
68extern "C" {
69# endif
70
49114fd4
LC
71# if !GNULIB_defined_struct_timespec
72# undef timespec
73# define timespec rpl_timespec
e65fc94b
LC
74struct timespec
75{
76 time_t tv_sec;
77 long int tv_nsec;
78};
49114fd4
LC
79# define GNULIB_defined_struct_timespec 1
80# endif
e65fc94b 81
a927b6c1 82# ifdef __cplusplus
f4c79b3c 83}
a927b6c1
LC
84# endif
85
86# endif
f4c79b3c
LC
87# endif
88
49114fd4 89# if !GNULIB_defined_struct_time_t_must_be_integral
0f00f2c3
LC
90/* Per http://austingroupbugs.net/view.php?id=327, POSIX requires
91 time_t to be an integer type, even though C99 permits floating
92 point. We don't know of any implementation that uses floating
93 point, and it is much easier to write code that doesn't have to
94 worry about that corner case, so we force the issue. */
95struct __time_t_must_be_integral {
96 unsigned int __floating_time_t_unsupported : (time_t) 1;
97};
49114fd4
LC
98# define GNULIB_defined_struct_time_t_must_be_integral 1
99# endif
0f00f2c3 100
e65fc94b
LC
101/* Sleep for at least RQTP seconds unless interrupted, If interrupted,
102 return -1 and store the remaining time into RMTP. See
103 <http://www.opengroup.org/susv3xsh/nanosleep.html>. */
f4c79b3c
LC
104# if @GNULIB_NANOSLEEP@
105# if @REPLACE_NANOSLEEP@
106# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
107# define nanosleep rpl_nanosleep
108# endif
109_GL_FUNCDECL_RPL (nanosleep, int,
110 (struct timespec const *__rqtp, struct timespec *__rmtp)
111 _GL_ARG_NONNULL ((1)));
112_GL_CXXALIAS_RPL (nanosleep, int,
113 (struct timespec const *__rqtp, struct timespec *__rmtp));
114# else
a927b6c1
LC
115# if ! @HAVE_NANOSLEEP@
116_GL_FUNCDECL_SYS (nanosleep, int,
117 (struct timespec const *__rqtp, struct timespec *__rmtp)
118 _GL_ARG_NONNULL ((1)));
119# endif
f4c79b3c
LC
120_GL_CXXALIAS_SYS (nanosleep, int,
121 (struct timespec const *__rqtp, struct timespec *__rmtp));
122# endif
123_GL_CXXALIASWARN (nanosleep);
e65fc94b
LC
124# endif
125
25361e4b 126/* Return the 'time_t' representation of TP and normalize TP. */
f4c79b3c
LC
127# if @GNULIB_MKTIME@
128# if @REPLACE_MKTIME@
129# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
130# define mktime rpl_mktime
131# endif
132_GL_FUNCDECL_RPL (mktime, time_t, (struct tm *__tp) _GL_ARG_NONNULL ((1)));
133_GL_CXXALIAS_RPL (mktime, time_t, (struct tm *__tp));
134# else
135_GL_CXXALIAS_SYS (mktime, time_t, (struct tm *__tp));
136# endif
137_GL_CXXALIASWARN (mktime);
25361e4b
LC
138# endif
139
e65fc94b
LC
140/* Convert TIMER to RESULT, assuming local time and UTC respectively. See
141 <http://www.opengroup.org/susv3xsh/localtime_r.html> and
142 <http://www.opengroup.org/susv3xsh/gmtime_r.html>. */
f4c79b3c
LC
143# if @GNULIB_TIME_R@
144# if @REPLACE_LOCALTIME_R@
145# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
146# undef localtime_r
147# define localtime_r rpl_localtime_r
148# endif
149_GL_FUNCDECL_RPL (localtime_r, struct tm *, (time_t const *restrict __timer,
150 struct tm *restrict __result)
151 _GL_ARG_NONNULL ((1, 2)));
152_GL_CXXALIAS_RPL (localtime_r, struct tm *, (time_t const *restrict __timer,
153 struct tm *restrict __result));
154# else
49114fd4 155# if ! @HAVE_DECL_LOCALTIME_R@
a927b6c1
LC
156_GL_FUNCDECL_SYS (localtime_r, struct tm *, (time_t const *restrict __timer,
157 struct tm *restrict __result)
158 _GL_ARG_NONNULL ((1, 2)));
159# endif
f4c79b3c
LC
160_GL_CXXALIAS_SYS (localtime_r, struct tm *, (time_t const *restrict __timer,
161 struct tm *restrict __result));
162# endif
49114fd4 163# if @HAVE_DECL_LOCALTIME_R@
f4c79b3c 164_GL_CXXALIASWARN (localtime_r);
49114fd4 165# endif
f4c79b3c
LC
166# if @REPLACE_LOCALTIME_R@
167# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
168# undef gmtime_r
169# define gmtime_r rpl_gmtime_r
170# endif
171_GL_FUNCDECL_RPL (gmtime_r, struct tm *, (time_t const *restrict __timer,
172 struct tm *restrict __result)
173 _GL_ARG_NONNULL ((1, 2)));
174_GL_CXXALIAS_RPL (gmtime_r, struct tm *, (time_t const *restrict __timer,
175 struct tm *restrict __result));
176# else
49114fd4 177# if ! @HAVE_DECL_LOCALTIME_R@
a927b6c1
LC
178_GL_FUNCDECL_SYS (gmtime_r, struct tm *, (time_t const *restrict __timer,
179 struct tm *restrict __result)
180 _GL_ARG_NONNULL ((1, 2)));
181# endif
f4c79b3c
LC
182_GL_CXXALIAS_SYS (gmtime_r, struct tm *, (time_t const *restrict __timer,
183 struct tm *restrict __result));
184# endif
49114fd4 185# if @HAVE_DECL_LOCALTIME_R@
f4c79b3c 186_GL_CXXALIASWARN (gmtime_r);
49114fd4 187# endif
e65fc94b
LC
188# endif
189
190/* Parse BUF as a time stamp, assuming FORMAT specifies its layout, and store
191 the resulting broken-down time into TM. See
192 <http://www.opengroup.org/susv3xsh/strptime.html>. */
f4c79b3c 193# if @GNULIB_STRPTIME@
a927b6c1
LC
194# if ! @HAVE_STRPTIME@
195_GL_FUNCDECL_SYS (strptime, char *, (char const *restrict __buf,
f4c79b3c
LC
196 char const *restrict __format,
197 struct tm *restrict __tm)
198 _GL_ARG_NONNULL ((1, 2, 3)));
a927b6c1 199# endif
f4c79b3c
LC
200_GL_CXXALIAS_SYS (strptime, char *, (char const *restrict __buf,
201 char const *restrict __format,
202 struct tm *restrict __tm));
f4c79b3c 203_GL_CXXALIASWARN (strptime);
e65fc94b
LC
204# endif
205
206/* Convert TM to a time_t value, assuming UTC. */
f4c79b3c
LC
207# if @GNULIB_TIMEGM@
208# if @REPLACE_TIMEGM@
209# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
210# undef timegm
211# define timegm rpl_timegm
212# endif
213_GL_FUNCDECL_RPL (timegm, time_t, (struct tm *__tm) _GL_ARG_NONNULL ((1)));
214_GL_CXXALIAS_RPL (timegm, time_t, (struct tm *__tm));
215# else
a927b6c1
LC
216# if ! @HAVE_TIMEGM@
217_GL_FUNCDECL_SYS (timegm, time_t, (struct tm *__tm) _GL_ARG_NONNULL ((1)));
218# endif
f4c79b3c
LC
219_GL_CXXALIAS_SYS (timegm, time_t, (struct tm *__tm));
220# endif
221_GL_CXXALIASWARN (timegm);
e65fc94b
LC
222# endif
223
224/* Encourage applications to avoid unsafe functions that can overrun
225 buffers when given outlandish struct tm values. Portable
226 applications should use strftime (or even sprintf) instead. */
a927b6c1 227# if defined GNULIB_POSIXCHECK
e65fc94b 228# undef asctime
a927b6c1
LC
229_GL_WARN_ON_USE (asctime, "asctime can overrun buffers in some cases - "
230 "better use strftime (or even sprintf) instead");
231# endif
232# if defined GNULIB_POSIXCHECK
e65fc94b 233# undef asctime_r
a927b6c1
LC
234_GL_WARN_ON_USE (asctime, "asctime_r can overrun buffers in some cases - "
235 "better use strftime (or even sprintf) instead");
236# endif
237# if defined GNULIB_POSIXCHECK
e65fc94b 238# undef ctime
a927b6c1
LC
239_GL_WARN_ON_USE (asctime, "ctime can overrun buffers in some cases - "
240 "better use strftime (or even sprintf) instead");
241# endif
242# if defined GNULIB_POSIXCHECK
e65fc94b 243# undef ctime_r
a927b6c1
LC
244_GL_WARN_ON_USE (asctime, "ctime_r can overrun buffers in some cases - "
245 "better use strftime (or even sprintf) instead");
e65fc94b
LC
246# endif
247
e65fc94b 248#endif