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 | * IDENTIFICATION |
12 | * src/timezone/private.h |
13 | */ |
14 | |
15 | /* |
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. |
20 | * Thank you! |
21 | */ |
22 | |
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 */ |
26 | |
27 | #include "pgtime.h" |
28 | |
29 | /* This string was in the Factory zone through version 2016f. */ |
30 | #define GRANDPARENTED "Local time zone must be set--see zic manual page" |
31 | |
32 | /* |
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. |
35 | */ |
36 | |
37 | #ifndef ENOTSUP |
38 | #define ENOTSUP EINVAL |
39 | #endif |
40 | #ifndef EOVERFLOW |
41 | #define EOVERFLOW EINVAL |
42 | #endif |
43 | |
44 | /* Unlike <ctype.h>'s isdigit, this also works if c < 0 | c > UCHAR_MAX. */ |
45 | #define is_digit(c) ((unsigned)(c) - '0' <= 9) |
46 | |
47 | /* PG doesn't currently rely on <inttypes.h>, so work around strtoimax() */ |
48 | #undef strtoimax |
49 | #ifdef HAVE_STRTOLL |
50 | #define strtoimax strtoll |
51 | #else |
52 | #define strtoimax strtol |
53 | #endif |
54 | |
55 | |
56 | /* |
57 | * Finally, some convenience items. |
58 | */ |
59 | |
60 | #define TYPE_BIT(type) (sizeof (type) * CHAR_BIT) |
61 | #define TYPE_SIGNED(type) (((type) -1) < 0) |
62 | #define TWOS_COMPLEMENT(t) ((t) ~ (t) 0 < 0) |
63 | |
64 | /* |
65 | * Max and min values of the integer type T, of which only the bottom |
66 | * B bits are used, and where the highest-order used bit is considered |
67 | * to be a sign bit if T is signed. |
68 | */ |
69 | #define MAXVAL(t, b) \ |
70 | ((t) (((t) 1 << ((b) - 1 - TYPE_SIGNED(t))) \ |
71 | - 1 + ((t) 1 << ((b) - 1 - TYPE_SIGNED(t))))) |
72 | #define MINVAL(t, b) \ |
73 | ((t) (TYPE_SIGNED(t) ? - TWOS_COMPLEMENT(t) - MAXVAL(t, b) : 0)) |
74 | |
75 | /* The extreme time values, assuming no padding. */ |
76 | #define TIME_T_MIN MINVAL(pg_time_t, TYPE_BIT(pg_time_t)) |
77 | #define TIME_T_MAX MAXVAL(pg_time_t, TYPE_BIT(pg_time_t)) |
78 | |
79 | /* |
80 | * 302 / 1000 is log10(2.0) rounded up. |
81 | * Subtract one for the sign bit if the type is signed; |
82 | * add one for integer division truncation; |
83 | * add one more for a minus sign if the type is signed. |
84 | */ |
85 | #define INT_STRLEN_MAXIMUM(type) \ |
86 | ((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + \ |
87 | 1 + TYPE_SIGNED(type)) |
88 | |
89 | /* |
90 | * INITIALIZE(x) |
91 | */ |
92 | #define INITIALIZE(x) ((x) = 0) |
93 | |
94 | #undef _ |
95 | #define _(msgid) (msgid) |
96 | |
97 | /* Handy macros that are independent of tzfile implementation. */ |
98 | |
99 | #define YEARSPERREPEAT 400 /* years before a Gregorian repeat */ |
100 | |
101 | #define SECSPERMIN 60 |
102 | #define MINSPERHOUR 60 |
103 | #define HOURSPERDAY 24 |
104 | #define DAYSPERWEEK 7 |
105 | #define DAYSPERNYEAR 365 |
106 | #define DAYSPERLYEAR 366 |
107 | #define SECSPERHOUR (SECSPERMIN * MINSPERHOUR) |
108 | #define SECSPERDAY ((int32) SECSPERHOUR * HOURSPERDAY) |
109 | #define MONSPERYEAR 12 |
110 | |
111 | #define TM_SUNDAY 0 |
112 | #define TM_MONDAY 1 |
113 | #define TM_TUESDAY 2 |
114 | #define TM_WEDNESDAY 3 |
115 | #define TM_THURSDAY 4 |
116 | #define TM_FRIDAY 5 |
117 | #define TM_SATURDAY 6 |
118 | |
119 | #define TM_JANUARY 0 |
120 | #define TM_FEBRUARY 1 |
121 | #define TM_MARCH 2 |
122 | #define TM_APRIL 3 |
123 | #define TM_MAY 4 |
124 | #define TM_JUNE 5 |
125 | #define TM_JULY 6 |
126 | #define TM_AUGUST 7 |
127 | #define TM_SEPTEMBER 8 |
128 | #define TM_OCTOBER 9 |
129 | #define TM_NOVEMBER 10 |
130 | #define TM_DECEMBER 11 |
131 | |
132 | #define TM_YEAR_BASE 1900 |
133 | |
134 | #define EPOCH_YEAR 1970 |
135 | #define EPOCH_WDAY TM_THURSDAY |
136 | |
137 | #define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0)) |
138 | |
139 | /* |
140 | * Since everything in isleap is modulo 400 (or a factor of 400), we know that |
141 | * isleap(y) == isleap(y % 400) |
142 | * and so |
143 | * isleap(a + b) == isleap((a + b) % 400) |
144 | * or |
145 | * isleap(a + b) == isleap(a % 400 + b % 400) |
146 | * This is true even if % means modulo rather than Fortran remainder |
147 | * (which is allowed by C89 but not by C99 or later). |
148 | * We use this to avoid addition overflow problems. |
149 | */ |
150 | |
151 | #define isleap_sum(a, b) isleap((a) % 400 + (b) % 400) |
152 | |
153 | |
154 | /* |
155 | * The Gregorian year averages 365.2425 days, which is 31556952 seconds. |
156 | */ |
157 | |
158 | #define AVGSECSPERYEAR 31556952L |
159 | #define SECSPERREPEAT \ |
160 | ((int64) YEARSPERREPEAT * (int64) AVGSECSPERYEAR) |
161 | #define SECSPERREPEAT_BITS 34 /* ceil(log2(SECSPERREPEAT)) */ |
162 | |
163 | #endif /* !defined PRIVATE_H */ |
164 | |