"Fossies" - the Fresh Open Source Software Archive

Member "private.h" (16 Jul 2018, 18765 Bytes) of package /linux/misc/tzcode2018i.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "private.h" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 2018e_vs_2018f.

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