summaryrefslogtreecommitdiffstats
path: root/gl/time.in.h
diff options
context:
space:
mode:
Diffstat (limited to 'gl/time.in.h')
-rw-r--r--gl/time.in.h116
1 files changed, 90 insertions, 26 deletions
diff --git a/gl/time.in.h b/gl/time.in.h
index df99c8ab..3ff16e3b 100644
--- a/gl/time.in.h
+++ b/gl/time.in.h
@@ -1,6 +1,6 @@
1/* A more-standard <time.h>. 1/* A more-standard <time.h>.
2 2
3 Copyright (C) 2007-2024 Free Software Foundation, Inc. 3 Copyright (C) 2007-2025 Free Software Foundation, Inc.
4 4
5 This file is free software: you can redistribute it and/or modify 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 6 it under the terms of the GNU Lesser General Public License as
@@ -122,6 +122,23 @@ struct __time_t_must_be_integral {
122# endif 122# endif
123# endif 123# endif
124 124
125# if @GNULIB_TZNAME@
126/* tzname[0..1]: Abbreviated time zone names, set by the tzset() function. */
127# if NEED_DECL_TZNAME
128extern
129# ifdef __cplusplus
130 "C"
131# endif
132 char *tzname[];
133# endif
134# if defined _WIN32 && !defined __CYGWIN__
135/* On native Windows, map 'tzname' to '_tzname' etc., so that -loldnames is not
136 required. */
137# undef tzname
138# define tzname _tzname
139# endif
140# endif
141
125/* Set *TS to the current time, and return BASE. 142/* Set *TS to the current time, and return BASE.
126 Upon failure, return 0. */ 143 Upon failure, return 0. */
127# if @GNULIB_TIMESPEC_GET@ 144# if @GNULIB_TIMESPEC_GET@
@@ -130,12 +147,12 @@ struct __time_t_must_be_integral {
130# undef timespec_get 147# undef timespec_get
131# define timespec_get rpl_timespec_get 148# define timespec_get rpl_timespec_get
132# endif 149# endif
133_GL_FUNCDECL_RPL (timespec_get, int, (struct timespec *ts, int base) 150_GL_FUNCDECL_RPL (timespec_get, int, (struct timespec *ts, int base),
134 _GL_ARG_NONNULL ((1))); 151 _GL_ARG_NONNULL ((1)));
135_GL_CXXALIAS_RPL (timespec_get, int, (struct timespec *ts, int base)); 152_GL_CXXALIAS_RPL (timespec_get, int, (struct timespec *ts, int base));
136# else 153# else
137# if !@HAVE_TIMESPEC_GET@ 154# if !@HAVE_TIMESPEC_GET@
138_GL_FUNCDECL_SYS (timespec_get, int, (struct timespec *ts, int base) 155_GL_FUNCDECL_SYS (timespec_get, int, (struct timespec *ts, int base),
139 _GL_ARG_NONNULL ((1))); 156 _GL_ARG_NONNULL ((1)));
140# endif 157# endif
141_GL_CXXALIAS_SYS (timespec_get, int, (struct timespec *ts, int base)); 158_GL_CXXALIAS_SYS (timespec_get, int, (struct timespec *ts, int base));
@@ -159,17 +176,19 @@ _GL_WARN_ON_USE (timespec_get, "timespec_get is unportable - "
159# undef timespec_getres 176# undef timespec_getres
160# define timespec_getres rpl_timespec_getres 177# define timespec_getres rpl_timespec_getres
161# endif 178# endif
162_GL_FUNCDECL_RPL (timespec_getres, int, (struct timespec *ts, int base) 179_GL_FUNCDECL_RPL (timespec_getres, int, (struct timespec *ts, int base),
163 _GL_ARG_NONNULL ((1))); 180 _GL_ARG_NONNULL ((1)));
164_GL_CXXALIAS_RPL (timespec_getres, int, (struct timespec *ts, int base)); 181_GL_CXXALIAS_RPL (timespec_getres, int, (struct timespec *ts, int base));
165# else 182# else
166# if !@HAVE_TIMESPEC_GETRES@ 183# if !@HAVE_TIMESPEC_GETRES@
167_GL_FUNCDECL_SYS (timespec_getres, int, (struct timespec *ts, int base) 184_GL_FUNCDECL_SYS (timespec_getres, int, (struct timespec *ts, int base),
168 _GL_ARG_NONNULL ((1))); 185 _GL_ARG_NONNULL ((1)));
169# endif 186# endif
170_GL_CXXALIAS_SYS (timespec_getres, int, (struct timespec *ts, int base)); 187_GL_CXXALIAS_SYS (timespec_getres, int, (struct timespec *ts, int base));
171# endif 188# endif
189# if __GLIBC__ >= 2
172_GL_CXXALIASWARN (timespec_getres); 190_GL_CXXALIASWARN (timespec_getres);
191# endif
173# elif defined GNULIB_POSIXCHECK 192# elif defined GNULIB_POSIXCHECK
174# undef timespec_getres 193# undef timespec_getres
175# if HAVE_RAW_DECL_TIMESPEC_GETRES 194# if HAVE_RAW_DECL_TIMESPEC_GETRES
@@ -184,7 +203,7 @@ _GL_WARN_ON_USE (timespec_getres, "timespec_getres is unportable - "
184# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 203# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
185# define time rpl_time 204# define time rpl_time
186# endif 205# endif
187_GL_FUNCDECL_RPL (time, time_t, (time_t *__tp)); 206_GL_FUNCDECL_RPL (time, time_t, (time_t *__tp), );
188_GL_CXXALIAS_RPL (time, time_t, (time_t *__tp)); 207_GL_CXXALIAS_RPL (time, time_t, (time_t *__tp));
189# else 208# else
190_GL_CXXALIAS_SYS (time, time_t, (time_t *__tp)); 209_GL_CXXALIAS_SYS (time, time_t, (time_t *__tp));
@@ -209,14 +228,14 @@ _GL_WARN_ON_USE (time, "time has consistency problems - "
209# define nanosleep rpl_nanosleep 228# define nanosleep rpl_nanosleep
210# endif 229# endif
211_GL_FUNCDECL_RPL (nanosleep, int, 230_GL_FUNCDECL_RPL (nanosleep, int,
212 (struct timespec const *__rqtp, struct timespec *__rmtp) 231 (struct timespec const *__rqtp, struct timespec *__rmtp),
213 _GL_ARG_NONNULL ((1))); 232 _GL_ARG_NONNULL ((1)));
214_GL_CXXALIAS_RPL (nanosleep, int, 233_GL_CXXALIAS_RPL (nanosleep, int,
215 (struct timespec const *__rqtp, struct timespec *__rmtp)); 234 (struct timespec const *__rqtp, struct timespec *__rmtp));
216# else 235# else
217# if ! @HAVE_NANOSLEEP@ 236# if ! @HAVE_NANOSLEEP@
218_GL_FUNCDECL_SYS (nanosleep, int, 237_GL_FUNCDECL_SYS (nanosleep, int,
219 (struct timespec const *__rqtp, struct timespec *__rmtp) 238 (struct timespec const *__rqtp, struct timespec *__rmtp),
220 _GL_ARG_NONNULL ((1))); 239 _GL_ARG_NONNULL ((1)));
221# endif 240# endif
222_GL_CXXALIAS_SYS (nanosleep, int, 241_GL_CXXALIAS_SYS (nanosleep, int,
@@ -238,7 +257,7 @@ _GL_WARN_ON_USE (nanosleep, "nanosleep is unportable - "
238# undef tzset 257# undef tzset
239# define tzset rpl_tzset 258# define tzset rpl_tzset
240# endif 259# endif
241_GL_FUNCDECL_RPL (tzset, void, (void)); 260_GL_FUNCDECL_RPL (tzset, void, (void), );
242_GL_CXXALIAS_RPL (tzset, void, (void)); 261_GL_CXXALIAS_RPL (tzset, void, (void));
243# elif defined _WIN32 && !defined __CYGWIN__ 262# elif defined _WIN32 && !defined __CYGWIN__
244# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 263# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
@@ -278,7 +297,7 @@ _GL_WARN_ON_USE (tzset, "tzset has portability problems - "
278# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 297# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
279# define mktime rpl_mktime 298# define mktime rpl_mktime
280# endif 299# endif
281_GL_FUNCDECL_RPL (mktime, time_t, (struct tm *__tp) _GL_ARG_NONNULL ((1))); 300_GL_FUNCDECL_RPL (mktime, time_t, (struct tm *__tp), _GL_ARG_NONNULL ((1)));
282_GL_CXXALIAS_RPL (mktime, time_t, (struct tm *__tp)); 301_GL_CXXALIAS_RPL (mktime, time_t, (struct tm *__tp));
283# else 302# else
284_GL_CXXALIAS_SYS (mktime, time_t, (struct tm *__tp)); 303_GL_CXXALIAS_SYS (mktime, time_t, (struct tm *__tp));
@@ -304,14 +323,14 @@ _GL_WARN_ON_USE (mktime, "mktime has portability problems - "
304# define localtime_r rpl_localtime_r 323# define localtime_r rpl_localtime_r
305# endif 324# endif
306_GL_FUNCDECL_RPL (localtime_r, struct tm *, (time_t const *restrict __timer, 325_GL_FUNCDECL_RPL (localtime_r, struct tm *, (time_t const *restrict __timer,
307 struct tm *restrict __result) 326 struct tm *restrict __result),
308 _GL_ARG_NONNULL ((1, 2))); 327 _GL_ARG_NONNULL ((1, 2)));
309_GL_CXXALIAS_RPL (localtime_r, struct tm *, (time_t const *restrict __timer, 328_GL_CXXALIAS_RPL (localtime_r, struct tm *, (time_t const *restrict __timer,
310 struct tm *restrict __result)); 329 struct tm *restrict __result));
311# else 330# else
312# if ! @HAVE_DECL_LOCALTIME_R@ 331# if ! @HAVE_DECL_LOCALTIME_R@
313_GL_FUNCDECL_SYS (localtime_r, struct tm *, (time_t const *restrict __timer, 332_GL_FUNCDECL_SYS (localtime_r, struct tm *, (time_t const *restrict __timer,
314 struct tm *restrict __result) 333 struct tm *restrict __result),
315 _GL_ARG_NONNULL ((1, 2))); 334 _GL_ARG_NONNULL ((1, 2)));
316# endif 335# endif
317_GL_CXXALIAS_SYS (localtime_r, struct tm *, (time_t const *restrict __timer, 336_GL_CXXALIAS_SYS (localtime_r, struct tm *, (time_t const *restrict __timer,
@@ -326,14 +345,14 @@ _GL_CXXALIASWARN (localtime_r);
326# define gmtime_r rpl_gmtime_r 345# define gmtime_r rpl_gmtime_r
327# endif 346# endif
328_GL_FUNCDECL_RPL (gmtime_r, struct tm *, (time_t const *restrict __timer, 347_GL_FUNCDECL_RPL (gmtime_r, struct tm *, (time_t const *restrict __timer,
329 struct tm *restrict __result) 348 struct tm *restrict __result),
330 _GL_ARG_NONNULL ((1, 2))); 349 _GL_ARG_NONNULL ((1, 2)));
331_GL_CXXALIAS_RPL (gmtime_r, struct tm *, (time_t const *restrict __timer, 350_GL_CXXALIAS_RPL (gmtime_r, struct tm *, (time_t const *restrict __timer,
332 struct tm *restrict __result)); 351 struct tm *restrict __result));
333# else 352# else
334# if ! @HAVE_DECL_LOCALTIME_R@ 353# if ! @HAVE_DECL_LOCALTIME_R@
335_GL_FUNCDECL_SYS (gmtime_r, struct tm *, (time_t const *restrict __timer, 354_GL_FUNCDECL_SYS (gmtime_r, struct tm *, (time_t const *restrict __timer,
336 struct tm *restrict __result) 355 struct tm *restrict __result),
337 _GL_ARG_NONNULL ((1, 2))); 356 _GL_ARG_NONNULL ((1, 2)));
338# endif 357# endif
339_GL_CXXALIAS_SYS (gmtime_r, struct tm *, (time_t const *restrict __timer, 358_GL_CXXALIAS_SYS (gmtime_r, struct tm *, (time_t const *restrict __timer,
@@ -364,7 +383,7 @@ _GL_WARN_ON_USE (gmtime_r, "gmtime_r is unportable - "
364# undef localtime 383# undef localtime
365# define localtime rpl_localtime 384# define localtime rpl_localtime
366# endif 385# endif
367_GL_FUNCDECL_RPL (localtime, struct tm *, (time_t const *__timer) 386_GL_FUNCDECL_RPL (localtime, struct tm *, (time_t const *__timer),
368 _GL_ARG_NONNULL ((1))); 387 _GL_ARG_NONNULL ((1)));
369_GL_CXXALIAS_RPL (localtime, struct tm *, (time_t const *__timer)); 388_GL_CXXALIAS_RPL (localtime, struct tm *, (time_t const *__timer));
370# else 389# else
@@ -387,7 +406,7 @@ _GL_WARN_ON_USE (localtime, "localtime has portability problems - "
387# undef gmtime 406# undef gmtime
388# define gmtime rpl_gmtime 407# define gmtime rpl_gmtime
389# endif 408# endif
390_GL_FUNCDECL_RPL (gmtime, struct tm *, (time_t const *__timer) 409_GL_FUNCDECL_RPL (gmtime, struct tm *, (time_t const *__timer),
391 _GL_ARG_NONNULL ((1))); 410 _GL_ARG_NONNULL ((1)));
392_GL_CXXALIAS_RPL (gmtime, struct tm *, (time_t const *__timer)); 411_GL_CXXALIAS_RPL (gmtime, struct tm *, (time_t const *__timer));
393# else 412# else
@@ -403,7 +422,7 @@ _GL_CXXALIASWARN (gmtime);
403# if ! @HAVE_STRPTIME@ 422# if ! @HAVE_STRPTIME@
404_GL_FUNCDECL_SYS (strptime, char *, (char const *restrict __buf, 423_GL_FUNCDECL_SYS (strptime, char *, (char const *restrict __buf,
405 char const *restrict __format, 424 char const *restrict __format,
406 struct tm *restrict __tm) 425 struct tm *restrict __tm),
407 _GL_ARG_NONNULL ((1, 2, 3))); 426 _GL_ARG_NONNULL ((1, 2, 3)));
408# endif 427# endif
409_GL_CXXALIAS_SYS (strptime, char *, (char const *restrict __buf, 428_GL_CXXALIAS_SYS (strptime, char *, (char const *restrict __buf,
@@ -428,7 +447,7 @@ _GL_WARN_ON_USE (strptime, "strptime is unportable - "
428# ifndef __cplusplus 447# ifndef __cplusplus
429_GL_ATTRIBUTE_DEPRECATED 448_GL_ATTRIBUTE_DEPRECATED
430# endif 449# endif
431_GL_FUNCDECL_RPL (ctime, char *, (time_t const *__tp) 450_GL_FUNCDECL_RPL (ctime, char *, (time_t const *__tp),
432 _GL_ARG_NONNULL ((1))); 451 _GL_ARG_NONNULL ((1)));
433_GL_CXXALIAS_RPL (ctime, char *, (time_t const *__tp)); 452_GL_CXXALIAS_RPL (ctime, char *, (time_t const *__tp));
434# else 453# else
@@ -450,7 +469,7 @@ _GL_CXXALIASWARN (ctime);
450# endif 469# endif
451_GL_FUNCDECL_RPL (strftime, size_t, 470_GL_FUNCDECL_RPL (strftime, size_t,
452 (char *restrict __buf, size_t __bufsize, 471 (char *restrict __buf, size_t __bufsize,
453 const char *restrict __fmt, const struct tm *restrict __tp) 472 const char *restrict __fmt, const struct tm *restrict __tp),
454 _GL_ARG_NONNULL ((1, 3, 4))); 473 _GL_ARG_NONNULL ((1, 3, 4)));
455_GL_CXXALIAS_RPL (strftime, size_t, 474_GL_CXXALIAS_RPL (strftime, size_t,
456 (char *restrict __buf, size_t __bufsize, 475 (char *restrict __buf, size_t __bufsize,
@@ -471,14 +490,24 @@ _GL_WARN_ON_USE (strftime, "strftime has portability problems - "
471# endif 490# endif
472# endif 491# endif
473 492
474# if defined _GNU_SOURCE && @GNULIB_TIME_RZ@ && ! @HAVE_TIMEZONE_T@ 493# if @GNULIB_TIME_RZ@
475/* Functions that use a first-class time zone data type, instead of 494/* Functions that use a first-class time zone data type, instead of
476 relying on an implicit global time zone. 495 relying on an implicit global time zone.
477 Inspired by NetBSD. */ 496 Inspired by NetBSD. */
478 497
479/* Represents a time zone. 498/* Represents a time zone.
480 (timezone_t) NULL stands for UTC. */ 499 (timezone_t) NULL stands for UTC. */
500# if !@HAVE_TZALLOC@
501# if !GNULIB_defined_timezone_t
502# if !@HAVE_TIMEZONE_T@
481typedef struct tm_zone *timezone_t; 503typedef struct tm_zone *timezone_t;
504# else
505typedef struct tm_zone *rpl_timezone_t;
506# define timezone_t rpl_timezone_t
507# endif
508# define GNULIB_defined_timezone_t 1
509# endif
510# endif
482 511
483/* tzalloc (name) 512/* tzalloc (name)
484 Returns a time zone object for the given time zone NAME. This object 513 Returns a time zone object for the given time zone NAME. This object
@@ -488,37 +517,72 @@ typedef struct tm_zone *timezone_t;
488 would use it the TZ environment variable was unset. 517 would use it the TZ environment variable was unset.
489 May return NULL if NAME is invalid (this is platform dependent) or 518 May return NULL if NAME is invalid (this is platform dependent) or
490 upon memory allocation failure. */ 519 upon memory allocation failure. */
491_GL_FUNCDECL_SYS (tzalloc, timezone_t, (char const *__name)); 520# if !@HAVE_TZALLOC@
521_GL_FUNCDECL_SYS (tzalloc, timezone_t, (char const *__name), );
492_GL_CXXALIAS_SYS (tzalloc, timezone_t, (char const *__name)); 522_GL_CXXALIAS_SYS (tzalloc, timezone_t, (char const *__name));
523# endif
493 524
494/* tzfree (tz) 525/* tzfree (tz)
495 Frees a time zone object. 526 Frees a time zone object.
496 The argument must have been returned by tzalloc(). */ 527 The argument must have been returned by tzalloc(). */
497_GL_FUNCDECL_SYS (tzfree, void, (timezone_t __tz)); 528# if !@HAVE_TZALLOC@
529_GL_FUNCDECL_SYS (tzfree, void, (timezone_t __tz), );
498_GL_CXXALIAS_SYS (tzfree, void, (timezone_t __tz)); 530_GL_CXXALIAS_SYS (tzfree, void, (timezone_t __tz));
531# endif
499 532
500/* localtime_rz (tz, &t, &result) 533/* localtime_rz (tz, &t, &result)
501 Converts an absolute time T to a broken-down time RESULT, assuming the 534 Converts an absolute time T to a broken-down time RESULT, assuming the
502 time zone TZ. 535 time zone TZ.
503 This function is like 'localtime_r', but relies on the argument TZ instead 536 This function is like 'localtime_r', but relies on the argument TZ instead
504 of an implicit global time zone. */ 537 of an implicit global time zone. */
538# if @REPLACE_LOCALTIME_RZ@
539# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
540# undef localtime_rz
541# define localtime_rz rpl_localtime_rz
542# endif
543_GL_FUNCDECL_RPL (localtime_rz, struct tm *,
544 (timezone_t __tz, time_t const *restrict __timer,
545 struct tm *restrict __result),
546 _GL_ARG_NONNULL ((2, 3)));
547_GL_CXXALIAS_RPL (localtime_rz, struct tm *,
548 (timezone_t __tz, time_t const *restrict __timer,
549 struct tm *restrict __result));
550# else
551# if !@HAVE_TZALLOC@
505_GL_FUNCDECL_SYS (localtime_rz, struct tm *, 552_GL_FUNCDECL_SYS (localtime_rz, struct tm *,
506 (timezone_t __tz, time_t const *restrict __timer, 553 (timezone_t __tz, time_t const *restrict __timer,
507 struct tm *restrict __result) _GL_ARG_NONNULL ((2, 3))); 554 struct tm *restrict __result),
555 _GL_ARG_NONNULL ((2, 3)));
556# endif
508_GL_CXXALIAS_SYS (localtime_rz, struct tm *, 557_GL_CXXALIAS_SYS (localtime_rz, struct tm *,
509 (timezone_t __tz, time_t const *restrict __timer, 558 (timezone_t __tz, time_t const *restrict __timer,
510 struct tm *restrict __result)); 559 struct tm *restrict __result));
560# endif
511 561
512/* mktime_z (tz, &tm) 562/* mktime_z (tz, &tm)
513 Normalizes the broken-down time TM and converts it to an absolute time, 563 Normalizes the broken-down time TM and converts it to an absolute time,
514 assuming the time zone TZ. Returns the absolute time. 564 assuming the time zone TZ. Returns the absolute time.
515 This function is like 'mktime', but relies on the argument TZ instead 565 This function is like 'mktime', but relies on the argument TZ instead
516 of an implicit global time zone. */ 566 of an implicit global time zone. */
567# if @REPLACE_MKTIME_Z@
568# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
569# undef mktime_z
570# define mktime_z rpl_mktime_z
571# endif
572_GL_FUNCDECL_RPL (mktime_z, time_t,
573 (timezone_t __tz, struct tm *restrict __tm),
574 _GL_ARG_NONNULL ((2)));
575_GL_CXXALIAS_RPL (mktime_z, time_t,
576 (timezone_t __tz, struct tm *restrict __tm));
577# else
578# if !@HAVE_TZALLOC@
517_GL_FUNCDECL_SYS (mktime_z, time_t, 579_GL_FUNCDECL_SYS (mktime_z, time_t,
518 (timezone_t __tz, struct tm *restrict __tm) 580 (timezone_t __tz, struct tm *restrict __tm),
519 _GL_ARG_NONNULL ((2))); 581 _GL_ARG_NONNULL ((2)));
582# endif
520_GL_CXXALIAS_SYS (mktime_z, time_t, 583_GL_CXXALIAS_SYS (mktime_z, time_t,
521 (timezone_t __tz, struct tm *restrict __tm)); 584 (timezone_t __tz, struct tm *restrict __tm));
585# endif
522 586
523/* Time zone abbreviation strings (returned by 'localtime_rz' or 'mktime_z' 587/* Time zone abbreviation strings (returned by 'localtime_rz' or 'mktime_z'
524 in the 'tm_zone' member of 'struct tm') are valid as long as 588 in the 'tm_zone' member of 'struct tm') are valid as long as
@@ -535,11 +599,11 @@ _GL_CXXALIAS_SYS (mktime_z, time_t,
535# undef timegm 599# undef timegm
536# define timegm rpl_timegm 600# define timegm rpl_timegm
537# endif 601# endif
538_GL_FUNCDECL_RPL (timegm, time_t, (struct tm *__tm) _GL_ARG_NONNULL ((1))); 602_GL_FUNCDECL_RPL (timegm, time_t, (struct tm *__tm), _GL_ARG_NONNULL ((1)));
539_GL_CXXALIAS_RPL (timegm, time_t, (struct tm *__tm)); 603_GL_CXXALIAS_RPL (timegm, time_t, (struct tm *__tm));
540# else 604# else
541# if ! @HAVE_TIMEGM@ 605# if ! @HAVE_TIMEGM@
542_GL_FUNCDECL_SYS (timegm, time_t, (struct tm *__tm) _GL_ARG_NONNULL ((1))); 606_GL_FUNCDECL_SYS (timegm, time_t, (struct tm *__tm), _GL_ARG_NONNULL ((1)));
543# endif 607# endif
544_GL_CXXALIAS_SYS (timegm, time_t, (struct tm *__tm)); 608_GL_CXXALIAS_SYS (timegm, time_t, (struct tm *__tm));
545# endif 609# endif