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