Debian Codegraph @

lib/time.in.h

raw symbols SCIP
1 /* A more-standard <time.h>.
2
3 Copyright (C) 2007-2023 Free Software Foundation, Inc.
4
5 This file is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) any later version.
9
10 This file 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, see <https://www.gnu.org/licenses/>. */
17
18 #if __GNUC__ >= 3
19 @PRAGMA_SYSTEM_HEADER@
20 #endif
21 @PRAGMA_COLUMNS@
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. (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)
33
34 # @INCLUDE_NEXT@ @NEXT_TIME_H@
35
36 #else
37
38 # define _@GUARD_PREFIX@_TIME_H
39
40 /* mingw's <time.h> provides the functions asctime_r, ctime_r, gmtime_r,
41 localtime_r only if <unistd.h> or <pthread.h> has been included before. */
42 # if defined __MINGW32__
43 # include <unistd.h>
44 # endif
45
46 # @INCLUDE_NEXT@ @NEXT_TIME_H@
47
48 /* NetBSD 5.0 mis-defines NULL. */
49 # include <stddef.h>
50
51 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
52
53 /* The definition of _GL_ARG_NONNULL is copied here. */
54
55 /* The definition of _GL_WARN_ON_USE is copied here. */
56
57 /* Some systems don't define struct timespec (e.g., AIX 4.1).
58 Or they define it with the wrong member names or define it in <sys/time.h>
59 (e.g., FreeBSD circa 1997). Stock Mingw prior to 3.0 does not define it,
60 but the pthreads-win32 library defines it in <pthread.h>. */
61 # if ! @TIME_H_DEFINES_STRUCT_TIMESPEC@
62 # if @SYS_TIME_H_DEFINES_STRUCT_TIMESPEC@
63 # include <sys/time.h>
64 # elif @PTHREAD_H_DEFINES_STRUCT_TIMESPEC@
65 # include <pthread.h>
66 # elif @UNISTD_H_DEFINES_STRUCT_TIMESPEC@
67 # include <unistd.h>
68 # else
69
70 # ifdef __cplusplus
71 extern "C" {
72 # endif
73
74 # if !GNULIB_defined_struct_timespec
75 # undef timespec
76 # define timespec rpl_timespec
77 struct timespec
78 {
79 time_t tv_sec;
80 long int tv_nsec;
81 };
82 # define GNULIB_defined_struct_timespec 1
83 # endif
84
85 # ifdef __cplusplus
86 }
87 # endif
88
89 # endif
90 # endif
91
92 # if !GNULIB_defined_struct_time_t_must_be_integral
93 /* https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_types.h.html
94 requires time_t to be an integer type, even though C99 permits floating
95 point. We don't know of any implementation that uses floating
96 point, and it is much easier to write code that doesn't have to
97 worry about that corner case, so we force the issue. */
98 struct __time_t_must_be_integral {
99 unsigned int __floating_time_t_unsupported : (time_t) 1;
100 };
101 # define GNULIB_defined_struct_time_t_must_be_integral 1
102 # endif
103
104 /* Define TIME_UTC, a positive integer constant used for timespec_get(). */
105 # if ! @TIME_H_DEFINES_TIME_UTC@
106 # if !GNULIB_defined_TIME_UTC
107 # define TIME_UTC 1
108 # define GNULIB_defined_TIME_UTC 1
109 # endif
110 # endif
111
112 /* Set *TS to the current time, and return BASE.
113 Upon failure, return 0. */
114 # if @GNULIB_TIMESPEC_GET@
115 # if @REPLACE_TIMESPEC_GET@
116 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
117 # undef timespec_get
118 # define timespec_get rpl_timespec_get
119 # endif
120 _GL_FUNCDECL_RPL (timespec_get, int, (struct timespec *ts, int base)
121 _GL_ARG_NONNULL ((1)));
122 _GL_CXXALIAS_RPL (timespec_get, int, (struct timespec *ts, int base));
123 # else
124 # if !@HAVE_TIMESPEC_GET@
125 _GL_FUNCDECL_SYS (timespec_get, int, (struct timespec *ts, int base)
126 _GL_ARG_NONNULL ((1)));
127 # endif
128 _GL_CXXALIAS_SYS (timespec_get, int, (struct timespec *ts, int base));
129 # endif
130 # if __GLIBC__ >= 2
131 _GL_CXXALIASWARN (timespec_get);
132 # endif
133 # endif
134
135 /* Set *TS to the current time resolution, and return BASE.
136 Upon failure, return 0. */
137 # if @GNULIB_TIMESPEC_GETRES@
138 # if ! @HAVE_TIMESPEC_GETRES@
139 _GL_FUNCDECL_SYS (timespec_getres, int, (struct timespec *ts, int base)
140 _GL_ARG_NONNULL ((1)));
141 # endif
142 _GL_CXXALIAS_SYS (timespec_getres, int, (struct timespec *ts, int base));
143 _GL_CXXALIASWARN (timespec_getres);
144 # endif
145
146 /* Sleep for at least RQTP seconds unless interrupted, If interrupted,
147 return -1 and store the remaining time into RMTP. See
148 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/nanosleep.html>. */
149 # if @GNULIB_NANOSLEEP@
150 # if @REPLACE_NANOSLEEP@
151 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
152 # define nanosleep rpl_nanosleep
153 # endif
154 _GL_FUNCDECL_RPL (nanosleep, int,
155 (struct timespec const *__rqtp, struct timespec *__rmtp)
156 _GL_ARG_NONNULL ((1)));
157 _GL_CXXALIAS_RPL (nanosleep, int,
158 (struct timespec const *__rqtp, struct timespec *__rmtp));
159 # else
160 # if ! @HAVE_NANOSLEEP@
161 _GL_FUNCDECL_SYS (nanosleep, int,
162 (struct timespec const *__rqtp, struct timespec *__rmtp)
163 _GL_ARG_NONNULL ((1)));
164 # endif
165 _GL_CXXALIAS_SYS (nanosleep, int,
166 (struct timespec const *__rqtp, struct timespec *__rmtp));
167 # endif
168 _GL_CXXALIASWARN (nanosleep);
169 # endif
170
171 /* Initialize time conversion information. */
172 # if @GNULIB_TZSET@
173 # if @REPLACE_TZSET@
174 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
175 # undef tzset
176 # define tzset rpl_tzset
177 # endif
178 _GL_FUNCDECL_RPL (tzset, void, (void));
179 _GL_CXXALIAS_RPL (tzset, void, (void));
180 # elif defined _WIN32 && !defined __CYGWIN__
181 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
182 # undef tzset
183 # define tzset _tzset
184 # endif
185 _GL_CXXALIAS_MDA (tzset, void, (void));
186 # else
187 _GL_CXXALIAS_SYS (tzset, void, (void));
188 # endif
189 _GL_CXXALIASWARN (tzset);
190 # elif @GNULIB_MDA_TZSET@
191 /* On native Windows, map 'tzset' to '_tzset', so that -loldnames is not
192 required. In C++ with GNULIB_NAMESPACE, avoid differences between
193 platforms by defining GNULIB_NAMESPACE::tzset always. */
194 # if defined _WIN32 && !defined __CYGWIN__
195 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
196 # undef tzset
197 # define tzset _tzset
198 # endif
199 _GL_CXXALIAS_MDA (tzset, void, (void));
200 # else
201 _GL_CXXALIAS_SYS (tzset, void, (void));
202 # endif
203 _GL_CXXALIASWARN (tzset);
204 # endif
205
206 /* Return the 'time_t' representation of TP and normalize TP. */
207 # if @GNULIB_MKTIME@
208 # if @REPLACE_MKTIME@
209 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
210 # define mktime rpl_mktime
211 # endif
212 _GL_FUNCDECL_RPL (mktime, time_t, (struct tm *__tp) _GL_ARG_NONNULL ((1)));
213 _GL_CXXALIAS_RPL (mktime, time_t, (struct tm *__tp));
214 # else
215 _GL_CXXALIAS_SYS (mktime, time_t, (struct tm *__tp));
216 # endif
217 # if __GLIBC__ >= 2
218 _GL_CXXALIASWARN (mktime);
219 # endif
220 # endif
221
222 /* Convert TIMER to RESULT, assuming local time and UTC respectively. See
223 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/localtime_r.html> and
224 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/gmtime_r.html>. */
225 # if @GNULIB_TIME_R@
226 # if @REPLACE_LOCALTIME_R@
227 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
228 # undef localtime_r
229 # define localtime_r rpl_localtime_r
230 # endif
231 _GL_FUNCDECL_RPL (localtime_r, struct tm *, (time_t const *restrict __timer,
232 struct tm *restrict __result)
233 _GL_ARG_NONNULL ((1, 2)));
234 _GL_CXXALIAS_RPL (localtime_r, struct tm *, (time_t const *restrict __timer,
235 struct tm *restrict __result));
236 # else
237 # if ! @HAVE_DECL_LOCALTIME_R@
238 _GL_FUNCDECL_SYS (localtime_r, struct tm *, (time_t const *restrict __timer,
239 struct tm *restrict __result)
240 _GL_ARG_NONNULL ((1, 2)));
241 # endif
242 _GL_CXXALIAS_SYS (localtime_r, struct tm *, (time_t const *restrict __timer,
243 struct tm *restrict __result));
244 # endif
245 # if @HAVE_DECL_LOCALTIME_R@
246 _GL_CXXALIASWARN (localtime_r);
247 # endif
248 # if @REPLACE_LOCALTIME_R@
249 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
250 # undef gmtime_r
251 # define gmtime_r rpl_gmtime_r
252 # endif
253 _GL_FUNCDECL_RPL (gmtime_r, struct tm *, (time_t const *restrict __timer,
254 struct tm *restrict __result)
255 _GL_ARG_NONNULL ((1, 2)));
256 _GL_CXXALIAS_RPL (gmtime_r, struct tm *, (time_t const *restrict __timer,
257 struct tm *restrict __result));
258 # else
259 # if ! @HAVE_DECL_LOCALTIME_R@
260 _GL_FUNCDECL_SYS (gmtime_r, struct tm *, (time_t const *restrict __timer,
261 struct tm *restrict __result)
262 _GL_ARG_NONNULL ((1, 2)));
263 # endif
264 _GL_CXXALIAS_SYS (gmtime_r, struct tm *, (time_t const *restrict __timer,
265 struct tm *restrict __result));
266 # endif
267 # if @HAVE_DECL_LOCALTIME_R@
268 _GL_CXXALIASWARN (gmtime_r);
269 # endif
270 # endif
271
272 /* Convert TIMER to RESULT, assuming local time and UTC respectively. See
273 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/localtime.html> and
274 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/gmtime.html>. */
275 # if @GNULIB_LOCALTIME@ || @REPLACE_LOCALTIME@
276 # if @REPLACE_LOCALTIME@
277 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
278 # undef localtime
279 # define localtime rpl_localtime
280 # endif
281 _GL_FUNCDECL_RPL (localtime, struct tm *, (time_t const *__timer)
282 _GL_ARG_NONNULL ((1)));
283 _GL_CXXALIAS_RPL (localtime, struct tm *, (time_t const *__timer));
284 # else
285 _GL_CXXALIAS_SYS (localtime, struct tm *, (time_t const *__timer));
286 # endif
287 # if __GLIBC__ >= 2
288 _GL_CXXALIASWARN (localtime);
289 # endif
290 # endif
291
292 # if 0 || @REPLACE_GMTIME@
293 # if @REPLACE_GMTIME@
294 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
295 # undef gmtime
296 # define gmtime rpl_gmtime
297 # endif
298 _GL_FUNCDECL_RPL (gmtime, struct tm *, (time_t const *__timer)
299 _GL_ARG_NONNULL ((1)));
300 _GL_CXXALIAS_RPL (gmtime, struct tm *, (time_t const *__timer));
301 # else
302 _GL_CXXALIAS_SYS (gmtime, struct tm *, (time_t const *__timer));
303 # endif
304 _GL_CXXALIASWARN (gmtime);
305 # endif
306
307 /* Parse BUF as a timestamp, assuming FORMAT specifies its layout, and store
308 the resulting broken-down time into TM. See
309 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/strptime.html>. */
310 # if @GNULIB_STRPTIME@
311 # if ! @HAVE_STRPTIME@
312 _GL_FUNCDECL_SYS (strptime, char *, (char const *restrict __buf,
313 char const *restrict __format,
314 struct tm *restrict __tm)
315 _GL_ARG_NONNULL ((1, 2, 3)));
316 # endif
317 _GL_CXXALIAS_SYS (strptime, char *, (char const *restrict __buf,
318 char const *restrict __format,
319 struct tm *restrict __tm));
320 _GL_CXXALIASWARN (strptime);
321 # endif
322
323 /* Convert *TP to a date and time string. See
324 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/ctime.html>. */
325 # if @GNULIB_CTIME@
326 # if @REPLACE_CTIME@
327 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
328 # define ctime rpl_ctime
329 # endif
330 _GL_ATTRIBUTE_DEPRECATED
331 _GL_FUNCDECL_RPL (ctime, char *, (time_t const *__tp)
332 _GL_ARG_NONNULL ((1)));
333 _GL_CXXALIAS_RPL (ctime, char *, (time_t const *__tp));
334 # else
335 _GL_CXXALIAS_SYS (ctime, char *, (time_t const *__tp));
336 # endif
337 # if __GLIBC__ >= 2
338 _GL_CXXALIASWARN (ctime);
339 # endif
340 # endif
341
342 /* Convert *TP to a date and time string. See
343 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/strftime.html>. */
344 # if @GNULIB_STRFTIME@
345 # if @REPLACE_STRFTIME@
346 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
347 # define strftime rpl_strftime
348 # endif
349 _GL_FUNCDECL_RPL (strftime, size_t,
350 (char *restrict __buf, size_t __bufsize,
351 const char *restrict __fmt, const struct tm *restrict __tp)
352 _GL_ARG_NONNULL ((1, 3, 4)));
353 _GL_CXXALIAS_RPL (strftime, size_t,
354 (char *restrict __buf, size_t __bufsize,
355 const char *restrict __fmt, const struct tm *restrict __tp));
356 # else
357 _GL_CXXALIAS_SYS (strftime, size_t,
358 (char *restrict __buf, size_t __bufsize,
359 const char *restrict __fmt, const struct tm *restrict __tp));
360 # endif
361 # if __GLIBC__ >= 2
362 _GL_CXXALIASWARN (strftime);
363 # endif
364 # endif
365
366 # if defined _GNU_SOURCE && @GNULIB_TIME_RZ@ && ! @HAVE_TIMEZONE_T@
367 /* Functions that use a first-class time zone data type, instead of
368 relying on an implicit global time zone.
369 Inspired by NetBSD. */
370
371 /* Represents a time zone.
372 (timezone_t) NULL stands for UTC. */
373 typedef struct tm_zone *timezone_t;
374
375 /* tzalloc (name)
376 Returns a time zone object for the given time zone NAME. This object
377 represents the time zone that other functions would use it the TZ
378 environment variable was set to NAME.
379 If NAME is NULL, the result represents the time zone that other functions
380 would use it the TZ environment variable was unset.
381 May return NULL if NAME is invalid (this is platform dependent) or
382 upon memory allocation failure. */
383 _GL_FUNCDECL_SYS (tzalloc, timezone_t, (char const *__name));
384 _GL_CXXALIAS_SYS (tzalloc, timezone_t, (char const *__name));
385
386 /* tzfree (tz)
387 Frees a time zone object.
388 The argument must have been returned by tzalloc(). */
389 _GL_FUNCDECL_SYS (tzfree, void, (timezone_t __tz));
390 _GL_CXXALIAS_SYS (tzfree, void, (timezone_t __tz));
391
392 /* localtime_rz (tz, &t, &result)
393 Converts an absolute time T to a broken-down time RESULT, assuming the
394 time zone TZ.
395 This function is like 'localtime_r', but relies on the argument TZ instead
396 of an implicit global time zone. */
397 _GL_FUNCDECL_SYS (localtime_rz, struct tm *,
398 (timezone_t __tz, time_t const *restrict __timer,
399 struct tm *restrict __result) _GL_ARG_NONNULL ((2, 3)));
400 _GL_CXXALIAS_SYS (localtime_rz, struct tm *,
401 (timezone_t __tz, time_t const *restrict __timer,
402 struct tm *restrict __result));
403
404 /* mktime_z (tz, &tm)
405 Normalizes the broken-down time TM and converts it to an absolute time,
406 assuming the time zone TZ. Returns the absolute time.
407 This function is like 'mktime', but relies on the argument TZ instead
408 of an implicit global time zone. */
409 _GL_FUNCDECL_SYS (mktime_z, time_t,
410 (timezone_t __tz, struct tm *restrict __tm)
411 _GL_ARG_NONNULL ((2)));
412 _GL_CXXALIAS_SYS (mktime_z, time_t,
413 (timezone_t __tz, struct tm *restrict __tm));
414
415 /* Time zone abbreviation strings (returned by 'localtime_rz' or 'mktime_z'
416 in the 'tm_zone' member of 'struct tm') are valid as long as
417 - the 'struct tm' argument is not destroyed or overwritten,
418 and
419 - the 'timezone_t' argument is not freed through tzfree(). */
420
421 # endif
422
423 /* Convert TM to a time_t value, assuming UTC. */
424 # if @GNULIB_TIMEGM@
425 # if @REPLACE_TIMEGM@
426 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
427 # undef timegm
428 # define timegm rpl_timegm
429 # endif
430 _GL_FUNCDECL_RPL (timegm, time_t, (struct tm *__tm) _GL_ARG_NONNULL ((1)));
431 _GL_CXXALIAS_RPL (timegm, time_t, (struct tm *__tm));
432 # else
433 # if ! @HAVE_TIMEGM@
434 _GL_FUNCDECL_SYS (timegm, time_t, (struct tm *__tm) _GL_ARG_NONNULL ((1)));
435 # endif
436 _GL_CXXALIAS_SYS (timegm, time_t, (struct tm *__tm));
437 # endif
438 # if __GLIBC__ >= 2
439 _GL_CXXALIASWARN (timegm);
440 # endif
441 # endif
442
443 /* Encourage applications to avoid unsafe functions that can overrun
444 buffers when given outlandish struct tm values. Portable
445 applications should use strftime (or even sprintf) instead. */
446 # if defined GNULIB_POSIXCHECK
447 # undef asctime
448 _GL_WARN_ON_USE (asctime, "asctime can overrun buffers in some cases - "
449 "better use strftime (or even sprintf) instead");
450 # endif
451 # if defined GNULIB_POSIXCHECK
452 # undef asctime_r
453 # if HAVE_RAW_DECL_ASCTIME_R
454 _GL_WARN_ON_USE (asctime_r, "asctime_r can overrun buffers in some cases - "
455 "better use strftime (or even sprintf) instead");
456 # endif
457 # endif
458 # if defined GNULIB_POSIXCHECK
459 # undef ctime
460 _GL_WARN_ON_USE (ctime, "ctime can overrun buffers in some cases - "
461 "better use strftime (or even sprintf) instead");
462 # endif
463 # if defined GNULIB_POSIXCHECK
464 # undef ctime_r
465 # if HAVE_RAW_DECL_CTIME_R
466 _GL_WARN_ON_USE (ctime_r, "ctime_r can overrun buffers in some cases - "
467 "better use strftime (or even sprintf) instead");
468 # endif
469 # endif
470
471 #endif