private.h revision 1.26.2.2 1 /* $NetBSD: private.h,v 1.26.2.2 2014/08/20 00:02:16 tls 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 #define GRANDPARENTED "Local time zone must be set--see zic manual page"
31
32 /*
33 ** Defaults for preprocessor symbols.
34 ** You can override these in your C compiler options, e.g. `-DHAVE_ADJTIME=0'.
35 */
36
37 #ifndef HAVE_ADJTIME
38 #define HAVE_ADJTIME 1
39 #endif /* !defined HAVE_ADJTIME */
40
41 #ifndef HAVE_GETTEXT
42 #define HAVE_GETTEXT 0
43 #endif /* !defined HAVE_GETTEXT */
44
45 #ifndef HAVE_INCOMPATIBLE_CTIME_R
46 #define HAVE_INCOMPATIBLE_CTIME_R 0
47 #endif /* !defined INCOMPATIBLE_CTIME_R */
48
49 #ifndef HAVE_LINK
50 #define HAVE_LINK 1
51 #endif /* !defined HAVE_LINK */
52
53 #ifndef HAVE_SETTIMEOFDAY
54 #define HAVE_SETTIMEOFDAY 3
55 #endif /* !defined HAVE_SETTIMEOFDAY */
56
57 #ifndef HAVE_SYMLINK
58 #define HAVE_SYMLINK 1
59 #endif /* !defined HAVE_SYMLINK */
60
61 #ifndef HAVE_SYS_STAT_H
62 #define HAVE_SYS_STAT_H 1
63 #endif /* !defined HAVE_SYS_STAT_H */
64
65 #ifndef HAVE_SYS_WAIT_H
66 #define HAVE_SYS_WAIT_H 1
67 #endif /* !defined HAVE_SYS_WAIT_H */
68
69 #ifndef HAVE_UNISTD_H
70 #define HAVE_UNISTD_H 1
71 #endif /* !defined HAVE_UNISTD_H */
72
73 #ifndef HAVE_UTMPX_H
74 #define HAVE_UTMPX_H 0
75 #endif /* !defined HAVE_UTMPX_H */
76
77 #ifdef LOCALE_HOME
78 #undef LOCALE_HOME /* not to be handled by tzcode itself */
79 #endif /* defined LOCALE_HOME */
80
81 #if HAVE_INCOMPATIBLE_CTIME_R
82 #define asctime_r _incompatible_asctime_r
83 #define ctime_r _incompatible_ctime_r
84 #endif /* HAVE_INCOMPATIBLE_CTIME_R */
85
86 /*
87 ** Nested includes
88 */
89
90 #include "sys/types.h" /* for time_t */
91 #include "stdio.h"
92 #include "errno.h"
93 #include "string.h"
94 #include "limits.h" /* for CHAR_BIT et al. */
95 #include "time.h"
96 #include "stdlib.h"
97
98 #if HAVE_GETTEXT
99 #include "libintl.h"
100 #endif /* HAVE_GETTEXT */
101
102 #if HAVE_SYS_WAIT_H
103 #include <sys/wait.h> /* for WIFEXITED and WEXITSTATUS */
104 #endif /* HAVE_SYS_WAIT_H */
105
106 #ifndef WIFEXITED
107 #define WIFEXITED(status) (((status) & 0xff) == 0)
108 #endif /* !defined WIFEXITED */
109 #ifndef WEXITSTATUS
110 #define WEXITSTATUS(status) (((status) >> 8) & 0xff)
111 #endif /* !defined WEXITSTATUS */
112
113 #if HAVE_UNISTD_H
114 #include "unistd.h" /* for F_OK, R_OK, and other POSIX goodness */
115 #endif /* HAVE_UNISTD_H */
116
117 #ifndef F_OK
118 #define F_OK 0
119 #endif /* !defined F_OK */
120 #ifndef R_OK
121 #define R_OK 4
122 #endif /* !defined R_OK */
123
124 /* Unlike <ctype.h>'s isdigit, this also works if c < 0 | c > UCHAR_MAX. */
125 #define is_digit(c) ((unsigned)(c) - '0' <= 9)
126
127 /*
128 ** Define HAVE_STDINT_H's default value here, rather than at the
129 ** start, since __GLIBC__'s value depends on previously-included
130 ** files.
131 ** (glibc 2.1 and later have stdint.h, even with pre-C99 compilers.)
132 */
133 #ifndef HAVE_STDINT_H
134 #define HAVE_STDINT_H \
135 (199901 <= __STDC_VERSION__ \
136 || 2 < __GLIBC__ + (1 <= __GLIBC_MINOR__) \
137 || __CYGWIN__)
138 #endif /* !defined HAVE_STDINT_H */
139
140 #if HAVE_STDINT_H
141 #include "stdint.h"
142 #endif /* !HAVE_STDINT_H */
143
144 #ifndef HAVE_INTTYPES_H
145 # define HAVE_INTTYPES_H HAVE_STDINT_H
146 #endif
147 #if HAVE_INTTYPES_H
148 # include <inttypes.h>
149 #endif
150
151 #ifndef INT_FAST64_MAX
152 /* Pre-C99 GCC compilers define __LONG_LONG_MAX__ instead of LLONG_MAX. */
153 #if defined LLONG_MAX || defined __LONG_LONG_MAX__
154 typedef long long int_fast64_t;
155 # ifdef LLONG_MAX
156 # define INT_FAST64_MIN LLONG_MIN
157 # define INT_FAST64_MAX LLONG_MAX
158 # else
159 # define INT_FAST64_MIN __LONG_LONG_MIN__
160 # define INT_FAST64_MAX __LONG_LONG_MAX__
161 # endif
162 # define SCNdFAST64 "lld"
163 #else /* ! (defined LLONG_MAX || defined __LONG_LONG_MAX__) */
164 #if (LONG_MAX >> 31) < 0xffffffff
165 Please use a compiler that supports a 64-bit integer type (or wider);
166 you may need to compile with "-DHAVE_STDINT_H".
167 #endif /* (LONG_MAX >> 31) < 0xffffffff */
168 typedef long int_fast64_t;
169 # define INT_FAST64_MIN LONG_MIN
170 # define INT_FAST64_MAX LONG_MAX
171 # define SCNdFAST64 "ld"
172 #endif /* ! (defined LLONG_MAX || defined __LONG_LONG_MAX__) */
173 #endif /* !defined INT_FAST64_MAX */
174
175 #ifndef INT_FAST32_MAX
176 # if INT_MAX >> 31 == 0
177 typedef long int_fast32_t;
178 # else
179 typedef int int_fast32_t;
180 # endif
181 #endif
182
183 #ifndef INTMAX_MAX
184 # if defined LLONG_MAX || defined __LONG_LONG_MAX__
185 typedef long long intmax_t;
186 # define strtoimax strtoll
187 # define PRIdMAX "lld"
188 # ifdef LLONG_MAX
189 # define INTMAX_MAX LLONG_MAX
190 # define INTMAX_MIN LLONG_MIN
191 # else
192 # define INTMAX_MAX __LONG_LONG_MAX__
193 # define INTMAX_MIN __LONG_LONG_MIN__
194 # endif
195 # else
196 typedef long intmax_t;
197 # define strtoimax strtol
198 # define PRIdMAX "ld"
199 # define INTMAX_MAX LONG_MAX
200 # define INTMAX_MIN LONG_MIN
201 # endif
202 #endif
203
204 #ifndef UINTMAX_MAX
205 # if defined ULLONG_MAX || defined __LONG_LONG_MAX__
206 typedef unsigned long long uintmax_t;
207 # define PRIuMAX "llu"
208 # else
209 typedef unsigned long uintmax_t;
210 # define PRIuMAX "lu"
211 # endif
212 #endif
213
214 #ifndef INT32_MAX
215 #define INT32_MAX 0x7fffffff
216 #endif /* !defined INT32_MAX */
217 #ifndef INT32_MIN
218 #define INT32_MIN (-1 - INT32_MAX)
219 #endif /* !defined INT32_MIN */
220
221 #ifndef SIZE_MAX
222 #define SIZE_MAX ((size_t) -1)
223 #endif
224
225 #if 2 < __GNUC__ + (96 <= __GNUC_MINOR__)
226 # define ATTRIBUTE_CONST __attribute__ ((__const__))
227 # define ATTRIBUTE_PURE __attribute__ ((__pure__))
228 # define ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
229 #else
230 # define ATTRIBUTE_CONST /* empty */
231 # define ATTRIBUTE_PURE /* empty */
232 # define ATTRIBUTE_FORMAT(spec) /* empty */
233 #endif
234
235 #if !defined _Noreturn && __STDC_VERSION__ < 201112
236 # if 2 < __GNUC__ + (8 <= __GNUC_MINOR__)
237 # define _Noreturn __attribute__ ((__noreturn__))
238 # else
239 # define _Noreturn
240 # endif
241 #endif
242
243 #if __STDC_VERSION__ < 199901 && !defined restrict
244 # define restrict /* empty */
245 #endif
246
247 /*
248 ** Workarounds for compilers/systems.
249 */
250
251 /*
252 ** Some time.h implementations don't declare asctime_r.
253 ** Others might define it as a macro.
254 ** Fix the former without affecting the latter.
255 */
256
257 #ifndef asctime_r
258 extern char * asctime_r(struct tm const *, char *);
259 #endif
260
261 /*
262 ** Compile with -Dtime_tz=T to build the tz package with a private
263 ** time_t type equivalent to T rather than the system-supplied time_t.
264 ** This debugging feature can test unusual design decisions
265 ** (e.g., time_t wider than 'long', or unsigned time_t) even on
266 ** typical platforms.
267 */
268 #ifdef time_tz
269 static time_t sys_time(time_t *x) { return time(x); }
270
271 # undef ctime
272 # define ctime tz_ctime
273 # undef ctime_r
274 # define ctime_r tz_ctime_r
275 # undef difftime
276 # define difftime tz_difftime
277 # undef gmtime
278 # define gmtime tz_gmtime
279 # undef gmtime_r
280 # define gmtime_r tz_gmtime_r
281 # undef localtime
282 # define localtime tz_localtime
283 # undef localtime_r
284 # define localtime_r tz_localtime_r
285 # undef mktime
286 # define mktime tz_mktime
287 # undef time
288 # define time tz_time
289 # undef time_t
290 # define time_t tz_time_t
291
292 typedef time_tz time_t;
293
294 char *ctime(time_t const *);
295 char *ctime_r(time_t const *, char *);
296 double difftime(time_t, time_t);
297 struct tm *gmtime(time_t const *);
298 struct tm *gmtime_r(time_t const *restrict, struct tm *restrict);
299 struct tm *localtime(time_t const *);
300 struct tm *localtime_r(time_t const *restrict, struct tm *restrict);
301 time_t mktime(struct tm *);
302
303 static time_t
304 time(time_t *p)
305 {
306 time_t r = sys_time(0);
307 if (p)
308 *p = r;
309 return r;
310 }
311 #endif
312
313 /*
314 ** Private function declarations.
315 */
316
317 char * icatalloc(char * old, const char * new);
318 char * icpyalloc(const char * string);
319 const char * scheck(const char * string, const char * format);
320
321 /*
322 ** Finally, some convenience items.
323 */
324
325 #ifndef TRUE
326 #define TRUE 1
327 #endif /* !defined TRUE */
328
329 #ifndef FALSE
330 #define FALSE 0
331 #endif /* !defined FALSE */
332
333 #ifndef TYPE_BIT
334 #define TYPE_BIT(type) (sizeof (type) * CHAR_BIT)
335 #endif /* !defined TYPE_BIT */
336
337 #ifndef TYPE_SIGNED
338 #define TYPE_SIGNED(type) (/*CONSTCOND*/((type) -1) < 0)
339 #endif /* !defined TYPE_SIGNED */
340
341 #ifndef INT_STRLEN_MAXIMUM
342 /*
343 ** 302 / 1000 is log10(2.0) rounded up.
344 ** Subtract one for the sign bit if the type is signed;
345 ** add one for integer division truncation;
346 ** add one more for a minus sign if the type is signed.
347 */
348 #define INT_STRLEN_MAXIMUM(type) \
349 ((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + \
350 1 + TYPE_SIGNED(type))
351 #endif /* !defined INT_STRLEN_MAXIMUM */
352
353 /*
354 ** INITIALIZE(x)
355 */
356
357 #ifndef GNUC_or_lint
358 #ifdef lint
359 #define GNUC_or_lint
360 #endif /* defined lint */
361 #ifndef lint
362 #ifdef __GNUC__
363 #define GNUC_or_lint
364 #endif /* defined __GNUC__ */
365 #endif /* !defined lint */
366 #endif /* !defined GNUC_or_lint */
367
368 #ifndef INITIALIZE
369 #ifdef GNUC_or_lint
370 #define INITIALIZE(x) ((x) = 0)
371 #endif /* defined GNUC_or_lint */
372 #ifndef GNUC_or_lint
373 #define INITIALIZE(x)
374 #endif /* !defined GNUC_or_lint */
375 #endif /* !defined INITIALIZE */
376
377 /*
378 ** For the benefit of GNU folk...
379 ** `_(MSGID)' uses the current locale's message library string for MSGID.
380 ** The default is to use gettext if available, and use MSGID otherwise.
381 */
382
383 #ifndef _
384 #if HAVE_GETTEXT
385 #define _(msgid) gettext(msgid)
386 #else /* !HAVE_GETTEXT */
387 #define _(msgid) msgid
388 #endif /* !HAVE_GETTEXT */
389 #endif /* !defined _ */
390
391 #ifndef TZ_DOMAIN
392 #define TZ_DOMAIN "tz"
393 #endif /* !defined TZ_DOMAIN */
394
395 #if HAVE_INCOMPATIBLE_CTIME_R
396 #undef asctime_r
397 #undef ctime_r
398 char *asctime_r(struct tm const *, char *);
399 char *ctime_r(time_t const *, char *);
400 #endif /* HAVE_INCOMPATIBLE_CTIME_R */
401
402 #ifndef YEARSPERREPEAT
403 #define YEARSPERREPEAT 400 /* years before a Gregorian repeat */
404 #endif /* !defined YEARSPERREPEAT */
405
406 /*
407 ** The Gregorian year averages 365.2425 days, which is 31556952 seconds.
408 */
409
410 #ifndef AVGSECSPERYEAR
411 #define AVGSECSPERYEAR 31556952L
412 #endif /* !defined AVGSECSPERYEAR */
413
414 #ifndef SECSPERREPEAT
415 #define SECSPERREPEAT ((int_fast64_t) YEARSPERREPEAT * (int_fast64_t) AVGSECSPERYEAR)
416 #endif /* !defined SECSPERREPEAT */
417
418 #ifndef SECSPERREPEAT_BITS
419 #define SECSPERREPEAT_BITS 34 /* ceil(log2(SECSPERREPEAT)) */
420 #endif /* !defined SECSPERREPEAT_BITS */
421
422 /*
423 ** UNIX was a registered trademark of The Open Group in 2003.
424 */
425
426 #endif /* !defined PRIVATE_H */
427