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