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