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