1 /* $NetBSD: private.h,v 1.30 2013/09/20 19:06:54 christos Exp $ */
7 #define TM_GMTOFF tm_gmtoff
8 #define TM_ZONE tm_zone
10 #define HAVE_LONG_DOUBLE 1
12 /* For when we build zic as a host tool. */
13 #if HAVE_NBTOOL_CONFIG_H
14 #include "nbtool_config.h"
18 ** This file is in the public domain, so clarified as of
19 ** 1996-06-05 by Arthur David Olson.
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.
30 #define GRANDPARENTED "Local time zone must be set--see zic manual page"
33 ** Defaults for preprocessor symbols.
34 ** You can override these in your C compiler options, e.g. `-DHAVE_ADJTIME=0'.
38 #define HAVE_ADJTIME 1
39 #endif /* !defined HAVE_ADJTIME */
42 #define HAVE_GETTEXT 0
43 #endif /* !defined HAVE_GETTEXT */
45 #ifndef HAVE_INCOMPATIBLE_CTIME_R
46 #define HAVE_INCOMPATIBLE_CTIME_R 0
47 #endif /* !defined INCOMPATIBLE_CTIME_R */
49 #ifndef HAVE_SETTIMEOFDAY
50 #define HAVE_SETTIMEOFDAY 3
51 #endif /* !defined HAVE_SETTIMEOFDAY */
54 #define HAVE_SYMLINK 1
55 #endif /* !defined HAVE_SYMLINK */
57 #ifndef HAVE_SYS_STAT_H
58 #define HAVE_SYS_STAT_H 1
59 #endif /* !defined HAVE_SYS_STAT_H */
61 #ifndef HAVE_SYS_WAIT_H
62 #define HAVE_SYS_WAIT_H 1
63 #endif /* !defined HAVE_SYS_WAIT_H */
66 #define HAVE_UNISTD_H 1
67 #endif /* !defined HAVE_UNISTD_H */
70 #define HAVE_UTMPX_H 0
71 #endif /* !defined HAVE_UTMPX_H */
74 #undef LOCALE_HOME /* not to be handled by tzcode itself */
75 #endif /* defined LOCALE_HOME */
77 #if HAVE_INCOMPATIBLE_CTIME_R
78 #define asctime_r _incompatible_asctime_r
79 #define ctime_r _incompatible_ctime_r
80 #endif /* HAVE_INCOMPATIBLE_CTIME_R */
86 #include "sys/types.h" /* for time_t */
90 #include "limits.h" /* for CHAR_BIT et al. */
96 #endif /* HAVE_GETTEXT */
99 #include <sys/wait.h> /* for WIFEXITED and WEXITSTATUS */
100 #endif /* HAVE_SYS_WAIT_H */
103 #define WIFEXITED(status) (((status) & 0xff) == 0)
104 #endif /* !defined WIFEXITED */
106 #define WEXITSTATUS(status) (((status) >> 8) & 0xff)
107 #endif /* !defined WEXITSTATUS */
110 #include "unistd.h" /* for F_OK, R_OK, and other POSIX goodness */
111 #endif /* HAVE_UNISTD_H */
115 #endif /* !defined F_OK */
118 #endif /* !defined R_OK */
120 /* Unlike <ctype.h>'s isdigit, this also works if c < 0 | c > UCHAR_MAX. */
121 #define is_digit(c) ((unsigned)(c) - '0' <= 9)
124 ** Define HAVE_STDINT_H's default value here, rather than at the
125 ** start, since __GLIBC__'s value depends on previously-included
127 ** (glibc 2.1 and later have stdint.h, even with pre-C99 compilers.)
129 #ifndef HAVE_STDINT_H
130 #define HAVE_STDINT_H \
131 (199901 <= __STDC_VERSION__ || \
132 2 < (__GLIBC__ + (0 < __GLIBC_MINOR__)))
133 #endif /* !defined HAVE_STDINT_H */
137 #endif /* !HAVE_STDINT_H */
139 #ifndef HAVE_INTTYPES_H
140 # define HAVE_INTTYPES_H HAVE_STDINT_H
143 # include <inttypes.h>
146 #ifndef INT_FAST64_MAX
147 /* Pre-C99 GCC compilers define __LONG_LONG_MAX__ instead of LLONG_MAX. */
148 #if defined LLONG_MAX || defined __LONG_LONG_MAX__
149 typedef long long int_fast64_t;
151 # define INT_FAST64_MIN LLONG_MIN
152 # define INT_FAST64_MAX LLONG_MAX
154 # define INT_FAST64_MIN __LONG_LONG_MIN__
155 # define INT_FAST64_MAX __LONG_LONG_MAX__
157 # define SCNdFAST64 "lld"
158 #else /* ! (defined LLONG_MAX || defined __LONG_LONG_MAX__) */
159 #if (LONG_MAX >> 31) < 0xffffffff
160 Please use a compiler that supports a
64-bit integer
type (or wider
);
161 you may need to compile with
"-DHAVE_STDINT_H".
162 #endif /* (LONG_MAX >> 31) < 0xffffffff */
163 typedef long int_fast64_t;
164 # define INT_FAST64_MIN LONG_MIN
165 # define INT_FAST64_MAX LONG_MAX
166 # define SCNdFAST64 "ld"
167 #endif /* ! (defined LLONG_MAX || defined __LONG_LONG_MAX__) */
168 #endif /* !defined INT_FAST64_MAX */
170 #ifndef INT_FAST32_MAX
171 # if INT_MAX >> 31 == 0
172 typedef long int_fast32_t;
174 typedef int int_fast32_t;
179 # if defined LLONG_MAX || defined __LONG_LONG_MAX__
180 typedef long long intmax_t;
181 # define strtoimax strtoll
182 # define PRIdMAX "lld"
184 # define INTMAX_MAX LLONG_MAX
185 # define INTMAX_MIN LLONG_MIN
187 # define INTMAX_MAX __LONG_LONG_MAX__
188 # define INTMAX_MIN __LONG_LONG_MIN__
191 typedef long intmax_t;
192 # define strtoimax strtol
193 # define PRIdMAX "ld"
194 # define INTMAX_MAX LONG_MAX
195 # define INTMAX_MIN LONG_MIN
200 # if defined ULLONG_MAX || defined __LONG_LONG_MAX__
201 typedef unsigned long long uintmax_t;
202 # define PRIuMAX "llu"
204 typedef unsigned long uintmax_t;
205 # define PRIuMAX "lu"
210 #define INT32_MAX 0x7fffffff
211 #endif /* !defined INT32_MAX */
213 #define INT32_MIN (-1 - INT32_MAX)
214 #endif /* !defined INT32_MIN */
216 #if 2 < __GNUC__ + (96 <= __GNUC_MINOR__)
217 # define ATTRIBUTE_CONST __attribute__ ((__const__))
218 # define ATTRIBUTE_PURE __attribute__ ((__pure__))
219 # define ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
221 # define ATTRIBUTE_CONST /* empty */
222 # define ATTRIBUTE_PURE /* empty */
223 # define ATTRIBUTE_FORMAT(spec) /* empty */
226 #if !defined _Noreturn && __STDC_VERSION__ < 201112
227 # if 2 < __GNUC__ + (8 <= __GNUC_MINOR__)
228 # define _Noreturn __attribute__ ((__noreturn__))
234 #if __STDC_VERSION__ < 199901 && !defined restrict
235 # define restrict /* empty */
239 ** Workarounds for compilers/systems.
243 ** Some time.h implementations don't declare asctime_r.
244 ** Others might define it as a macro.
245 ** Fix the former without affecting the latter.
249 extern char * asctime_r(struct tm
const *, char *);
253 ** Compile with -Dtime_tz=T to build the tz package with a private
254 ** time_t type equivalent to T rather than the system-supplied time_t.
255 ** This debugging feature can test unusual design decisions
256 ** (e.g., time_t wider than 'long', or unsigned time_t) even on
257 ** typical platforms.
260 static time_t sys_time(time_t *x
) { return time(x
); }
263 # define ctime tz_ctime
265 # define ctime_r tz_ctime_r
267 # define difftime tz_difftime
269 # define gmtime tz_gmtime
271 # define gmtime_r tz_gmtime_r
273 # define localtime tz_localtime
275 # define localtime_r tz_localtime_r
277 # define mktime tz_mktime
279 # define time tz_time
281 # define time_t tz_time_t
283 typedef time_tz
time_t;
285 char *ctime(time_t const *);
286 char *ctime_r(time_t const *, char *);
287 double difftime(time_t, time_t);
288 struct tm
*gmtime(time_t const *);
289 struct tm
*gmtime_r(time_t const *restrict
, struct tm
*restrict
);
290 struct tm
*localtime(time_t const *);
291 struct tm
*localtime_r(time_t const *restrict
, struct tm
*restrict
);
292 time_t mktime(struct tm
*);
297 time_t r
= sys_time(0);
305 ** Private function declarations.
308 char * icatalloc(char * old
, const char * new);
309 char * icpyalloc(const char * string
);
310 const char * scheck(const char * string
, const char * format
);
313 ** Finally, some convenience items.
318 #endif /* !defined TRUE */
322 #endif /* !defined FALSE */
325 #define TYPE_BIT(type) (sizeof (type) * CHAR_BIT)
326 #endif /* !defined TYPE_BIT */
329 #define TYPE_SIGNED(type) (/*CONSTCOND*/((type) -1) < 0)
330 #endif /* !defined TYPE_SIGNED */
332 /* The minimum and maximum finite time values. */
333 static time_t const time_t_min
=
335 ? (time_t) -1 << (int)(CHAR_BIT
* sizeof (time_t) - 1)
336 /*###336 [lint] warning semantics of 'p << p' change in ANSI C; use explicit cast [118]%%%*/
338 static time_t const time_t_max
=
340 ? - (~ 0 < 0) - ((time_t) -1 << (int)(CHAR_BIT
* sizeof (time_t) - 1))
343 #ifndef INT_STRLEN_MAXIMUM
345 ** 302 / 1000 is log10(2.0) rounded up.
346 ** Subtract one for the sign bit if the type is signed;
347 ** add one for integer division truncation;
348 ** add one more for a minus sign if the type is signed.
350 #define INT_STRLEN_MAXIMUM(type) \
351 ((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + \
352 1 + TYPE_SIGNED(type))
353 #endif /* !defined INT_STRLEN_MAXIMUM */
362 #endif /* defined lint */
366 #endif /* defined __GNUC__ */
367 #endif /* !defined lint */
368 #endif /* !defined GNUC_or_lint */
372 #define INITIALIZE(x) ((x) = 0)
373 #endif /* defined GNUC_or_lint */
375 #define INITIALIZE(x)
376 #endif /* !defined GNUC_or_lint */
377 #endif /* !defined INITIALIZE */
380 ** For the benefit of GNU folk...
381 ** `_(MSGID)' uses the current locale's message library string for MSGID.
382 ** The default is to use gettext if available, and use MSGID otherwise.
387 #define _(msgid) gettext(msgid)
388 #else /* !HAVE_GETTEXT */
389 #define _(msgid) msgid
390 #endif /* !HAVE_GETTEXT */
391 #endif /* !defined _ */
394 #define TZ_DOMAIN "tz"
395 #endif /* !defined TZ_DOMAIN */
397 #if HAVE_INCOMPATIBLE_CTIME_R
400 char *asctime_r(struct tm
const *, char *);
401 char *ctime_r(time_t const *, char *);
402 #endif /* HAVE_INCOMPATIBLE_CTIME_R */
404 #ifndef YEARSPERREPEAT
405 #define YEARSPERREPEAT 400 /* years before a Gregorian repeat */
406 #endif /* !defined YEARSPERREPEAT */
409 ** The Gregorian year averages 365.2425 days, which is 31556952 seconds.
412 #ifndef AVGSECSPERYEAR
413 #define AVGSECSPERYEAR 31556952L
414 #endif /* !defined AVGSECSPERYEAR */
416 #ifndef SECSPERREPEAT
417 #define SECSPERREPEAT ((int_fast64_t) YEARSPERREPEAT * (int_fast64_t) AVGSECSPERYEAR)
418 #endif /* !defined SECSPERREPEAT */
420 #ifndef SECSPERREPEAT_BITS
421 #define SECSPERREPEAT_BITS 34 /* ceil(log2(SECSPERREPEAT)) */
422 #endif /* !defined SECSPERREPEAT_BITS */
425 ** UNIX was a registered trademark of The Open Group in 2003.
428 #endif /* !defined PRIVATE_H */