5 * This file is in the public domain, so clarified as of
6 * 1996-06-05 by Arthur David Olson.
9 * src/timezone/private.h
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.
20 #include <limits.h> /* for CHAR_BIT et al. */
21 #include <sys/wait.h> /* for WIFEXITED and WEXITSTATUS */
22 #include <unistd.h> /* for F_OK and R_OK */
26 #define GRANDPARENTED "Local time zone must be set--see zic manual page"
29 * IANA has a bunch of HAVE_FOO #defines here, but in PG we want pretty
30 * much all of that to be done by PG's configure script.
34 #define ENOTSUP EINVAL
37 #define EOVERFLOW EINVAL
41 #define WIFEXITED(status) (((status) & 0xff) == 0)
42 #endif /* !defined WIFEXITED */
44 #define WEXITSTATUS(status) (((status) >> 8) & 0xff)
45 #endif /* !defined WEXITSTATUS */
47 /* Unlike <ctype.h>'s isdigit, this also works if c < 0 | c > UCHAR_MAX. */
48 #define is_digit(c) ((unsigned)(c) - '0' <= 9)
51 #define SIZE_MAX ((size_t) -1)
55 * SunOS 4.1.1 libraries lack remove.
59 extern int unlink(const char *filename);
62 #endif /* !defined remove */
66 * Finally, some convenience items.
70 #define TYPE_BIT(type) (sizeof (type) * CHAR_BIT)
71 #endif /* !defined TYPE_BIT */
74 #define TYPE_SIGNED(type) (((type) -1) < 0)
75 #endif /* !defined TYPE_SIGNED */
77 #define TWOS_COMPLEMENT(t) ((t) ~ (t) 0 < 0)
80 * Max and min values of the integer type T, of which only the bottom
81 * B bits are used, and where the highest-order used bit is considered
82 * to be a sign bit if T is signed.
84 #define MAXVAL(t, b) \
85 ((t) (((t) 1 << ((b) - 1 - TYPE_SIGNED(t))) \
86 - 1 + ((t) 1 << ((b) - 1 - TYPE_SIGNED(t)))))
87 #define MINVAL(t, b) \
88 ((t) (TYPE_SIGNED(t) ? - TWOS_COMPLEMENT(t) - MAXVAL(t, b) : 0))
90 #ifndef INT_STRLEN_MAXIMUM
92 * 302 / 1000 is log10(2.0) rounded up.
93 * Subtract one for the sign bit if the type is signed;
94 * add one for integer division truncation;
95 * add one more for a minus sign if the type is signed.
97 #define INT_STRLEN_MAXIMUM(type) \
98 ((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + \
99 1 + TYPE_SIGNED(type))
100 #endif /* !defined INT_STRLEN_MAXIMUM */
105 #define INITIALIZE(x) ((x) = 0)
108 #define _(msgid) (msgid)
110 #ifndef YEARSPERREPEAT
111 #define YEARSPERREPEAT 400 /* years before a Gregorian repeat */
112 #endif /* !defined YEARSPERREPEAT */
115 * The Gregorian year averages 365.2425 days, which is 31556952 seconds.
118 #ifndef AVGSECSPERYEAR
119 #define AVGSECSPERYEAR 31556952L
120 #endif /* !defined AVGSECSPERYEAR */
122 #ifndef SECSPERREPEAT
123 #define SECSPERREPEAT ((int64) YEARSPERREPEAT * (int64) AVGSECSPERYEAR)
124 #endif /* !defined SECSPERREPEAT */
126 #ifndef SECSPERREPEAT_BITS
127 #define SECSPERREPEAT_BITS 34 /* ceil(log2(SECSPERREPEAT)) */
128 #endif /* !defined SECSPERREPEAT_BITS */
130 #endif /* !defined PRIVATE_H */