Home | History | Annotate | Line # | Download | only in time
private.h revision 1.54
      1  1.53  christos /* Private header for tzdb code.  */
      2  1.53  christos 
      3  1.54  christos /*	$NetBSD: private.h,v 1.54 2019/04/04 19:27:28 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.54  christos #include "reentrant.h"
     20  1.54  christos 
     21   1.1       jtc /*
     22   1.6       jtc ** This file is in the public domain, so clarified as of
     23  1.25   mlelstv ** 1996-06-05 by Arthur David Olson.
     24   1.6       jtc */
     25   1.6       jtc 
     26   1.6       jtc /*
     27   1.1       jtc ** This header is for use ONLY with the time conversion code.
     28   1.1       jtc ** There is no guarantee that it will remain unchanged,
     29   1.1       jtc ** or that it will remain at all.
     30   1.1       jtc ** Do NOT copy it to any system include directory.
     31   1.1       jtc ** Thank you!
     32   1.1       jtc */
     33   1.1       jtc 
     34  1.52  christos /*
     35  1.52  christos ** zdump has been made independent of the rest of the time
     36  1.52  christos ** conversion package to increase confidence in the verification it provides.
     37  1.52  christos ** You can use zdump to help in verifying other implementations.
     38  1.52  christos ** To do this, compile with -DUSE_LTZ=0 and link without the tz library.
     39  1.52  christos */
     40  1.52  christos #ifndef USE_LTZ
     41  1.52  christos # define USE_LTZ 1
     42  1.52  christos #endif
     43  1.52  christos 
     44  1.46  christos /* This string was in the Factory zone through version 2016f.  */
     45  1.25   mlelstv #define GRANDPARENTED	"Local time zone must be set--see zic manual page"
     46  1.25   mlelstv 
     47   1.1       jtc /*
     48   1.1       jtc ** Defaults for preprocessor symbols.
     49  1.43  christos ** You can override these in your C compiler options, e.g. '-DHAVE_GETTEXT=1'.
     50   1.1       jtc */
     51   1.1       jtc 
     52  1.45  christos #ifndef HAVE_DECL_ASCTIME_R
     53  1.45  christos #define HAVE_DECL_ASCTIME_R 1
     54  1.45  christos #endif
     55  1.45  christos 
     56  1.51  christos #if !defined HAVE_GENERIC && defined __has_extension
     57  1.51  christos # if __has_extension(c_generic_selections)
     58  1.51  christos #  define HAVE_GENERIC 1
     59  1.51  christos # else
     60  1.51  christos #  define HAVE_GENERIC 0
     61  1.51  christos # endif
     62  1.51  christos #endif
     63  1.51  christos /* _Generic is buggy in pre-4.9 GCC.  */
     64  1.51  christos #if !defined HAVE_GENERIC && defined __GNUC__
     65  1.51  christos # define HAVE_GENERIC (4 < __GNUC__ + (9 <= __GNUC_MINOR__))
     66  1.51  christos #endif
     67  1.51  christos #ifndef HAVE_GENERIC
     68  1.51  christos # define HAVE_GENERIC (201112 <= __STDC_VERSION__)
     69  1.51  christos #endif
     70  1.51  christos 
     71   1.6       jtc #ifndef HAVE_GETTEXT
     72   1.6       jtc #define HAVE_GETTEXT		0
     73   1.6       jtc #endif /* !defined HAVE_GETTEXT */
     74   1.6       jtc 
     75  1.17    kleink #ifndef HAVE_INCOMPATIBLE_CTIME_R
     76  1.17    kleink #define HAVE_INCOMPATIBLE_CTIME_R	0
     77  1.51  christos #endif
     78  1.17    kleink 
     79  1.32  christos #ifndef HAVE_LINK
     80  1.32  christos #define HAVE_LINK		1
     81  1.32  christos #endif /* !defined HAVE_LINK */
     82  1.32  christos 
     83  1.45  christos #ifndef HAVE_POSIX_DECLS
     84  1.45  christos #define HAVE_POSIX_DECLS 1
     85  1.45  christos #endif
     86  1.45  christos 
     87  1.51  christos #ifndef HAVE_STDBOOL_H
     88  1.51  christos #define HAVE_STDBOOL_H (199901 <= __STDC_VERSION__)
     89  1.51  christos #endif
     90  1.51  christos 
     91  1.40  christos #ifndef HAVE_STRDUP
     92  1.40  christos #define HAVE_STRDUP 1
     93  1.40  christos #endif
     94  1.40  christos 
     95  1.52  christos #ifndef HAVE_STRTOLL
     96  1.52  christos #define HAVE_STRTOLL 1
     97  1.52  christos #endif
     98  1.52  christos 
     99  1.12    kleink #ifndef HAVE_SYMLINK
    100  1.12    kleink #define HAVE_SYMLINK		1
    101  1.12    kleink #endif /* !defined HAVE_SYMLINK */
    102   1.6       jtc 
    103  1.20    kleink #ifndef HAVE_SYS_STAT_H
    104  1.20    kleink #define HAVE_SYS_STAT_H		1
    105  1.20    kleink #endif /* !defined HAVE_SYS_STAT_H */
    106  1.20    kleink 
    107  1.14    kleink #ifndef HAVE_SYS_WAIT_H
    108  1.14    kleink #define HAVE_SYS_WAIT_H		1
    109  1.14    kleink #endif /* !defined HAVE_SYS_WAIT_H */
    110  1.14    kleink 
    111   1.1       jtc #ifndef HAVE_UNISTD_H
    112   1.1       jtc #define HAVE_UNISTD_H		1
    113   1.1       jtc #endif /* !defined HAVE_UNISTD_H */
    114   1.1       jtc 
    115   1.5       jtc #ifndef HAVE_UTMPX_H
    116  1.43  christos #define HAVE_UTMPX_H		1
    117   1.5       jtc #endif /* !defined HAVE_UTMPX_H */
    118   1.5       jtc 
    119  1.36  christos #ifndef NETBSD_INSPIRED
    120  1.36  christos # define NETBSD_INSPIRED 1
    121  1.36  christos #endif
    122   1.1       jtc 
    123  1.17    kleink #if HAVE_INCOMPATIBLE_CTIME_R
    124  1.17    kleink #define asctime_r _incompatible_asctime_r
    125  1.17    kleink #define ctime_r _incompatible_ctime_r
    126  1.17    kleink #endif /* HAVE_INCOMPATIBLE_CTIME_R */
    127  1.17    kleink 
    128  1.51  christos /* Enable tm_gmtoff, tm_zone, and environ on GNUish systems.  */
    129  1.36  christos #define _GNU_SOURCE 1
    130  1.47  christos /* Fix asctime_r on Solaris 11.  */
    131  1.36  christos #define _POSIX_PTHREAD_SEMANTICS 1
    132  1.47  christos /* Enable strtoimax on pre-C99 Solaris 11.  */
    133  1.36  christos #define __EXTENSIONS__ 1
    134  1.36  christos 
    135  1.51  christos /* To avoid having 'stat' fail unnecessarily with errno == EOVERFLOW,
    136  1.51  christos    enable large files on GNUish systems ...  */
    137  1.51  christos #ifndef _FILE_OFFSET_BITS
    138  1.51  christos # define _FILE_OFFSET_BITS 64
    139  1.51  christos #endif
    140  1.51  christos /* ... and on AIX ...  */
    141  1.51  christos #define _LARGE_FILES 1
    142  1.51  christos /* ... and enable large inode numbers on Mac OS X 10.5 and later.  */
    143  1.51  christos #define _DARWIN_USE_64_BIT_INODE 1
    144  1.51  christos 
    145   1.1       jtc /*
    146   1.1       jtc ** Nested includes
    147   1.1       jtc */
    148   1.1       jtc 
    149  1.36  christos #ifndef __NetBSD__
    150  1.36  christos /* Avoid clashes with NetBSD by renaming NetBSD's declarations.  */
    151  1.36  christos #define localtime_rz sys_localtime_rz
    152  1.36  christos #define mktime_z sys_mktime_z
    153  1.36  christos #define posix2time_z sys_posix2time_z
    154  1.36  christos #define time2posix_z sys_time2posix_z
    155  1.36  christos #define timezone_t sys_timezone_t
    156  1.36  christos #define tzalloc sys_tzalloc
    157  1.36  christos #define tzfree sys_tzfree
    158  1.36  christos #include <time.h>
    159  1.36  christos #undef localtime_rz
    160  1.36  christos #undef mktime_z
    161  1.36  christos #undef posix2time_z
    162  1.36  christos #undef time2posix_z
    163  1.36  christos #undef timezone_t
    164  1.36  christos #undef tzalloc
    165  1.36  christos #undef tzfree
    166  1.36  christos #else
    167  1.36  christos #include "time.h"
    168  1.36  christos #endif
    169  1.36  christos 
    170  1.50  christos #include <sys/types.h>	/* for time_t */
    171  1.50  christos #include <string.h>
    172  1.50  christos #include <limits.h>	/* for CHAR_BIT et al. */
    173  1.50  christos #include <stdlib.h>
    174   1.1       jtc 
    175  1.50  christos #include <errno.h>
    176  1.38  christos 
    177  1.38  christos #ifndef ENAMETOOLONG
    178  1.38  christos # define ENAMETOOLONG EINVAL
    179  1.38  christos #endif
    180  1.45  christos #ifndef ENOTSUP
    181  1.45  christos # define ENOTSUP EINVAL
    182  1.45  christos #endif
    183  1.38  christos #ifndef EOVERFLOW
    184  1.38  christos # define EOVERFLOW EINVAL
    185  1.38  christos #endif
    186  1.38  christos 
    187  1.25   mlelstv #if HAVE_GETTEXT
    188  1.50  christos #include <libintl.h>
    189  1.25   mlelstv #endif /* HAVE_GETTEXT */
    190  1.14    kleink 
    191  1.25   mlelstv #if HAVE_UNISTD_H
    192  1.51  christos #include <unistd.h>	/* for R_OK, and other POSIX goodness */
    193  1.25   mlelstv #endif /* HAVE_UNISTD_H */
    194   1.1       jtc 
    195  1.36  christos #ifndef HAVE_STRFTIME_L
    196  1.36  christos # if _POSIX_VERSION < 200809
    197  1.36  christos #  define HAVE_STRFTIME_L 0
    198  1.36  christos # else
    199  1.36  christos #  define HAVE_STRFTIME_L 1
    200  1.36  christos # endif
    201  1.36  christos #endif
    202  1.36  christos 
    203  1.51  christos #ifndef USG_COMPAT
    204  1.51  christos # ifndef _XOPEN_VERSION
    205  1.51  christos #  define USG_COMPAT 0
    206  1.51  christos # else
    207  1.51  christos #  define USG_COMPAT 1
    208  1.51  christos # endif
    209  1.51  christos #endif
    210  1.51  christos 
    211  1.51  christos #ifndef HAVE_TZNAME
    212  1.51  christos # if _POSIX_VERSION < 198808 && !USG_COMPAT
    213  1.51  christos #  define HAVE_TZNAME 0
    214  1.51  christos # else
    215  1.51  christos #  define HAVE_TZNAME 1
    216  1.51  christos # endif
    217  1.51  christos #endif
    218  1.51  christos 
    219   1.1       jtc #ifndef R_OK
    220   1.1       jtc #define R_OK	4
    221   1.1       jtc #endif /* !defined R_OK */
    222   1.1       jtc 
    223  1.25   mlelstv /* Unlike <ctype.h>'s isdigit, this also works if c < 0 | c > UCHAR_MAX. */
    224   1.4       jtc #define is_digit(c) ((unsigned)(c) - '0' <= 9)
    225   1.4       jtc 
    226   1.1       jtc /*
    227  1.25   mlelstv ** Define HAVE_STDINT_H's default value here, rather than at the
    228  1.47  christos ** start, since __GLIBC__ and INTMAX_MAX's values depend on
    229  1.47  christos ** previously-included files.  glibc 2.1 and Solaris 10 and later have
    230  1.47  christos ** stdint.h, even with pre-C99 compilers.
    231  1.25   mlelstv */
    232  1.25   mlelstv #ifndef HAVE_STDINT_H
    233  1.25   mlelstv #define HAVE_STDINT_H \
    234  1.33  christos    (199901 <= __STDC_VERSION__ \
    235  1.33  christos     || 2 < __GLIBC__ + (1 <= __GLIBC_MINOR__)	\
    236  1.47  christos     || __CYGWIN__ || INTMAX_MAX)
    237  1.25   mlelstv #endif /* !defined HAVE_STDINT_H */
    238  1.25   mlelstv 
    239  1.25   mlelstv #if HAVE_STDINT_H
    240  1.50  christos #include <stdint.h>
    241  1.25   mlelstv #endif /* !HAVE_STDINT_H */
    242  1.25   mlelstv 
    243  1.29  christos #ifndef HAVE_INTTYPES_H
    244  1.29  christos # define HAVE_INTTYPES_H HAVE_STDINT_H
    245  1.29  christos #endif
    246  1.29  christos #if HAVE_INTTYPES_H
    247  1.29  christos # include <inttypes.h>
    248  1.29  christos #endif
    249  1.29  christos 
    250  1.36  christos /* Pre-C99 GCC compilers define __LONG_LONG_MAX__ instead of LLONG_MAX.  */
    251  1.36  christos #ifdef __LONG_LONG_MAX__
    252  1.36  christos # ifndef LLONG_MAX
    253  1.36  christos #  define LLONG_MAX __LONG_LONG_MAX__
    254  1.36  christos # endif
    255  1.36  christos # ifndef LLONG_MIN
    256  1.36  christos #  define LLONG_MIN (-1 - LLONG_MAX)
    257  1.36  christos # endif
    258  1.36  christos #endif
    259  1.36  christos 
    260  1.25   mlelstv #ifndef INT_FAST64_MAX
    261  1.36  christos # ifdef LLONG_MAX
    262  1.25   mlelstv typedef long long	int_fast64_t;
    263  1.29  christos #  define INT_FAST64_MIN LLONG_MIN
    264  1.29  christos #  define INT_FAST64_MAX LLONG_MAX
    265  1.29  christos # else
    266  1.43  christos #  if LONG_MAX >> 31 < 0xffffffff
    267  1.25   mlelstv Please use a compiler that supports a 64-bit integer type (or wider);
    268  1.25   mlelstv you may need to compile with "-DHAVE_STDINT_H".
    269  1.36  christos #  endif
    270  1.25   mlelstv typedef long		int_fast64_t;
    271  1.36  christos #  define INT_FAST64_MIN LONG_MIN
    272  1.36  christos #  define INT_FAST64_MAX LONG_MAX
    273  1.36  christos # endif
    274  1.36  christos #endif
    275  1.36  christos 
    276  1.48  christos #ifndef PRIdFAST64
    277  1.36  christos # if INT_FAST64_MAX == LLONG_MAX
    278  1.48  christos #  define PRIdFAST64 "lld"
    279  1.36  christos # else
    280  1.48  christos #  define PRIdFAST64 "ld"
    281  1.36  christos # endif
    282  1.36  christos #endif
    283  1.25   mlelstv 
    284  1.48  christos #ifndef SCNdFAST64
    285  1.48  christos # define SCNdFAST64 PRIdFAST64
    286  1.48  christos #endif
    287  1.48  christos 
    288  1.29  christos #ifndef INT_FAST32_MAX
    289  1.29  christos # if INT_MAX >> 31 == 0
    290  1.29  christos typedef long int_fast32_t;
    291  1.36  christos #  define INT_FAST32_MAX LONG_MAX
    292  1.36  christos #  define INT_FAST32_MIN LONG_MIN
    293  1.29  christos # else
    294  1.29  christos typedef int int_fast32_t;
    295  1.36  christos #  define INT_FAST32_MAX INT_MAX
    296  1.36  christos #  define INT_FAST32_MIN INT_MIN
    297  1.29  christos # endif
    298  1.29  christos #endif
    299  1.29  christos 
    300  1.29  christos #ifndef INTMAX_MAX
    301  1.36  christos # ifdef LLONG_MAX
    302  1.29  christos typedef long long intmax_t;
    303  1.52  christos #  if HAVE_STRTOLL
    304  1.52  christos #   define strtoimax strtoll
    305  1.52  christos #  endif
    306  1.36  christos #  define INTMAX_MAX LLONG_MAX
    307  1.36  christos #  define INTMAX_MIN LLONG_MIN
    308  1.29  christos # else
    309  1.29  christos typedef long intmax_t;
    310  1.30  christos #  define INTMAX_MAX LONG_MAX
    311  1.30  christos #  define INTMAX_MIN LONG_MIN
    312  1.29  christos # endif
    313  1.52  christos # ifndef strtoimax
    314  1.52  christos #  define strtoimax strtol
    315  1.52  christos # endif
    316  1.29  christos #endif
    317  1.29  christos 
    318  1.36  christos #ifndef PRIdMAX
    319  1.36  christos # if INTMAX_MAX == LLONG_MAX
    320  1.36  christos #  define PRIdMAX "lld"
    321  1.36  christos # else
    322  1.36  christos #  define PRIdMAX "ld"
    323  1.36  christos # endif
    324  1.36  christos #endif
    325  1.36  christos 
    326  1.43  christos #ifndef UINT_FAST64_MAX
    327  1.43  christos # if defined ULLONG_MAX || defined __LONG_LONG_MAX__
    328  1.43  christos typedef unsigned long long uint_fast64_t;
    329  1.43  christos # else
    330  1.43  christos #  if ULONG_MAX >> 31 >> 1 < 0xffffffff
    331  1.43  christos Please use a compiler that supports a 64-bit integer type (or wider);
    332  1.43  christos you may need to compile with "-DHAVE_STDINT_H".
    333  1.43  christos #  endif
    334  1.43  christos typedef unsigned long	uint_fast64_t;
    335  1.43  christos # endif
    336  1.43  christos #endif
    337  1.43  christos 
    338  1.29  christos #ifndef UINTMAX_MAX
    339  1.29  christos # if defined ULLONG_MAX || defined __LONG_LONG_MAX__
    340  1.29  christos typedef unsigned long long uintmax_t;
    341  1.36  christos # else
    342  1.36  christos typedef unsigned long uintmax_t;
    343  1.36  christos # endif
    344  1.36  christos #endif
    345  1.36  christos 
    346  1.36  christos #ifndef PRIuMAX
    347  1.36  christos # if defined ULLONG_MAX || defined __LONG_LONG_MAX__
    348  1.29  christos #  define PRIuMAX "llu"
    349  1.29  christos # else
    350  1.29  christos #  define PRIuMAX "lu"
    351  1.29  christos # endif
    352  1.29  christos #endif
    353  1.29  christos 
    354  1.25   mlelstv #ifndef INT32_MAX
    355  1.25   mlelstv #define INT32_MAX 0x7fffffff
    356  1.25   mlelstv #endif /* !defined INT32_MAX */
    357  1.25   mlelstv #ifndef INT32_MIN
    358  1.25   mlelstv #define INT32_MIN (-1 - INT32_MAX)
    359  1.25   mlelstv #endif /* !defined INT32_MIN */
    360   1.1       jtc 
    361  1.33  christos #ifndef SIZE_MAX
    362  1.33  christos #define SIZE_MAX ((size_t) -1)
    363  1.33  christos #endif
    364  1.33  christos 
    365  1.52  christos #if 3 <= __GNUC__
    366  1.29  christos # define ATTRIBUTE_CONST __attribute__ ((__const__))
    367  1.52  christos # define ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
    368  1.29  christos # define ATTRIBUTE_PURE __attribute__ ((__pure__))
    369  1.30  christos # define ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
    370  1.27  christos #else
    371  1.29  christos # define ATTRIBUTE_CONST /* empty */
    372  1.52  christos # define ATTRIBUTE_MALLOC /* empty */
    373  1.29  christos # define ATTRIBUTE_PURE /* empty */
    374  1.30  christos # define ATTRIBUTE_FORMAT(spec) /* empty */
    375  1.27  christos #endif
    376  1.29  christos 
    377  1.29  christos #if !defined _Noreturn && __STDC_VERSION__ < 201112
    378  1.29  christos # if 2 < __GNUC__ + (8 <= __GNUC_MINOR__)
    379  1.29  christos #  define _Noreturn __attribute__ ((__noreturn__))
    380  1.29  christos # else
    381  1.29  christos #  define _Noreturn
    382  1.29  christos # endif
    383  1.29  christos #endif
    384  1.29  christos 
    385  1.29  christos #if __STDC_VERSION__ < 199901 && !defined restrict
    386  1.29  christos # define restrict /* empty */
    387  1.27  christos #endif
    388  1.27  christos 
    389   1.1       jtc /*
    390  1.25   mlelstv ** Workarounds for compilers/systems.
    391   1.1       jtc */
    392   1.1       jtc 
    393  1.48  christos #ifndef EPOCH_LOCAL
    394  1.48  christos # define EPOCH_LOCAL 0
    395  1.48  christos #endif
    396  1.48  christos #ifndef EPOCH_OFFSET
    397  1.48  christos # define EPOCH_OFFSET 0
    398  1.48  christos #endif
    399  1.52  christos #ifndef RESERVE_STD_EXT_IDS
    400  1.52  christos # define RESERVE_STD_EXT_IDS 0
    401  1.52  christos #endif
    402  1.52  christos 
    403  1.52  christos /* If standard C identifiers with external linkage (e.g., localtime)
    404  1.52  christos    are reserved and are not already being renamed anyway, rename them
    405  1.52  christos    as if compiling with '-Dtime_tz=time_t'.  */
    406  1.52  christos #if !defined time_tz && RESERVE_STD_EXT_IDS && USE_LTZ
    407  1.52  christos # define time_tz time_t
    408  1.52  christos #endif
    409  1.48  christos 
    410   1.1       jtc /*
    411  1.29  christos ** Compile with -Dtime_tz=T to build the tz package with a private
    412  1.29  christos ** time_t type equivalent to T rather than the system-supplied time_t.
    413  1.29  christos ** This debugging feature can test unusual design decisions
    414  1.29  christos ** (e.g., time_t wider than 'long', or unsigned time_t) even on
    415  1.29  christos ** typical platforms.
    416  1.29  christos */
    417  1.48  christos #if defined time_tz || EPOCH_LOCAL || EPOCH_OFFSET != 0
    418  1.51  christos # define TZ_TIME_T 1
    419  1.51  christos #else
    420  1.51  christos # define TZ_TIME_T 0
    421  1.51  christos #endif
    422  1.51  christos 
    423  1.51  christos #if TZ_TIME_T
    424  1.36  christos # ifdef LOCALTIME_IMPLEMENTATION
    425  1.29  christos static time_t sys_time(time_t *x) { return time(x); }
    426  1.36  christos # endif
    427  1.29  christos 
    428  1.39  christos typedef time_tz tz_time_t;
    429  1.39  christos 
    430  1.29  christos # undef  ctime
    431  1.29  christos # define ctime tz_ctime
    432  1.29  christos # undef  ctime_r
    433  1.29  christos # define ctime_r tz_ctime_r
    434  1.29  christos # undef  difftime
    435  1.29  christos # define difftime tz_difftime
    436  1.29  christos # undef  gmtime
    437  1.29  christos # define gmtime tz_gmtime
    438  1.29  christos # undef  gmtime_r
    439  1.29  christos # define gmtime_r tz_gmtime_r
    440  1.29  christos # undef  localtime
    441  1.29  christos # define localtime tz_localtime
    442  1.29  christos # undef  localtime_r
    443  1.29  christos # define localtime_r tz_localtime_r
    444  1.39  christos # undef  localtime_rz
    445  1.39  christos # define localtime_rz tz_localtime_rz
    446  1.29  christos # undef  mktime
    447  1.29  christos # define mktime tz_mktime
    448  1.39  christos # undef  mktime_z
    449  1.39  christos # define mktime_z tz_mktime_z
    450  1.36  christos # undef  offtime
    451  1.36  christos # define offtime tz_offtime
    452  1.36  christos # undef  posix2time
    453  1.36  christos # define posix2time tz_posix2time
    454  1.39  christos # undef  posix2time_z
    455  1.39  christos # define posix2time_z tz_posix2time_z
    456  1.51  christos # undef  strftime
    457  1.51  christos # define strftime tz_strftime
    458  1.29  christos # undef  time
    459  1.29  christos # define time tz_time
    460  1.36  christos # undef  time2posix
    461  1.36  christos # define time2posix tz_time2posix
    462  1.39  christos # undef  time2posix_z
    463  1.39  christos # define time2posix_z tz_time2posix_z
    464  1.29  christos # undef  time_t
    465  1.29  christos # define time_t tz_time_t
    466  1.36  christos # undef  timegm
    467  1.36  christos # define timegm tz_timegm
    468  1.36  christos # undef  timelocal
    469  1.36  christos # define timelocal tz_timelocal
    470  1.36  christos # undef  timeoff
    471  1.36  christos # define timeoff tz_timeoff
    472  1.39  christos # undef  tzalloc
    473  1.39  christos # define tzalloc tz_tzalloc
    474  1.39  christos # undef  tzfree
    475  1.39  christos # define tzfree tz_tzfree
    476  1.39  christos # undef  tzset
    477  1.39  christos # define tzset tz_tzset
    478  1.39  christos # undef  tzsetwall
    479  1.39  christos # define tzsetwall tz_tzsetwall
    480  1.51  christos # if HAVE_STRFTIME_L
    481  1.51  christos #  undef  strftime_l
    482  1.51  christos #  define strftime_l tz_strftime_l
    483  1.51  christos # endif
    484  1.51  christos # if HAVE_TZNAME
    485  1.51  christos #  undef  tzname
    486  1.51  christos #  define tzname tz_tzname
    487  1.51  christos # endif
    488  1.51  christos # if USG_COMPAT
    489  1.51  christos #  undef  daylight
    490  1.51  christos #  define daylight tz_daylight
    491  1.51  christos #  undef  timezone
    492  1.51  christos #  define timezone tz_timezone
    493  1.51  christos # endif
    494  1.51  christos # ifdef ALTZONE
    495  1.51  christos #  undef  altzone
    496  1.51  christos #  define altzone tz_altzone
    497  1.51  christos # endif
    498  1.29  christos 
    499  1.29  christos char *ctime(time_t const *);
    500  1.29  christos char *ctime_r(time_t const *, char *);
    501  1.51  christos double difftime(time_t, time_t) ATTRIBUTE_CONST;
    502  1.51  christos size_t strftime(char *restrict, size_t, char const *restrict,
    503  1.51  christos 		struct tm const *restrict);
    504  1.51  christos # if HAVE_STRFTIME_L
    505  1.51  christos size_t strftime_l(char *restrict, size_t, char const *restrict,
    506  1.51  christos 		  struct tm const *restrict, locale_t);
    507  1.51  christos # endif
    508  1.29  christos struct tm *gmtime(time_t const *);
    509  1.29  christos struct tm *gmtime_r(time_t const *restrict, struct tm *restrict);
    510  1.29  christos struct tm *localtime(time_t const *);
    511  1.29  christos struct tm *localtime_r(time_t const *restrict, struct tm *restrict);
    512  1.29  christos time_t mktime(struct tm *);
    513  1.36  christos time_t time(time_t *);
    514  1.39  christos void tzset(void);
    515  1.36  christos #endif
    516  1.29  christos 
    517  1.45  christos #if !HAVE_DECL_ASCTIME_R && !defined asctime_r
    518  1.45  christos extern char *asctime_r(struct tm const *restrict, char *restrict);
    519  1.36  christos #endif
    520  1.36  christos 
    521  1.51  christos #ifndef HAVE_DECL_ENVIRON
    522  1.51  christos # if defined environ || defined __USE_GNU
    523  1.51  christos #  define HAVE_DECL_ENVIRON 1
    524  1.51  christos # else
    525  1.51  christos #  define HAVE_DECL_ENVIRON 0
    526  1.51  christos # endif
    527  1.51  christos #endif
    528  1.51  christos 
    529  1.51  christos #if !HAVE_DECL_ENVIRON
    530  1.51  christos extern char **environ;
    531  1.51  christos #endif
    532  1.51  christos 
    533  1.51  christos #if TZ_TIME_T || !HAVE_POSIX_DECLS
    534  1.51  christos # if HAVE_TZNAME
    535  1.51  christos extern char *tzname[];
    536  1.51  christos # endif
    537  1.51  christos # if USG_COMPAT
    538  1.44  christos extern long timezone;
    539  1.44  christos extern int daylight;
    540  1.44  christos # endif
    541  1.44  christos #endif
    542  1.45  christos 
    543  1.51  christos #ifdef ALTZONE
    544  1.44  christos extern long altzone;
    545  1.44  christos #endif
    546  1.44  christos 
    547  1.36  christos /*
    548  1.36  christos ** The STD_INSPIRED functions are similar, but most also need
    549  1.36  christos ** declarations if time_tz is defined.
    550  1.36  christos */
    551  1.36  christos 
    552  1.36  christos #ifdef STD_INSPIRED
    553  1.51  christos # if TZ_TIME_T || !defined tzsetwall
    554  1.36  christos void tzsetwall(void);
    555  1.36  christos # endif
    556  1.51  christos # if TZ_TIME_T || !defined offtime
    557  1.36  christos struct tm *offtime(time_t const *, long);
    558  1.36  christos # endif
    559  1.51  christos # if TZ_TIME_T || !defined timegm
    560  1.36  christos time_t timegm(struct tm *);
    561  1.36  christos # endif
    562  1.51  christos # if TZ_TIME_T || !defined timelocal
    563  1.36  christos time_t timelocal(struct tm *);
    564  1.36  christos # endif
    565  1.51  christos # if TZ_TIME_T || !defined timeoff
    566  1.36  christos time_t timeoff(struct tm *, long);
    567  1.36  christos # endif
    568  1.51  christos # if TZ_TIME_T || !defined time2posix
    569  1.36  christos time_t time2posix(time_t);
    570  1.36  christos # endif
    571  1.51  christos # if TZ_TIME_T || !defined posix2time
    572  1.36  christos time_t posix2time(time_t);
    573  1.36  christos # endif
    574  1.36  christos #endif
    575  1.36  christos 
    576  1.36  christos /* Infer TM_ZONE on systems where this information is known, but suppress
    577  1.36  christos    guessing if NO_TM_ZONE is defined.  Similarly for TM_GMTOFF.  */
    578  1.36  christos #if (defined __GLIBC__ \
    579  1.36  christos      || defined __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__ \
    580  1.36  christos      || (defined __APPLE__ && defined __MACH__))
    581  1.36  christos # if !defined TM_GMTOFF && !defined NO_TM_GMTOFF
    582  1.36  christos #  define TM_GMTOFF tm_gmtoff
    583  1.36  christos # endif
    584  1.36  christos # if !defined TM_ZONE && !defined NO_TM_ZONE
    585  1.36  christos #  define TM_ZONE tm_zone
    586  1.36  christos # endif
    587  1.36  christos #endif
    588  1.36  christos 
    589  1.36  christos /*
    590  1.36  christos ** Define functions that are ABI compatible with NetBSD but have
    591  1.36  christos ** better prototypes.  NetBSD 6.1.4 defines a pointer type timezone_t
    592  1.36  christos ** and labors under the misconception that 'const timezone_t' is a
    593  1.36  christos ** pointer to a constant.  This use of 'const' is ineffective, so it
    594  1.36  christos ** is not done here.  What we call 'struct state' NetBSD calls
    595  1.36  christos ** 'struct __state', but this is a private name so it doesn't matter.
    596  1.36  christos */
    597  1.37  christos #ifndef __NetBSD__
    598  1.36  christos #if NETBSD_INSPIRED
    599  1.36  christos typedef struct state *timezone_t;
    600  1.36  christos struct tm *localtime_rz(timezone_t restrict, time_t const *restrict,
    601  1.36  christos 			struct tm *restrict);
    602  1.36  christos time_t mktime_z(timezone_t restrict, struct tm *restrict);
    603  1.36  christos timezone_t tzalloc(char const *);
    604  1.36  christos void tzfree(timezone_t);
    605  1.36  christos # ifdef STD_INSPIRED
    606  1.51  christos #  if TZ_TIME_T || !defined posix2time_z
    607  1.36  christos time_t posix2time_z(timezone_t __restrict, time_t) ATTRIBUTE_PURE;
    608  1.36  christos #  endif
    609  1.51  christos #  if TZ_TIME_T || !defined time2posix_z
    610  1.36  christos time_t time2posix_z(timezone_t __restrict, time_t) ATTRIBUTE_PURE;
    611  1.36  christos #  endif
    612  1.36  christos # endif
    613  1.29  christos #endif
    614  1.37  christos #endif
    615  1.29  christos 
    616  1.29  christos /*
    617   1.1       jtc ** Finally, some convenience items.
    618   1.1       jtc */
    619   1.1       jtc 
    620  1.51  christos #if HAVE_STDBOOL_H
    621  1.51  christos # include <stdbool.h>
    622  1.51  christos #else
    623  1.36  christos # define true 1
    624  1.36  christos # define false 0
    625  1.36  christos # define bool int
    626  1.36  christos #endif
    627   1.1       jtc 
    628   1.5       jtc #define TYPE_BIT(type)	(sizeof (type) * CHAR_BIT)
    629  1.28  christos #define TYPE_SIGNED(type) (/*CONSTCOND*/((type) -1) < 0)
    630  1.41  christos #define TWOS_COMPLEMENT(t) (/*CONSTCOND*/(t) ~ (t) 0 < 0)
    631  1.41  christos 
    632  1.41  christos /* Max and min values of the integer type T, of which only the bottom
    633  1.41  christos    B bits are used, and where the highest-order used bit is considered
    634  1.41  christos    to be a sign bit if T is signed.  */
    635  1.41  christos #define MAXVAL(t, b) /*LINTED*/					\
    636  1.41  christos   ((t) (((t) 1 << ((b) - 1 - TYPE_SIGNED(t)))			\
    637  1.41  christos 	- 1 + ((t) 1 << ((b) - 1 - TYPE_SIGNED(t)))))
    638  1.41  christos #define MINVAL(t, b)						\
    639  1.41  christos   ((t) (TYPE_SIGNED(t) ? - TWOS_COMPLEMENT(t) - MAXVAL(t, b) : 0))
    640  1.41  christos 
    641  1.51  christos /* The extreme time values, assuming no padding.  */
    642  1.51  christos #define TIME_T_MIN_NO_PADDING MINVAL(time_t, TYPE_BIT(time_t))
    643  1.51  christos #define TIME_T_MAX_NO_PADDING MAXVAL(time_t, TYPE_BIT(time_t))
    644  1.51  christos 
    645  1.51  christos /* The extreme time values.  These are macros, not constants, so that
    646  1.51  christos    any portability problem occur only when compiling .c files that use
    647  1.51  christos    the macros, which is safer for applications that need only zdump and zic.
    648  1.51  christos    This implementation assumes no padding if time_t is signed and
    649  1.51  christos    either the compiler lacks support for _Generic or time_t is not one
    650  1.51  christos    of the standard signed integer types.  */
    651  1.51  christos #if HAVE_GENERIC
    652  1.51  christos # define TIME_T_MIN \
    653  1.51  christos     _Generic((time_t) 0, \
    654  1.51  christos 	     signed char: SCHAR_MIN, short: SHRT_MIN, \
    655  1.51  christos 	     int: INT_MIN, long: LONG_MIN, long long: LLONG_MIN, \
    656  1.51  christos 	     default: TIME_T_MIN_NO_PADDING)
    657  1.51  christos # define TIME_T_MAX \
    658  1.51  christos     (TYPE_SIGNED(time_t) \
    659  1.51  christos      ? _Generic((time_t) 0, \
    660  1.51  christos 		signed char: SCHAR_MAX, short: SHRT_MAX, \
    661  1.51  christos 		int: INT_MAX, long: LONG_MAX, long long: LLONG_MAX, \
    662  1.51  christos 		default: TIME_T_MAX_NO_PADDING)			    \
    663  1.51  christos      : (time_t) -1)
    664  1.48  christos #else
    665  1.51  christos # define TIME_T_MIN TIME_T_MIN_NO_PADDING
    666  1.51  christos # define TIME_T_MAX TIME_T_MAX_NO_PADDING
    667  1.48  christos #endif
    668  1.36  christos 
    669   1.1       jtc /*
    670   1.1       jtc ** 302 / 1000 is log10(2.0) rounded up.
    671   1.5       jtc ** Subtract one for the sign bit if the type is signed;
    672   1.5       jtc ** add one for integer division truncation;
    673   1.5       jtc ** add one more for a minus sign if the type is signed.
    674   1.1       jtc */
    675   1.1       jtc #define INT_STRLEN_MAXIMUM(type) \
    676  1.25   mlelstv 	((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + \
    677  1.25   mlelstv 	1 + TYPE_SIGNED(type))
    678   1.1       jtc 
    679   1.1       jtc /*
    680   1.1       jtc ** INITIALIZE(x)
    681   1.1       jtc */
    682   1.1       jtc 
    683  1.35  christos #if defined(__GNUC__) || defined(__lint__)
    684  1.34  christos # define INITIALIZE(x)	((x) = 0)
    685  1.34  christos #else
    686  1.34  christos # define INITIALIZE(x)
    687  1.34  christos #endif
    688   1.6       jtc 
    689  1.36  christos #ifndef UNINIT_TRAP
    690  1.36  christos # define UNINIT_TRAP 0
    691  1.36  christos #endif
    692  1.36  christos 
    693   1.6       jtc /*
    694   1.6       jtc ** For the benefit of GNU folk...
    695  1.34  christos ** '_(MSGID)' uses the current locale's message library string for MSGID.
    696   1.6       jtc ** The default is to use gettext if available, and use MSGID otherwise.
    697   1.6       jtc */
    698   1.6       jtc 
    699  1.25   mlelstv #if HAVE_GETTEXT
    700   1.6       jtc #define _(msgid) gettext(msgid)
    701  1.25   mlelstv #else /* !HAVE_GETTEXT */
    702   1.6       jtc #define _(msgid) msgid
    703  1.25   mlelstv #endif /* !HAVE_GETTEXT */
    704   1.6       jtc 
    705  1.34  christos #if !defined TZ_DOMAIN && defined HAVE_GETTEXT
    706  1.34  christos # define TZ_DOMAIN "tz"
    707  1.34  christos #endif
    708  1.17    kleink 
    709  1.17    kleink #if HAVE_INCOMPATIBLE_CTIME_R
    710  1.17    kleink #undef asctime_r
    711  1.17    kleink #undef ctime_r
    712  1.25   mlelstv char *asctime_r(struct tm const *, char *);
    713  1.25   mlelstv char *ctime_r(time_t const *, char *);
    714  1.17    kleink #endif /* HAVE_INCOMPATIBLE_CTIME_R */
    715   1.1       jtc 
    716  1.50  christos /* Handy macros that are independent of tzfile implementation.  */
    717  1.50  christos 
    718  1.25   mlelstv #define YEARSPERREPEAT		400	/* years before a Gregorian repeat */
    719  1.50  christos 
    720  1.50  christos #define SECSPERMIN	60
    721  1.50  christos #define MINSPERHOUR	60
    722  1.50  christos #define HOURSPERDAY	24
    723  1.50  christos #define DAYSPERWEEK	7
    724  1.50  christos #define DAYSPERNYEAR	365
    725  1.50  christos #define DAYSPERLYEAR	366
    726  1.50  christos #define SECSPERHOUR	(SECSPERMIN * MINSPERHOUR)
    727  1.50  christos #define SECSPERDAY	((int_fast32_t) SECSPERHOUR * HOURSPERDAY)
    728  1.50  christos #define MONSPERYEAR	12
    729  1.50  christos 
    730  1.50  christos #define TM_SUNDAY	0
    731  1.50  christos #define TM_MONDAY	1
    732  1.50  christos #define TM_TUESDAY	2
    733  1.50  christos #define TM_WEDNESDAY	3
    734  1.50  christos #define TM_THURSDAY	4
    735  1.50  christos #define TM_FRIDAY	5
    736  1.50  christos #define TM_SATURDAY	6
    737  1.50  christos 
    738  1.50  christos #define TM_JANUARY	0
    739  1.50  christos #define TM_FEBRUARY	1
    740  1.50  christos #define TM_MARCH	2
    741  1.50  christos #define TM_APRIL	3
    742  1.50  christos #define TM_MAY		4
    743  1.50  christos #define TM_JUNE		5
    744  1.50  christos #define TM_JULY		6
    745  1.50  christos #define TM_AUGUST	7
    746  1.50  christos #define TM_SEPTEMBER	8
    747  1.50  christos #define TM_OCTOBER	9
    748  1.50  christos #define TM_NOVEMBER	10
    749  1.50  christos #define TM_DECEMBER	11
    750  1.50  christos 
    751  1.50  christos #define TM_YEAR_BASE	1900
    752  1.50  christos 
    753  1.50  christos #define EPOCH_YEAR	1970
    754  1.50  christos #define EPOCH_WDAY	TM_THURSDAY
    755  1.50  christos 
    756  1.50  christos #define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
    757  1.50  christos 
    758  1.50  christos /*
    759  1.50  christos ** Since everything in isleap is modulo 400 (or a factor of 400), we know that
    760  1.50  christos **	isleap(y) == isleap(y % 400)
    761  1.50  christos ** and so
    762  1.50  christos **	isleap(a + b) == isleap((a + b) % 400)
    763  1.50  christos ** or
    764  1.50  christos **	isleap(a + b) == isleap(a % 400 + b % 400)
    765  1.50  christos ** This is true even if % means modulo rather than Fortran remainder
    766  1.51  christos ** (which is allowed by C89 but not by C99 or later).
    767  1.50  christos ** We use this to avoid addition overflow problems.
    768  1.50  christos */
    769  1.50  christos 
    770  1.50  christos #define isleap_sum(a, b)	isleap((a) % 400 + (b) % 400)
    771  1.50  christos 
    772  1.25   mlelstv 
    773  1.25   mlelstv /*
    774  1.25   mlelstv ** The Gregorian year averages 365.2425 days, which is 31556952 seconds.
    775  1.25   mlelstv */
    776  1.25   mlelstv 
    777  1.25   mlelstv #define AVGSECSPERYEAR		31556952L
    778  1.50  christos #define SECSPERREPEAT \
    779  1.50  christos   ((int_fast64_t) YEARSPERREPEAT * (int_fast64_t) AVGSECSPERYEAR)
    780  1.25   mlelstv #define SECSPERREPEAT_BITS	34	/* ceil(log2(SECSPERREPEAT)) */
    781  1.25   mlelstv 
    782  1.54  christos extern struct __state *__lclptr;
    783  1.54  christos #if defined(__LIBC12_SOURCE__)
    784  1.54  christos #define tzset_unlocked __tzset_unlocked
    785  1.54  christos #else
    786  1.54  christos #define tzset_unlocked __tzset_unlocked50
    787  1.54  christos #endif
    788  1.54  christos 
    789  1.54  christos void tzset_unlocked(void);
    790  1.54  christos #ifdef _REENTRANT
    791  1.54  christos extern rwlock_t __lcl_lock;
    792  1.54  christos #endif
    793  1.54  christos 
    794   1.1       jtc #endif /* !defined PRIVATE_H */
    795