private.h (46c599340f187db577b9212ab18022f3c7380c68) private.h (a979394afeb5c20fc58c5f5b005d51eb8f92f666)
1/* Private header for tzdb code. */
2
3#ifndef PRIVATE_H
4
5#define PRIVATE_H
6
7/*
8** This file is in the public domain, so clarified as of

--- 5 unchanged lines hidden (view full) ---

14** There is no guarantee that it will remain unchanged,
15** or that it will remain at all.
16** Do NOT copy it to any system include directory.
17** Thank you!
18*/
19
20/* PORT_TO_C89 means the code should work even if the underlying
21 compiler and library support only C89 plus C99's 'long long'
1/* Private header for tzdb code. */
2
3#ifndef PRIVATE_H
4
5#define PRIVATE_H
6
7/*
8** This file is in the public domain, so clarified as of

--- 5 unchanged lines hidden (view full) ---

14** There is no guarantee that it will remain unchanged,
15** or that it will remain at all.
16** Do NOT copy it to any system include directory.
17** Thank you!
18*/
19
20/* PORT_TO_C89 means the code should work even if the underlying
21 compiler and library support only C89 plus C99's 'long long'
22 and perhaps a few other extensions to C89. SUPPORT_C89 means the
23 tzcode library should support C89 callers in addition to the usual
24 support for C99-and-later callers; however, C89 support can trigger
25 latent bugs in C99-and-later callers. These macros are obsolescent,
26 and the plan is to remove them along with any code needed only when
27 they are nonzero. A good time to do that might be in the year 2029
22 and perhaps a few other extensions to C89.
23
24 This macro is obsolescent, and the plan is to remove it along with
25 associated code. A good time to do that might be in the year 2029
28 because RHEL 7 (whose GCC defaults to C89) extended life cycle
29 support (ELS) is scheduled to end on 2028-06-30. */
30#ifndef PORT_TO_C89
31# define PORT_TO_C89 0
32#endif
26 because RHEL 7 (whose GCC defaults to C89) extended life cycle
27 support (ELS) is scheduled to end on 2028-06-30. */
28#ifndef PORT_TO_C89
29# define PORT_TO_C89 0
30#endif
31
32/* SUPPORT_C89 means the tzcode library should support C89 callers
33 in addition to the usual support for C99-and-later callers.
34 This defaults to 1 as POSIX requires, even though that can trigger
35 latent bugs in callers. */
33#ifndef SUPPORT_C89
36#ifndef SUPPORT_C89
34# define SUPPORT_C89 0
37# define SUPPORT_C89 1
35#endif
36
37#ifndef __STDC_VERSION__
38# define __STDC_VERSION__ 0
39#endif
40
41/* Define true, false and bool if they don't work out of the box. */
42#if PORT_TO_C89 && __STDC_VERSION__ < 199901

--- 21 unchanged lines hidden (view full) ---

64/* This string was in the Factory zone through version 2016f. */
65#define GRANDPARENTED "Local time zone must be set--use tzsetup"
66
67/*
68** Defaults for preprocessor symbols.
69** You can override these in your C compiler options, e.g. '-DHAVE_GETTEXT=1'.
70*/
71
38#endif
39
40#ifndef __STDC_VERSION__
41# define __STDC_VERSION__ 0
42#endif
43
44/* Define true, false and bool if they don't work out of the box. */
45#if PORT_TO_C89 && __STDC_VERSION__ < 199901

--- 21 unchanged lines hidden (view full) ---

67/* This string was in the Factory zone through version 2016f. */
68#define GRANDPARENTED "Local time zone must be set--use tzsetup"
69
70/*
71** Defaults for preprocessor symbols.
72** You can override these in your C compiler options, e.g. '-DHAVE_GETTEXT=1'.
73*/
74
72#ifndef HAVE_DECL_ASCTIME_R
73# define HAVE_DECL_ASCTIME_R 1
74#endif
75
76#if !defined HAVE__GENERIC && defined __has_extension
77# if !__has_extension(c_generic_selections)
78# define HAVE__GENERIC 0
79# endif
80#endif
81/* _Generic is buggy in pre-4.9 GCC. */
82#if !defined HAVE__GENERIC && defined __GNUC__ && !defined __STRICT_ANSI__
83# define HAVE__GENERIC (4 < __GNUC__ + (9 <= __GNUC_MINOR__))

--- 147 unchanged lines hidden (view full) ---

231#if HAVE_GETTEXT
232# include <libintl.h>
233#endif /* HAVE_GETTEXT */
234
235#if HAVE_UNISTD_H
236# include <unistd.h> /* for R_OK, and other POSIX goodness */
237#endif /* HAVE_UNISTD_H */
238
75#if !defined HAVE__GENERIC && defined __has_extension
76# if !__has_extension(c_generic_selections)
77# define HAVE__GENERIC 0
78# endif
79#endif
80/* _Generic is buggy in pre-4.9 GCC. */
81#if !defined HAVE__GENERIC && defined __GNUC__ && !defined __STRICT_ANSI__
82# define HAVE__GENERIC (4 < __GNUC__ + (9 <= __GNUC_MINOR__))

--- 147 unchanged lines hidden (view full) ---

230#if HAVE_GETTEXT
231# include <libintl.h>
232#endif /* HAVE_GETTEXT */
233
234#if HAVE_UNISTD_H
235# include <unistd.h> /* for R_OK, and other POSIX goodness */
236#endif /* HAVE_UNISTD_H */
237
238/* SUPPORT_POSIX2008 means the tzcode library should support
239 POSIX.1-2017-and-earlier callers in addition to the usual support for
240 POSIX.1-2024-and-later callers; however, this can be
241 incompatible with POSIX.1-2024-and-later callers.
242 This macro is obsolescent, and the plan is to remove it
243 along with any code needed only when it is nonzero.
244 A good time to do that might be in the year 2034.
245 This macro's name is SUPPORT_POSIX2008 because _POSIX_VERSION == 200809
246 in POSIX.1-2017, a minor revision of POSIX.1-2008. */
247#ifndef SUPPORT_POSIX2008
248# if defined _POSIX_VERSION && _POSIX_VERSION <= 200809
249# define SUPPORT_POSIX2008 1
250# else
251# define SUPPORT_POSIX2008 0
252# endif
253#endif
254
255#ifndef HAVE_DECL_ASCTIME_R
256# if SUPPORT_POSIX2008
257# define HAVE_DECL_ASCTIME_R 1
258# else
259# define HAVE_DECL_ASCTIME_R 0
260# endif
261#endif
262
239#ifndef HAVE_STRFTIME_L
240# if _POSIX_VERSION < 200809
241# define HAVE_STRFTIME_L 0
242# else
243# define HAVE_STRFTIME_L 1
244# endif
245#endif
246

--- 208 unchanged lines hidden (view full) ---

455# define ckd_mul(r, a, b) __builtin_mul_overflow(a, b, r)
456# endif
457#elif 7 <= __GNUC__
458# define ckd_add(r, a, b) __builtin_add_overflow(a, b, r)
459# define ckd_sub(r, a, b) __builtin_sub_overflow(a, b, r)
460# define ckd_mul(r, a, b) __builtin_mul_overflow(a, b, r)
461#endif
462
263#ifndef HAVE_STRFTIME_L
264# if _POSIX_VERSION < 200809
265# define HAVE_STRFTIME_L 0
266# else
267# define HAVE_STRFTIME_L 1
268# endif
269#endif
270

--- 208 unchanged lines hidden (view full) ---

479# define ckd_mul(r, a, b) __builtin_mul_overflow(a, b, r)
480# endif
481#elif 7 <= __GNUC__
482# define ckd_add(r, a, b) __builtin_add_overflow(a, b, r)
483# define ckd_sub(r, a, b) __builtin_sub_overflow(a, b, r)
484# define ckd_mul(r, a, b) __builtin_mul_overflow(a, b, r)
485#endif
486
463#if 3 <= __GNUC__
464# define ATTRIBUTE_MALLOC __attribute__((malloc))
465# define ATTRIBUTE_FORMAT(spec) __attribute__((format spec))
466#else
467# define ATTRIBUTE_MALLOC /* empty */
468# define ATTRIBUTE_FORMAT(spec) /* empty */
469#endif
470
471#if (defined __has_c_attribute \
472 && (202311 <= __STDC_VERSION__ || !defined __STRICT_ANSI__))
473# define HAVE___HAS_C_ATTRIBUTE true
474#else
475# define HAVE___HAS_C_ATTRIBUTE false
476#endif
477
478#if HAVE___HAS_C_ATTRIBUTE

--- 51 unchanged lines hidden (view full) ---

530#endif
531
532#if HAVE___HAS_C_ATTRIBUTE
533# if __has_c_attribute(reproducible)
534# define ATTRIBUTE_REPRODUCIBLE [[reproducible]]
535# endif
536#endif
537#ifndef ATTRIBUTE_REPRODUCIBLE
487#if (defined __has_c_attribute \
488 && (202311 <= __STDC_VERSION__ || !defined __STRICT_ANSI__))
489# define HAVE___HAS_C_ATTRIBUTE true
490#else
491# define HAVE___HAS_C_ATTRIBUTE false
492#endif
493
494#if HAVE___HAS_C_ATTRIBUTE

--- 51 unchanged lines hidden (view full) ---

546#endif
547
548#if HAVE___HAS_C_ATTRIBUTE
549# if __has_c_attribute(reproducible)
550# define ATTRIBUTE_REPRODUCIBLE [[reproducible]]
551# endif
552#endif
553#ifndef ATTRIBUTE_REPRODUCIBLE
538# if 3 <= __GNUC__
539# define ATTRIBUTE_REPRODUCIBLE __attribute__((pure))
540# else
541# define ATTRIBUTE_REPRODUCIBLE /* empty */
542# endif
554# define ATTRIBUTE_REPRODUCIBLE /* empty */
543#endif
544
555#endif
556
545#if HAVE___HAS_C_ATTRIBUTE
546# if __has_c_attribute(unsequenced)
547# define ATTRIBUTE_UNSEQUENCED [[unsequenced]]
548# endif
557/* GCC attributes that are useful in tzcode.
558 __attribute__((pure)) is stricter than [[reproducible]],
559 so the latter is an adequate substitute in non-GCC C23 platforms. */
560#if __GNUC__ < 3
561# define ATTRIBUTE_FORMAT(spec) /* empty */
562# define ATTRIBUTE_PURE ATTRIBUTE_REPRODUCIBLE
563#else
564# define ATTRIBUTE_FORMAT(spec) __attribute__((format spec))
565# define ATTRIBUTE_PURE __attribute__((pure))
549#endif
566#endif
550#ifndef ATTRIBUTE_UNSEQUENCED
551# if 3 <= __GNUC__
552# define ATTRIBUTE_UNSEQUENCED __attribute__((const))
553# else
554# define ATTRIBUTE_UNSEQUENCED /* empty */
555# endif
567
568/* Avoid GCC bug 114833 <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114833>.
569 Remove this macro and its uses when the bug is fixed in a GCC release,
570 because only the latest GCC matters for $(GCC_DEBUG_FLAGS). */
571#ifdef GCC_LINT
572# define ATTRIBUTE_PURE_114833 ATTRIBUTE_PURE
573#else
574# define ATTRIBUTE_PURE_114833 /* empty */
556#endif
557
558#if (__STDC_VERSION__ < 199901 && !defined restrict \
559 && (PORT_TO_C89 || defined _MSC_VER))
560# define restrict /* empty */
561#endif
562
563/*

--- 35 unchanged lines hidden (view full) ---

599#endif
600
601#if TZ_TIME_T
602
603typedef time_tz tz_time_t;
604
605# undef asctime
606# define asctime tz_asctime
575#endif
576
577#if (__STDC_VERSION__ < 199901 && !defined restrict \
578 && (PORT_TO_C89 || defined _MSC_VER))
579# define restrict /* empty */
580#endif
581
582/*

--- 35 unchanged lines hidden (view full) ---

618#endif
619
620#if TZ_TIME_T
621
622typedef time_tz tz_time_t;
623
624# undef asctime
625# define asctime tz_asctime
607# undef asctime_r
608# define asctime_r tz_asctime_r
609# undef ctime
610# define ctime tz_ctime
626# undef ctime
627# define ctime tz_ctime
611# undef ctime_r
612# define ctime_r tz_ctime_r
613# undef difftime
614# define difftime tz_difftime
615# undef gmtime
616# define gmtime tz_gmtime
617# undef gmtime_r
618# define gmtime_r tz_gmtime_r
619# undef localtime
620# define localtime tz_localtime

--- 30 unchanged lines hidden (view full) ---

651# undef timeoff
652# define timeoff tz_timeoff
653# undef tzalloc
654# define tzalloc tz_tzalloc
655# undef tzfree
656# define tzfree tz_tzfree
657# undef tzset
658# define tzset tz_tzset
628# undef difftime
629# define difftime tz_difftime
630# undef gmtime
631# define gmtime tz_gmtime
632# undef gmtime_r
633# define gmtime_r tz_gmtime_r
634# undef localtime
635# define localtime tz_localtime

--- 30 unchanged lines hidden (view full) ---

666# undef timeoff
667# define timeoff tz_timeoff
668# undef tzalloc
669# define tzalloc tz_tzalloc
670# undef tzfree
671# define tzfree tz_tzfree
672# undef tzset
673# define tzset tz_tzset
674# if SUPPORT_POSIX2008
675# undef asctime_r
676# define asctime_r tz_asctime_r
677# undef ctime_r
678# define ctime_r tz_ctime_r
679# endif
659# if HAVE_STRFTIME_L
660# undef strftime_l
661# define strftime_l tz_strftime_l
662# endif
663# if HAVE_TZNAME
664# undef tzname
665# define tzname tz_tzname
666# endif

--- 9 unchanged lines hidden (view full) ---

676# endif
677
678# if __STDC_VERSION__ < 202311
679# define DEPRECATED_IN_C23 /* empty */
680# else
681# define DEPRECATED_IN_C23 ATTRIBUTE_DEPRECATED
682# endif
683DEPRECATED_IN_C23 char *asctime(struct tm const *);
680# if HAVE_STRFTIME_L
681# undef strftime_l
682# define strftime_l tz_strftime_l
683# endif
684# if HAVE_TZNAME
685# undef tzname
686# define tzname tz_tzname
687# endif

--- 9 unchanged lines hidden (view full) ---

697# endif
698
699# if __STDC_VERSION__ < 202311
700# define DEPRECATED_IN_C23 /* empty */
701# else
702# define DEPRECATED_IN_C23 ATTRIBUTE_DEPRECATED
703# endif
704DEPRECATED_IN_C23 char *asctime(struct tm const *);
684char *asctime_r(struct tm const *restrict, char *restrict);
685DEPRECATED_IN_C23 char *ctime(time_t const *);
705DEPRECATED_IN_C23 char *ctime(time_t const *);
706#if SUPPORT_POSIX2008
707char *asctime_r(struct tm const *restrict, char *restrict);
686char *ctime_r(time_t const *, char *);
708char *ctime_r(time_t const *, char *);
687ATTRIBUTE_UNSEQUENCED double difftime(time_t, time_t);
709#endif
710double difftime(time_t, time_t);
688size_t strftime(char *restrict, size_t, char const *restrict,
689 struct tm const *restrict);
690# if HAVE_STRFTIME_L
691size_t strftime_l(char *restrict, size_t, char const *restrict,
692 struct tm const *restrict, locale_t);
693# endif
694struct tm *gmtime(time_t const *);
695struct tm *gmtime_r(time_t const *restrict, struct tm *restrict);

--- 14 unchanged lines hidden (view full) ---

710# else
711# define HAVE_DECL_TIMEGM false
712# endif
713#endif
714#if !HAVE_DECL_TIMEGM && !defined timegm
715time_t timegm(struct tm *);
716#endif
717
711size_t strftime(char *restrict, size_t, char const *restrict,
712 struct tm const *restrict);
713# if HAVE_STRFTIME_L
714size_t strftime_l(char *restrict, size_t, char const *restrict,
715 struct tm const *restrict, locale_t);
716# endif
717struct tm *gmtime(time_t const *);
718struct tm *gmtime_r(time_t const *restrict, struct tm *restrict);

--- 14 unchanged lines hidden (view full) ---

733# else
734# define HAVE_DECL_TIMEGM false
735# endif
736#endif
737#if !HAVE_DECL_TIMEGM && !defined timegm
738time_t timegm(struct tm *);
739#endif
740
718#if !HAVE_DECL_ASCTIME_R && !defined asctime_r
741#if !HAVE_DECL_ASCTIME_R && !defined asctime_r && SUPPORT_POSIX2008
719extern char *asctime_r(struct tm const *restrict, char *restrict);
720#endif
721
722#ifndef HAVE_DECL_ENVIRON
723# if defined environ || defined __USE_GNU
724# define HAVE_DECL_ENVIRON 1
725# else
726# define HAVE_DECL_ENVIRON 0

--- 71 unchanged lines hidden (view full) ---

798typedef struct state *timezone_t;
799struct tm *localtime_rz(timezone_t restrict, time_t const *restrict,
800 struct tm *restrict);
801time_t mktime_z(timezone_t restrict, struct tm *restrict);
802timezone_t tzalloc(char const *);
803void tzfree(timezone_t);
804# if STD_INSPIRED
805# if TZ_TIME_T || !defined posix2time_z
742extern char *asctime_r(struct tm const *restrict, char *restrict);
743#endif
744
745#ifndef HAVE_DECL_ENVIRON
746# if defined environ || defined __USE_GNU
747# define HAVE_DECL_ENVIRON 1
748# else
749# define HAVE_DECL_ENVIRON 0

--- 71 unchanged lines hidden (view full) ---

821typedef struct state *timezone_t;
822struct tm *localtime_rz(timezone_t restrict, time_t const *restrict,
823 struct tm *restrict);
824time_t mktime_z(timezone_t restrict, struct tm *restrict);
825timezone_t tzalloc(char const *);
826void tzfree(timezone_t);
827# if STD_INSPIRED
828# if TZ_TIME_T || !defined posix2time_z
806ATTRIBUTE_REPRODUCIBLE time_t posix2time_z(timezone_t, time_t);
829ATTRIBUTE_PURE time_t posix2time_z(timezone_t, time_t);
807# endif
808# if TZ_TIME_T || !defined time2posix_z
830# endif
831# if TZ_TIME_T || !defined time2posix_z
809ATTRIBUTE_REPRODUCIBLE time_t time2posix_z(timezone_t, time_t);
832ATTRIBUTE_PURE time_t time2posix_z(timezone_t, time_t);
810# endif
811# endif
812#endif
813
814/*
815** Finally, some convenience items.
816*/
817

--- 155 unchanged lines hidden (view full) ---

973#define SECSPERDAY ((int_fast32_t) SECSPERHOUR * HOURSPERDAY)
974
975#define DAYSPERREPEAT ((int_fast32_t) 400 * 365 + 100 - 4 + 1)
976#define SECSPERREPEAT ((int_fast64_t) DAYSPERREPEAT * SECSPERDAY)
977#define AVGSECSPERYEAR (SECSPERREPEAT / YEARSPERREPEAT)
978
979/* How many years to generate (in zic.c) or search through (in localtime.c).
980 This is two years larger than the obvious 400, to avoid edge cases.
833# endif
834# endif
835#endif
836
837/*
838** Finally, some convenience items.
839*/
840

--- 155 unchanged lines hidden (view full) ---

996#define SECSPERDAY ((int_fast32_t) SECSPERHOUR * HOURSPERDAY)
997
998#define DAYSPERREPEAT ((int_fast32_t) 400 * 365 + 100 - 4 + 1)
999#define SECSPERREPEAT ((int_fast64_t) DAYSPERREPEAT * SECSPERDAY)
1000#define AVGSECSPERYEAR (SECSPERREPEAT / YEARSPERREPEAT)
1001
1002/* How many years to generate (in zic.c) or search through (in localtime.c).
1003 This is two years larger than the obvious 400, to avoid edge cases.
981 E.g., suppose a non-POSIX.1-2017 rule applies from 2012 on with transitions
982 in March and September, plus one-off transitions in November 2013.
1004 E.g., suppose a rule applies from 2012 on with transitions
1005 in March and September, plus one-off transitions in November 2013,
1006 and suppose the rule cannot be expressed as a proleptic TZ string.
983 If zic looked only at the last 400 years, it would set max_year=2413,
984 with the intent that the 400 years 2014 through 2413 will be repeated.
985 The last transition listed in the tzfile would be in 2413-09,
986 less than 400 years after the last one-off transition in 2013-11.
987 Two years is not overkill for localtime.c, as a one-year bump
988 would mishandle 2023d's America/Ciudad_Juarez for November 2422. */
989enum { years_of_observations = YEARSPERREPEAT + 2 };
990

--- 49 unchanged lines hidden ---
1007 If zic looked only at the last 400 years, it would set max_year=2413,
1008 with the intent that the 400 years 2014 through 2413 will be repeated.
1009 The last transition listed in the tzfile would be in 2413-09,
1010 less than 400 years after the last one-off transition in 2013-11.
1011 Two years is not overkill for localtime.c, as a one-year bump
1012 would mishandle 2023d's America/Ciudad_Juarez for November 2422. */
1013enum { years_of_observations = YEARSPERREPEAT + 2 };
1014

--- 49 unchanged lines hidden ---