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