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