Avoid line length limitation from HP NonStop system header files.
[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 @PRAGMA_COLUMNS@
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
41 /* NetBSD 5.0 mis-defines NULL.  */
42 # include <stddef.h>
43
44 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here.  */
45
46 /* The definition of _GL_ARG_NONNULL is copied here.  */
47
48 /* The definition of _GL_WARN_ON_USE is copied here.  */
49
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>
52    (e.g., FreeBSD circa 1997).  Stock Mingw does not define it, but the
53    pthreads-win32 library defines it in <pthread.h>.  */
54 # if ! @TIME_H_DEFINES_STRUCT_TIMESPEC@
55 #  if @SYS_TIME_H_DEFINES_STRUCT_TIMESPEC@
56 #   include <sys/time.h>
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
66 #  else
67
68 #   ifdef __cplusplus
69 extern "C" {
70 #   endif
71
72 #   undef timespec
73 #   define timespec rpl_timespec
74 struct timespec
75 {
76   time_t tv_sec;
77   long int tv_nsec;
78 };
79
80 #   ifdef __cplusplus
81 }
82 #   endif
83
84 #  endif
85 # endif
86
87 /* Sleep for at least RQTP seconds unless interrupted,  If interrupted,
88    return -1 and store the remaining time into RMTP.  See
89    <http://www.opengroup.org/susv3xsh/nanosleep.html>.  */
90 # if @GNULIB_NANOSLEEP@
91 #  if @REPLACE_NANOSLEEP@
92 #   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
93 #    define nanosleep rpl_nanosleep
94 #   endif
95 _GL_FUNCDECL_RPL (nanosleep, int,
96                   (struct timespec const *__rqtp, struct timespec *__rmtp)
97                   _GL_ARG_NONNULL ((1)));
98 _GL_CXXALIAS_RPL (nanosleep, int,
99                   (struct timespec const *__rqtp, struct timespec *__rmtp));
100 #  else
101 #   if ! @HAVE_NANOSLEEP@
102 _GL_FUNCDECL_SYS (nanosleep, int,
103                   (struct timespec const *__rqtp, struct timespec *__rmtp)
104                   _GL_ARG_NONNULL ((1)));
105 #   endif
106 _GL_CXXALIAS_SYS (nanosleep, int,
107                   (struct timespec const *__rqtp, struct timespec *__rmtp));
108 #  endif
109 _GL_CXXALIASWARN (nanosleep);
110 # endif
111
112 /* Return the 'time_t' representation of TP and normalize TP.  */
113 # if @GNULIB_MKTIME@
114 #  if @REPLACE_MKTIME@
115 #   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
116 #    define mktime rpl_mktime
117 #   endif
118 _GL_FUNCDECL_RPL (mktime, time_t, (struct tm *__tp) _GL_ARG_NONNULL ((1)));
119 _GL_CXXALIAS_RPL (mktime, time_t, (struct tm *__tp));
120 #  else
121 _GL_CXXALIAS_SYS (mktime, time_t, (struct tm *__tp));
122 #  endif
123 _GL_CXXALIASWARN (mktime);
124 # endif
125
126 /* Convert TIMER to RESULT, assuming local time and UTC respectively.  See
127    <http://www.opengroup.org/susv3xsh/localtime_r.html> and
128    <http://www.opengroup.org/susv3xsh/gmtime_r.html>.  */
129 # if @GNULIB_TIME_R@
130 #  if @REPLACE_LOCALTIME_R@
131 #   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
132 #    undef localtime_r
133 #    define localtime_r rpl_localtime_r
134 #   endif
135 _GL_FUNCDECL_RPL (localtime_r, struct tm *, (time_t const *restrict __timer,
136                                              struct tm *restrict __result)
137                                             _GL_ARG_NONNULL ((1, 2)));
138 _GL_CXXALIAS_RPL (localtime_r, struct tm *, (time_t const *restrict __timer,
139                                              struct tm *restrict __result));
140 #  else
141 #   if ! @HAVE_LOCALTIME_R@
142 _GL_FUNCDECL_SYS (localtime_r, struct tm *, (time_t const *restrict __timer,
143                                              struct tm *restrict __result)
144                                             _GL_ARG_NONNULL ((1, 2)));
145 #   endif
146 _GL_CXXALIAS_SYS (localtime_r, struct tm *, (time_t const *restrict __timer,
147                                              struct tm *restrict __result));
148 #  endif
149 _GL_CXXALIASWARN (localtime_r);
150 #  if @REPLACE_LOCALTIME_R@
151 #   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
152 #    undef gmtime_r
153 #    define gmtime_r rpl_gmtime_r
154 #   endif
155 _GL_FUNCDECL_RPL (gmtime_r, struct tm *, (time_t const *restrict __timer,
156                                           struct tm *restrict __result)
157                                          _GL_ARG_NONNULL ((1, 2)));
158 _GL_CXXALIAS_RPL (gmtime_r, struct tm *, (time_t const *restrict __timer,
159                                           struct tm *restrict __result));
160 #  else
161 #   if ! @HAVE_LOCALTIME_R@
162 _GL_FUNCDECL_SYS (gmtime_r, struct tm *, (time_t const *restrict __timer,
163                                           struct tm *restrict __result)
164                                          _GL_ARG_NONNULL ((1, 2)));
165 #   endif
166 _GL_CXXALIAS_SYS (gmtime_r, struct tm *, (time_t const *restrict __timer,
167                                           struct tm *restrict __result));
168 #  endif
169 _GL_CXXALIASWARN (gmtime_r);
170 # endif
171
172 /* Parse BUF as a time stamp, assuming FORMAT specifies its layout, and store
173    the resulting broken-down time into TM.  See
174    <http://www.opengroup.org/susv3xsh/strptime.html>.  */
175 # if @GNULIB_STRPTIME@
176 #  if ! @HAVE_STRPTIME@
177 _GL_FUNCDECL_SYS (strptime, char *, (char const *restrict __buf,
178                                      char const *restrict __format,
179                                      struct tm *restrict __tm)
180                                     _GL_ARG_NONNULL ((1, 2, 3)));
181 #  endif
182 _GL_CXXALIAS_SYS (strptime, char *, (char const *restrict __buf,
183                                      char const *restrict __format,
184                                      struct tm *restrict __tm));
185 _GL_CXXALIASWARN (strptime);
186 # endif
187
188 /* Convert TM to a time_t value, assuming UTC.  */
189 # if @GNULIB_TIMEGM@
190 #  if @REPLACE_TIMEGM@
191 #   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
192 #    undef timegm
193 #    define timegm rpl_timegm
194 #   endif
195 _GL_FUNCDECL_RPL (timegm, time_t, (struct tm *__tm) _GL_ARG_NONNULL ((1)));
196 _GL_CXXALIAS_RPL (timegm, time_t, (struct tm *__tm));
197 #  else
198 #   if ! @HAVE_TIMEGM@
199 _GL_FUNCDECL_SYS (timegm, time_t, (struct tm *__tm) _GL_ARG_NONNULL ((1)));
200 #   endif
201 _GL_CXXALIAS_SYS (timegm, time_t, (struct tm *__tm));
202 #  endif
203 _GL_CXXALIASWARN (timegm);
204 # endif
205
206 /* Encourage applications to avoid unsafe functions that can overrun
207    buffers when given outlandish struct tm values.  Portable
208    applications should use strftime (or even sprintf) instead.  */
209 # if defined GNULIB_POSIXCHECK
210 #  undef asctime
211 _GL_WARN_ON_USE (asctime, "asctime can overrun buffers in some cases - "
212                  "better use strftime (or even sprintf) instead");
213 # endif
214 # if defined GNULIB_POSIXCHECK
215 #  undef asctime_r
216 _GL_WARN_ON_USE (asctime, "asctime_r can overrun buffers in some cases - "
217                  "better use strftime (or even sprintf) instead");
218 # endif
219 # if defined GNULIB_POSIXCHECK
220 #  undef ctime
221 _GL_WARN_ON_USE (asctime, "ctime can overrun buffers in some cases - "
222                  "better use strftime (or even sprintf) instead");
223 # endif
224 # if defined GNULIB_POSIXCHECK
225 #  undef ctime_r
226 _GL_WARN_ON_USE (asctime, "ctime_r can overrun buffers in some cases - "
227                  "better use strftime (or even sprintf) instead");
228 # endif
229
230 #endif