Home | History | Annotate | Line # | Download | only in time
private.h revision 1.39
      1  1.39  christos /*	$NetBSD: private.h,v 1.39 2015/03/24 20:01:18 christos Exp $	*/
      2   1.2       jtc 
      3   1.1       jtc #ifndef PRIVATE_H
      4   1.1       jtc #define PRIVATE_H
      5   1.3       jtc 
      6   1.3       jtc /* NetBSD defaults */
      7   1.3       jtc #define TM_GMTOFF	tm_gmtoff
      8   1.3       jtc #define TM_ZONE		tm_zone
      9   1.3       jtc #define STD_INSPIRED	1
     10   1.3       jtc #define HAVE_LONG_DOUBLE 1
     11  1.21     bjh21 
     12  1.21     bjh21 /* For when we build zic as a host tool. */
     13  1.23     lukem #if HAVE_NBTOOL_CONFIG_H
     14  1.23     lukem #include "nbtool_config.h"
     15  1.21     bjh21 #endif
     16   1.1       jtc 
     17   1.1       jtc /*
     18   1.6       jtc ** This file is in the public domain, so clarified as of
     19  1.25   mlelstv ** 1996-06-05 by Arthur David Olson.
     20   1.6       jtc */
     21   1.6       jtc 
     22   1.6       jtc /*
     23   1.1       jtc ** This header is for use ONLY with the time conversion code.
     24   1.1       jtc ** There is no guarantee that it will remain unchanged,
     25   1.1       jtc ** or that it will remain at all.
     26   1.1       jtc ** Do NOT copy it to any system include directory.
     27   1.1       jtc ** Thank you!
     28   1.1       jtc */
     29   1.1       jtc 
     30  1.25   mlelstv #define GRANDPARENTED	"Local time zone must be set--see zic manual page"
     31  1.25   mlelstv 
     32   1.1       jtc /*
     33   1.1       jtc ** Defaults for preprocessor symbols.
     34  1.34  christos ** You can override these in your C compiler options, e.g. '-DHAVE_ADJTIME=0'.
     35   1.1       jtc */
     36   1.1       jtc 
     37   1.1       jtc #ifndef HAVE_ADJTIME
     38   1.1       jtc #define HAVE_ADJTIME		1
     39   1.1       jtc #endif /* !defined HAVE_ADJTIME */
     40   1.1       jtc 
     41   1.6       jtc #ifndef HAVE_GETTEXT
     42   1.6       jtc #define HAVE_GETTEXT		0
     43   1.6       jtc #endif /* !defined HAVE_GETTEXT */
     44   1.6       jtc 
     45  1.17    kleink #ifndef HAVE_INCOMPATIBLE_CTIME_R
     46  1.17    kleink #define HAVE_INCOMPATIBLE_CTIME_R	0
     47  1.17    kleink #endif /* !defined INCOMPATIBLE_CTIME_R */
     48  1.17    kleink 
     49  1.32  christos #ifndef HAVE_LINK
     50  1.32  christos #define HAVE_LINK		1
     51  1.32  christos #endif /* !defined HAVE_LINK */
     52  1.32  christos 
     53   1.1       jtc #ifndef HAVE_SETTIMEOFDAY
     54   1.1       jtc #define HAVE_SETTIMEOFDAY	3
     55   1.1       jtc #endif /* !defined HAVE_SETTIMEOFDAY */
     56   1.1       jtc 
     57  1.12    kleink #ifndef HAVE_SYMLINK
     58  1.12    kleink #define HAVE_SYMLINK		1
     59  1.12    kleink #endif /* !defined HAVE_SYMLINK */
     60   1.6       jtc 
     61  1.20    kleink #ifndef HAVE_SYS_STAT_H
     62  1.20    kleink #define HAVE_SYS_STAT_H		1
     63  1.20    kleink #endif /* !defined HAVE_SYS_STAT_H */
     64  1.20    kleink 
     65  1.14    kleink #ifndef HAVE_SYS_WAIT_H
     66  1.14    kleink #define HAVE_SYS_WAIT_H		1
     67  1.14    kleink #endif /* !defined HAVE_SYS_WAIT_H */
     68  1.14    kleink 
     69   1.1       jtc #ifndef HAVE_UNISTD_H
     70   1.1       jtc #define HAVE_UNISTD_H		1
     71   1.1       jtc #endif /* !defined HAVE_UNISTD_H */
     72   1.1       jtc 
     73   1.5       jtc #ifndef HAVE_UTMPX_H
     74   1.5       jtc #define HAVE_UTMPX_H		0
     75   1.5       jtc #endif /* !defined HAVE_UTMPX_H */
     76   1.5       jtc 
     77  1.36  christos #ifndef NETBSD_INSPIRED
     78  1.36  christos # define NETBSD_INSPIRED 1
     79  1.36  christos #endif
     80   1.1       jtc 
     81  1.17    kleink #if HAVE_INCOMPATIBLE_CTIME_R
     82  1.17    kleink #define asctime_r _incompatible_asctime_r
     83  1.17    kleink #define ctime_r _incompatible_ctime_r
     84  1.17    kleink #endif /* HAVE_INCOMPATIBLE_CTIME_R */
     85  1.17    kleink 
     86  1.36  christos /* Enable tm_gmtoff and tm_zone on GNUish systems.  */
     87  1.36  christos #define _GNU_SOURCE 1
     88  1.36  christos /* Fix asctime_r on Solaris 10.  */
     89  1.36  christos #define _POSIX_PTHREAD_SEMANTICS 1
     90  1.36  christos /* Enable strtoimax on Solaris 10.  */
     91  1.36  christos #define __EXTENSIONS__ 1
     92  1.36  christos 
     93   1.1       jtc /*
     94   1.1       jtc ** Nested includes
     95   1.1       jtc */
     96   1.1       jtc 
     97  1.36  christos #ifndef __NetBSD__
     98  1.36  christos /* Avoid clashes with NetBSD by renaming NetBSD's declarations.  */
     99  1.36  christos #define localtime_rz sys_localtime_rz
    100  1.36  christos #define mktime_z sys_mktime_z
    101  1.36  christos #define posix2time_z sys_posix2time_z
    102  1.36  christos #define time2posix_z sys_time2posix_z
    103  1.36  christos #define timezone_t sys_timezone_t
    104  1.36  christos #define tzalloc sys_tzalloc
    105  1.36  christos #define tzfree sys_tzfree
    106  1.36  christos #include <time.h>
    107  1.36  christos #undef localtime_rz
    108  1.36  christos #undef mktime_z
    109  1.36  christos #undef posix2time_z
    110  1.36  christos #undef time2posix_z
    111  1.36  christos #undef timezone_t
    112  1.36  christos #undef tzalloc
    113  1.36  christos #undef tzfree
    114  1.36  christos #else
    115  1.36  christos #include "time.h"
    116  1.36  christos #endif
    117  1.36  christos 
    118   1.1       jtc #include "sys/types.h"	/* for time_t */
    119   1.1       jtc #include "stdio.h"
    120   1.1       jtc #include "string.h"
    121  1.25   mlelstv #include "limits.h"	/* for CHAR_BIT et al. */
    122   1.1       jtc #include "stdlib.h"
    123   1.1       jtc 
    124  1.38  christos #include "errno.h"
    125  1.38  christos 
    126  1.38  christos #ifndef ENAMETOOLONG
    127  1.38  christos # define ENAMETOOLONG EINVAL
    128  1.38  christos #endif
    129  1.38  christos #ifndef EOVERFLOW
    130  1.38  christos # define EOVERFLOW EINVAL
    131  1.38  christos #endif
    132  1.38  christos 
    133  1.25   mlelstv #if HAVE_GETTEXT
    134   1.6       jtc #include "libintl.h"
    135  1.25   mlelstv #endif /* HAVE_GETTEXT */
    136  1.14    kleink 
    137  1.25   mlelstv #if HAVE_SYS_WAIT_H
    138  1.14    kleink #include <sys/wait.h>	/* for WIFEXITED and WEXITSTATUS */
    139  1.25   mlelstv #endif /* HAVE_SYS_WAIT_H */
    140  1.14    kleink 
    141  1.14    kleink #ifndef WIFEXITED
    142  1.14    kleink #define WIFEXITED(status)	(((status) & 0xff) == 0)
    143  1.14    kleink #endif /* !defined WIFEXITED */
    144  1.14    kleink #ifndef WEXITSTATUS
    145  1.14    kleink #define WEXITSTATUS(status)	(((status) >> 8) & 0xff)
    146  1.14    kleink #endif /* !defined WEXITSTATUS */
    147   1.6       jtc 
    148  1.25   mlelstv #if HAVE_UNISTD_H
    149  1.25   mlelstv #include "unistd.h"	/* for F_OK, R_OK, and other POSIX goodness */
    150  1.25   mlelstv #endif /* HAVE_UNISTD_H */
    151   1.1       jtc 
    152  1.36  christos #ifndef HAVE_STRFTIME_L
    153  1.36  christos # if _POSIX_VERSION < 200809
    154  1.36  christos #  define HAVE_STRFTIME_L 0
    155  1.36  christos # else
    156  1.36  christos #  define HAVE_STRFTIME_L 1
    157  1.36  christos # endif
    158  1.36  christos #endif
    159  1.36  christos 
    160   1.1       jtc #ifndef F_OK
    161   1.1       jtc #define F_OK	0
    162   1.1       jtc #endif /* !defined F_OK */
    163   1.1       jtc #ifndef R_OK
    164   1.1       jtc #define R_OK	4
    165   1.1       jtc #endif /* !defined R_OK */
    166   1.1       jtc 
    167  1.25   mlelstv /* Unlike <ctype.h>'s isdigit, this also works if c < 0 | c > UCHAR_MAX. */
    168   1.4       jtc #define is_digit(c) ((unsigned)(c) - '0' <= 9)
    169   1.4       jtc 
    170   1.1       jtc /*
    171  1.25   mlelstv ** Define HAVE_STDINT_H's default value here, rather than at the
    172  1.25   mlelstv ** start, since __GLIBC__'s value depends on previously-included
    173  1.25   mlelstv ** files.
    174  1.25   mlelstv ** (glibc 2.1 and later have stdint.h, even with pre-C99 compilers.)
    175  1.25   mlelstv */
    176  1.25   mlelstv #ifndef HAVE_STDINT_H
    177  1.25   mlelstv #define HAVE_STDINT_H \
    178  1.33  christos    (199901 <= __STDC_VERSION__ \
    179  1.33  christos     || 2 < __GLIBC__ + (1 <= __GLIBC_MINOR__)	\
    180  1.33  christos     || __CYGWIN__)
    181  1.25   mlelstv #endif /* !defined HAVE_STDINT_H */
    182  1.25   mlelstv 
    183  1.25   mlelstv #if HAVE_STDINT_H
    184  1.25   mlelstv #include "stdint.h"
    185  1.25   mlelstv #endif /* !HAVE_STDINT_H */
    186  1.25   mlelstv 
    187  1.29  christos #ifndef HAVE_INTTYPES_H
    188  1.29  christos # define HAVE_INTTYPES_H HAVE_STDINT_H
    189  1.29  christos #endif
    190  1.29  christos #if HAVE_INTTYPES_H
    191  1.29  christos # include <inttypes.h>
    192  1.29  christos #endif
    193  1.29  christos 
    194  1.36  christos /* Pre-C99 GCC compilers define __LONG_LONG_MAX__ instead of LLONG_MAX.  */
    195  1.36  christos #ifdef __LONG_LONG_MAX__
    196  1.36  christos # ifndef LLONG_MAX
    197  1.36  christos #  define LLONG_MAX __LONG_LONG_MAX__
    198  1.36  christos # endif
    199  1.36  christos # ifndef LLONG_MIN
    200  1.36  christos #  define LLONG_MIN (-1 - LLONG_MAX)
    201  1.36  christos # endif
    202  1.36  christos #endif
    203  1.36  christos 
    204  1.25   mlelstv #ifndef INT_FAST64_MAX
    205  1.36  christos # ifdef LLONG_MAX
    206  1.25   mlelstv typedef long long	int_fast64_t;
    207  1.29  christos #  define INT_FAST64_MIN LLONG_MIN
    208  1.29  christos #  define INT_FAST64_MAX LLONG_MAX
    209  1.29  christos # else
    210  1.36  christos #  if (LONG_MAX >> 31) < 0xffffffff
    211  1.25   mlelstv Please use a compiler that supports a 64-bit integer type (or wider);
    212  1.25   mlelstv you may need to compile with "-DHAVE_STDINT_H".
    213  1.36  christos #  endif
    214  1.25   mlelstv typedef long		int_fast64_t;
    215  1.36  christos #  define INT_FAST64_MIN LONG_MIN
    216  1.36  christos #  define INT_FAST64_MAX LONG_MAX
    217  1.36  christos # endif
    218  1.36  christos #endif
    219  1.36  christos 
    220  1.36  christos #ifndef SCNdFAST64
    221  1.36  christos # if INT_FAST64_MAX == LLONG_MAX
    222  1.36  christos #  define SCNdFAST64 "lld"
    223  1.36  christos # else
    224  1.36  christos #  define SCNdFAST64 "ld"
    225  1.36  christos # endif
    226  1.36  christos #endif
    227  1.25   mlelstv 
    228  1.29  christos #ifndef INT_FAST32_MAX
    229  1.29  christos # if INT_MAX >> 31 == 0
    230  1.29  christos typedef long int_fast32_t;
    231  1.36  christos #  define INT_FAST32_MAX LONG_MAX
    232  1.36  christos #  define INT_FAST32_MIN LONG_MIN
    233  1.29  christos # else
    234  1.29  christos typedef int int_fast32_t;
    235  1.36  christos #  define INT_FAST32_MAX INT_MAX
    236  1.36  christos #  define INT_FAST32_MIN INT_MIN
    237  1.29  christos # endif
    238  1.29  christos #endif
    239  1.29  christos 
    240  1.29  christos #ifndef INTMAX_MAX
    241  1.36  christos # ifdef LLONG_MAX
    242  1.29  christos typedef long long intmax_t;
    243  1.30  christos #  define strtoimax strtoll
    244  1.36  christos #  define INTMAX_MAX LLONG_MAX
    245  1.36  christos #  define INTMAX_MIN LLONG_MIN
    246  1.29  christos # else
    247  1.29  christos typedef long intmax_t;
    248  1.30  christos #  define strtoimax strtol
    249  1.30  christos #  define INTMAX_MAX LONG_MAX
    250  1.30  christos #  define INTMAX_MIN LONG_MIN
    251  1.29  christos # endif
    252  1.29  christos #endif
    253  1.29  christos 
    254  1.36  christos #ifndef PRIdMAX
    255  1.36  christos # if INTMAX_MAX == LLONG_MAX
    256  1.36  christos #  define PRIdMAX "lld"
    257  1.36  christos # else
    258  1.36  christos #  define PRIdMAX "ld"
    259  1.36  christos # endif
    260  1.36  christos #endif
    261  1.36  christos 
    262  1.29  christos #ifndef UINTMAX_MAX
    263  1.29  christos # if defined ULLONG_MAX || defined __LONG_LONG_MAX__
    264  1.29  christos typedef unsigned long long uintmax_t;
    265  1.36  christos # else
    266  1.36  christos typedef unsigned long uintmax_t;
    267  1.36  christos # endif
    268  1.36  christos #endif
    269  1.36  christos 
    270  1.36  christos #ifndef PRIuMAX
    271  1.36  christos # if defined ULLONG_MAX || defined __LONG_LONG_MAX__
    272  1.29  christos #  define PRIuMAX "llu"
    273  1.29  christos # else
    274  1.29  christos #  define PRIuMAX "lu"
    275  1.29  christos # endif
    276  1.29  christos #endif
    277  1.29  christos 
    278  1.25   mlelstv #ifndef INT32_MAX
    279  1.25   mlelstv #define INT32_MAX 0x7fffffff
    280  1.25   mlelstv #endif /* !defined INT32_MAX */
    281  1.25   mlelstv #ifndef INT32_MIN
    282  1.25   mlelstv #define INT32_MIN (-1 - INT32_MAX)
    283  1.25   mlelstv #endif /* !defined INT32_MIN */
    284   1.1       jtc 
    285  1.33  christos #ifndef SIZE_MAX
    286  1.33  christos #define SIZE_MAX ((size_t) -1)
    287  1.33  christos #endif
    288  1.33  christos 
    289  1.29  christos #if 2 < __GNUC__ + (96 <= __GNUC_MINOR__)
    290  1.29  christos # define ATTRIBUTE_CONST __attribute__ ((__const__))
    291  1.29  christos # define ATTRIBUTE_PURE __attribute__ ((__pure__))
    292  1.30  christos # define ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
    293  1.27  christos #else
    294  1.29  christos # define ATTRIBUTE_CONST /* empty */
    295  1.29  christos # define ATTRIBUTE_PURE /* empty */
    296  1.30  christos # define ATTRIBUTE_FORMAT(spec) /* empty */
    297  1.27  christos #endif
    298  1.29  christos 
    299  1.29  christos #if !defined _Noreturn && __STDC_VERSION__ < 201112
    300  1.29  christos # if 2 < __GNUC__ + (8 <= __GNUC_MINOR__)
    301  1.29  christos #  define _Noreturn __attribute__ ((__noreturn__))
    302  1.29  christos # else
    303  1.29  christos #  define _Noreturn
    304  1.29  christos # endif
    305  1.29  christos #endif
    306  1.29  christos 
    307  1.29  christos #if __STDC_VERSION__ < 199901 && !defined restrict
    308  1.29  christos # define restrict /* empty */
    309  1.27  christos #endif
    310  1.27  christos 
    311   1.1       jtc /*
    312  1.25   mlelstv ** Workarounds for compilers/systems.
    313   1.1       jtc */
    314   1.1       jtc 
    315   1.1       jtc /*
    316  1.29  christos ** Compile with -Dtime_tz=T to build the tz package with a private
    317  1.29  christos ** time_t type equivalent to T rather than the system-supplied time_t.
    318  1.29  christos ** This debugging feature can test unusual design decisions
    319  1.29  christos ** (e.g., time_t wider than 'long', or unsigned time_t) even on
    320  1.29  christos ** typical platforms.
    321  1.29  christos */
    322  1.29  christos #ifdef time_tz
    323  1.36  christos # ifdef LOCALTIME_IMPLEMENTATION
    324  1.29  christos static time_t sys_time(time_t *x) { return time(x); }
    325  1.36  christos # endif
    326  1.29  christos 
    327  1.39  christos typedef time_tz tz_time_t;
    328  1.39  christos 
    329  1.29  christos # undef  ctime
    330  1.29  christos # define ctime tz_ctime
    331  1.29  christos # undef  ctime_r
    332  1.29  christos # define ctime_r tz_ctime_r
    333  1.29  christos # undef  difftime
    334  1.29  christos # define difftime tz_difftime
    335  1.29  christos # undef  gmtime
    336  1.29  christos # define gmtime tz_gmtime
    337  1.29  christos # undef  gmtime_r
    338  1.29  christos # define gmtime_r tz_gmtime_r
    339  1.29  christos # undef  localtime
    340  1.29  christos # define localtime tz_localtime
    341  1.29  christos # undef  localtime_r
    342  1.29  christos # define localtime_r tz_localtime_r
    343  1.39  christos # undef  localtime_rz
    344  1.39  christos # define localtime_rz tz_localtime_rz
    345  1.29  christos # undef  mktime
    346  1.29  christos # define mktime tz_mktime
    347  1.39  christos # undef  mktime_z
    348  1.39  christos # define mktime_z tz_mktime_z
    349  1.36  christos # undef  offtime
    350  1.36  christos # define offtime tz_offtime
    351  1.36  christos # undef  posix2time
    352  1.36  christos # define posix2time tz_posix2time
    353  1.39  christos # undef  posix2time_z
    354  1.39  christos # define posix2time_z tz_posix2time_z
    355  1.29  christos # undef  time
    356  1.29  christos # define time tz_time
    357  1.36  christos # undef  time2posix
    358  1.36  christos # define time2posix tz_time2posix
    359  1.39  christos # undef  time2posix_z
    360  1.39  christos # define time2posix_z tz_time2posix_z
    361  1.29  christos # undef  time_t
    362  1.29  christos # define time_t tz_time_t
    363  1.36  christos # undef  timegm
    364  1.36  christos # define timegm tz_timegm
    365  1.36  christos # undef  timelocal
    366  1.36  christos # define timelocal tz_timelocal
    367  1.36  christos # undef  timeoff
    368  1.36  christos # define timeoff tz_timeoff
    369  1.39  christos # undef  tzalloc
    370  1.39  christos # define tzalloc tz_tzalloc
    371  1.39  christos # undef  tzfree
    372  1.39  christos # define tzfree tz_tzfree
    373  1.39  christos # undef  tzset
    374  1.39  christos # define tzset tz_tzset
    375  1.39  christos # undef  tzsetwall
    376  1.39  christos # define tzsetwall tz_tzsetwall
    377  1.29  christos 
    378  1.29  christos char *ctime(time_t const *);
    379  1.29  christos char *ctime_r(time_t const *, char *);
    380  1.29  christos double difftime(time_t, time_t);
    381  1.29  christos struct tm *gmtime(time_t const *);
    382  1.29  christos struct tm *gmtime_r(time_t const *restrict, struct tm *restrict);
    383  1.29  christos struct tm *localtime(time_t const *);
    384  1.29  christos struct tm *localtime_r(time_t const *restrict, struct tm *restrict);
    385  1.29  christos time_t mktime(struct tm *);
    386  1.36  christos time_t time(time_t *);
    387  1.39  christos void tzset(void);
    388  1.36  christos #endif
    389  1.29  christos 
    390  1.36  christos /*
    391  1.36  christos ** Some time.h implementations don't declare asctime_r.
    392  1.36  christos ** Others might define it as a macro.
    393  1.36  christos ** Fix the former without affecting the latter.
    394  1.36  christos */
    395  1.36  christos 
    396  1.36  christos #ifndef asctime_r
    397  1.36  christos extern char *	asctime_r(struct tm const *restrict, char *restrict);
    398  1.36  christos #endif
    399  1.36  christos 
    400  1.36  christos /*
    401  1.36  christos ** The STD_INSPIRED functions are similar, but most also need
    402  1.36  christos ** declarations if time_tz is defined.
    403  1.36  christos */
    404  1.36  christos 
    405  1.36  christos #ifdef STD_INSPIRED
    406  1.39  christos # if !defined tzsetwall || defined time_tz
    407  1.36  christos void tzsetwall(void);
    408  1.36  christos # endif
    409  1.36  christos # if !defined offtime || defined time_tz
    410  1.36  christos struct tm *offtime(time_t const *, long);
    411  1.36  christos # endif
    412  1.36  christos # if !defined timegm || defined time_tz
    413  1.36  christos time_t timegm(struct tm *);
    414  1.36  christos # endif
    415  1.36  christos # if !defined timelocal || defined time_tz
    416  1.36  christos time_t timelocal(struct tm *);
    417  1.36  christos # endif
    418  1.36  christos # if !defined timeoff || defined time_tz
    419  1.36  christos time_t timeoff(struct tm *, long);
    420  1.36  christos # endif
    421  1.36  christos # if !defined time2posix || defined time_tz
    422  1.36  christos time_t time2posix(time_t);
    423  1.36  christos # endif
    424  1.36  christos # if !defined posix2time || defined time_tz
    425  1.36  christos time_t posix2time(time_t);
    426  1.36  christos # endif
    427  1.36  christos #endif
    428  1.36  christos 
    429  1.36  christos /* Infer TM_ZONE on systems where this information is known, but suppress
    430  1.36  christos    guessing if NO_TM_ZONE is defined.  Similarly for TM_GMTOFF.  */
    431  1.36  christos #if (defined __GLIBC__ \
    432  1.36  christos      || defined __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__ \
    433  1.36  christos      || (defined __APPLE__ && defined __MACH__))
    434  1.36  christos # if !defined TM_GMTOFF && !defined NO_TM_GMTOFF
    435  1.36  christos #  define TM_GMTOFF tm_gmtoff
    436  1.36  christos # endif
    437  1.36  christos # if !defined TM_ZONE && !defined NO_TM_ZONE
    438  1.36  christos #  define TM_ZONE tm_zone
    439  1.36  christos # endif
    440  1.36  christos #endif
    441  1.36  christos 
    442  1.36  christos /*
    443  1.36  christos ** Define functions that are ABI compatible with NetBSD but have
    444  1.36  christos ** better prototypes.  NetBSD 6.1.4 defines a pointer type timezone_t
    445  1.36  christos ** and labors under the misconception that 'const timezone_t' is a
    446  1.36  christos ** pointer to a constant.  This use of 'const' is ineffective, so it
    447  1.36  christos ** is not done here.  What we call 'struct state' NetBSD calls
    448  1.36  christos ** 'struct __state', but this is a private name so it doesn't matter.
    449  1.36  christos */
    450  1.37  christos #ifndef __NetBSD__
    451  1.36  christos #if NETBSD_INSPIRED
    452  1.36  christos typedef struct state *timezone_t;
    453  1.36  christos struct tm *localtime_rz(timezone_t restrict, time_t const *restrict,
    454  1.36  christos 			struct tm *restrict);
    455  1.36  christos time_t mktime_z(timezone_t restrict, struct tm *restrict);
    456  1.36  christos timezone_t tzalloc(char const *);
    457  1.36  christos void tzfree(timezone_t);
    458  1.36  christos # ifdef STD_INSPIRED
    459  1.36  christos #  if !defined posix2time_z || defined time_tz
    460  1.36  christos time_t posix2time_z(timezone_t __restrict, time_t) ATTRIBUTE_PURE;
    461  1.36  christos #  endif
    462  1.36  christos #  if !defined time2posix_z || defined time_tz
    463  1.36  christos time_t time2posix_z(timezone_t __restrict, time_t) ATTRIBUTE_PURE;
    464  1.36  christos #  endif
    465  1.36  christos # endif
    466  1.29  christos #endif
    467  1.37  christos #endif
    468  1.29  christos 
    469  1.29  christos /*
    470   1.8       jtc ** Private function declarations.
    471   1.8       jtc */
    472   1.8       jtc 
    473  1.25   mlelstv char *		icatalloc(char * old, const char * new);
    474  1.25   mlelstv char *		icpyalloc(const char * string);
    475  1.25   mlelstv const char *	scheck(const char * string, const char * format);
    476   1.6       jtc 
    477   1.6       jtc /*
    478   1.1       jtc ** Finally, some convenience items.
    479   1.1       jtc */
    480   1.1       jtc 
    481  1.36  christos #if __STDC_VERSION__ < 199901
    482  1.36  christos # define true 1
    483  1.36  christos # define false 0
    484  1.36  christos # define bool int
    485  1.36  christos #else
    486  1.36  christos # include <stdbool.h>
    487  1.36  christos #endif
    488   1.1       jtc 
    489   1.5       jtc #ifndef TYPE_BIT
    490   1.5       jtc #define TYPE_BIT(type)	(sizeof (type) * CHAR_BIT)
    491   1.5       jtc #endif /* !defined TYPE_BIT */
    492   1.5       jtc 
    493   1.5       jtc #ifndef TYPE_SIGNED
    494  1.28  christos #define TYPE_SIGNED(type) (/*CONSTCOND*/((type) -1) < 0)
    495   1.5       jtc #endif /* !defined TYPE_SIGNED */
    496   1.5       jtc 
    497  1.36  christos #ifdef LOCALTIME_IMPLEMENTATION
    498  1.36  christos /* The minimum and maximum finite time values.  */
    499  1.36  christos static time_t const time_t_min =
    500  1.36  christos   (TYPE_SIGNED(time_t)
    501  1.36  christos    ? (time_t) -1 << (int)(CHAR_BIT * sizeof (time_t) - 1)
    502  1.36  christos    : 0);
    503  1.36  christos static time_t const time_t_max =
    504  1.36  christos   (TYPE_SIGNED(time_t)
    505  1.36  christos    ? - (~ 0 < 0) - ((time_t) -1 << (int)(CHAR_BIT * sizeof (time_t) - 1))
    506  1.36  christos    : -1);
    507  1.36  christos #endif
    508  1.36  christos 
    509   1.1       jtc #ifndef INT_STRLEN_MAXIMUM
    510   1.1       jtc /*
    511   1.1       jtc ** 302 / 1000 is log10(2.0) rounded up.
    512   1.5       jtc ** Subtract one for the sign bit if the type is signed;
    513   1.5       jtc ** add one for integer division truncation;
    514   1.5       jtc ** add one more for a minus sign if the type is signed.
    515   1.1       jtc */
    516   1.1       jtc #define INT_STRLEN_MAXIMUM(type) \
    517  1.25   mlelstv 	((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + \
    518  1.25   mlelstv 	1 + TYPE_SIGNED(type))
    519   1.1       jtc #endif /* !defined INT_STRLEN_MAXIMUM */
    520   1.1       jtc 
    521   1.1       jtc /*
    522   1.1       jtc ** INITIALIZE(x)
    523   1.1       jtc */
    524   1.1       jtc 
    525  1.35  christos #if defined(__GNUC__) || defined(__lint__)
    526  1.34  christos # define INITIALIZE(x)	((x) = 0)
    527  1.34  christos #else
    528  1.34  christos # define INITIALIZE(x)
    529  1.34  christos #endif
    530   1.6       jtc 
    531  1.36  christos #ifndef UNINIT_TRAP
    532  1.36  christos # define UNINIT_TRAP 0
    533  1.36  christos #endif
    534  1.36  christos 
    535   1.6       jtc /*
    536   1.6       jtc ** For the benefit of GNU folk...
    537  1.34  christos ** '_(MSGID)' uses the current locale's message library string for MSGID.
    538   1.6       jtc ** The default is to use gettext if available, and use MSGID otherwise.
    539   1.6       jtc */
    540   1.6       jtc 
    541   1.6       jtc #ifndef _
    542  1.25   mlelstv #if HAVE_GETTEXT
    543   1.6       jtc #define _(msgid) gettext(msgid)
    544  1.25   mlelstv #else /* !HAVE_GETTEXT */
    545   1.6       jtc #define _(msgid) msgid
    546  1.25   mlelstv #endif /* !HAVE_GETTEXT */
    547   1.6       jtc #endif /* !defined _ */
    548   1.6       jtc 
    549  1.34  christos #if !defined TZ_DOMAIN && defined HAVE_GETTEXT
    550  1.34  christos # define TZ_DOMAIN "tz"
    551  1.34  christos #endif
    552  1.17    kleink 
    553  1.17    kleink #if HAVE_INCOMPATIBLE_CTIME_R
    554  1.17    kleink #undef asctime_r
    555  1.17    kleink #undef ctime_r
    556  1.25   mlelstv char *asctime_r(struct tm const *, char *);
    557  1.25   mlelstv char *ctime_r(time_t const *, char *);
    558  1.17    kleink #endif /* HAVE_INCOMPATIBLE_CTIME_R */
    559   1.1       jtc 
    560  1.25   mlelstv #ifndef YEARSPERREPEAT
    561  1.25   mlelstv #define YEARSPERREPEAT		400	/* years before a Gregorian repeat */
    562  1.25   mlelstv #endif /* !defined YEARSPERREPEAT */
    563  1.25   mlelstv 
    564  1.25   mlelstv /*
    565  1.25   mlelstv ** The Gregorian year averages 365.2425 days, which is 31556952 seconds.
    566  1.25   mlelstv */
    567  1.25   mlelstv 
    568  1.25   mlelstv #ifndef AVGSECSPERYEAR
    569  1.25   mlelstv #define AVGSECSPERYEAR		31556952L
    570  1.25   mlelstv #endif /* !defined AVGSECSPERYEAR */
    571  1.25   mlelstv 
    572  1.25   mlelstv #ifndef SECSPERREPEAT
    573  1.25   mlelstv #define SECSPERREPEAT		((int_fast64_t) YEARSPERREPEAT * (int_fast64_t) AVGSECSPERYEAR)
    574  1.25   mlelstv #endif /* !defined SECSPERREPEAT */
    575  1.25   mlelstv 
    576  1.25   mlelstv #ifndef SECSPERREPEAT_BITS
    577  1.25   mlelstv #define SECSPERREPEAT_BITS	34	/* ceil(log2(SECSPERREPEAT)) */
    578  1.25   mlelstv #endif /* !defined SECSPERREPEAT_BITS */
    579  1.25   mlelstv 
    580   1.1       jtc #endif /* !defined PRIVATE_H */
    581