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