Ensure no #include statements inside extern "C" { ... }.
[gnulib.git] / lib / time.in.h
1 /* A more-standard <time.h>.
2
3    Copyright (C) 2007-2010 Free Software Foundation, Inc.
4
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)
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 General Public License for more details.
14
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.  */
18
19 #if __GNUC__ >= 3
20 @PRAGMA_SYSTEM_HEADER@
21 #endif
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 \
30      || defined _GL_TIME_H)
31
32 # @INCLUDE_NEXT@ @NEXT_TIME_H@
33
34 #else
35
36 # define _GL_TIME_H
37
38 # @INCLUDE_NEXT@ @NEXT_TIME_H@
39
40 /* NetBSD 5.0 mis-defines NULL.  */
41 #include <stddef.h>
42
43 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here.  */
44
45 /* The definition of _GL_ARG_NONNULL is copied here.  */
46
47 /* The definition of _GL_WARN_ON_USE is copied here.  */
48
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>
51    (e.g., FreeBSD circa 1997).  */
52 # if ! @TIME_H_DEFINES_STRUCT_TIMESPEC@
53 #  if @SYS_TIME_H_DEFINES_STRUCT_TIMESPEC@
54 #   include <sys/time.h>
55 #  else
56
57 #   ifdef __cplusplus
58 extern "C" {
59 #   endif
60
61 #   undef timespec
62 #   define timespec rpl_timespec
63 struct timespec
64 {
65   time_t tv_sec;
66   long int tv_nsec;
67 };
68
69 #   ifdef __cplusplus
70 }
71 #   endif
72
73 #  endif
74 # endif
75
76 /* Sleep for at least RQTP seconds unless interrupted,  If interrupted,
77    return -1 and store the remaining time into RMTP.  See
78    <http://www.opengroup.org/susv3xsh/nanosleep.html>.  */
79 # if @GNULIB_NANOSLEEP@
80 #  if @REPLACE_NANOSLEEP@
81 #   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
82 #    define nanosleep rpl_nanosleep
83 #   endif
84 _GL_FUNCDECL_RPL (nanosleep, int,
85                   (struct timespec const *__rqtp, struct timespec *__rmtp)
86                   _GL_ARG_NONNULL ((1)));
87 _GL_CXXALIAS_RPL (nanosleep, int,
88                   (struct timespec const *__rqtp, struct timespec *__rmtp));
89 #  else
90 _GL_CXXALIAS_SYS (nanosleep, int,
91                   (struct timespec const *__rqtp, struct timespec *__rmtp));
92 #  endif
93 _GL_CXXALIASWARN (nanosleep);
94 # endif
95
96 /* Return the 'time_t' representation of TP and normalize TP.  */
97 # if @GNULIB_MKTIME@
98 #  if @REPLACE_MKTIME@
99 #   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
100 #    define mktime rpl_mktime
101 #   endif
102 _GL_FUNCDECL_RPL (mktime, time_t, (struct tm *__tp) _GL_ARG_NONNULL ((1)));
103 _GL_CXXALIAS_RPL (mktime, time_t, (struct tm *__tp));
104 #  else
105 _GL_CXXALIAS_SYS (mktime, time_t, (struct tm *__tp));
106 #  endif
107 _GL_CXXALIASWARN (mktime);
108 # endif
109
110 /* Convert TIMER to RESULT, assuming local time and UTC respectively.  See
111    <http://www.opengroup.org/susv3xsh/localtime_r.html> and
112    <http://www.opengroup.org/susv3xsh/gmtime_r.html>.  */
113 # if @GNULIB_TIME_R@
114 #  if @REPLACE_LOCALTIME_R@
115 #   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
116 #    undef localtime_r
117 #    define localtime_r rpl_localtime_r
118 #   endif
119 _GL_FUNCDECL_RPL (localtime_r, struct tm *, (time_t const *restrict __timer,
120                                              struct tm *restrict __result)
121                                             _GL_ARG_NONNULL ((1, 2)));
122 _GL_CXXALIAS_RPL (localtime_r, struct tm *, (time_t const *restrict __timer,
123                                              struct tm *restrict __result));
124 #  else
125 _GL_CXXALIAS_SYS (localtime_r, struct tm *, (time_t const *restrict __timer,
126                                              struct tm *restrict __result));
127 #  endif
128 _GL_CXXALIASWARN (localtime_r);
129 #  if @REPLACE_LOCALTIME_R@
130 #   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
131 #    undef gmtime_r
132 #    define gmtime_r rpl_gmtime_r
133 #   endif
134 _GL_FUNCDECL_RPL (gmtime_r, struct tm *, (time_t const *restrict __timer,
135                                           struct tm *restrict __result)
136                                          _GL_ARG_NONNULL ((1, 2)));
137 _GL_CXXALIAS_RPL (gmtime_r, struct tm *, (time_t const *restrict __timer,
138                                           struct tm *restrict __result));
139 #  else
140 _GL_CXXALIAS_SYS (gmtime_r, struct tm *, (time_t const *restrict __timer,
141                                           struct tm *restrict __result));
142 #  endif
143 _GL_CXXALIASWARN (gmtime_r);
144 # endif
145
146 /* Parse BUF as a time stamp, assuming FORMAT specifies its layout, and store
147    the resulting broken-down time into TM.  See
148    <http://www.opengroup.org/susv3xsh/strptime.html>.  */
149 # if @GNULIB_STRPTIME@
150 #  if @REPLACE_STRPTIME@
151 #   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
152 #    undef strptime
153 #    define strptime rpl_strptime
154 #   endif
155 _GL_FUNCDECL_RPL (strptime, char *, (char const *restrict __buf,
156                                      char const *restrict __format,
157                                      struct tm *restrict __tm)
158                                     _GL_ARG_NONNULL ((1, 2, 3)));
159 _GL_CXXALIAS_RPL (strptime, char *, (char const *restrict __buf,
160                                      char const *restrict __format,
161                                      struct tm *restrict __tm));
162 #  else
163 _GL_CXXALIAS_SYS (strptime, char *, (char const *restrict __buf,
164                                      char const *restrict __format,
165                                      struct tm *restrict __tm));
166 #  endif
167 _GL_CXXALIASWARN (strptime);
168 # endif
169
170 /* Convert TM to a time_t value, assuming UTC.  */
171 # if @GNULIB_TIMEGM@
172 #  if @REPLACE_TIMEGM@
173 #   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
174 #    undef timegm
175 #    define timegm rpl_timegm
176 #   endif
177 _GL_FUNCDECL_RPL (timegm, time_t, (struct tm *__tm) _GL_ARG_NONNULL ((1)));
178 _GL_CXXALIAS_RPL (timegm, time_t, (struct tm *__tm));
179 #  else
180 _GL_CXXALIAS_SYS (timegm, time_t, (struct tm *__tm));
181 #  endif
182 _GL_CXXALIASWARN (timegm);
183 # endif
184
185 /* Encourage applications to avoid unsafe functions that can overrun
186    buffers when given outlandish struct tm values.  Portable
187    applications should use strftime (or even sprintf) instead.  */
188 # if GNULIB_PORTCHECK
189 #  undef asctime
190 #  define asctime eschew_asctime
191 #  undef asctime_r
192 #  define asctime_r eschew_asctime_r
193 #  undef ctime
194 #  define ctime eschew_ctime
195 #  undef ctime_r
196 #  define ctime_r eschew_ctime_r
197 # endif
198
199 #endif