xref: /netbsd-src/lib/libc/time/private.h (revision 796c32c94f6e154afc9de0f63da35c91bb739b45)
1 /*	$NetBSD: private.h,v 1.51 2017/10/24 17:38:17 christos 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 #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_SYMLINK
82 #define HAVE_SYMLINK		1
83 #endif /* !defined HAVE_SYMLINK */
84 
85 #ifndef HAVE_SYS_STAT_H
86 #define HAVE_SYS_STAT_H		1
87 #endif /* !defined HAVE_SYS_STAT_H */
88 
89 #ifndef HAVE_SYS_WAIT_H
90 #define HAVE_SYS_WAIT_H		1
91 #endif /* !defined HAVE_SYS_WAIT_H */
92 
93 #ifndef HAVE_UNISTD_H
94 #define HAVE_UNISTD_H		1
95 #endif /* !defined HAVE_UNISTD_H */
96 
97 #ifndef HAVE_UTMPX_H
98 #define HAVE_UTMPX_H		1
99 #endif /* !defined HAVE_UTMPX_H */
100 
101 #ifndef NETBSD_INSPIRED
102 # define NETBSD_INSPIRED 1
103 #endif
104 
105 #if HAVE_INCOMPATIBLE_CTIME_R
106 #define asctime_r _incompatible_asctime_r
107 #define ctime_r _incompatible_ctime_r
108 #endif /* HAVE_INCOMPATIBLE_CTIME_R */
109 
110 /* Enable tm_gmtoff, tm_zone, and environ on GNUish systems.  */
111 #define _GNU_SOURCE 1
112 /* Fix asctime_r on Solaris 11.  */
113 #define _POSIX_PTHREAD_SEMANTICS 1
114 /* Enable strtoimax on pre-C99 Solaris 11.  */
115 #define __EXTENSIONS__ 1
116 
117 /* To avoid having 'stat' fail unnecessarily with errno == EOVERFLOW,
118    enable large files on GNUish systems ...  */
119 #ifndef _FILE_OFFSET_BITS
120 # define _FILE_OFFSET_BITS 64
121 #endif
122 /* ... and on AIX ...  */
123 #define _LARGE_FILES 1
124 /* ... and enable large inode numbers on Mac OS X 10.5 and later.  */
125 #define _DARWIN_USE_64_BIT_INODE 1
126 
127 /*
128 ** Nested includes
129 */
130 
131 #ifndef __NetBSD__
132 /* Avoid clashes with NetBSD by renaming NetBSD's declarations.  */
133 #define localtime_rz sys_localtime_rz
134 #define mktime_z sys_mktime_z
135 #define posix2time_z sys_posix2time_z
136 #define time2posix_z sys_time2posix_z
137 #define timezone_t sys_timezone_t
138 #define tzalloc sys_tzalloc
139 #define tzfree sys_tzfree
140 #include <time.h>
141 #undef localtime_rz
142 #undef mktime_z
143 #undef posix2time_z
144 #undef time2posix_z
145 #undef timezone_t
146 #undef tzalloc
147 #undef tzfree
148 #else
149 #include "time.h"
150 #endif
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 #  define strtoimax strtoll
286 #  define INTMAX_MAX LLONG_MAX
287 #  define INTMAX_MIN LLONG_MIN
288 # else
289 typedef long intmax_t;
290 #  define strtoimax strtol
291 #  define INTMAX_MAX LONG_MAX
292 #  define INTMAX_MIN LONG_MIN
293 # endif
294 #endif
295 
296 #ifndef PRIdMAX
297 # if INTMAX_MAX == LLONG_MAX
298 #  define PRIdMAX "lld"
299 # else
300 #  define PRIdMAX "ld"
301 # endif
302 #endif
303 
304 #ifndef UINT_FAST64_MAX
305 # if defined ULLONG_MAX || defined __LONG_LONG_MAX__
306 typedef unsigned long long uint_fast64_t;
307 # else
308 #  if ULONG_MAX >> 31 >> 1 < 0xffffffff
309 Please use a compiler that supports a 64-bit integer type (or wider);
310 you may need to compile with "-DHAVE_STDINT_H".
311 #  endif
312 typedef unsigned long	uint_fast64_t;
313 # endif
314 #endif
315 
316 #ifndef UINTMAX_MAX
317 # if defined ULLONG_MAX || defined __LONG_LONG_MAX__
318 typedef unsigned long long uintmax_t;
319 # else
320 typedef unsigned long uintmax_t;
321 # endif
322 #endif
323 
324 #ifndef PRIuMAX
325 # if defined ULLONG_MAX || defined __LONG_LONG_MAX__
326 #  define PRIuMAX "llu"
327 # else
328 #  define PRIuMAX "lu"
329 # endif
330 #endif
331 
332 #ifndef INT32_MAX
333 #define INT32_MAX 0x7fffffff
334 #endif /* !defined INT32_MAX */
335 #ifndef INT32_MIN
336 #define INT32_MIN (-1 - INT32_MAX)
337 #endif /* !defined INT32_MIN */
338 
339 #ifndef SIZE_MAX
340 #define SIZE_MAX ((size_t) -1)
341 #endif
342 
343 #if 2 < __GNUC__ + (96 <= __GNUC_MINOR__)
344 # define ATTRIBUTE_CONST __attribute__ ((__const__))
345 # define ATTRIBUTE_PURE __attribute__ ((__pure__))
346 # define ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
347 #else
348 # define ATTRIBUTE_CONST /* empty */
349 # define ATTRIBUTE_PURE /* empty */
350 # define ATTRIBUTE_FORMAT(spec) /* empty */
351 #endif
352 
353 #if !defined _Noreturn && __STDC_VERSION__ < 201112
354 # if 2 < __GNUC__ + (8 <= __GNUC_MINOR__)
355 #  define _Noreturn __attribute__ ((__noreturn__))
356 # else
357 #  define _Noreturn
358 # endif
359 #endif
360 
361 #if __STDC_VERSION__ < 199901 && !defined restrict
362 # define restrict /* empty */
363 #endif
364 
365 /*
366 ** Workarounds for compilers/systems.
367 */
368 
369 #ifndef EPOCH_LOCAL
370 # define EPOCH_LOCAL 0
371 #endif
372 #ifndef EPOCH_OFFSET
373 # define EPOCH_OFFSET 0
374 #endif
375 
376 /*
377 ** Compile with -Dtime_tz=T to build the tz package with a private
378 ** time_t type equivalent to T rather than the system-supplied time_t.
379 ** This debugging feature can test unusual design decisions
380 ** (e.g., time_t wider than 'long', or unsigned time_t) even on
381 ** typical platforms.
382 */
383 #if defined time_tz || EPOCH_LOCAL || EPOCH_OFFSET != 0
384 # define TZ_TIME_T 1
385 #else
386 # define TZ_TIME_T 0
387 #endif
388 
389 #if TZ_TIME_T
390 # ifdef LOCALTIME_IMPLEMENTATION
391 static time_t sys_time(time_t *x) { return time(x); }
392 # endif
393 
394 typedef time_tz tz_time_t;
395 
396 # undef  ctime
397 # define ctime tz_ctime
398 # undef  ctime_r
399 # define ctime_r tz_ctime_r
400 # undef  difftime
401 # define difftime tz_difftime
402 # undef  gmtime
403 # define gmtime tz_gmtime
404 # undef  gmtime_r
405 # define gmtime_r tz_gmtime_r
406 # undef  localtime
407 # define localtime tz_localtime
408 # undef  localtime_r
409 # define localtime_r tz_localtime_r
410 # undef  localtime_rz
411 # define localtime_rz tz_localtime_rz
412 # undef  mktime
413 # define mktime tz_mktime
414 # undef  mktime_z
415 # define mktime_z tz_mktime_z
416 # undef  offtime
417 # define offtime tz_offtime
418 # undef  posix2time
419 # define posix2time tz_posix2time
420 # undef  posix2time_z
421 # define posix2time_z tz_posix2time_z
422 # undef  strftime
423 # define strftime tz_strftime
424 # undef  time
425 # define time tz_time
426 # undef  time2posix
427 # define time2posix tz_time2posix
428 # undef  time2posix_z
429 # define time2posix_z tz_time2posix_z
430 # undef  time_t
431 # define time_t tz_time_t
432 # undef  timegm
433 # define timegm tz_timegm
434 # undef  timelocal
435 # define timelocal tz_timelocal
436 # undef  timeoff
437 # define timeoff tz_timeoff
438 # undef  tzalloc
439 # define tzalloc tz_tzalloc
440 # undef  tzfree
441 # define tzfree tz_tzfree
442 # undef  tzset
443 # define tzset tz_tzset
444 # undef  tzsetwall
445 # define tzsetwall tz_tzsetwall
446 # if HAVE_STRFTIME_L
447 #  undef  strftime_l
448 #  define strftime_l tz_strftime_l
449 # endif
450 # if HAVE_TZNAME
451 #  undef  tzname
452 #  define tzname tz_tzname
453 # endif
454 # if USG_COMPAT
455 #  undef  daylight
456 #  define daylight tz_daylight
457 #  undef  timezone
458 #  define timezone tz_timezone
459 # endif
460 # ifdef ALTZONE
461 #  undef  altzone
462 #  define altzone tz_altzone
463 # endif
464 
465 char *ctime(time_t const *);
466 char *ctime_r(time_t const *, char *);
467 double difftime(time_t, time_t) ATTRIBUTE_CONST;
468 size_t strftime(char *restrict, size_t, char const *restrict,
469 		struct tm const *restrict);
470 # if HAVE_STRFTIME_L
471 size_t strftime_l(char *restrict, size_t, char const *restrict,
472 		  struct tm const *restrict, locale_t);
473 # endif
474 struct tm *gmtime(time_t const *);
475 struct tm *gmtime_r(time_t const *restrict, struct tm *restrict);
476 struct tm *localtime(time_t const *);
477 struct tm *localtime_r(time_t const *restrict, struct tm *restrict);
478 time_t mktime(struct tm *);
479 time_t time(time_t *);
480 void tzset(void);
481 #endif
482 
483 #if !HAVE_DECL_ASCTIME_R && !defined asctime_r
484 extern char *asctime_r(struct tm const *restrict, char *restrict);
485 #endif
486 
487 #ifndef HAVE_DECL_ENVIRON
488 # if defined environ || defined __USE_GNU
489 #  define HAVE_DECL_ENVIRON 1
490 # else
491 #  define HAVE_DECL_ENVIRON 0
492 # endif
493 #endif
494 
495 #if !HAVE_DECL_ENVIRON
496 extern char **environ;
497 #endif
498 
499 #if TZ_TIME_T || !HAVE_POSIX_DECLS
500 # if HAVE_TZNAME
501 extern char *tzname[];
502 # endif
503 # if USG_COMPAT
504 extern long timezone;
505 extern int daylight;
506 # endif
507 #endif
508 
509 #ifdef ALTZONE
510 extern long altzone;
511 #endif
512 
513 /*
514 ** The STD_INSPIRED functions are similar, but most also need
515 ** declarations if time_tz is defined.
516 */
517 
518 #ifdef STD_INSPIRED
519 # if TZ_TIME_T || !defined tzsetwall
520 void tzsetwall(void);
521 # endif
522 # if TZ_TIME_T || !defined offtime
523 struct tm *offtime(time_t const *, long);
524 # endif
525 # if TZ_TIME_T || !defined timegm
526 time_t timegm(struct tm *);
527 # endif
528 # if TZ_TIME_T || !defined timelocal
529 time_t timelocal(struct tm *);
530 # endif
531 # if TZ_TIME_T || !defined timeoff
532 time_t timeoff(struct tm *, long);
533 # endif
534 # if TZ_TIME_T || !defined time2posix
535 time_t time2posix(time_t);
536 # endif
537 # if TZ_TIME_T || !defined posix2time
538 time_t posix2time(time_t);
539 # endif
540 #endif
541 
542 /* Infer TM_ZONE on systems where this information is known, but suppress
543    guessing if NO_TM_ZONE is defined.  Similarly for TM_GMTOFF.  */
544 #if (defined __GLIBC__ \
545      || defined __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__ \
546      || (defined __APPLE__ && defined __MACH__))
547 # if !defined TM_GMTOFF && !defined NO_TM_GMTOFF
548 #  define TM_GMTOFF tm_gmtoff
549 # endif
550 # if !defined TM_ZONE && !defined NO_TM_ZONE
551 #  define TM_ZONE tm_zone
552 # endif
553 #endif
554 
555 /*
556 ** Define functions that are ABI compatible with NetBSD but have
557 ** better prototypes.  NetBSD 6.1.4 defines a pointer type timezone_t
558 ** and labors under the misconception that 'const timezone_t' is a
559 ** pointer to a constant.  This use of 'const' is ineffective, so it
560 ** is not done here.  What we call 'struct state' NetBSD calls
561 ** 'struct __state', but this is a private name so it doesn't matter.
562 */
563 #ifndef __NetBSD__
564 #if NETBSD_INSPIRED
565 typedef struct state *timezone_t;
566 struct tm *localtime_rz(timezone_t restrict, time_t const *restrict,
567 			struct tm *restrict);
568 time_t mktime_z(timezone_t restrict, struct tm *restrict);
569 timezone_t tzalloc(char const *);
570 void tzfree(timezone_t);
571 # ifdef STD_INSPIRED
572 #  if TZ_TIME_T || !defined posix2time_z
573 time_t posix2time_z(timezone_t __restrict, time_t) ATTRIBUTE_PURE;
574 #  endif
575 #  if TZ_TIME_T || !defined time2posix_z
576 time_t time2posix_z(timezone_t __restrict, time_t) ATTRIBUTE_PURE;
577 #  endif
578 # endif
579 #endif
580 #endif
581 
582 /*
583 ** Finally, some convenience items.
584 */
585 
586 #if HAVE_STDBOOL_H
587 # include <stdbool.h>
588 #else
589 # define true 1
590 # define false 0
591 # define bool int
592 #endif
593 
594 #define TYPE_BIT(type)	(sizeof (type) * CHAR_BIT)
595 #define TYPE_SIGNED(type) (/*CONSTCOND*/((type) -1) < 0)
596 #define TWOS_COMPLEMENT(t) (/*CONSTCOND*/(t) ~ (t) 0 < 0)
597 
598 /* Max and min values of the integer type T, of which only the bottom
599    B bits are used, and where the highest-order used bit is considered
600    to be a sign bit if T is signed.  */
601 #define MAXVAL(t, b) /*LINTED*/					\
602   ((t) (((t) 1 << ((b) - 1 - TYPE_SIGNED(t)))			\
603 	- 1 + ((t) 1 << ((b) - 1 - TYPE_SIGNED(t)))))
604 #define MINVAL(t, b)						\
605   ((t) (TYPE_SIGNED(t) ? - TWOS_COMPLEMENT(t) - MAXVAL(t, b) : 0))
606 
607 /* The extreme time values, assuming no padding.  */
608 #define TIME_T_MIN_NO_PADDING MINVAL(time_t, TYPE_BIT(time_t))
609 #define TIME_T_MAX_NO_PADDING MAXVAL(time_t, TYPE_BIT(time_t))
610 
611 /* The extreme time values.  These are macros, not constants, so that
612    any portability problem occur only when compiling .c files that use
613    the macros, which is safer for applications that need only zdump and zic.
614    This implementation assumes no padding if time_t is signed and
615    either the compiler lacks support for _Generic or time_t is not one
616    of the standard signed integer types.  */
617 #if HAVE_GENERIC
618 # define TIME_T_MIN \
619     _Generic((time_t) 0, \
620 	     signed char: SCHAR_MIN, short: SHRT_MIN, \
621 	     int: INT_MIN, long: LONG_MIN, long long: LLONG_MIN, \
622 	     default: TIME_T_MIN_NO_PADDING)
623 # define TIME_T_MAX \
624     (TYPE_SIGNED(time_t) \
625      ? _Generic((time_t) 0, \
626 		signed char: SCHAR_MAX, short: SHRT_MAX, \
627 		int: INT_MAX, long: LONG_MAX, long long: LLONG_MAX, \
628 		default: TIME_T_MAX_NO_PADDING)			    \
629      : (time_t) -1)
630 #else
631 # define TIME_T_MIN TIME_T_MIN_NO_PADDING
632 # define TIME_T_MAX TIME_T_MAX_NO_PADDING
633 #endif
634 
635 /*
636 ** 302 / 1000 is log10(2.0) rounded up.
637 ** Subtract one for the sign bit if the type is signed;
638 ** add one for integer division truncation;
639 ** add one more for a minus sign if the type is signed.
640 */
641 #define INT_STRLEN_MAXIMUM(type) \
642 	((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + \
643 	1 + TYPE_SIGNED(type))
644 
645 /*
646 ** INITIALIZE(x)
647 */
648 
649 #if defined(__GNUC__) || defined(__lint__)
650 # define INITIALIZE(x)	((x) = 0)
651 #else
652 # define INITIALIZE(x)
653 #endif
654 
655 #ifndef UNINIT_TRAP
656 # define UNINIT_TRAP 0
657 #endif
658 
659 /*
660 ** For the benefit of GNU folk...
661 ** '_(MSGID)' uses the current locale's message library string for MSGID.
662 ** The default is to use gettext if available, and use MSGID otherwise.
663 */
664 
665 #if HAVE_GETTEXT
666 #define _(msgid) gettext(msgid)
667 #else /* !HAVE_GETTEXT */
668 #define _(msgid) msgid
669 #endif /* !HAVE_GETTEXT */
670 
671 #if !defined TZ_DOMAIN && defined HAVE_GETTEXT
672 # define TZ_DOMAIN "tz"
673 #endif
674 
675 #if HAVE_INCOMPATIBLE_CTIME_R
676 #undef asctime_r
677 #undef ctime_r
678 char *asctime_r(struct tm const *, char *);
679 char *ctime_r(time_t const *, char *);
680 #endif /* HAVE_INCOMPATIBLE_CTIME_R */
681 
682 /* Handy macros that are independent of tzfile implementation.  */
683 
684 #define YEARSPERREPEAT		400	/* years before a Gregorian repeat */
685 
686 #define SECSPERMIN	60
687 #define MINSPERHOUR	60
688 #define HOURSPERDAY	24
689 #define DAYSPERWEEK	7
690 #define DAYSPERNYEAR	365
691 #define DAYSPERLYEAR	366
692 #define SECSPERHOUR	(SECSPERMIN * MINSPERHOUR)
693 #define SECSPERDAY	((int_fast32_t) SECSPERHOUR * HOURSPERDAY)
694 #define MONSPERYEAR	12
695 
696 #define TM_SUNDAY	0
697 #define TM_MONDAY	1
698 #define TM_TUESDAY	2
699 #define TM_WEDNESDAY	3
700 #define TM_THURSDAY	4
701 #define TM_FRIDAY	5
702 #define TM_SATURDAY	6
703 
704 #define TM_JANUARY	0
705 #define TM_FEBRUARY	1
706 #define TM_MARCH	2
707 #define TM_APRIL	3
708 #define TM_MAY		4
709 #define TM_JUNE		5
710 #define TM_JULY		6
711 #define TM_AUGUST	7
712 #define TM_SEPTEMBER	8
713 #define TM_OCTOBER	9
714 #define TM_NOVEMBER	10
715 #define TM_DECEMBER	11
716 
717 #define TM_YEAR_BASE	1900
718 
719 #define EPOCH_YEAR	1970
720 #define EPOCH_WDAY	TM_THURSDAY
721 
722 #define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
723 
724 /*
725 ** Since everything in isleap is modulo 400 (or a factor of 400), we know that
726 **	isleap(y) == isleap(y % 400)
727 ** and so
728 **	isleap(a + b) == isleap((a + b) % 400)
729 ** or
730 **	isleap(a + b) == isleap(a % 400 + b % 400)
731 ** This is true even if % means modulo rather than Fortran remainder
732 ** (which is allowed by C89 but not by C99 or later).
733 ** We use this to avoid addition overflow problems.
734 */
735 
736 #define isleap_sum(a, b)	isleap((a) % 400 + (b) % 400)
737 
738 
739 /*
740 ** The Gregorian year averages 365.2425 days, which is 31556952 seconds.
741 */
742 
743 #define AVGSECSPERYEAR		31556952L
744 #define SECSPERREPEAT \
745   ((int_fast64_t) YEARSPERREPEAT * (int_fast64_t) AVGSECSPERYEAR)
746 #define SECSPERREPEAT_BITS	34	/* ceil(log2(SECSPERREPEAT)) */
747 
748 #endif /* !defined PRIVATE_H */
749