Home | History | Annotate | Line # | Download | only in time
private.h revision 1.66
      1  1.53  christos /* Private header for tzdb code.  */
      2  1.53  christos 
      3  1.66  christos /*	$NetBSD: private.h,v 1.66 2023/09/16 18:40:26 christos Exp $	*/
      4   1.2       jtc 
      5   1.1       jtc #ifndef PRIVATE_H
      6   1.1       jtc #define PRIVATE_H
      7   1.3       jtc 
      8   1.3       jtc /* NetBSD defaults */
      9   1.3       jtc #define TM_GMTOFF	tm_gmtoff
     10   1.3       jtc #define TM_ZONE		tm_zone
     11   1.3       jtc #define STD_INSPIRED	1
     12   1.3       jtc #define HAVE_LONG_DOUBLE 1
     13  1.21     bjh21 
     14  1.21     bjh21 /* For when we build zic as a host tool. */
     15  1.23     lukem #if HAVE_NBTOOL_CONFIG_H
     16  1.23     lukem #include "nbtool_config.h"
     17  1.21     bjh21 #endif
     18   1.1       jtc 
     19   1.1       jtc /*
     20   1.6       jtc ** This file is in the public domain, so clarified as of
     21  1.25   mlelstv ** 1996-06-05 by Arthur David Olson.
     22   1.6       jtc */
     23   1.6       jtc 
     24   1.6       jtc /*
     25   1.1       jtc ** This header is for use ONLY with the time conversion code.
     26   1.1       jtc ** There is no guarantee that it will remain unchanged,
     27   1.1       jtc ** or that it will remain at all.
     28   1.1       jtc ** Do NOT copy it to any system include directory.
     29   1.1       jtc ** Thank you!
     30   1.1       jtc */
     31   1.1       jtc 
     32  1.66  christos /* PORT_TO_C89 means the code should work even if the underlying
     33  1.66  christos    compiler and library support only C89.  SUPPORT_C89 means the
     34  1.66  christos    tzcode library should support C89 callers in addition to the usual
     35  1.66  christos    support for C99-and-later callers.  These macros are obsolescent,
     36  1.66  christos    and the plan is to remove them along with any code needed only when
     37  1.66  christos    they are nonzero.  */
     38  1.66  christos #ifndef PORT_TO_C89
     39  1.66  christos # define PORT_TO_C89 0
     40  1.66  christos #endif
     41  1.66  christos #ifndef SUPPORT_C89
     42  1.66  christos # define SUPPORT_C89 0
     43  1.66  christos #endif
     44  1.66  christos 
     45  1.64  christos #ifndef __STDC_VERSION__
     46  1.64  christos # define __STDC_VERSION__ 0
     47  1.64  christos #endif
     48  1.64  christos 
     49  1.61  christos /* Define true, false and bool if they don't work out of the box.  */
     50  1.66  christos #if PORT_TO_C89 && __STDC_VERSION__ < 199901
     51  1.61  christos # define true 1
     52  1.61  christos # define false 0
     53  1.61  christos # define bool int
     54  1.61  christos #elif __STDC_VERSION__ < 202311
     55  1.61  christos # include <stdbool.h>
     56  1.61  christos #endif
     57  1.61  christos 
     58  1.66  christos #if __STDC_VERSION__ < 202311
     59  1.66  christos # define static_assert(cond) extern int static_assert_check[(cond) ? 1 : -1]
     60  1.66  christos #endif
     61  1.66  christos 
     62  1.52  christos /*
     63  1.52  christos ** zdump has been made independent of the rest of the time
     64  1.52  christos ** conversion package to increase confidence in the verification it provides.
     65  1.52  christos ** You can use zdump to help in verifying other implementations.
     66  1.52  christos ** To do this, compile with -DUSE_LTZ=0 and link without the tz library.
     67  1.52  christos */
     68  1.52  christos #ifndef USE_LTZ
     69  1.52  christos # define USE_LTZ 1
     70  1.52  christos #endif
     71  1.52  christos 
     72  1.46  christos /* This string was in the Factory zone through version 2016f.  */
     73  1.25   mlelstv #define GRANDPARENTED	"Local time zone must be set--see zic manual page"
     74  1.25   mlelstv 
     75   1.1       jtc /*
     76   1.1       jtc ** Defaults for preprocessor symbols.
     77  1.43  christos ** You can override these in your C compiler options, e.g. '-DHAVE_GETTEXT=1'.
     78   1.1       jtc */
     79   1.1       jtc 
     80  1.45  christos #ifndef HAVE_DECL_ASCTIME_R
     81  1.59  christos # define HAVE_DECL_ASCTIME_R 1
     82  1.45  christos #endif
     83  1.45  christos 
     84  1.66  christos #if !defined HAVE__GENERIC && defined __has_extension
     85  1.51  christos # if __has_extension(c_generic_selections)
     86  1.66  christos #  define HAVE__GENERIC 1
     87  1.51  christos # else
     88  1.66  christos #  define HAVE__GENERIC 0
     89  1.51  christos # endif
     90  1.51  christos #endif
     91  1.51  christos /* _Generic is buggy in pre-4.9 GCC.  */
     92  1.66  christos #if !defined HAVE__GENERIC && defined __GNUC__ && !defined __STRICT_ANSI__
     93  1.66  christos # define HAVE__GENERIC (4 < __GNUC__ + (9 <= __GNUC_MINOR__))
     94  1.51  christos #endif
     95  1.66  christos #ifndef HAVE__GENERIC
     96  1.66  christos # define HAVE__GENERIC (201112 <= __STDC_VERSION__)
     97  1.51  christos #endif
     98  1.51  christos 
     99  1.61  christos #if !defined HAVE_GETTEXT && defined __has_include
    100  1.61  christos # if __has_include(<libintl.h>)
    101  1.61  christos #  define HAVE_GETTEXT true
    102  1.61  christos # endif
    103  1.61  christos #endif
    104   1.6       jtc #ifndef HAVE_GETTEXT
    105  1.61  christos # define HAVE_GETTEXT false
    106  1.61  christos #endif
    107   1.6       jtc 
    108  1.17    kleink #ifndef HAVE_INCOMPATIBLE_CTIME_R
    109  1.59  christos # define HAVE_INCOMPATIBLE_CTIME_R 0
    110  1.51  christos #endif
    111  1.17    kleink 
    112  1.32  christos #ifndef HAVE_LINK
    113  1.59  christos # define HAVE_LINK 1
    114  1.32  christos #endif /* !defined HAVE_LINK */
    115  1.32  christos 
    116  1.57  christos #ifndef HAVE_MALLOC_ERRNO
    117  1.59  christos # define HAVE_MALLOC_ERRNO 1
    118  1.57  christos #endif
    119  1.57  christos 
    120  1.45  christos #ifndef HAVE_POSIX_DECLS
    121  1.59  christos # define HAVE_POSIX_DECLS 1
    122  1.45  christos #endif
    123  1.45  christos 
    124  1.61  christos #ifndef HAVE_SETENV
    125  1.61  christos # define HAVE_SETENV 1
    126  1.51  christos #endif
    127  1.51  christos 
    128  1.40  christos #ifndef HAVE_STRDUP
    129  1.59  christos # define HAVE_STRDUP 1
    130  1.40  christos #endif
    131  1.40  christos 
    132  1.12    kleink #ifndef HAVE_SYMLINK
    133  1.59  christos # define HAVE_SYMLINK 1
    134  1.12    kleink #endif /* !defined HAVE_SYMLINK */
    135   1.6       jtc 
    136  1.61  christos #if !defined HAVE_SYS_STAT_H && defined __has_include
    137  1.61  christos # if !__has_include(<sys/stat.h>)
    138  1.61  christos #  define HAVE_SYS_STAT_H false
    139  1.61  christos # endif
    140  1.61  christos #endif
    141  1.20    kleink #ifndef HAVE_SYS_STAT_H
    142  1.61  christos # define HAVE_SYS_STAT_H true
    143  1.61  christos #endif
    144  1.20    kleink 
    145  1.61  christos #if !defined HAVE_UNISTD_H && defined __has_include
    146  1.61  christos # if !__has_include(<unistd.h>)
    147  1.61  christos #  define HAVE_UNISTD_H false
    148  1.61  christos # endif
    149  1.61  christos #endif
    150   1.1       jtc #ifndef HAVE_UNISTD_H
    151  1.61  christos # define HAVE_UNISTD_H true
    152  1.61  christos #endif
    153   1.5       jtc 
    154  1.36  christos #ifndef NETBSD_INSPIRED
    155  1.36  christos # define NETBSD_INSPIRED 1
    156  1.36  christos #endif
    157   1.1       jtc 
    158  1.17    kleink #if HAVE_INCOMPATIBLE_CTIME_R
    159  1.59  christos # define asctime_r _incompatible_asctime_r
    160  1.59  christos # define ctime_r _incompatible_ctime_r
    161  1.17    kleink #endif /* HAVE_INCOMPATIBLE_CTIME_R */
    162  1.17    kleink 
    163  1.51  christos /* Enable tm_gmtoff, tm_zone, and environ on GNUish systems.  */
    164  1.36  christos #define _GNU_SOURCE 1
    165  1.47  christos /* Fix asctime_r on Solaris 11.  */
    166  1.36  christos #define _POSIX_PTHREAD_SEMANTICS 1
    167  1.47  christos /* Enable strtoimax on pre-C99 Solaris 11.  */
    168  1.36  christos #define __EXTENSIONS__ 1
    169  1.36  christos 
    170  1.61  christos /* On GNUish systems where time_t might be 32 or 64 bits, use 64.
    171  1.61  christos    On these platforms _FILE_OFFSET_BITS must also be 64; otherwise
    172  1.61  christos    setting _TIME_BITS to 64 does not work.  The code does not
    173  1.61  christos    otherwise rely on _FILE_OFFSET_BITS being 64, since it does not
    174  1.61  christos    use off_t or functions like 'stat' that depend on off_t.  */
    175  1.51  christos #ifndef _FILE_OFFSET_BITS
    176  1.51  christos # define _FILE_OFFSET_BITS 64
    177  1.51  christos #endif
    178  1.61  christos #if !defined _TIME_BITS && _FILE_OFFSET_BITS == 64
    179  1.61  christos # define _TIME_BITS 64
    180  1.61  christos #endif
    181  1.51  christos 
    182   1.1       jtc /*
    183   1.1       jtc ** Nested includes
    184   1.1       jtc */
    185   1.1       jtc 
    186  1.36  christos #ifndef __NetBSD__
    187  1.56  christos /* Avoid clashes with NetBSD by renaming NetBSD's declarations.
    188  1.56  christos    If defining the 'timezone' variable, avoid a clash with FreeBSD's
    189  1.56  christos    'timezone' function by renaming its declaration.  */
    190  1.36  christos #define localtime_rz sys_localtime_rz
    191  1.36  christos #define mktime_z sys_mktime_z
    192  1.36  christos #define posix2time_z sys_posix2time_z
    193  1.36  christos #define time2posix_z sys_time2posix_z
    194  1.56  christos #if defined USG_COMPAT && USG_COMPAT == 2
    195  1.56  christos # define timezone sys_timezone
    196  1.56  christos #endif
    197  1.36  christos #define timezone_t sys_timezone_t
    198  1.36  christos #define tzalloc sys_tzalloc
    199  1.36  christos #define tzfree sys_tzfree
    200  1.36  christos #include <time.h>
    201  1.36  christos #undef localtime_rz
    202  1.36  christos #undef mktime_z
    203  1.36  christos #undef posix2time_z
    204  1.36  christos #undef time2posix_z
    205  1.56  christos #if defined USG_COMPAT && USG_COMPAT == 2
    206  1.56  christos # undef timezone
    207  1.56  christos #endif
    208  1.36  christos #undef timezone_t
    209  1.36  christos #undef tzalloc
    210  1.36  christos #undef tzfree
    211  1.36  christos #else
    212  1.36  christos #include "time.h"
    213  1.36  christos #endif
    214  1.36  christos 
    215  1.61  christos #include <stddef.h>
    216  1.50  christos #include <string.h>
    217  1.66  christos #if !PORT_TO_C89
    218  1.66  christos # include <inttypes.h>
    219  1.66  christos #endif
    220  1.50  christos #include <limits.h>	/* for CHAR_BIT et al. */
    221  1.50  christos #include <stdlib.h>
    222   1.1       jtc 
    223  1.50  christos #include <errno.h>
    224  1.38  christos 
    225  1.57  christos #ifndef EINVAL
    226  1.57  christos # define EINVAL ERANGE
    227  1.57  christos #endif
    228  1.57  christos 
    229  1.60  christos #ifndef ELOOP
    230  1.60  christos # define ELOOP EINVAL
    231  1.60  christos #endif
    232  1.38  christos #ifndef ENAMETOOLONG
    233  1.38  christos # define ENAMETOOLONG EINVAL
    234  1.38  christos #endif
    235  1.57  christos #ifndef ENOMEM
    236  1.57  christos # define ENOMEM EINVAL
    237  1.57  christos #endif
    238  1.45  christos #ifndef ENOTSUP
    239  1.45  christos # define ENOTSUP EINVAL
    240  1.45  christos #endif
    241  1.38  christos #ifndef EOVERFLOW
    242  1.38  christos # define EOVERFLOW EINVAL
    243  1.38  christos #endif
    244  1.38  christos 
    245  1.25   mlelstv #if HAVE_GETTEXT
    246  1.59  christos # include <libintl.h>
    247  1.25   mlelstv #endif /* HAVE_GETTEXT */
    248  1.14    kleink 
    249  1.25   mlelstv #if HAVE_UNISTD_H
    250  1.59  christos # include <unistd.h> /* for R_OK, and other POSIX goodness */
    251  1.25   mlelstv #endif /* HAVE_UNISTD_H */
    252   1.1       jtc 
    253  1.36  christos #ifndef HAVE_STRFTIME_L
    254  1.36  christos # if _POSIX_VERSION < 200809
    255  1.36  christos #  define HAVE_STRFTIME_L 0
    256  1.36  christos # else
    257  1.36  christos #  define HAVE_STRFTIME_L 1
    258  1.36  christos # endif
    259  1.36  christos #endif
    260  1.36  christos 
    261  1.51  christos #ifndef USG_COMPAT
    262  1.51  christos # ifndef _XOPEN_VERSION
    263  1.51  christos #  define USG_COMPAT 0
    264  1.51  christos # else
    265  1.51  christos #  define USG_COMPAT 1
    266  1.51  christos # endif
    267  1.51  christos #endif
    268  1.51  christos 
    269  1.51  christos #ifndef HAVE_TZNAME
    270  1.51  christos # if _POSIX_VERSION < 198808 && !USG_COMPAT
    271  1.51  christos #  define HAVE_TZNAME 0
    272  1.51  christos # else
    273  1.51  christos #  define HAVE_TZNAME 1
    274  1.51  christos # endif
    275  1.51  christos #endif
    276  1.51  christos 
    277  1.56  christos #ifndef ALTZONE
    278  1.56  christos # if defined __sun || defined _M_XENIX
    279  1.56  christos #  define ALTZONE 1
    280  1.56  christos # else
    281  1.56  christos #  define ALTZONE 0
    282  1.56  christos # endif
    283  1.56  christos #endif
    284  1.56  christos 
    285   1.1       jtc #ifndef R_OK
    286  1.59  christos # define R_OK 4
    287   1.1       jtc #endif /* !defined R_OK */
    288   1.1       jtc 
    289  1.66  christos #if PORT_TO_C89
    290  1.66  christos 
    291   1.1       jtc /*
    292  1.25   mlelstv ** Define HAVE_STDINT_H's default value here, rather than at the
    293  1.47  christos ** start, since __GLIBC__ and INTMAX_MAX's values depend on
    294  1.66  christos ** previously included files.  glibc 2.1 and Solaris 10 and later have
    295  1.47  christos ** stdint.h, even with pre-C99 compilers.
    296  1.25   mlelstv */
    297  1.61  christos #if !defined HAVE_STDINT_H && defined __has_include
    298  1.61  christos # define HAVE_STDINT_H true /* C23 __has_include implies C99 stdint.h.  */
    299  1.61  christos #endif
    300  1.25   mlelstv #ifndef HAVE_STDINT_H
    301  1.59  christos # define HAVE_STDINT_H \
    302  1.33  christos    (199901 <= __STDC_VERSION__ \
    303  1.59  christos     || 2 < __GLIBC__ + (1 <= __GLIBC_MINOR__) \
    304  1.47  christos     || __CYGWIN__ || INTMAX_MAX)
    305  1.25   mlelstv #endif /* !defined HAVE_STDINT_H */
    306  1.25   mlelstv 
    307  1.25   mlelstv #if HAVE_STDINT_H
    308  1.59  christos # include <stdint.h>
    309  1.25   mlelstv #endif /* !HAVE_STDINT_H */
    310  1.25   mlelstv 
    311  1.29  christos #ifndef HAVE_INTTYPES_H
    312  1.29  christos # define HAVE_INTTYPES_H HAVE_STDINT_H
    313  1.29  christos #endif
    314  1.29  christos #if HAVE_INTTYPES_H
    315  1.29  christos # include <inttypes.h>
    316  1.29  christos #endif
    317  1.29  christos 
    318  1.36  christos /* Pre-C99 GCC compilers define __LONG_LONG_MAX__ instead of LLONG_MAX.  */
    319  1.64  christos #if defined __LONG_LONG_MAX__ && !defined __STRICT_ANSI__
    320  1.36  christos # ifndef LLONG_MAX
    321  1.36  christos #  define LLONG_MAX __LONG_LONG_MAX__
    322  1.36  christos # endif
    323  1.36  christos # ifndef LLONG_MIN
    324  1.36  christos #  define LLONG_MIN (-1 - LLONG_MAX)
    325  1.36  christos # endif
    326  1.64  christos # ifndef ULLONG_MAX
    327  1.64  christos #  define ULLONG_MAX (LLONG_MAX * 2ull + 1)
    328  1.64  christos # endif
    329  1.36  christos #endif
    330  1.36  christos 
    331  1.25   mlelstv #ifndef INT_FAST64_MAX
    332  1.64  christos # if 1 <= LONG_MAX >> 31 >> 31
    333  1.64  christos typedef long int_fast64_t;
    334  1.64  christos #  define INT_FAST64_MIN LONG_MIN
    335  1.64  christos #  define INT_FAST64_MAX LONG_MAX
    336  1.64  christos # else
    337  1.64  christos /* If this fails, compile with -DHAVE_STDINT_H or with a better compiler.  */
    338  1.64  christos typedef long long int_fast64_t;
    339  1.29  christos #  define INT_FAST64_MIN LLONG_MIN
    340  1.29  christos #  define INT_FAST64_MAX LLONG_MAX
    341  1.36  christos # endif
    342  1.36  christos #endif
    343  1.36  christos 
    344  1.48  christos #ifndef PRIdFAST64
    345  1.64  christos # if INT_FAST64_MAX == LONG_MAX
    346  1.64  christos #  define PRIdFAST64 "ld"
    347  1.64  christos # else
    348  1.48  christos #  define PRIdFAST64 "lld"
    349  1.36  christos # endif
    350  1.36  christos #endif
    351  1.25   mlelstv 
    352  1.48  christos #ifndef SCNdFAST64
    353  1.48  christos # define SCNdFAST64 PRIdFAST64
    354  1.48  christos #endif
    355  1.48  christos 
    356  1.29  christos #ifndef INT_FAST32_MAX
    357  1.29  christos # if INT_MAX >> 31 == 0
    358  1.29  christos typedef long int_fast32_t;
    359  1.36  christos #  define INT_FAST32_MAX LONG_MAX
    360  1.36  christos #  define INT_FAST32_MIN LONG_MIN
    361  1.29  christos # else
    362  1.29  christos typedef int int_fast32_t;
    363  1.36  christos #  define INT_FAST32_MAX INT_MAX
    364  1.36  christos #  define INT_FAST32_MIN INT_MIN
    365  1.29  christos # endif
    366  1.29  christos #endif
    367  1.29  christos 
    368  1.29  christos #ifndef INTMAX_MAX
    369  1.36  christos # ifdef LLONG_MAX
    370  1.29  christos typedef long long intmax_t;
    371  1.66  christos #  ifndef HAVE_STRTOLL
    372  1.66  christos #   define HAVE_STRTOLL true
    373  1.66  christos #  endif
    374  1.52  christos #  if HAVE_STRTOLL
    375  1.52  christos #   define strtoimax strtoll
    376  1.52  christos #  endif
    377  1.36  christos #  define INTMAX_MAX LLONG_MAX
    378  1.36  christos #  define INTMAX_MIN LLONG_MIN
    379  1.29  christos # else
    380  1.29  christos typedef long intmax_t;
    381  1.30  christos #  define INTMAX_MAX LONG_MAX
    382  1.30  christos #  define INTMAX_MIN LONG_MIN
    383  1.29  christos # endif
    384  1.52  christos # ifndef strtoimax
    385  1.52  christos #  define strtoimax strtol
    386  1.52  christos # endif
    387  1.29  christos #endif
    388  1.29  christos 
    389  1.36  christos #ifndef PRIdMAX
    390  1.36  christos # if INTMAX_MAX == LLONG_MAX
    391  1.36  christos #  define PRIdMAX "lld"
    392  1.36  christos # else
    393  1.36  christos #  define PRIdMAX "ld"
    394  1.36  christos # endif
    395  1.36  christos #endif
    396  1.36  christos 
    397  1.64  christos #ifndef PTRDIFF_MAX
    398  1.64  christos # define PTRDIFF_MAX MAXVAL(ptrdiff_t, TYPE_BIT(ptrdiff_t))
    399  1.64  christos #endif
    400  1.64  christos 
    401  1.57  christos #ifndef UINT_FAST32_MAX
    402  1.57  christos typedef unsigned long uint_fast32_t;
    403  1.57  christos #endif
    404  1.57  christos 
    405  1.43  christos #ifndef UINT_FAST64_MAX
    406  1.64  christos # if 3 <= ULONG_MAX >> 31 >> 31
    407  1.64  christos typedef unsigned long uint_fast64_t;
    408  1.64  christos #  define UINT_FAST64_MAX ULONG_MAX
    409  1.64  christos # else
    410  1.64  christos /* If this fails, compile with -DHAVE_STDINT_H or with a better compiler.  */
    411  1.43  christos typedef unsigned long long uint_fast64_t;
    412  1.64  christos #  define UINT_FAST64_MAX ULLONG_MAX
    413  1.43  christos # endif
    414  1.43  christos #endif
    415  1.43  christos 
    416  1.29  christos #ifndef UINTMAX_MAX
    417  1.64  christos # ifdef ULLONG_MAX
    418  1.29  christos typedef unsigned long long uintmax_t;
    419  1.66  christos #  define UINTMAX_MAX ULLONG_MAX
    420  1.36  christos # else
    421  1.36  christos typedef unsigned long uintmax_t;
    422  1.66  christos #  define UINTMAX_MAX ULONG_MAX
    423  1.36  christos # endif
    424  1.36  christos #endif
    425  1.36  christos 
    426  1.36  christos #ifndef PRIuMAX
    427  1.64  christos # ifdef ULLONG_MAX
    428  1.29  christos #  define PRIuMAX "llu"
    429  1.29  christos # else
    430  1.29  christos #  define PRIuMAX "lu"
    431  1.29  christos # endif
    432  1.29  christos #endif
    433  1.29  christos 
    434  1.33  christos #ifndef SIZE_MAX
    435  1.59  christos # define SIZE_MAX ((size_t) -1)
    436  1.33  christos #endif
    437  1.33  christos 
    438  1.66  christos #endif /* PORT_TO_C89 */
    439  1.66  christos 
    440  1.66  christos /* The maximum size of any created object, as a signed integer.
    441  1.66  christos    Although the C standard does not outright prohibit larger objects,
    442  1.66  christos    behavior is undefined if the result of pointer subtraction does not
    443  1.66  christos    fit into ptrdiff_t, and the code assumes in several places that
    444  1.66  christos    pointer subtraction works.  As a practical matter it's OK to not
    445  1.66  christos    support objects larger than this.  */
    446  1.66  christos #define INDEX_MAX ((ptrdiff_t) min(PTRDIFF_MAX, SIZE_MAX))
    447  1.66  christos 
    448  1.64  christos /* Support ckd_add, ckd_sub, ckd_mul on C23 or recent-enough GCC-like
    449  1.64  christos    hosts, unless compiled with -DHAVE_STDCKDINT_H=0 or with pre-C23 EDG.  */
    450  1.64  christos #if !defined HAVE_STDCKDINT_H && defined __has_include
    451  1.64  christos # if __has_include(<stdckdint.h>)
    452  1.64  christos #  define HAVE_STDCKDINT_H true
    453  1.64  christos # endif
    454  1.64  christos #endif
    455  1.64  christos #ifdef HAVE_STDCKDINT_H
    456  1.64  christos # if HAVE_STDCKDINT_H
    457  1.64  christos #  include <stdckdint.h>
    458  1.64  christos # endif
    459  1.64  christos #elif defined __EDG__
    460  1.64  christos /* Do nothing, to work around EDG bug <https://bugs.gnu.org/53256>.  */
    461  1.64  christos #elif defined __has_builtin
    462  1.64  christos # if __has_builtin(__builtin_add_overflow)
    463  1.64  christos #  define ckd_add(r, a, b) __builtin_add_overflow(a, b, r)
    464  1.64  christos # endif
    465  1.64  christos # if __has_builtin(__builtin_sub_overflow)
    466  1.64  christos #  define ckd_sub(r, a, b) __builtin_sub_overflow(a, b, r)
    467  1.64  christos # endif
    468  1.64  christos # if __has_builtin(__builtin_mul_overflow)
    469  1.64  christos #  define ckd_mul(r, a, b) __builtin_mul_overflow(a, b, r)
    470  1.64  christos # endif
    471  1.64  christos #elif 7 <= __GNUC__
    472  1.64  christos # define ckd_add(r, a, b) __builtin_add_overflow(a, b, r)
    473  1.64  christos # define ckd_sub(r, a, b) __builtin_sub_overflow(a, b, r)
    474  1.64  christos # define ckd_mul(r, a, b) __builtin_mul_overflow(a, b, r)
    475  1.64  christos #endif
    476  1.64  christos 
    477  1.52  christos #if 3 <= __GNUC__
    478  1.57  christos # define ATTRIBUTE_MALLOC __attribute__((__malloc__))
    479  1.57  christos # define ATTRIBUTE_FORMAT(spec) __attribute__((__format__ spec))
    480  1.27  christos #else
    481  1.52  christos # define ATTRIBUTE_MALLOC /* empty */
    482  1.30  christos # define ATTRIBUTE_FORMAT(spec) /* empty */
    483  1.27  christos #endif
    484  1.29  christos 
    485  1.64  christos #if (defined __has_c_attribute \
    486  1.64  christos      && (202311 <= __STDC_VERSION__ || !defined __STRICT_ANSI__))
    487  1.66  christos # define HAVE___HAS_C_ATTRIBUTE true
    488  1.64  christos #else
    489  1.66  christos # define HAVE___HAS_C_ATTRIBUTE false
    490  1.64  christos #endif
    491  1.64  christos 
    492  1.66  christos #if HAVE___HAS_C_ATTRIBUTE
    493  1.66  christos # if __has_c_attribute(deprecated)
    494  1.66  christos #  define ATTRIBUTE_DEPRECATED [[deprecated]]
    495  1.66  christos # endif
    496  1.66  christos #endif
    497  1.66  christos #ifndef ATTRIBUTE_DEPRECATED
    498  1.66  christos # if 3 < __GNUC__ + (2 <= __GNUC_MINOR__)
    499  1.66  christos #  define ATTRIBUTE_DEPRECATED __attribute__((deprecated))
    500  1.66  christos # else
    501  1.66  christos #  define ATTRIBUTE_DEPRECATED /* empty */
    502  1.66  christos # endif
    503  1.66  christos #endif
    504  1.66  christos 
    505  1.66  christos #if HAVE___HAS_C_ATTRIBUTE
    506  1.64  christos # if __has_c_attribute(fallthrough)
    507  1.64  christos #  define ATTRIBUTE_FALLTHROUGH [[fallthrough]]
    508  1.64  christos # endif
    509  1.64  christos #endif
    510  1.64  christos #ifndef ATTRIBUTE_FALLTHROUGH
    511  1.64  christos # if 7 <= __GNUC__
    512  1.64  christos #  define ATTRIBUTE_FALLTHROUGH __attribute__((fallthrough))
    513  1.64  christos # else
    514  1.64  christos #  define ATTRIBUTE_FALLTHROUGH ((void) 0)
    515  1.64  christos # endif
    516  1.64  christos #endif
    517  1.64  christos 
    518  1.66  christos #if HAVE___HAS_C_ATTRIBUTE
    519  1.64  christos # if __has_c_attribute(maybe_unused)
    520  1.64  christos #  define ATTRIBUTE_MAYBE_UNUSED [[maybe_unused]]
    521  1.64  christos # endif
    522  1.64  christos #endif
    523  1.64  christos #ifndef ATTRIBUTE_MAYBE_UNUSED
    524  1.64  christos # if 2 < __GNUC__ + (7 <= __GNUC_MINOR__)
    525  1.64  christos #  define ATTRIBUTE_MAYBE_UNUSED __attribute__((unused))
    526  1.29  christos # else
    527  1.64  christos #  define ATTRIBUTE_MAYBE_UNUSED /* empty */
    528  1.64  christos # endif
    529  1.64  christos #endif
    530  1.64  christos 
    531  1.66  christos #if HAVE___HAS_C_ATTRIBUTE
    532  1.64  christos # if __has_c_attribute(noreturn)
    533  1.64  christos #  define ATTRIBUTE_NORETURN [[noreturn]]
    534  1.64  christos # endif
    535  1.64  christos #endif
    536  1.64  christos #ifndef ATTRIBUTE_NORETURN
    537  1.64  christos # if 201112 <= __STDC_VERSION__
    538  1.64  christos #  define ATTRIBUTE_NORETURN _Noreturn
    539  1.64  christos # elif 2 < __GNUC__ + (8 <= __GNUC_MINOR__)
    540  1.64  christos #  define ATTRIBUTE_NORETURN __attribute__((noreturn))
    541  1.64  christos # else
    542  1.64  christos #  define ATTRIBUTE_NORETURN /* empty */
    543  1.64  christos # endif
    544  1.64  christos #endif
    545  1.64  christos 
    546  1.66  christos #if HAVE___HAS_C_ATTRIBUTE
    547  1.64  christos # if __has_c_attribute(reproducible)
    548  1.64  christos #  define ATTRIBUTE_REPRODUCIBLE [[reproducible]]
    549  1.64  christos # endif
    550  1.64  christos #endif
    551  1.64  christos #ifndef ATTRIBUTE_REPRODUCIBLE
    552  1.64  christos # if 3 <= __GNUC__
    553  1.64  christos #  define ATTRIBUTE_REPRODUCIBLE __attribute__((pure))
    554  1.64  christos # else
    555  1.64  christos #  define ATTRIBUTE_REPRODUCIBLE /* empty */
    556  1.64  christos # endif
    557  1.64  christos #endif
    558  1.64  christos 
    559  1.66  christos #if HAVE___HAS_C_ATTRIBUTE
    560  1.64  christos # if __has_c_attribute(unsequenced)
    561  1.64  christos #  define ATTRIBUTE_UNSEQUENCED [[unsequenced]]
    562  1.64  christos # endif
    563  1.64  christos #endif
    564  1.64  christos #ifndef ATTRIBUTE_UNSEQUENCED
    565  1.64  christos # if 3 <= __GNUC__
    566  1.64  christos #  define ATTRIBUTE_UNSEQUENCED __attribute__((const))
    567  1.64  christos # else
    568  1.64  christos #  define ATTRIBUTE_UNSEQUENCED /* empty */
    569  1.29  christos # endif
    570  1.29  christos #endif
    571  1.29  christos 
    572  1.66  christos #if (__STDC_VERSION__ < 199901 && !defined restrict \
    573  1.66  christos      && (PORT_TO_C89 || defined _MSC_VER))
    574  1.29  christos # define restrict /* empty */
    575  1.27  christos #endif
    576  1.27  christos 
    577   1.1       jtc /*
    578  1.25   mlelstv ** Workarounds for compilers/systems.
    579   1.1       jtc */
    580   1.1       jtc 
    581  1.48  christos #ifndef EPOCH_LOCAL
    582  1.48  christos # define EPOCH_LOCAL 0
    583  1.48  christos #endif
    584  1.48  christos #ifndef EPOCH_OFFSET
    585  1.48  christos # define EPOCH_OFFSET 0
    586  1.48  christos #endif
    587  1.52  christos #ifndef RESERVE_STD_EXT_IDS
    588  1.52  christos # define RESERVE_STD_EXT_IDS 0
    589  1.52  christos #endif
    590  1.52  christos 
    591  1.52  christos /* If standard C identifiers with external linkage (e.g., localtime)
    592  1.52  christos    are reserved and are not already being renamed anyway, rename them
    593  1.52  christos    as if compiling with '-Dtime_tz=time_t'.  */
    594  1.52  christos #if !defined time_tz && RESERVE_STD_EXT_IDS && USE_LTZ
    595  1.52  christos # define time_tz time_t
    596  1.52  christos #endif
    597  1.48  christos 
    598   1.1       jtc /*
    599  1.29  christos ** Compile with -Dtime_tz=T to build the tz package with a private
    600  1.29  christos ** time_t type equivalent to T rather than the system-supplied time_t.
    601  1.29  christos ** This debugging feature can test unusual design decisions
    602  1.29  christos ** (e.g., time_t wider than 'long', or unsigned time_t) even on
    603  1.29  christos ** typical platforms.
    604  1.29  christos */
    605  1.48  christos #if defined time_tz || EPOCH_LOCAL || EPOCH_OFFSET != 0
    606  1.51  christos # define TZ_TIME_T 1
    607  1.51  christos #else
    608  1.51  christos # define TZ_TIME_T 0
    609  1.51  christos #endif
    610  1.51  christos 
    611  1.57  christos #if defined LOCALTIME_IMPLEMENTATION && TZ_TIME_T
    612  1.57  christos static time_t sys_time(time_t *x) { return time(x); }
    613  1.57  christos #endif
    614  1.57  christos 
    615  1.51  christos #if TZ_TIME_T
    616  1.29  christos 
    617  1.39  christos typedef time_tz tz_time_t;
    618  1.39  christos 
    619  1.56  christos # undef  asctime
    620  1.56  christos # define asctime tz_asctime
    621  1.56  christos # undef  asctime_r
    622  1.56  christos # define asctime_r tz_asctime_r
    623  1.29  christos # undef  ctime
    624  1.29  christos # define ctime tz_ctime
    625  1.29  christos # undef  ctime_r
    626  1.29  christos # define ctime_r tz_ctime_r
    627  1.29  christos # undef  difftime
    628  1.29  christos # define difftime tz_difftime
    629  1.29  christos # undef  gmtime
    630  1.29  christos # define gmtime tz_gmtime
    631  1.29  christos # undef  gmtime_r
    632  1.29  christos # define gmtime_r tz_gmtime_r
    633  1.29  christos # undef  localtime
    634  1.29  christos # define localtime tz_localtime
    635  1.29  christos # undef  localtime_r
    636  1.29  christos # define localtime_r tz_localtime_r
    637  1.39  christos # undef  localtime_rz
    638  1.39  christos # define localtime_rz tz_localtime_rz
    639  1.29  christos # undef  mktime
    640  1.29  christos # define mktime tz_mktime
    641  1.39  christos # undef  mktime_z
    642  1.39  christos # define mktime_z tz_mktime_z
    643  1.36  christos # undef  offtime
    644  1.36  christos # define offtime tz_offtime
    645  1.36  christos # undef  posix2time
    646  1.36  christos # define posix2time tz_posix2time
    647  1.39  christos # undef  posix2time_z
    648  1.39  christos # define posix2time_z tz_posix2time_z
    649  1.51  christos # undef  strftime
    650  1.51  christos # define strftime tz_strftime
    651  1.29  christos # undef  time
    652  1.29  christos # define time tz_time
    653  1.36  christos # undef  time2posix
    654  1.36  christos # define time2posix tz_time2posix
    655  1.39  christos # undef  time2posix_z
    656  1.39  christos # define time2posix_z tz_time2posix_z
    657  1.29  christos # undef  time_t
    658  1.29  christos # define time_t tz_time_t
    659  1.36  christos # undef  timegm
    660  1.36  christos # define timegm tz_timegm
    661  1.36  christos # undef  timelocal
    662  1.36  christos # define timelocal tz_timelocal
    663  1.36  christos # undef  timeoff
    664  1.36  christos # define timeoff tz_timeoff
    665  1.39  christos # undef  tzalloc
    666  1.39  christos # define tzalloc tz_tzalloc
    667  1.39  christos # undef  tzfree
    668  1.39  christos # define tzfree tz_tzfree
    669  1.39  christos # undef  tzset
    670  1.39  christos # define tzset tz_tzset
    671  1.39  christos # undef  tzsetwall
    672  1.39  christos # define tzsetwall tz_tzsetwall
    673  1.51  christos # if HAVE_STRFTIME_L
    674  1.51  christos #  undef  strftime_l
    675  1.51  christos #  define strftime_l tz_strftime_l
    676  1.51  christos # endif
    677  1.51  christos # if HAVE_TZNAME
    678  1.51  christos #  undef  tzname
    679  1.51  christos #  define tzname tz_tzname
    680  1.51  christos # endif
    681  1.51  christos # if USG_COMPAT
    682  1.51  christos #  undef  daylight
    683  1.51  christos #  define daylight tz_daylight
    684  1.51  christos #  undef  timezone
    685  1.51  christos #  define timezone tz_timezone
    686  1.51  christos # endif
    687  1.56  christos # if ALTZONE
    688  1.51  christos #  undef  altzone
    689  1.51  christos #  define altzone tz_altzone
    690  1.51  christos # endif
    691  1.29  christos 
    692  1.66  christos # if __STDC_VERSION__ < 202311
    693  1.66  christos #  define DEPRECATED_IN_C23 /* empty */
    694  1.66  christos # else
    695  1.66  christos #  define DEPRECATED_IN_C23 ATTRIBUTE_DEPRECATED
    696  1.66  christos # endif
    697  1.66  christos DEPRECATED_IN_C23 char *asctime(struct tm const *);
    698  1.56  christos char *asctime_r(struct tm const *restrict, char *restrict);
    699  1.66  christos DEPRECATED_IN_C23 char *ctime(time_t const *);
    700  1.29  christos char *ctime_r(time_t const *, char *);
    701  1.65  christos ATTRIBUTE_UNSEQUENCED double difftime(time_t, time_t);
    702  1.51  christos size_t strftime(char *restrict, size_t, char const *restrict,
    703  1.51  christos 		struct tm const *restrict);
    704  1.51  christos # if HAVE_STRFTIME_L
    705  1.51  christos size_t strftime_l(char *restrict, size_t, char const *restrict,
    706  1.51  christos 		  struct tm const *restrict, locale_t);
    707  1.51  christos # endif
    708  1.29  christos struct tm *gmtime(time_t const *);
    709  1.29  christos struct tm *gmtime_r(time_t const *restrict, struct tm *restrict);
    710  1.29  christos struct tm *localtime(time_t const *);
    711  1.29  christos struct tm *localtime_r(time_t const *restrict, struct tm *restrict);
    712  1.29  christos time_t mktime(struct tm *);
    713  1.36  christos time_t time(time_t *);
    714  1.64  christos time_t timegm(struct tm *);
    715  1.39  christos void tzset(void);
    716  1.36  christos #endif
    717  1.29  christos 
    718  1.64  christos #ifndef HAVE_DECL_TIMEGM
    719  1.64  christos # if (202311 <= __STDC_VERSION__ \
    720  1.64  christos       || defined __GLIBC__ || defined __tm_zone /* musl */ \
    721  1.64  christos       || defined __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__ \
    722  1.64  christos       || (defined __APPLE__ && defined __MACH__))
    723  1.64  christos #  define HAVE_DECL_TIMEGM true
    724  1.64  christos # else
    725  1.64  christos #  define HAVE_DECL_TIMEGM false
    726  1.64  christos # endif
    727  1.64  christos #endif
    728  1.64  christos #if !HAVE_DECL_TIMEGM && !defined timegm
    729  1.64  christos time_t timegm(struct tm *);
    730  1.64  christos #endif
    731  1.64  christos 
    732  1.45  christos #if !HAVE_DECL_ASCTIME_R && !defined asctime_r
    733  1.45  christos extern char *asctime_r(struct tm const *restrict, char *restrict);
    734  1.36  christos #endif
    735  1.36  christos 
    736  1.51  christos #ifndef HAVE_DECL_ENVIRON
    737  1.51  christos # if defined environ || defined __USE_GNU
    738  1.51  christos #  define HAVE_DECL_ENVIRON 1
    739  1.51  christos # else
    740  1.51  christos #  define HAVE_DECL_ENVIRON 0
    741  1.51  christos # endif
    742  1.51  christos #endif
    743  1.51  christos 
    744  1.51  christos #if !HAVE_DECL_ENVIRON
    745  1.51  christos extern char **environ;
    746  1.51  christos #endif
    747  1.51  christos 
    748  1.56  christos #if 2 <= HAVE_TZNAME + (TZ_TIME_T || !HAVE_POSIX_DECLS)
    749  1.51  christos extern char *tzname[];
    750  1.56  christos #endif
    751  1.56  christos #if 2 <= USG_COMPAT + (TZ_TIME_T || !HAVE_POSIX_DECLS)
    752  1.44  christos extern long timezone;
    753  1.44  christos extern int daylight;
    754  1.44  christos #endif
    755  1.56  christos #if 2 <= ALTZONE + (TZ_TIME_T || !HAVE_POSIX_DECLS)
    756  1.44  christos extern long altzone;
    757  1.44  christos #endif
    758  1.44  christos 
    759  1.36  christos /*
    760  1.36  christos ** The STD_INSPIRED functions are similar, but most also need
    761  1.36  christos ** declarations if time_tz is defined.
    762  1.36  christos */
    763  1.36  christos 
    764  1.66  christos #ifndef STD_INSPIRED
    765  1.66  christos # define STD_INSPIRED 0
    766  1.66  christos #endif
    767  1.66  christos #if STD_INSPIRED
    768  1.51  christos # if TZ_TIME_T || !defined tzsetwall
    769  1.36  christos void tzsetwall(void);
    770  1.36  christos # endif
    771  1.51  christos # if TZ_TIME_T || !defined offtime
    772  1.36  christos struct tm *offtime(time_t const *, long);
    773  1.36  christos # endif
    774  1.51  christos # if TZ_TIME_T || !defined timelocal
    775  1.36  christos time_t timelocal(struct tm *);
    776  1.36  christos # endif
    777  1.51  christos # if TZ_TIME_T || !defined timeoff
    778  1.36  christos time_t timeoff(struct tm *, long);
    779  1.36  christos # endif
    780  1.51  christos # if TZ_TIME_T || !defined time2posix
    781  1.36  christos time_t time2posix(time_t);
    782  1.36  christos # endif
    783  1.51  christos # if TZ_TIME_T || !defined posix2time
    784  1.36  christos time_t posix2time(time_t);
    785  1.36  christos # endif
    786  1.36  christos #endif
    787  1.36  christos 
    788  1.36  christos /* Infer TM_ZONE on systems where this information is known, but suppress
    789  1.36  christos    guessing if NO_TM_ZONE is defined.  Similarly for TM_GMTOFF.  */
    790  1.36  christos #if (defined __GLIBC__ \
    791  1.64  christos      || defined __tm_zone /* musl */ \
    792  1.36  christos      || defined __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__ \
    793  1.36  christos      || (defined __APPLE__ && defined __MACH__))
    794  1.36  christos # if !defined TM_GMTOFF && !defined NO_TM_GMTOFF
    795  1.36  christos #  define TM_GMTOFF tm_gmtoff
    796  1.36  christos # endif
    797  1.36  christos # if !defined TM_ZONE && !defined NO_TM_ZONE
    798  1.36  christos #  define TM_ZONE tm_zone
    799  1.36  christos # endif
    800  1.36  christos #endif
    801  1.36  christos 
    802  1.36  christos /*
    803  1.36  christos ** Define functions that are ABI compatible with NetBSD but have
    804  1.36  christos ** better prototypes.  NetBSD 6.1.4 defines a pointer type timezone_t
    805  1.36  christos ** and labors under the misconception that 'const timezone_t' is a
    806  1.36  christos ** pointer to a constant.  This use of 'const' is ineffective, so it
    807  1.36  christos ** is not done here.  What we call 'struct state' NetBSD calls
    808  1.36  christos ** 'struct __state', but this is a private name so it doesn't matter.
    809  1.36  christos */
    810  1.37  christos #ifndef __NetBSD__
    811  1.36  christos #if NETBSD_INSPIRED
    812  1.36  christos typedef struct state *timezone_t;
    813  1.36  christos struct tm *localtime_rz(timezone_t restrict, time_t const *restrict,
    814  1.36  christos 			struct tm *restrict);
    815  1.36  christos time_t mktime_z(timezone_t restrict, struct tm *restrict);
    816  1.36  christos timezone_t tzalloc(char const *);
    817  1.36  christos void tzfree(timezone_t);
    818  1.66  christos # if STD_INSPIRED
    819  1.51  christos #  if TZ_TIME_T || !defined posix2time_z
    820  1.65  christos ATTRIBUTE_REPRODUCIBLE time_t posix2time_z(timezone_t __restrict, time_t);
    821  1.36  christos #  endif
    822  1.51  christos #  if TZ_TIME_T || !defined time2posix_z
    823  1.65  christos ATTRIBUTE_REPRODUCIBLE time_t time2posix_z(timezone_t __restrict, time_t);
    824  1.36  christos #  endif
    825  1.36  christos # endif
    826  1.29  christos #endif
    827  1.37  christos #endif
    828  1.29  christos 
    829  1.29  christos /*
    830   1.1       jtc ** Finally, some convenience items.
    831   1.1       jtc */
    832   1.1       jtc 
    833  1.66  christos #define TYPE_BIT(type) (CHAR_BIT * (ptrdiff_t) sizeof(type))
    834  1.28  christos #define TYPE_SIGNED(type) (/*CONSTCOND*/((type) -1) < 0)
    835  1.41  christos #define TWOS_COMPLEMENT(t) (/*CONSTCOND*/(t) ~ (t) 0 < 0)
    836  1.41  christos 
    837  1.59  christos /* Minimum and maximum of two values.  Use lower case to avoid
    838  1.59  christos    naming clashes with standard include files.  */
    839  1.59  christos #define max(a, b) ((a) > (b) ? (a) : (b))
    840  1.59  christos #define min(a, b) ((a) < (b) ? (a) : (b))
    841  1.59  christos 
    842  1.41  christos /* Max and min values of the integer type T, of which only the bottom
    843  1.41  christos    B bits are used, and where the highest-order used bit is considered
    844  1.41  christos    to be a sign bit if T is signed.  */
    845  1.41  christos #define MAXVAL(t, b) /*LINTED*/					\
    846  1.41  christos   ((t) (((t) 1 << ((b) - 1 - TYPE_SIGNED(t)))			\
    847  1.41  christos 	- 1 + ((t) 1 << ((b) - 1 - TYPE_SIGNED(t)))))
    848  1.41  christos #define MINVAL(t, b)						\
    849  1.41  christos   ((t) (TYPE_SIGNED(t) ? - TWOS_COMPLEMENT(t) - MAXVAL(t, b) : 0))
    850  1.41  christos 
    851  1.51  christos /* The extreme time values, assuming no padding.  */
    852  1.51  christos #define TIME_T_MIN_NO_PADDING MINVAL(time_t, TYPE_BIT(time_t))
    853  1.51  christos #define TIME_T_MAX_NO_PADDING MAXVAL(time_t, TYPE_BIT(time_t))
    854  1.51  christos 
    855  1.51  christos /* The extreme time values.  These are macros, not constants, so that
    856  1.57  christos    any portability problems occur only when compiling .c files that use
    857  1.51  christos    the macros, which is safer for applications that need only zdump and zic.
    858  1.51  christos    This implementation assumes no padding if time_t is signed and
    859  1.51  christos    either the compiler lacks support for _Generic or time_t is not one
    860  1.51  christos    of the standard signed integer types.  */
    861  1.66  christos #if HAVE__GENERIC
    862  1.51  christos # define TIME_T_MIN \
    863  1.51  christos     _Generic((time_t) 0, \
    864  1.51  christos 	     signed char: SCHAR_MIN, short: SHRT_MIN, \
    865  1.51  christos 	     int: INT_MIN, long: LONG_MIN, long long: LLONG_MIN, \
    866  1.51  christos 	     default: TIME_T_MIN_NO_PADDING)
    867  1.51  christos # define TIME_T_MAX \
    868  1.51  christos     (TYPE_SIGNED(time_t) \
    869  1.51  christos      ? _Generic((time_t) 0, \
    870  1.51  christos 		signed char: SCHAR_MAX, short: SHRT_MAX, \
    871  1.51  christos 		int: INT_MAX, long: LONG_MAX, long long: LLONG_MAX, \
    872  1.51  christos 		default: TIME_T_MAX_NO_PADDING)			    \
    873  1.51  christos      : (time_t) -1)
    874  1.66  christos enum { SIGNED_PADDING_CHECK_NEEDED
    875  1.66  christos          = _Generic((time_t) 0,
    876  1.66  christos 		    signed char: false, short: false,
    877  1.66  christos 		    int: false, long: false, long long: false,
    878  1.66  christos 		    default: true) };
    879  1.48  christos #else
    880  1.51  christos # define TIME_T_MIN TIME_T_MIN_NO_PADDING
    881  1.51  christos # define TIME_T_MAX TIME_T_MAX_NO_PADDING
    882  1.66  christos enum { SIGNED_PADDING_CHECK_NEEDED = true };
    883  1.48  christos #endif
    884  1.66  christos /* Try to check the padding assumptions.  Although TIME_T_MAX and the
    885  1.66  christos    following check can both have undefined behavior on oddball
    886  1.66  christos    platforms due to shifts exceeding widths of signed integers, these
    887  1.66  christos    platforms' compilers are likely to diagnose these issues in integer
    888  1.66  christos    constant expressions, so it shouldn't hurt to check statically.  */
    889  1.66  christos static_assert(! TYPE_SIGNED(time_t) || ! SIGNED_PADDING_CHECK_NEEDED
    890  1.66  christos 	      || TIME_T_MAX >> (TYPE_BIT(time_t) - 2) == 1);
    891  1.36  christos 
    892   1.1       jtc /*
    893   1.1       jtc ** 302 / 1000 is log10(2.0) rounded up.
    894   1.5       jtc ** Subtract one for the sign bit if the type is signed;
    895   1.5       jtc ** add one for integer division truncation;
    896   1.5       jtc ** add one more for a minus sign if the type is signed.
    897   1.1       jtc */
    898   1.1       jtc #define INT_STRLEN_MAXIMUM(type) \
    899  1.25   mlelstv 	((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + \
    900  1.25   mlelstv 	1 + TYPE_SIGNED(type))
    901   1.1       jtc 
    902   1.1       jtc /*
    903   1.1       jtc ** INITIALIZE(x)
    904   1.1       jtc */
    905   1.1       jtc 
    906  1.35  christos #if defined(__GNUC__) || defined(__lint__)
    907  1.34  christos # define INITIALIZE(x)	((x) = 0)
    908  1.34  christos #else
    909  1.34  christos # define INITIALIZE(x)
    910  1.34  christos #endif
    911   1.6       jtc 
    912  1.58  christos /* Whether memory access must strictly follow the C standard.
    913  1.58  christos    If 0, it's OK to read uninitialized storage so long as the value is
    914  1.58  christos    not relied upon.  Defining it to 0 lets mktime access parts of
    915  1.58  christos    struct tm that might be uninitialized, as a heuristic when the
    916  1.58  christos    standard doesn't say what to return and when tm_gmtoff can help
    917  1.58  christos    mktime likely infer a better value.  */
    918  1.36  christos #ifndef UNINIT_TRAP
    919  1.36  christos # define UNINIT_TRAP 0
    920  1.36  christos #endif
    921  1.36  christos 
    922  1.57  christos #ifdef DEBUG
    923  1.61  christos # undef unreachable
    924  1.61  christos # define unreachable() abort()
    925  1.61  christos #elif !defined unreachable
    926  1.61  christos # ifdef __has_builtin
    927  1.61  christos #  if __has_builtin(__builtin_unreachable)
    928  1.61  christos #   define unreachable() __builtin_unreachable()
    929  1.61  christos #  endif
    930  1.61  christos # elif 4 < __GNUC__ + (5 <= __GNUC_MINOR__)
    931  1.61  christos #  define unreachable() __builtin_unreachable()
    932  1.61  christos # endif
    933  1.61  christos # ifndef unreachable
    934  1.61  christos #  define unreachable() ((void) 0)
    935  1.57  christos # endif
    936  1.57  christos #endif
    937  1.57  christos 
    938   1.6       jtc /*
    939   1.6       jtc ** For the benefit of GNU folk...
    940  1.34  christos ** '_(MSGID)' uses the current locale's message library string for MSGID.
    941   1.6       jtc ** The default is to use gettext if available, and use MSGID otherwise.
    942   1.6       jtc */
    943   1.6       jtc 
    944  1.25   mlelstv #if HAVE_GETTEXT
    945   1.6       jtc #define _(msgid) gettext(msgid)
    946  1.25   mlelstv #else /* !HAVE_GETTEXT */
    947   1.6       jtc #define _(msgid) msgid
    948  1.25   mlelstv #endif /* !HAVE_GETTEXT */
    949   1.6       jtc 
    950  1.34  christos #if !defined TZ_DOMAIN && defined HAVE_GETTEXT
    951  1.34  christos # define TZ_DOMAIN "tz"
    952  1.34  christos #endif
    953  1.17    kleink 
    954  1.17    kleink #if HAVE_INCOMPATIBLE_CTIME_R
    955  1.17    kleink #undef asctime_r
    956  1.17    kleink #undef ctime_r
    957  1.66  christos char *asctime_r(struct tm const *restrict, char *restrict);
    958  1.25   mlelstv char *ctime_r(time_t const *, char *);
    959  1.17    kleink #endif /* HAVE_INCOMPATIBLE_CTIME_R */
    960   1.1       jtc 
    961  1.50  christos /* Handy macros that are independent of tzfile implementation.  */
    962  1.50  christos 
    963  1.59  christos #ifndef SECSPERMIN
    964  1.59  christos enum {
    965  1.59  christos   SECSPERMIN = 60,
    966  1.59  christos   MINSPERHOUR = 60,
    967  1.59  christos   SECSPERHOUR = SECSPERMIN * MINSPERHOUR,
    968  1.59  christos   HOURSPERDAY = 24,
    969  1.59  christos   DAYSPERWEEK = 7,
    970  1.59  christos   DAYSPERNYEAR = 365,
    971  1.59  christos   DAYSPERLYEAR = DAYSPERNYEAR + 1,
    972  1.59  christos   MONSPERYEAR = 12,
    973  1.59  christos   YEARSPERREPEAT = 400	/* years before a Gregorian repeat */
    974  1.59  christos };
    975  1.59  christos #endif
    976  1.59  christos 
    977  1.50  christos #define SECSPERDAY	((int_fast32_t) SECSPERHOUR * HOURSPERDAY)
    978  1.50  christos 
    979  1.57  christos #define DAYSPERREPEAT		((int_fast32_t) 400 * 365 + 100 - 4 + 1)
    980  1.57  christos #define SECSPERREPEAT		((int_fast64_t) DAYSPERREPEAT * SECSPERDAY)
    981  1.57  christos #define AVGSECSPERYEAR		(SECSPERREPEAT / YEARSPERREPEAT)
    982  1.57  christos 
    983  1.59  christos #ifndef TM_SUNDAY
    984  1.59  christos enum {
    985  1.59  christos   TM_SUNDAY,
    986  1.59  christos   TM_MONDAY,
    987  1.59  christos   TM_TUESDAY,
    988  1.59  christos   TM_WEDNESDAY,
    989  1.59  christos   TM_THURSDAY,
    990  1.59  christos   TM_FRIDAY,
    991  1.59  christos   TM_SATURDAY
    992  1.59  christos };
    993  1.59  christos #endif
    994  1.59  christos 
    995  1.59  christos #ifndef TM_JANUARY
    996  1.59  christos enum {
    997  1.59  christos   TM_JANUARY,
    998  1.59  christos   TM_FEBRUARY,
    999  1.59  christos   TM_MARCH,
   1000  1.59  christos   TM_APRIL,
   1001  1.59  christos   TM_MAY,
   1002  1.59  christos   TM_JUNE,
   1003  1.59  christos   TM_JULY,
   1004  1.59  christos   TM_AUGUST,
   1005  1.59  christos   TM_SEPTEMBER,
   1006  1.59  christos   TM_OCTOBER,
   1007  1.59  christos   TM_NOVEMBER,
   1008  1.59  christos   TM_DECEMBER
   1009  1.59  christos };
   1010  1.59  christos #endif
   1011  1.59  christos 
   1012  1.59  christos #ifndef TM_YEAR_BASE
   1013  1.59  christos enum {
   1014  1.59  christos   TM_YEAR_BASE = 1900,
   1015  1.59  christos   TM_WDAY_BASE = TM_MONDAY,
   1016  1.59  christos   EPOCH_YEAR = 1970,
   1017  1.59  christos   EPOCH_WDAY = TM_THURSDAY
   1018  1.59  christos };
   1019  1.59  christos #endif
   1020  1.50  christos 
   1021  1.50  christos #define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
   1022  1.50  christos 
   1023  1.50  christos /*
   1024  1.50  christos ** Since everything in isleap is modulo 400 (or a factor of 400), we know that
   1025  1.50  christos **	isleap(y) == isleap(y % 400)
   1026  1.50  christos ** and so
   1027  1.50  christos **	isleap(a + b) == isleap((a + b) % 400)
   1028  1.50  christos ** or
   1029  1.50  christos **	isleap(a + b) == isleap(a % 400 + b % 400)
   1030  1.50  christos ** This is true even if % means modulo rather than Fortran remainder
   1031  1.51  christos ** (which is allowed by C89 but not by C99 or later).
   1032  1.50  christos ** We use this to avoid addition overflow problems.
   1033  1.50  christos */
   1034  1.50  christos 
   1035  1.50  christos #define isleap_sum(a, b)	isleap((a) % 400 + (b) % 400)
   1036  1.50  christos 
   1037  1.55  christos #ifdef _LIBC
   1038  1.55  christos #include "reentrant.h"
   1039  1.54  christos extern struct __state *__lclptr;
   1040  1.54  christos #if defined(__LIBC12_SOURCE__)
   1041  1.54  christos #define tzset_unlocked __tzset_unlocked
   1042  1.54  christos #else
   1043  1.54  christos #define tzset_unlocked __tzset_unlocked50
   1044  1.54  christos #endif
   1045  1.54  christos 
   1046  1.54  christos void tzset_unlocked(void);
   1047  1.54  christos #ifdef _REENTRANT
   1048  1.54  christos extern rwlock_t __lcl_lock;
   1049  1.54  christos #endif
   1050  1.55  christos #endif
   1051  1.54  christos 
   1052   1.1       jtc #endif /* !defined PRIVATE_H */
   1053