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