Home | History | Annotate | Line # | Download | only in time
      1 /* Private header for tzdb code.  */
      2 
      3 /*	$NetBSD: private.h,v 1.78 2026/09/12 19:43:35 christos Exp $	*/
      4 
      5 #ifndef PRIVATE_H
      6 #define PRIVATE_H
      7 
      8 /* NetBSD defaults */
      9 #define TM_GMTOFF	tm_gmtoff
     10 #define TM_ZONE		tm_zone
     11 #define STD_INSPIRED	1
     12 #define HAVE_LONG_DOUBLE 1
     13 
     14 /* For when we build zic as a host tool. */
     15 #if HAVE_NBTOOL_CONFIG_H
     16 #include "nbtool_config.h"
     17 #endif
     18 
     19 /*
     20 ** This file is in the public domain, so clarified as of
     21 ** 1996-06-05 by Arthur David Olson.
     22 */
     23 
     24 /*
     25 ** This header is for use ONLY with the time conversion code.
     26 ** There is no guarantee that it will remain unchanged,
     27 ** or that it will remain at all.
     28 ** Do NOT copy it to any system include directory.
     29 ** Thank you!
     30 */
     31 
     32 /* PORT_TO_C89 means the code should work even if the underlying
     33    compiler and library support only C89 plus C99's 'long long'
     34    and perhaps a few other extensions to C89.
     35 
     36    This macro is obsolescent, and the plan is to remove it along with
     37    associated code.  A good time to do that might be in the year 2029
     38    because RHEL 7 (whose GCC defaults to C89) extended life cycle
     39    support (ELS) is scheduled to end on 2028-06-30.  */
     40 #ifndef PORT_TO_C89
     41 # define PORT_TO_C89 0
     42 #endif
     43 
     44 /* SUPPORT_C89 means the tzcode library should support C89 callers
     45    in addition to the usual support for C99-and-later callers.
     46    This defaults to 1 as POSIX requires, even though that can trigger
     47    latent bugs in callers.  */
     48 #ifndef SUPPORT_C89
     49 # define SUPPORT_C89 1
     50 #endif
     51 
     52 
     53 /* The following feature-test macros should be defined before
     54    any #include of a system header.  */
     55 
     56 /* Enable tm_gmtoff, tm_zone, and environ on GNUish systems.  */
     57 #define _GNU_SOURCE 1
     58 /* Fix asctime_r on Solaris 11.  */
     59 #define _POSIX_PTHREAD_SEMANTICS 1
     60 /* Enable strtoimax on pre-C99 Solaris 11.  */
     61 #define __EXTENSIONS__ 1
     62 /* Cause MS-Windows headers to define POSIX names.  */
     63 #define _CRT_DECLARE_NONSTDC_NAMES 1
     64 /* Prevent MS-Windows headers from defining min and max.  */
     65 #define NOMINMAX 1
     66 
     67 /* On GNUish systems where time_t might be 32 or 64 bits, use 64.
     68    On these platforms _FILE_OFFSET_BITS must also be 64; otherwise
     69    setting _TIME_BITS to 64 does not work.  The code does not
     70    otherwise rely on _FILE_OFFSET_BITS being 64, since it does not
     71    use off_t or functions like 'stat' that depend on off_t.  */
     72 #ifndef _TIME_BITS
     73 # ifndef _FILE_OFFSET_BITS
     74 #  define _FILE_OFFSET_BITS 64
     75 # endif
     76 # if _FILE_OFFSET_BITS == 64
     77 #  define _TIME_BITS 64
     78 # endif
     79 #endif
     80 
     81 /* End of feature-test macro definitions.  */
     82 
     83 
     84 #ifndef __STDC_VERSION__
     85 # define __STDC_VERSION__ 0
     86 #endif
     87 
     88 /* Define true, false and bool if they don't work out of the box.  */
     89 #if PORT_TO_C89 && __STDC_VERSION__ < 199901
     90 # define true 1
     91 # define false 0
     92 # define bool int
     93 #elif __STDC_VERSION__ < 202311
     94 # include <stdbool.h>
     95 #endif
     96 
     97 /* For pre-C23 compilers, a substitute for static_assert.
     98    Some of these compilers may warn if it is used outside the top level.  */
     99 #if __STDC_VERSION__ < 202311 && !defined static_assert
    100 # define static_assert(cond) extern int static_assert_check[(cond) ? 1 : -1]
    101 #endif
    102 
    103 /*
    104 ** zdump has been made independent of the rest of the time
    105 ** conversion package to increase confidence in the verification it provides.
    106 ** You can use zdump to help in verifying other implementations.
    107 ** To do this, compile with -DUSE_LTZ=0 and link without the tz library.
    108 */
    109 #ifndef USE_LTZ
    110 # define USE_LTZ 1
    111 #endif
    112 
    113 /* This string was in the Factory zone through version 2016f.  */
    114 #ifndef GRANDPARENTED
    115 # define GRANDPARENTED	"Local time zone must be set--see zic manual page"
    116 #endif
    117 
    118 /*
    119 ** Defaults for preprocessor symbols.
    120 ** You can override these in your C compiler options, e.g. '-DHAVE_GETTEXT=1'.
    121 */
    122 
    123 #if !defined HAVE__GENERIC && defined __has_extension
    124 # if !__has_extension(c_generic_selections)
    125 #  define HAVE__GENERIC 0
    126 # endif
    127 #endif
    128 /* _Generic is buggy in pre-4.9 GCC.  */
    129 #if !defined HAVE__GENERIC && defined __GNUC__ && !defined __STRICT_ANSI__
    130 # define HAVE__GENERIC (4 < __GNUC__ + (9 <= __GNUC_MINOR__))
    131 #endif
    132 #ifndef HAVE__GENERIC
    133 # define HAVE__GENERIC (201112 <= __STDC_VERSION__)
    134 #endif
    135 
    136 #ifndef HAVE_GETEUID
    137 # define HAVE_GETEUID 1
    138 #endif
    139 
    140 #ifndef HAVE_GETRESUID
    141 # define HAVE_GETRESUID 1
    142 #endif
    143 
    144 #if !defined HAVE_GETTEXT && defined __has_include
    145 # if __has_include(<libintl.h>)
    146 #  define HAVE_GETTEXT 1
    147 # endif
    148 #endif
    149 #ifndef HAVE_GETTEXT
    150 # define HAVE_GETTEXT 0
    151 #endif
    152 
    153 #ifndef HAVE_INCOMPATIBLE_CTIME_R
    154 # define HAVE_INCOMPATIBLE_CTIME_R 0
    155 #endif
    156 
    157 #ifndef HAVE_LINK
    158 # define HAVE_LINK 1
    159 #endif /* !defined HAVE_LINK */
    160 
    161 #ifndef HAVE_MALLOC_ERRNO
    162 # define HAVE_MALLOC_ERRNO 1
    163 #endif
    164 
    165 #ifndef HAVE_POSIX_DECLS
    166 # define HAVE_POSIX_DECLS 1
    167 #endif
    168 
    169 #ifndef HAVE_SETENV
    170 # define HAVE_SETENV 1
    171 #endif
    172 
    173 #ifndef HAVE_STRDUP
    174 # define HAVE_STRDUP 1
    175 #endif
    176 
    177 #ifndef HAVE_SYMLINK
    178 # define HAVE_SYMLINK 1
    179 #endif /* !defined HAVE_SYMLINK */
    180 
    181 #if !defined HAVE_SYS_STAT_H && defined __has_include
    182 # if !__has_include(<sys/stat.h>)
    183 #  define HAVE_SYS_STAT_H 0
    184 # endif
    185 #endif
    186 #ifndef HAVE_SYS_STAT_H
    187 # define HAVE_SYS_STAT_H 1
    188 #endif
    189 
    190 #if !defined HAVE_UNISTD_H && defined __has_include
    191 # if !__has_include(<unistd.h>)
    192 #  define HAVE_UNISTD_H 0
    193 # endif
    194 #endif
    195 #ifndef HAVE_UNISTD_H
    196 # define HAVE_UNISTD_H 1
    197 #endif
    198 
    199 #ifndef NETBSD_INSPIRED
    200 # define NETBSD_INSPIRED 1
    201 #endif
    202 
    203 #if HAVE_INCOMPATIBLE_CTIME_R
    204 # define asctime_r _incompatible_asctime_r
    205 # define ctime_r _incompatible_ctime_r
    206 #endif /* HAVE_INCOMPATIBLE_CTIME_R */
    207 
    208 #ifndef TZ_RUNTIME_LEAPS
    209 # define TZ_RUNTIME_LEAPS 1
    210 #endif
    211 
    212 /*
    213 ** Nested includes
    214 */
    215 
    216 #include <stddef.h>
    217 
    218 /* If defining the 'timezone' variable a la POSIX, avoid clashing with the old
    219    'timezone' function of FreeBSD <= 14, by renaming the latter's declaration.
    220    This hack can be removed after 2028-11-30, FreeBSD 14's expected EOL.  */
    221 #if (defined __FreeBSD__  && __FreeBSD__ < 15 && defined __BSD_VISIBLE \
    222      && defined USG_COMPAT  && USG_COMPAT == 2)
    223 # define timezone sys_timezone
    224 # define timezone_defined
    225 #endif
    226 
    227 #include <time.h>
    228 
    229 #ifdef timezone_defined
    230 # undef timezone
    231 # undef timezone_defined
    232 #endif
    233 
    234 #include <time.h>
    235 
    236 #include <string.h>
    237 #if defined HAVE_STRNLEN && !HAVE_STRNLEN
    238 static size_t
    239 strnlen (char const *s, size_t maxlen)
    240 {
    241   size_t i;
    242   for (i = 0; i < maxlen && s[i]; i++)
    243     continue;
    244   return i;
    245 }
    246 #endif
    247 
    248 #if !PORT_TO_C89
    249 # include <inttypes.h>
    250 #endif
    251 #include <limits.h>	/* for CHAR_BIT et al. */
    252 #include <stdlib.h>
    253 
    254 #include <errno.h>
    255 
    256 #ifndef EINVAL
    257 # define EINVAL ERANGE
    258 #endif
    259 
    260 #ifndef EFTYPE
    261 # define EFTYPE EINVAL
    262 #endif
    263 #ifndef ELOOP
    264 # define ELOOP EINVAL
    265 #endif
    266 #ifndef ENAMETOOLONG
    267 # define ENAMETOOLONG EINVAL
    268 #endif
    269 #ifndef ENOMEM
    270 # define ENOMEM EINVAL
    271 #endif
    272 #ifndef ENOSYS
    273 # define ENOSYS EINVAL
    274 #endif
    275 #ifndef ENOTCAPABLE
    276 # define ENOTCAPABLE EINVAL
    277 #endif
    278 #ifndef ENOTSUP
    279 # define ENOTSUP EINVAL
    280 #endif
    281 #ifndef EOVERFLOW
    282 # define EOVERFLOW EINVAL
    283 #endif
    284 #ifndef EPERM
    285 # define EPERM EINVAL
    286 #endif
    287 
    288 #if HAVE_GETTEXT
    289 # include <libintl.h>
    290 #endif /* HAVE_GETTEXT */
    291 
    292 #if HAVE_UNISTD_H
    293 # include <unistd.h>
    294 #else
    295 /* Assume getopt.o or equivalent is linked via Makefile configuration.  */
    296 int getopt(int, char *const[], char const *);
    297 extern char *optarg;
    298 extern int optind;
    299 #endif /* HAVE_UNISTD_H */
    300 
    301 /* SUPPORT_POSIX2008 means the tzcode library should support
    302    POSIX.1-2017-and-earlier callers in addition to the usual support for
    303    POSIX.1-2024-and-later callers; however, this can be
    304    incompatible with POSIX.1-2024-and-later callers.
    305    This macro is obsolescent, and the plan is to remove it
    306    along with any code needed only when it is nonzero.
    307    A good time to do that might be in the year 2034.
    308    This macro's name is SUPPORT_POSIX2008 because _POSIX_VERSION == 200809
    309    in POSIX.1-2017, a minor revision of POSIX.1-2008.  */
    310 #ifndef SUPPORT_POSIX2008
    311 # if defined _POSIX_VERSION && _POSIX_VERSION <= 200809
    312 #  define SUPPORT_POSIX2008 1
    313 # else
    314 #  define SUPPORT_POSIX2008 0
    315 # endif
    316 #endif
    317 
    318 #ifndef HAVE_DECL_ASCTIME_R
    319 # if SUPPORT_POSIX2008
    320 #  define HAVE_DECL_ASCTIME_R 1
    321 # else
    322 #  define HAVE_DECL_ASCTIME_R 0
    323 # endif
    324 #endif
    325 
    326 #ifndef HAVE_ISSETUGID
    327 # if (defined __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__ \
    328       || defined __DragonFly__ \
    329       || (defined __linux__ && !defined __GLIBC__) /* Android, musl, etc. */ \
    330       || (defined __APPLE__ && defined __MACH__) || defined __sun)
    331 #  define HAVE_ISSETUGID 1
    332 # else
    333 #  define HAVE_ISSETUGID 0
    334 # endif
    335 #endif
    336 
    337 #ifndef HAVE_SNPRINTF
    338 # define HAVE_SNPRINTF (!PORT_TO_C89 || 199901 <= __STDC_VERSION__)
    339 #endif
    340 
    341 #ifndef HAVE_STRFTIME_L
    342 # if _POSIX_VERSION < 200809
    343 #  define HAVE_STRFTIME_L 0
    344 # else
    345 #  define HAVE_STRFTIME_L 1
    346 # endif
    347 #endif
    348 
    349 #ifndef USG_COMPAT
    350 # ifndef _XOPEN_VERSION
    351 #  define USG_COMPAT 0
    352 # else
    353 #  define USG_COMPAT 1
    354 # endif
    355 #endif
    356 
    357 #ifndef HAVE_TZNAME
    358 # if _POSIX_VERSION < 198808 && !USG_COMPAT
    359 #  define HAVE_TZNAME 0
    360 # else
    361 #  define HAVE_TZNAME 1
    362 # endif
    363 #endif
    364 
    365 #ifndef ALTZONE
    366 # if defined __sun || defined _M_XENIX
    367 #  define ALTZONE 1
    368 # else
    369 #  define ALTZONE 0
    370 # endif
    371 #endif
    372 
    373 #if PORT_TO_C89
    374 
    375 /*
    376 ** Define HAVE_STDINT_H's default value here, rather than at the
    377 ** start, since __GLIBC__ and INTMAX_MAX's values depend on
    378 ** previously included files.  glibc 2.1 and Solaris 10 and later have
    379 ** stdint.h, even with pre-C99 compilers.
    380 */
    381 # if !defined HAVE_STDINT_H && defined __has_include
    382 #  define HAVE_STDINT_H 1 /* C23 __has_include implies C99 stdint.h.  */
    383 # endif
    384 # ifndef HAVE_STDINT_H
    385 #  define HAVE_STDINT_H \
    386     (199901 <= __STDC_VERSION__ \
    387      || 2 < __GLIBC__ + (1 <= __GLIBC_MINOR__) \
    388      || __CYGWIN__ || INTMAX_MAX)
    389 # endif /* !defined HAVE_STDINT_H */
    390 
    391 # if HAVE_STDINT_H
    392 #  include <stdint.h>
    393 # endif /* !HAVE_STDINT_H */
    394 
    395 # ifndef HAVE_INTTYPES_H
    396 #  define HAVE_INTTYPES_H HAVE_STDINT_H
    397 # endif
    398 # if HAVE_INTTYPES_H
    399 #  include <inttypes.h>
    400 # endif
    401 
    402 /* Pre-C99 GCC compilers define __LONG_LONG_MAX__ instead of LLONG_MAX.  */
    403 # if defined __LONG_LONG_MAX__ && !defined __STRICT_ANSI__
    404 #  ifndef LLONG_MAX
    405 #   define LLONG_MAX __LONG_LONG_MAX__
    406 #  endif
    407 #  ifndef LLONG_MIN
    408 #   define LLONG_MIN (-1 - LLONG_MAX)
    409 #  endif
    410 #  ifndef ULLONG_MAX
    411 #   define ULLONG_MAX (LLONG_MAX * 2ull + 1)
    412 #  endif
    413 # endif
    414 
    415 # ifndef INT_FAST64_MAX
    416 #  if 1 <= LONG_MAX >> 31 >> 31
    417 typedef long int_fast64_t;
    418 #   define INT_FAST64_MIN LONG_MIN
    419 #   define INT_FAST64_MAX LONG_MAX
    420 #  else
    421 /* If this fails, compile with -DHAVE_STDINT_H or with a better compiler.  */
    422 typedef long long int_fast64_t;
    423 #   define INT_FAST64_MIN LLONG_MIN
    424 #   define INT_FAST64_MAX LLONG_MAX
    425 #  endif
    426 # endif
    427 
    428 # ifndef PRIdFAST64
    429 #  if INT_FAST64_MAX == LONG_MAX
    430 #   define PRIdFAST64 "ld"
    431 #  else
    432 #   define PRIdFAST64 "lld"
    433 #  endif
    434 # endif
    435 
    436 # ifndef SCNdFAST64
    437 #  define SCNdFAST64 PRIdFAST64
    438 # endif
    439 
    440 # ifndef INT_FAST32_MAX
    441 typedef long int_fast32_t;
    442 #  define INT_FAST32_MAX LONG_MAX
    443 #  define INT_FAST32_MIN LONG_MIN
    444 # endif
    445 
    446 # ifndef INT_LEAST32_MAX
    447 typedef int_fast32_t int_least32_t;
    448 # endif
    449 
    450 # ifndef INTMAX_MAX
    451 #  ifdef LLONG_MAX
    452 typedef long long intmax_t;
    453 #   ifndef HAVE_STRTOLL
    454 #    define HAVE_STRTOLL 1
    455 #   endif
    456 #   if HAVE_STRTOLL
    457 #    define strtoimax strtoll
    458 #   endif
    459 #   define INTMAX_MAX LLONG_MAX
    460 #   define INTMAX_MIN LLONG_MIN
    461 #  else
    462 typedef long intmax_t;
    463 #   define INTMAX_MAX LONG_MAX
    464 #   define INTMAX_MIN LONG_MIN
    465 #  endif
    466 #  ifndef strtoimax
    467 #   define strtoimax strtol
    468 #  endif
    469 # endif
    470 
    471 # ifndef PRIdMAX
    472 #  if INTMAX_MAX == LLONG_MAX
    473 #   define PRIdMAX "lld"
    474 #  else
    475 #   define PRIdMAX "ld"
    476 #  endif
    477 # endif
    478 
    479 # ifndef PTRDIFF_MAX
    480 #  define PTRDIFF_MAX MAXVAL(ptrdiff_t, TYPE_BIT(ptrdiff_t))
    481 # endif
    482 
    483 # ifndef UINT_FAST32_MAX
    484 typedef unsigned long uint_fast32_t;
    485 # endif
    486 
    487 # ifndef UINT_FAST64_MAX
    488 #  if 3 <= ULONG_MAX >> 31 >> 31
    489 typedef unsigned long uint_fast64_t;
    490 #   define UINT_FAST64_MAX ULONG_MAX
    491 #  else
    492 /* If this fails, compile with -DHAVE_STDINT_H or with a better compiler.  */
    493 typedef unsigned long long uint_fast64_t;
    494 #   define UINT_FAST64_MAX ULLONG_MAX
    495 #  endif
    496 # endif
    497 
    498 # ifndef UINTMAX_MAX
    499 #  ifdef ULLONG_MAX
    500 typedef unsigned long long uintmax_t;
    501 #   define UINTMAX_MAX ULLONG_MAX
    502 #  else
    503 typedef unsigned long uintmax_t;
    504 #   define UINTMAX_MAX ULONG_MAX
    505 #  endif
    506 # endif
    507 
    508 # ifndef PRIuMAX
    509 #  ifdef ULLONG_MAX
    510 #   define PRIuMAX "llu"
    511 #  else
    512 #   define PRIuMAX "lu"
    513 #  endif
    514 # endif
    515 
    516 # ifndef SIZE_MAX
    517 #  define SIZE_MAX ((size_t) -1)
    518 # endif
    519 
    520 #endif /* PORT_TO_C89 */
    521 
    522 /* The maximum size of any created object, as a signed integer.
    523    Although the C standard does not outright prohibit larger objects,
    524    behavior is undefined if the result of pointer subtraction does not
    525    fit into ptrdiff_t, and the code assumes in several places that
    526    pointer subtraction works.  As a practical matter it's OK to not
    527    support objects larger than this.  */
    528 #define INDEX_MAX ((ptrdiff_t) min(PTRDIFF_MAX, SIZE_MAX))
    529 
    530 /* Support ckd_add, ckd_sub, ckd_mul on C23 or recent-enough GCC-like
    531    hosts, unless compiled with -DHAVE_STDCKDINT_H=0 or with pre-C23 EDG.  */
    532 #if !defined HAVE_STDCKDINT_H && defined __has_include
    533 # if __has_include(<stdckdint.h>)
    534 #  define HAVE_STDCKDINT_H 1
    535 # endif
    536 #endif
    537 #ifdef HAVE_STDCKDINT_H
    538 # if HAVE_STDCKDINT_H
    539 #  include <stdckdint.h>
    540 # endif
    541 #elif defined __EDG__
    542 /* Do nothing, to work around EDG bug <https://bugs.gnu.org/53256>.  */
    543 #elif defined __has_builtin
    544 # if __has_builtin(__builtin_add_overflow)
    545 #  define ckd_add(r, a, b) __builtin_add_overflow(a, b, r)
    546 # endif
    547 # if __has_builtin(__builtin_sub_overflow)
    548 #  define ckd_sub(r, a, b) __builtin_sub_overflow(a, b, r)
    549 # endif
    550 # if __has_builtin(__builtin_mul_overflow)
    551 #  define ckd_mul(r, a, b) __builtin_mul_overflow(a, b, r)
    552 # endif
    553 #elif 7 <= __GNUC__
    554 # define ckd_add(r, a, b) __builtin_add_overflow(a, b, r)
    555 # define ckd_sub(r, a, b) __builtin_sub_overflow(a, b, r)
    556 # define ckd_mul(r, a, b) __builtin_mul_overflow(a, b, r)
    557 #endif
    558 
    559 #if (defined __has_c_attribute \
    560      && (202311 <= __STDC_VERSION__ || !defined __STRICT_ANSI__))
    561 # define HAVE___HAS_C_ATTRIBUTE true
    562 #else
    563 # define HAVE___HAS_C_ATTRIBUTE false
    564 #endif
    565 
    566 #ifdef __has_attribute
    567 # if __has_attribute (nonstring)
    568 #  define ATTRIBUTE_NONSTRING __attribute__((__nonstring__))
    569 # endif
    570 #endif
    571 #ifndef ATTRIBUTE_NONSTRING
    572 # define ATTRIBUTE_NONSTRING
    573 #endif
    574 
    575 #if HAVE___HAS_C_ATTRIBUTE
    576 # if __has_c_attribute(deprecated)
    577 #  define ATTRIBUTE_DEPRECATED [[deprecated]]
    578 # endif
    579 #endif
    580 #ifndef ATTRIBUTE_DEPRECATED
    581 # if 3 < __GNUC__ + (2 <= __GNUC_MINOR__)
    582 #  define ATTRIBUTE_DEPRECATED __attribute__((deprecated))
    583 # else
    584 #  define ATTRIBUTE_DEPRECATED /* empty */
    585 # endif
    586 #endif
    587 
    588 #if HAVE___HAS_C_ATTRIBUTE
    589 # if __has_c_attribute(fallthrough)
    590 #  define ATTRIBUTE_FALLTHROUGH [[fallthrough]]
    591 # endif
    592 #endif
    593 #ifndef ATTRIBUTE_FALLTHROUGH
    594 # if 7 <= __GNUC__
    595 #  define ATTRIBUTE_FALLTHROUGH __attribute__((fallthrough))
    596 # else
    597 #  define ATTRIBUTE_FALLTHROUGH ((void) 0)
    598 # endif
    599 #endif
    600 
    601 #if HAVE___HAS_C_ATTRIBUTE
    602 # if __has_c_attribute(maybe_unused)
    603 #  define ATTRIBUTE_MAYBE_UNUSED [[maybe_unused]]
    604 # endif
    605 #endif
    606 #ifndef ATTRIBUTE_MAYBE_UNUSED
    607 # if 2 < __GNUC__ + (7 <= __GNUC_MINOR__)
    608 #  define ATTRIBUTE_MAYBE_UNUSED __attribute__((unused))
    609 # else
    610 #  define ATTRIBUTE_MAYBE_UNUSED /* empty */
    611 # endif
    612 #endif
    613 
    614 #if HAVE___HAS_C_ATTRIBUTE
    615 # if __has_c_attribute(noreturn)
    616 #  define ATTRIBUTE_NORETURN [[noreturn]]
    617 # endif
    618 #endif
    619 #ifndef ATTRIBUTE_NORETURN
    620 # if 201112 <= __STDC_VERSION__
    621 #  define ATTRIBUTE_NORETURN _Noreturn
    622 # elif 2 < __GNUC__ + (8 <= __GNUC_MINOR__)
    623 #  define ATTRIBUTE_NORETURN __attribute__((noreturn))
    624 # else
    625 #  define ATTRIBUTE_NORETURN /* empty */
    626 # endif
    627 #endif
    628 
    629 #if HAVE___HAS_C_ATTRIBUTE
    630 # if __has_c_attribute(reproducible)
    631 #  define ATTRIBUTE_REPRODUCIBLE [[reproducible]]
    632 # endif
    633 #endif
    634 #ifndef ATTRIBUTE_REPRODUCIBLE
    635 # define ATTRIBUTE_REPRODUCIBLE /* empty */
    636 #endif
    637 
    638 #if HAVE___HAS_C_ATTRIBUTE
    639 # if __has_c_attribute(unsequenced)
    640 #  define ATTRIBUTE_UNSEQUENCED [[unsequenced]]
    641 # endif
    642 #endif
    643 #ifndef ATTRIBUTE_UNSEQUENCED
    644 # define ATTRIBUTE_UNSEQUENCED /* empty */
    645 #endif
    646 
    647 /* GNU C attributes that are useful in tzcode.
    648    Although neither __attribute__((const)) nor __attribute__((pure)) are
    649    stricter than their C23 counterparts [[unsequenced]] and [[reproducible]],
    650    the C23 attributes happen to work in each tzcode use of ATTRIBUTE_CONST
    651    and ATTRIBUTE_PURE.  (This might not work outside of tzcode!)  */
    652 #if __GNUC__ < 3
    653 # define ATTRIBUTE_CONST ATTRIBUTE_UNSEQUENCED
    654 # define ATTRIBUTE_FORMAT(spec) /* empty */
    655 # define ATTRIBUTE_PURE ATTRIBUTE_REPRODUCIBLE
    656 #else
    657 # define ATTRIBUTE_CONST __attribute__((const))
    658 # define ATTRIBUTE_FORMAT(spec) __attribute__((format spec))
    659 # define ATTRIBUTE_PURE __attribute__((pure))
    660 #endif
    661 
    662 /* Avoid GCC bug 114833 <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114833>.
    663    Remove this macro and its uses when the bug is fixed in a GCC release,
    664    because only the latest GCC matters for $(GCC_DEBUG_FLAGS).  */
    665 #ifdef GCC_LINT
    666 # define ATTRIBUTE_PURE_114833 ATTRIBUTE_PURE
    667 #else
    668 # define ATTRIBUTE_PURE_114833 /* empty */
    669 #endif
    670 /* GCC_LINT hack to pacify GCC bug 114833 even though the attribute is
    671    not strictly correct, as the function might not return whereas pure
    672    functions are supposed to return exactly once.  This hack is not
    673    known to generate wrong code for tzcode on any platform.
    674    Remove this macro and its uses when the bug is fixed in a GCC release.  */
    675 #define ATTRIBUTE_PURE_114833_HACK ATTRIBUTE_PURE_114833
    676 
    677 #if (__STDC_VERSION__ < 199901 && !defined restrict \
    678      && (PORT_TO_C89 || defined _MSC_VER))
    679 # define restrict /* empty */
    680 #endif
    681 
    682 /*
    683 ** Workarounds for compilers/systems.
    684 */
    685 
    686 #ifndef EPOCH_LOCAL
    687 # define EPOCH_LOCAL 0
    688 #endif
    689 #ifndef EPOCH_OFFSET
    690 # define EPOCH_OFFSET 0
    691 #endif
    692 #ifndef RESERVE_STD_EXT_IDS
    693 # define RESERVE_STD_EXT_IDS 0
    694 #endif
    695 
    696 #ifdef time_tz
    697 # define defined_time_tz true
    698 #else
    699 # define defined_time_tz false
    700 #endif
    701 
    702 /* If standard C identifiers with external linkage (e.g., localtime)
    703    are reserved and are not already being renamed anyway, rename them
    704    as if compiling with '-Dtime_tz=time_t'.  */
    705 #if !defined time_tz && RESERVE_STD_EXT_IDS && USE_LTZ
    706 # define time_tz time_t
    707 #endif
    708 
    709 /*
    710 ** Compile with -Dtime_tz=T to build the tz package with a private
    711 ** time_t type equivalent to T rather than the system-supplied time_t.
    712 ** This debugging feature can test unusual design decisions
    713 ** (e.g., time_t wider than 'long', or unsigned time_t) even on
    714 ** typical platforms.
    715 */
    716 #if defined time_tz || EPOCH_LOCAL || EPOCH_OFFSET != 0
    717 # define TZ_TIME_T true
    718 #else
    719 # define TZ_TIME_T false
    720 #endif
    721 
    722 #if defined LOCALTIME_IMPLEMENTATION && TZ_TIME_T
    723 static time_t sys_time(time_t *x) { return time(x); }
    724 #endif
    725 
    726 #if TZ_TIME_T
    727 
    728 typedef time_tz tz_time_t;
    729 
    730 # undef  asctime
    731 # define asctime tz_asctime
    732 # undef  ctime
    733 # define ctime tz_ctime
    734 # undef  difftime
    735 # define difftime tz_difftime
    736 # undef  gmtime
    737 # define gmtime tz_gmtime
    738 # undef  gmtime_r
    739 # define gmtime_r tz_gmtime_r
    740 # undef  localtime
    741 # define localtime tz_localtime
    742 # undef  localtime_r
    743 # define localtime_r tz_localtime_r
    744 # undef  localtime_rz
    745 # define localtime_rz tz_localtime_rz
    746 # undef  mktime
    747 # define mktime tz_mktime
    748 # undef  mktime_z
    749 # define mktime_z tz_mktime_z
    750 # undef  offtime
    751 # define offtime tz_offtime
    752 # undef  offtime_r
    753 # define offtime_r tz_offtime_r
    754 # undef  posix2time
    755 # define posix2time tz_posix2time
    756 # undef  posix2time_z
    757 # define posix2time_z tz_posix2time_z
    758 # undef  strftime
    759 # define strftime tz_strftime
    760 # undef  time
    761 # define time tz_time
    762 # undef  time2posix
    763 # define time2posix tz_time2posix
    764 # undef  time2posix_z
    765 # define time2posix_z tz_time2posix_z
    766 # undef  time_t
    767 # define time_t tz_time_t
    768 # undef  timegm
    769 # define timegm tz_timegm
    770 # undef  timelocal
    771 # define timelocal tz_timelocal
    772 # undef  timeoff
    773 # define timeoff tz_timeoff
    774 # undef  tzalloc
    775 # define tzalloc tz_tzalloc
    776 # undef  tzfree
    777 # define tzfree tz_tzfree
    778 # undef  tzset
    779 # define tzset tz_tzset
    780 # undef  tzsetwall
    781 # define tzsetwall tz_tzsetwall
    782 # if SUPPORT_POSIX2008
    783 #  undef  asctime_r
    784 #  define asctime_r tz_asctime_r
    785 #  undef  ctime_r
    786 #  define ctime_r tz_ctime_r
    787 # endif
    788 # if HAVE_STRFTIME_L
    789 #  undef  strftime_l
    790 #  define strftime_l tz_strftime_l
    791 # endif
    792 # if HAVE_TZNAME
    793 #  undef  tzname
    794 #  define tzname tz_tzname
    795 # endif
    796 # if USG_COMPAT
    797 #  undef  daylight
    798 #  define daylight tz_daylight
    799 #  undef  timezone
    800 #  define timezone tz_timezone
    801 # endif
    802 # if ALTZONE
    803 #  undef  altzone
    804 #  define altzone tz_altzone
    805 # endif
    806 
    807 # if __STDC_VERSION__ < 202311
    808 #  define DEPRECATED_IN_C23 /* empty */
    809 # else
    810 #  define DEPRECATED_IN_C23 ATTRIBUTE_DEPRECATED
    811 # endif
    812 DEPRECATED_IN_C23 char *asctime(struct tm const *);
    813 DEPRECATED_IN_C23 char *ctime(time_t const *);
    814 # if SUPPORT_POSIX2008
    815 char *asctime_r(struct tm const *restrict, char *restrict);
    816 char *ctime_r(time_t const *, char *);
    817 # endif
    818 ATTRIBUTE_CONST double difftime(time_t, time_t);
    819 size_t strftime(char *restrict, size_t, char const *restrict,
    820 		struct tm const *restrict);
    821 # if HAVE_STRFTIME_L
    822 size_t strftime_l(char *restrict, size_t, char const *restrict,
    823 		  struct tm const *restrict, locale_t);
    824 # endif
    825 struct tm *gmtime(time_t const *);
    826 struct tm *gmtime_r(time_t const *restrict, struct tm *restrict);
    827 struct tm *localtime(time_t const *);
    828 struct tm *localtime_r(time_t const *restrict, struct tm *restrict);
    829 time_t mktime(struct tm *);
    830 time_t time(time_t *);
    831 time_t timegm(struct tm *);
    832 void tzset(void);
    833 #endif
    834 
    835 #ifndef HAVE_DECL_TIMEGM
    836 # if (202311 <= __STDC_VERSION__ \
    837       || defined __GLIBC__ || defined __tm_zone /* musl */ \
    838       || defined __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__ \
    839       || defined __DragonFly__ || defined __HAIKU__ \
    840       || (defined __APPLE__ && defined __MACH__))
    841 #  define HAVE_DECL_TIMEGM 1
    842 # else
    843 #  define HAVE_DECL_TIMEGM 0
    844 # endif
    845 #endif
    846 #if !HAVE_DECL_TIMEGM && !defined timegm
    847 time_t timegm(struct tm *);
    848 #endif
    849 
    850 #if !HAVE_DECL_ASCTIME_R && !defined asctime_r && SUPPORT_POSIX2008
    851 extern char *asctime_r(struct tm const *restrict, char *restrict);
    852 #endif
    853 
    854 #ifndef HAVE_DECL_ENVIRON
    855 # if defined environ || defined __USE_GNU
    856 #  define HAVE_DECL_ENVIRON 1
    857 # else
    858 #  define HAVE_DECL_ENVIRON 0
    859 # endif
    860 #endif
    861 
    862 #if !HAVE_DECL_ENVIRON
    863 extern char **environ;
    864 #endif
    865 
    866 #ifndef HAVE_MEMPCPY
    867 # if (defined mempcpy \
    868       || defined __FreeBSD__ || defined __NetBSD__ || defined __DragonFly__ \
    869       || defined __linux__ \
    870       || defined HAVE_NBTOOL_CONFIG_H)
    871 #  define HAVE_MEMPCPY 1
    872 # else
    873 #  define HAVE_MEMPCPY 0
    874 # endif
    875 #endif
    876 #if !HAVE_MEMPCPY
    877 static void *
    878 mempcpy(void *restrict s1, void const *restrict s2, size_t n)
    879 {
    880   char *p = memcpy(s1, s2, n);
    881   return p + n;
    882 }
    883 #endif
    884 
    885 #if 2 <= HAVE_TZNAME + (TZ_TIME_T || !HAVE_POSIX_DECLS)
    886 extern char *tzname[];
    887 #endif
    888 #if 2 <= USG_COMPAT + (TZ_TIME_T || !HAVE_POSIX_DECLS)
    889 extern long timezone;
    890 extern int daylight;
    891 #endif
    892 #if 2 <= ALTZONE + (TZ_TIME_T || !HAVE_POSIX_DECLS)
    893 extern long altzone;
    894 #endif
    895 
    896 /*
    897 ** The STD_INSPIRED functions are similar, but most also need
    898 ** declarations if time_tz is defined.
    899 */
    900 
    901 #ifndef STD_INSPIRED
    902 # ifdef __NetBSD__
    903 #  define STD_INSPIRED 1
    904 # else
    905 #  define STD_INSPIRED 0
    906 # endif
    907 #endif
    908 #if STD_INSPIRED
    909 # if TZ_TIME_T || !defined tzsetwall
    910 void tzsetwall(void);
    911 # endif
    912 # if TZ_TIME_T || !defined offtime
    913 struct tm *offtime(time_t const *, long);
    914 # endif
    915 # if TZ_TIME_T || !defined offtime_r
    916 struct tm *offtime_r(time_t const *restrict, long, struct tm *restrict);
    917 # endif
    918 # if TZ_TIME_T || !defined timelocal
    919 time_t timelocal(struct tm *);
    920 # endif
    921 # if TZ_TIME_T || !defined timeoff
    922 #  define EXTERN_TIMEOFF
    923 # endif
    924 # if TZ_TIME_T || !defined time2posix
    925 time_t time2posix(time_t);
    926 # endif
    927 # if TZ_TIME_T || !defined posix2time
    928 time_t posix2time(time_t);
    929 # endif
    930 #endif
    931 
    932 /* Infer TM_ZONE on systems where this information is known, but suppress
    933    guessing if NO_TM_ZONE is defined.  Similarly for TM_GMTOFF.  */
    934 #if (200809 < _POSIX_VERSION \
    935      || defined __GLIBC__ \
    936      || defined __tm_zone /* musl */ \
    937      || defined __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__ \
    938      || defined __DragonFly__ || defined __HAIKU__ \
    939      || (defined __APPLE__ && defined __MACH__))
    940 # if !defined TM_GMTOFF && !defined NO_TM_GMTOFF
    941 #  define TM_GMTOFF tm_gmtoff
    942 # endif
    943 # if !defined TM_ZONE && !defined NO_TM_ZONE
    944 #  define TM_ZONE tm_zone
    945 # endif
    946 #endif
    947 
    948 /*
    949 ** Define functions that are ABI compatible with NetBSD.
    950 ** What we call 'struct state' NetBSD calls
    951 ** 'struct __state', but this is a private name so it doesn't matter.
    952 */
    953 #if NETBSD_INSPIRED
    954 # ifdef _NETBSD_SOURCE
    955 #  define state __state
    956 # else
    957 typedef struct state *timezone_t;
    958 # endif
    959 #endif
    960 struct tm *localtime_rz(timezone_t restrict, time_t const *restrict,
    961 			struct tm *restrict);
    962 time_t mktime_z(timezone_t restrict, struct tm *restrict);
    963 timezone_t tzalloc(char const *);
    964 void tzfree(timezone_t);
    965 # if STD_INSPIRED
    966 #  if TZ_RUNTIME_LEAPS
    967 #   define ATTRIBUTE_POSIX2TIME ATTRIBUTE_PURE
    968 #  else
    969 #   define ATTRIBUTE_POSIX2TIME ATTRIBUTE_CONST
    970 #  endif
    971 #  if TZ_TIME_T || !defined posix2time_z
    972 ATTRIBUTE_POSIX2TIME time_t posix2time_z(timezone_t __restrict, time_t);
    973 #  endif
    974 #  if TZ_TIME_T || !defined time2posix_z
    975 ATTRIBUTE_POSIX2TIME time_t time2posix_z(timezone_t __restrict, time_t);
    976 #  endif
    977 # endif
    978 #endif
    979 
    980 /*
    981 ** Finally, some convenience items.
    982 */
    983 
    984 #define TYPE_BIT(type) (CHAR_BIT * (ptrdiff_t) sizeof(type))
    985 #define TYPE_SIGNED(type) \
    986      (/*LINTED*/((type)~(type)0 >> (sizeof(type) * CHAR_BIT - 1)) == (type)-1)
    987 #define TWOS_COMPLEMENT(type) (TYPE_SIGNED (type) && (! ~ (type) -1))
    988 
    989 /* Yield the value of the arithmetic expression X after integer promotion.
    990    This is safer than a cast, which in general would accept even
    991    pointers and which might trap or yield a value not equal to X.  */
    992 #define INT_PROMOTE(x) (+(x))
    993 
    994 /* Minimum and maximum of two values.  Use lower case to avoid
    995    naming clashes with standard include files.  */
    996 #define max(a, b) ((a) > (b) ? (a) : (b))
    997 #define min(a, b) ((a) < (b) ? (a) : (b))
    998 
    999 /* Max and min values of the integer type T, of which only the bottom
   1000    B bits are used, and where the highest-order used bit is considered
   1001    to be a sign bit if T is signed.  */
   1002 #define MAXVAL(t, b) /*LINTED*/					\
   1003   ((t) (((t) 1 << ((b) - 1 - TYPE_SIGNED(t)))			\
   1004 	- 1 + ((t) 1 << ((b) - 1 - TYPE_SIGNED(t)))))
   1005 #define MINVAL(t, b)						\
   1006   ((t) (TYPE_SIGNED(t) ? - TWOS_COMPLEMENT(t) - MAXVAL(t, b) : 0))
   1007 
   1008 /* The extreme time values, assuming no padding.  */
   1009 #define TIME_T_MIN_NO_PADDING MINVAL(time_t, TYPE_BIT(time_t))
   1010 #define TIME_T_MAX_NO_PADDING MAXVAL(time_t, TYPE_BIT(time_t))
   1011 
   1012 /* The extreme time values.  These are macros, not constants, so that
   1013    any portability problems occur only when compiling .c files that use
   1014    the macros, which is safer for applications that need only zdump and zic.
   1015    This implementation assumes no padding if time_t is signed and
   1016    either the compiler lacks support for _Generic or time_t is not one
   1017    of the standard signed integer types.  */
   1018 #if HAVE__GENERIC
   1019 # define TIME_T_MIN \
   1020     _Generic((time_t) 0, \
   1021 	     signed char: SCHAR_MIN, short: SHRT_MIN, \
   1022 	     int: INT_MIN, long: LONG_MIN, long long: LLONG_MIN, \
   1023 	     default: TIME_T_MIN_NO_PADDING)
   1024 # define TIME_T_MAX \
   1025     (TYPE_SIGNED(time_t) \
   1026      ? _Generic((time_t) 0, \
   1027 		signed char: SCHAR_MAX, short: SHRT_MAX, \
   1028 		int: INT_MAX, long: LONG_MAX, long long: LLONG_MAX, \
   1029 		default: TIME_T_MAX_NO_PADDING)			    \
   1030      : (time_t) -1)
   1031 enum { SIGNED_PADDING_CHECK_NEEDED
   1032 	 = _Generic((time_t) 0,
   1033 		    signed char: false, short: false,
   1034 		    int: false, long: false, long long: false,
   1035 		    default: true) };
   1036 #else
   1037 # define TIME_T_MIN TIME_T_MIN_NO_PADDING
   1038 # define TIME_T_MAX TIME_T_MAX_NO_PADDING
   1039 enum { SIGNED_PADDING_CHECK_NEEDED = true };
   1040 #endif
   1041 /* Try to check the padding assumptions.  Although TIME_T_MAX and the
   1042    following check can both have undefined behavior on oddball
   1043    platforms due to shifts exceeding widths of signed integers, these
   1044    platforms' compilers are likely to diagnose these issues in integer
   1045    constant expressions, so it shouldn't hurt to check statically.  */
   1046 static_assert(! TYPE_SIGNED(time_t) || ! SIGNED_PADDING_CHECK_NEEDED
   1047 	      || TIME_T_MAX >> (TYPE_BIT(time_t) - 2) == 1);
   1048 
   1049 /*
   1050 ** 302 / 1000 is log10(2.0) rounded up.
   1051 ** Subtract one for the sign bit if the type is signed;
   1052 ** add one for integer division truncation;
   1053 ** add one more for a minus sign if the type is signed.
   1054 */
   1055 #define INT_STRLEN_MAXIMUM(type) \
   1056 	((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + \
   1057 	1 + TYPE_SIGNED(type))
   1058 
   1059 /*
   1060 ** INITIALIZE(x)
   1061 */
   1062 
   1063 #if defined(__GNUC__) || defined(__lint__)
   1064 # define INITIALIZE(x)	((x) = 0)
   1065 #else
   1066 # define INITIALIZE(x)
   1067 #endif
   1068 
   1069 /* Whether memory access must strictly follow the C standard.
   1070    If 0, it's OK to read uninitialized storage so long as the value is
   1071    not relied upon.  Defining it to 0 lets mktime access parts of
   1072    struct tm that might be uninitialized, as a heuristic when the
   1073    standard doesn't say what to return and when tm_gmtoff can help
   1074    mktime likely infer a better value.  */
   1075 #ifndef UNINIT_TRAP
   1076 # define UNINIT_TRAP 0
   1077 #endif
   1078 
   1079 /* strftime.c sometimes needs access to timeoff if it is not already public.
   1080    tz_private_timeoff should be used only by localtime.c and strftime.c.  */
   1081 #if (!defined EXTERN_TIMEOFF \
   1082      && defined TM_GMTOFF && (200809 < _POSIX_VERSION || ! UNINIT_TRAP))
   1083 # ifndef timeoff
   1084 #  define timeoff tz_private_timeoff
   1085 # endif
   1086 # define EXTERN_TIMEOFF
   1087 #endif
   1088 #ifdef EXTERN_TIMEOFF
   1089 time_t timeoff(struct tm *, long);
   1090 #endif
   1091 
   1092 #ifdef DEBUG
   1093 # undef unreachable
   1094 # define unreachable() abort()
   1095 #elif !defined unreachable
   1096 # ifdef __has_builtin
   1097 #  if __has_builtin(__builtin_unreachable)
   1098 #   define unreachable() __builtin_unreachable()
   1099 #  endif
   1100 # elif 4 < __GNUC__ + (5 <= __GNUC_MINOR__)
   1101 #  define unreachable() __builtin_unreachable()
   1102 # endif
   1103 # ifndef unreachable
   1104 #  define unreachable() ((void) 0)
   1105 # endif
   1106 #endif
   1107 
   1108 /*
   1109 ** For the benefit of GNU folk...
   1110 ** '_(MSGID)' uses the current locale's message library string for MSGID.
   1111 ** The default is to use gettext if available, and use MSGID otherwise.
   1112 */
   1113 
   1114 #ifndef _
   1115 # if HAVE_GETTEXT
   1116 #  define _(msgid) gettext(msgid)
   1117 # else
   1118 #  define _(msgid) (msgid)
   1119 # endif
   1120 #endif
   1121 #ifndef N_
   1122 # define N_(msgid) (msgid)
   1123 #endif
   1124 
   1125 #if !defined TZ_DOMAIN && defined HAVE_GETTEXT
   1126 # define TZ_DOMAIN "tz"
   1127 #endif
   1128 
   1129 #if HAVE_INCOMPATIBLE_CTIME_R
   1130 # undef asctime_r
   1131 # undef ctime_r
   1132 char *asctime_r(struct tm const *restrict, char *restrict);
   1133 char *ctime_r(time_t const *, char *);
   1134 #endif /* HAVE_INCOMPATIBLE_CTIME_R */
   1135 
   1136 /* Handy constants that are independent of tzfile implementation.  */
   1137 
   1138 /* 2**31 - 1 as a signed integer, and usable in #if.  */
   1139 #define TWO_31_MINUS_1 2147483647
   1140 
   1141 #ifndef SECSPERMIN
   1142 enum {
   1143   SECSPERMIN = 60,
   1144   MINSPERHOUR = 60,
   1145   SECSPERHOUR = SECSPERMIN * MINSPERHOUR,
   1146   HOURSPERDAY = 24,
   1147   DAYSPERWEEK = 7,
   1148   DAYSPERNYEAR = 365,
   1149   DAYSPERLYEAR = DAYSPERNYEAR + 1,
   1150   MONSPERYEAR = 12,
   1151   YEARSPERREPEAT = 400	/* years before a Gregorian repeat */
   1152 };
   1153 #endif
   1154 
   1155 #define SECSPERDAY	((int_fast32_t) SECSPERHOUR * HOURSPERDAY)
   1156 
   1157 #define DAYSPERREPEAT		((int_fast32_t) 400 * 365 + 100 - 4 + 1)
   1158 #define SECSPERREPEAT		((int_fast64_t) DAYSPERREPEAT * SECSPERDAY)
   1159 #define AVGSECSPERYEAR		(SECSPERREPEAT / YEARSPERREPEAT)
   1160 
   1161 /* How many years to generate (in zic.c) or search through (in localtime.c).
   1162    This is two years larger than the obvious 400, to avoid edge cases.
   1163    E.g., suppose a rule applies from 2012 on with transitions
   1164    in March and September, plus one-off transitions in November 2013,
   1165    and suppose the rule cannot be expressed as a proleptic TZ string.
   1166    If zic looked only at the last 400 years, it would set max_year=2413,
   1167    with the intent that the 400 years 2014 through 2413 will be repeated.
   1168    The last transition listed in the tzfile would be in 2413-09,
   1169    less than 400 years after the last one-off transition in 2013-11.
   1170    Two years is not overkill for localtime.c, as a one-year bump
   1171    would mishandle 2023d's America/Ciudad_Juarez for November 2422.  */
   1172 enum { years_of_observations = YEARSPERREPEAT + 2 };
   1173 
   1174 #ifndef TM_SUNDAY
   1175 enum {
   1176   TM_SUNDAY,
   1177   TM_MONDAY,
   1178   TM_TUESDAY,
   1179   TM_WEDNESDAY,
   1180   TM_THURSDAY,
   1181   TM_FRIDAY,
   1182   TM_SATURDAY
   1183 };
   1184 #endif
   1185 
   1186 #ifndef TM_JANUARY
   1187 enum {
   1188   TM_JANUARY,
   1189   TM_FEBRUARY,
   1190   TM_MARCH,
   1191   TM_APRIL,
   1192   TM_MAY,
   1193   TM_JUNE,
   1194   TM_JULY,
   1195   TM_AUGUST,
   1196   TM_SEPTEMBER,
   1197   TM_OCTOBER,
   1198   TM_NOVEMBER,
   1199   TM_DECEMBER
   1200 };
   1201 #endif
   1202 
   1203 #ifndef TM_YEAR_BASE
   1204 enum {
   1205   TM_YEAR_BASE = 1900,
   1206   TM_WDAY_BASE = TM_MONDAY,
   1207   EPOCH_YEAR = 1970,
   1208   EPOCH_WDAY = TM_THURSDAY
   1209 };
   1210 #endif
   1211 
   1212 #define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
   1213 #define year_days(y) (DAYSPERNYEAR + isleap(y))
   1214 
   1215 /*
   1216 ** Since everything in isleap is modulo 400 (or a factor of 400), we know that
   1217 **	isleap(y) == isleap(y % 400)
   1218 ** and so
   1219 **	isleap(a + b) == isleap((a + b) % 400)
   1220 ** or
   1221 **	isleap(a + b) == isleap(a % 400 + b % 400)
   1222 ** This is true even if % means modulo rather than Fortran remainder
   1223 ** (which is allowed by C89 but not by C99 or later).
   1224 ** We use this to avoid addition overflow problems.
   1225 */
   1226 
   1227 #define year_sum_days(a, b) (DAYSPERNYEAR + isleap((a) % 400 + (b) % 400))
   1228 
   1229 #ifdef _LIBC
   1230 #include "reentrant.h"
   1231 extern struct __state *__lcl_ptr;
   1232 extern int_fast64_t __lcl_get_monotonic_time(void);
   1233 extern int __lcl_lock(void);
   1234 extern void __lcl_unlock(bool);
   1235 void tzset_unlocked(bool, bool, int_fast64_t);
   1236 
   1237 #endif /* !defined PRIVATE_H */
   1238