Rebase for tzdata 2016f
[platform/upstream/tzdata.git] / private.h
1 #ifndef PRIVATE_H
2
3 #define PRIVATE_H
4
5 /*
6 ** This file is in the public domain, so clarified as of
7 ** 1996-06-05 by Arthur David Olson.
8 */
9
10 /*
11 ** This header is for use ONLY with the time conversion code.
12 ** There is no guarantee that it will remain unchanged,
13 ** or that it will remain at all.
14 ** Do NOT copy it to any system include directory.
15 ** Thank you!
16 */
17
18 #define GRANDPARENTED   "Local time zone must be set--see zic manual page"
19
20 /*
21 ** Defaults for preprocessor symbols.
22 ** You can override these in your C compiler options, e.g. `-DHAVE_ADJTIME=0'.
23 */
24
25 #ifndef HAVE_ADJTIME
26 #define HAVE_ADJTIME            1
27 #endif /* !defined HAVE_ADJTIME */
28
29 #ifndef HAVE_GETTEXT
30 #define HAVE_GETTEXT            0
31 #endif /* !defined HAVE_GETTEXT */
32
33 #ifndef HAVE_INCOMPATIBLE_CTIME_R
34 #define HAVE_INCOMPATIBLE_CTIME_R       0
35 #endif /* !defined INCOMPATIBLE_CTIME_R */
36
37 #ifndef HAVE_SETTIMEOFDAY
38 #define HAVE_SETTIMEOFDAY       3
39 #endif /* !defined HAVE_SETTIMEOFDAY */
40
41 #ifndef HAVE_SYMLINK
42 #define HAVE_SYMLINK            1
43 #endif /* !defined HAVE_SYMLINK */
44
45 #ifndef HAVE_SYS_STAT_H
46 #define HAVE_SYS_STAT_H         1
47 #endif /* !defined HAVE_SYS_STAT_H */
48
49 #ifndef HAVE_SYS_WAIT_H
50 #define HAVE_SYS_WAIT_H         1
51 #endif /* !defined HAVE_SYS_WAIT_H */
52
53 #ifndef HAVE_UNISTD_H
54 #define HAVE_UNISTD_H           1
55 #endif /* !defined HAVE_UNISTD_H */
56
57 #ifndef HAVE_UTMPX_H
58 #define HAVE_UTMPX_H            0
59 #endif /* !defined HAVE_UTMPX_H */
60
61 #ifndef LOCALE_HOME
62 #define LOCALE_HOME             "/usr/lib/locale"
63 #endif /* !defined LOCALE_HOME */
64
65 #if HAVE_INCOMPATIBLE_CTIME_R
66 #define asctime_r _incompatible_asctime_r
67 #define ctime_r _incompatible_ctime_r
68 #endif /* HAVE_INCOMPATIBLE_CTIME_R */
69
70 /*
71 ** Nested includes
72 */
73
74 #include "sys/types.h"  /* for time_t */
75 #include "stdio.h"
76 #include "errno.h"
77 #include "string.h"
78 #include "limits.h"     /* for CHAR_BIT et al. */
79 #include "time.h"
80 #include "stdlib.h"
81
82 #if HAVE_GETTEXT
83 #include "libintl.h"
84 #endif /* HAVE_GETTEXT */
85
86 #if HAVE_SYS_WAIT_H
87 #include <sys/wait.h>   /* for WIFEXITED and WEXITSTATUS */
88 #endif /* HAVE_SYS_WAIT_H */
89
90 #ifndef WIFEXITED
91 #define WIFEXITED(status)       (((status) & 0xff) == 0)
92 #endif /* !defined WIFEXITED */
93 #ifndef WEXITSTATUS
94 #define WEXITSTATUS(status)     (((status) >> 8) & 0xff)
95 #endif /* !defined WEXITSTATUS */
96
97 #if HAVE_UNISTD_H
98 #include "unistd.h"     /* for F_OK, R_OK, and other POSIX goodness */
99 #endif /* HAVE_UNISTD_H */
100
101 #ifndef F_OK
102 #define F_OK    0
103 #endif /* !defined F_OK */
104 #ifndef R_OK
105 #define R_OK    4
106 #endif /* !defined R_OK */
107
108 /* Unlike <ctype.h>'s isdigit, this also works if c < 0 | c > UCHAR_MAX. */
109 #define is_digit(c) ((unsigned)(c) - '0' <= 9)
110
111 /*
112 ** Define HAVE_STDINT_H's default value here, rather than at the
113 ** start, since __GLIBC__'s value depends on previously-included
114 ** files.
115 ** (glibc 2.1 and later have stdint.h, even with pre-C99 compilers.)
116 */
117 #ifndef HAVE_STDINT_H
118 #define HAVE_STDINT_H \
119         (199901 <= __STDC_VERSION__ || \
120         2 < (__GLIBC__ + (0 < __GLIBC_MINOR__)))
121 #endif /* !defined HAVE_STDINT_H */
122
123 #if HAVE_STDINT_H
124 #include "stdint.h"
125 #endif /* !HAVE_STDINT_H */
126
127 #ifndef INT_FAST64_MAX
128 /* Pre-C99 GCC compilers define __LONG_LONG_MAX__ instead of LLONG_MAX.  */
129 #if defined LLONG_MAX || defined __LONG_LONG_MAX__
130 typedef long long       int_fast64_t;
131 #else /* ! (defined LLONG_MAX || defined __LONG_LONG_MAX__) */
132 #if (LONG_MAX >> 31) < 0xffffffff
133 Please use a compiler that supports a 64-bit integer type (or wider);
134 you may need to compile with "-DHAVE_STDINT_H".
135 #endif /* (LONG_MAX >> 31) < 0xffffffff */
136 typedef long            int_fast64_t;
137 #endif /* ! (defined LLONG_MAX || defined __LONG_LONG_MAX__) */
138 #endif /* !defined INT_FAST64_MAX */
139
140 #ifndef INT32_MAX
141 #define INT32_MAX 0x7fffffff
142 #endif /* !defined INT32_MAX */
143 #ifndef INT32_MIN
144 #define INT32_MIN (-1 - INT32_MAX)
145 #endif /* !defined INT32_MIN */
146
147 /*
148 ** Workarounds for compilers/systems.
149 */
150
151 /*
152 ** Some time.h implementations don't declare asctime_r.
153 ** Others might define it as a macro.
154 ** Fix the former without affecting the latter.
155 */
156
157 #ifndef asctime_r
158 extern char *   asctime_r(struct tm const *, char *);
159 #endif
160
161 /*
162 ** Private function declarations.
163 */
164
165 char *          icalloc(int nelem, int elsize);
166 char *          icatalloc(char * old, const char * new);
167 char *          icpyalloc(const char * string);
168 char *          imalloc(int n);
169 void *          irealloc(void * pointer, int size);
170 void            icfree(char * pointer);
171 void            ifree(char * pointer);
172 const char *    scheck(const char * string, const char * format);
173
174 /*
175 ** Finally, some convenience items.
176 */
177
178 #ifndef TRUE
179 #define TRUE    1
180 #endif /* !defined TRUE */
181
182 #ifndef FALSE
183 #define FALSE   0
184 #endif /* !defined FALSE */
185
186 #ifndef TYPE_BIT
187 #define TYPE_BIT(type)  (sizeof (type) * CHAR_BIT)
188 #endif /* !defined TYPE_BIT */
189
190 #ifndef TYPE_SIGNED
191 #define TYPE_SIGNED(type) (((type) -1) < 0)
192 #endif /* !defined TYPE_SIGNED */
193
194 /*
195 ** Since the definition of TYPE_INTEGRAL contains floating point numbers,
196 ** it cannot be used in preprocessor directives.
197 */
198
199 #ifndef TYPE_INTEGRAL
200 #define TYPE_INTEGRAL(type) (((type) 0.5) != 0.5)
201 #endif /* !defined TYPE_INTEGRAL */
202
203 #ifndef INT_STRLEN_MAXIMUM
204 /*
205 ** 302 / 1000 is log10(2.0) rounded up.
206 ** Subtract one for the sign bit if the type is signed;
207 ** add one for integer division truncation;
208 ** add one more for a minus sign if the type is signed.
209 */
210 #define INT_STRLEN_MAXIMUM(type) \
211         ((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + \
212         1 + TYPE_SIGNED(type))
213 #endif /* !defined INT_STRLEN_MAXIMUM */
214
215 /*
216 ** INITIALIZE(x)
217 */
218
219 #ifndef GNUC_or_lint
220 #ifdef lint
221 #define GNUC_or_lint
222 #endif /* defined lint */
223 #ifndef lint
224 #ifdef __GNUC__
225 #define GNUC_or_lint
226 #endif /* defined __GNUC__ */
227 #endif /* !defined lint */
228 #endif /* !defined GNUC_or_lint */
229
230 #ifndef INITIALIZE
231 #ifdef GNUC_or_lint
232 #define INITIALIZE(x)   ((x) = 0)
233 #endif /* defined GNUC_or_lint */
234 #ifndef GNUC_or_lint
235 #define INITIALIZE(x)
236 #endif /* !defined GNUC_or_lint */
237 #endif /* !defined INITIALIZE */
238
239 /*
240 ** For the benefit of GNU folk...
241 ** `_(MSGID)' uses the current locale's message library string for MSGID.
242 ** The default is to use gettext if available, and use MSGID otherwise.
243 */
244
245 #ifndef _
246 #if HAVE_GETTEXT
247 #define _(msgid) gettext(msgid)
248 #else /* !HAVE_GETTEXT */
249 #define _(msgid) msgid
250 #endif /* !HAVE_GETTEXT */
251 #endif /* !defined _ */
252
253 #ifndef TZ_DOMAIN
254 #define TZ_DOMAIN "tz"
255 #endif /* !defined TZ_DOMAIN */
256
257 #if HAVE_INCOMPATIBLE_CTIME_R
258 #undef asctime_r
259 #undef ctime_r
260 char *asctime_r(struct tm const *, char *);
261 char *ctime_r(time_t const *, char *);
262 #endif /* HAVE_INCOMPATIBLE_CTIME_R */
263
264 #ifndef YEARSPERREPEAT
265 #define YEARSPERREPEAT          400     /* years before a Gregorian repeat */
266 #endif /* !defined YEARSPERREPEAT */
267
268 /*
269 ** The Gregorian year averages 365.2425 days, which is 31556952 seconds.
270 */
271
272 #ifndef AVGSECSPERYEAR
273 #define AVGSECSPERYEAR          31556952L
274 #endif /* !defined AVGSECSPERYEAR */
275
276 #ifndef SECSPERREPEAT
277 #define SECSPERREPEAT           ((int_fast64_t) YEARSPERREPEAT * (int_fast64_t) AVGSECSPERYEAR)
278 #endif /* !defined SECSPERREPEAT */
279
280 #ifndef SECSPERREPEAT_BITS
281 #define SECSPERREPEAT_BITS      34      /* ceil(log2(SECSPERREPEAT)) */
282 #endif /* !defined SECSPERREPEAT_BITS */
283
284 /*
285 ** UNIX was a registered trademark of The Open Group in 2003.
286 */
287
288 #endif /* !defined PRIVATE_H */