1 /* Private header for tzdb code. */
8 * This file is in the public domain, so clarified as of
9 * 1996-06-05 by Arthur David Olson.
12 * src/timezone/private.h
16 * This header is for use ONLY with the time conversion code.
17 * There is no guarantee that it will remain unchanged,
18 * or that it will remain at all.
19 * Do NOT copy it to any system include directory.
23 #include <limits.h> /* for CHAR_BIT et al. */
24 #include <sys/wait.h> /* for WIFEXITED and WEXITSTATUS */
25 #include <unistd.h> /* for F_OK and R_OK */
29 /* This string was in the Factory zone through version 2016f. */
30 #define GRANDPARENTED "Local time zone must be set--see zic manual page"
33 * IANA has a bunch of HAVE_FOO #defines here, but in PG we want pretty
34 * much all of that to be done by PG's configure script.
38 #define ENOTSUP EINVAL
41 #define EOVERFLOW EINVAL
44 /* Unlike <ctype.h>'s isdigit, this also works if c < 0 | c > UCHAR_MAX. */
45 #define is_digit(c) ((unsigned)(c) - '0' <= 9)
47 /* PG doesn't currently rely on <inttypes.h>, so work around strtoimax() */
49 #define strtoimax strtoll
53 * Finally, some convenience items.
56 #define TYPE_BIT(type) (sizeof (type) * CHAR_BIT)
57 #define TYPE_SIGNED(type) (((type) -1) < 0)
58 #define TWOS_COMPLEMENT(t) ((t) ~ (t) 0 < 0)
61 * Max and min values of the integer type T, of which only the bottom
62 * B bits are used, and where the highest-order used bit is considered
63 * to be a sign bit if T is signed.
65 #define MAXVAL(t, b) \
66 ((t) (((t) 1 << ((b) - 1 - TYPE_SIGNED(t))) \
67 - 1 + ((t) 1 << ((b) - 1 - TYPE_SIGNED(t)))))
68 #define MINVAL(t, b) \
69 ((t) (TYPE_SIGNED(t) ? - TWOS_COMPLEMENT(t) - MAXVAL(t, b) : 0))
71 /* The extreme time values, assuming no padding. */
72 #define TIME_T_MIN MINVAL(pg_time_t, TYPE_BIT(pg_time_t))
73 #define TIME_T_MAX MAXVAL(pg_time_t, TYPE_BIT(pg_time_t))
76 * 302 / 1000 is log10(2.0) rounded up.
77 * Subtract one for the sign bit if the type is signed;
78 * add one for integer division truncation;
79 * add one more for a minus sign if the type is signed.
81 #define INT_STRLEN_MAXIMUM(type) \
82 ((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + \
83 1 + TYPE_SIGNED(type))
88 #define INITIALIZE(x) ((x) = 0)
91 #define _(msgid) (msgid)
93 /* Handy macros that are independent of tzfile implementation. */
95 #define YEARSPERREPEAT 400 /* years before a Gregorian repeat */
98 #define MINSPERHOUR 60
99 #define HOURSPERDAY 24
100 #define DAYSPERWEEK 7
101 #define DAYSPERNYEAR 365
102 #define DAYSPERLYEAR 366
103 #define SECSPERHOUR (SECSPERMIN * MINSPERHOUR)
104 #define SECSPERDAY ((int32) SECSPERHOUR * HOURSPERDAY)
105 #define MONSPERYEAR 12
110 #define TM_WEDNESDAY 3
111 #define TM_THURSDAY 4
113 #define TM_SATURDAY 6
116 #define TM_FEBRUARY 1
123 #define TM_SEPTEMBER 8
125 #define TM_NOVEMBER 10
126 #define TM_DECEMBER 11
128 #define TM_YEAR_BASE 1900
130 #define EPOCH_YEAR 1970
131 #define EPOCH_WDAY TM_THURSDAY
133 #define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
136 * Since everything in isleap is modulo 400 (or a factor of 400), we know that
137 * isleap(y) == isleap(y % 400)
139 * isleap(a + b) == isleap((a + b) % 400)
141 * isleap(a + b) == isleap(a % 400 + b % 400)
142 * This is true even if % means modulo rather than Fortran remainder
143 * (which is allowed by C89 but not by C99 or later).
144 * We use this to avoid addition overflow problems.
147 #define isleap_sum(a, b) isleap((a) % 400 + (b) % 400)
151 * The Gregorian year averages 365.2425 days, which is 31556952 seconds.
154 #define AVGSECSPERYEAR 31556952L
155 #define SECSPERREPEAT \
156 ((int64) YEARSPERREPEAT * (int64) AVGSECSPERYEAR)
157 #define SECSPERREPEAT_BITS 34 /* ceil(log2(SECSPERREPEAT)) */
159 #endif /* !defined PRIVATE_H */