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