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