xref: /netbsd-src/lib/libc/time/private.h (revision 8a705cc17d9661734a1beae130cdbb7daf4a7d17)
1 /*	$NetBSD: private.h,v 1.21 2002/04/26 17:31:54 bjh21 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 #ifdef HAVE_CONFIG_H
14 #include "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 (arthur_david_olson@nih.gov).
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	7.52";
38 #endif
39 #endif /* !defined NOID */
40 #endif /* !defined lint */
41 
42 /*
43 ** Defaults for preprocessor symbols.
44 ** You can override these in your C compiler options, e.g. `-DHAVE_ADJTIME=0'.
45 */
46 
47 #ifndef HAVE_ADJTIME
48 #define HAVE_ADJTIME		1
49 #endif /* !defined HAVE_ADJTIME */
50 
51 #ifndef HAVE_GETTEXT
52 #define HAVE_GETTEXT		0
53 #endif /* !defined HAVE_GETTEXT */
54 
55 #ifndef HAVE_INCOMPATIBLE_CTIME_R
56 #define HAVE_INCOMPATIBLE_CTIME_R	0
57 #endif /* !defined INCOMPATIBLE_CTIME_R */
58 
59 #ifndef HAVE_SETTIMEOFDAY
60 #define HAVE_SETTIMEOFDAY	3
61 #endif /* !defined HAVE_SETTIMEOFDAY */
62 
63 #ifndef HAVE_STRERROR
64 #define HAVE_STRERROR		1
65 #endif /* !defined HAVE_STRERROR */
66 
67 #ifndef HAVE_SYMLINK
68 #define HAVE_SYMLINK		1
69 #endif /* !defined HAVE_SYMLINK */
70 
71 #ifndef HAVE_SYS_STAT_H
72 #define HAVE_SYS_STAT_H		1
73 #endif /* !defined HAVE_SYS_STAT_H */
74 
75 #ifndef HAVE_SYS_WAIT_H
76 #define HAVE_SYS_WAIT_H		1
77 #endif /* !defined HAVE_SYS_WAIT_H */
78 
79 #ifndef HAVE_UNISTD_H
80 #define HAVE_UNISTD_H		1
81 #endif /* !defined HAVE_UNISTD_H */
82 
83 #ifndef HAVE_UTMPX_H
84 #define HAVE_UTMPX_H		0
85 #endif /* !defined HAVE_UTMPX_H */
86 
87 #ifdef LOCALE_HOME
88 #undef LOCALE_HOME		/* not to be handled by tzcode itself */
89 #endif /* defined LOCALE_HOME */
90 
91 #if HAVE_INCOMPATIBLE_CTIME_R
92 #define asctime_r _incompatible_asctime_r
93 #define ctime_r _incompatible_ctime_r
94 #endif /* HAVE_INCOMPATIBLE_CTIME_R */
95 
96 /*
97 ** Nested includes
98 */
99 
100 #include "sys/types.h"	/* for time_t */
101 #include "stdio.h"
102 #include "errno.h"
103 #include "string.h"
104 #include "limits.h"	/* for CHAR_BIT */
105 #include "time.h"
106 #include "stdlib.h"
107 
108 #if HAVE_GETTEXT - 0
109 #include "libintl.h"
110 #endif /* HAVE_GETTEXT - 0 */
111 
112 #if HAVE_SYS_WAIT_H - 0
113 #include <sys/wait.h>	/* for WIFEXITED and WEXITSTATUS */
114 #endif /* HAVE_SYS_WAIT_H - 0 */
115 
116 #ifndef WIFEXITED
117 #define WIFEXITED(status)	(((status) & 0xff) == 0)
118 #endif /* !defined WIFEXITED */
119 #ifndef WEXITSTATUS
120 #define WEXITSTATUS(status)	(((status) >> 8) & 0xff)
121 #endif /* !defined WEXITSTATUS */
122 
123 #if HAVE_UNISTD_H - 0
124 #include "unistd.h"	/* for F_OK and R_OK */
125 #endif /* HAVE_UNISTD_H - 0 */
126 
127 #if !(HAVE_UNISTD_H - 0)
128 #ifndef F_OK
129 #define F_OK	0
130 #endif /* !defined F_OK */
131 #ifndef R_OK
132 #define R_OK	4
133 #endif /* !defined R_OK */
134 #endif /* !(HAVE_UNISTD_H - 0) */
135 
136 /* Unlike <ctype.h>'s isdigit, this also works if c < 0 | c > UCHAR_MAX.  */
137 #define is_digit(c) ((unsigned)(c) - '0' <= 9)
138 
139 /*
140 ** Workarounds for compilers/systems.
141 */
142 
143 /*
144 ** SunOS 4.1.1 cc lacks prototypes.
145 */
146 
147 #ifndef P
148 #ifdef __STDC__
149 #define P(x)	x
150 #endif /* defined __STDC__ */
151 #ifndef __STDC__
152 #define P(x)	()
153 #endif /* !defined __STDC__ */
154 #endif /* !defined P */
155 
156 /*
157 ** SunOS 4.1.1 headers lack EXIT_SUCCESS.
158 */
159 
160 #ifndef EXIT_SUCCESS
161 #define EXIT_SUCCESS	0
162 #endif /* !defined EXIT_SUCCESS */
163 
164 /*
165 ** SunOS 4.1.1 headers lack EXIT_FAILURE.
166 */
167 
168 #ifndef EXIT_FAILURE
169 #define EXIT_FAILURE	1
170 #endif /* !defined EXIT_FAILURE */
171 
172 /*
173 ** SunOS 4.1.1 headers lack FILENAME_MAX.
174 */
175 
176 #ifndef FILENAME_MAX
177 
178 #ifndef MAXPATHLEN
179 #ifdef unix
180 #include "sys/param.h"
181 #endif /* defined unix */
182 #endif /* !defined MAXPATHLEN */
183 
184 #ifdef MAXPATHLEN
185 #define FILENAME_MAX	MAXPATHLEN
186 #endif /* defined MAXPATHLEN */
187 #ifndef MAXPATHLEN
188 #define FILENAME_MAX	1024		/* Pure guesswork */
189 #endif /* !defined MAXPATHLEN */
190 
191 #endif /* !defined FILENAME_MAX */
192 
193 /*
194 ** SunOS 4.1.1 libraries lack remove.
195 */
196 
197 #ifndef __NetBSD__
198 #ifndef remove
199 extern int	unlink P((const char * filename));
200 #define remove	unlink
201 #endif /* !defined remove */
202 #endif
203 
204 /*
205 ** Some ancient errno.h implementations don't declare errno.
206 ** But some newer errno.h implementations define it as a macro.
207 ** Fix the former without affecting the latter.
208 */
209 #ifndef errno
210 extern int errno;
211 #endif /* !defined errno */
212 
213 /*
214 ** Private function declarations.
215 */
216 char *	icalloc P((int nelem, int elsize));
217 char *	icatalloc P((char * old, const char * new));
218 char *	icpyalloc P((const char * string));
219 char *	imalloc P((int n));
220 void *	irealloc P((void * pointer, int size));
221 void	icfree P((char * pointer));
222 void	ifree P((char * pointer));
223 char *	scheck P((const char *string, const char *format))
224 	__attribute__((__format_arg__(2)));
225 
226 
227 /*
228 ** Finally, some convenience items.
229 */
230 
231 #ifndef TRUE
232 #define TRUE	1
233 #endif /* !defined TRUE */
234 
235 #ifndef FALSE
236 #define FALSE	0
237 #endif /* !defined FALSE */
238 
239 #ifndef TYPE_BIT
240 #define TYPE_BIT(type)	(sizeof (type) * CHAR_BIT)
241 #endif /* !defined TYPE_BIT */
242 
243 #ifndef TYPE_SIGNED
244 #define TYPE_SIGNED(type) (((type) -1) < 0)
245 #endif /* !defined TYPE_SIGNED */
246 
247 #ifndef INT_STRLEN_MAXIMUM
248 /*
249 ** 302 / 1000 is log10(2.0) rounded up.
250 ** Subtract one for the sign bit if the type is signed;
251 ** add one for integer division truncation;
252 ** add one more for a minus sign if the type is signed.
253 */
254 #define INT_STRLEN_MAXIMUM(type) \
255     ((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + 1 + TYPE_SIGNED(type))
256 #endif /* !defined INT_STRLEN_MAXIMUM */
257 
258 /*
259 ** INITIALIZE(x)
260 */
261 
262 #ifndef GNUC_or_lint
263 #ifdef lint
264 #define GNUC_or_lint
265 #endif /* defined lint */
266 #ifndef lint
267 #ifdef __GNUC__
268 #define GNUC_or_lint
269 #endif /* defined __GNUC__ */
270 #endif /* !defined lint */
271 #endif /* !defined GNUC_or_lint */
272 
273 #ifndef INITIALIZE
274 #ifdef GNUC_or_lint
275 #define INITIALIZE(x)	((x) = 0)
276 #endif /* defined GNUC_or_lint */
277 #ifndef GNUC_or_lint
278 #define INITIALIZE(x)
279 #endif /* !defined GNUC_or_lint */
280 #endif /* !defined INITIALIZE */
281 
282 /*
283 ** For the benefit of GNU folk...
284 ** `_(MSGID)' uses the current locale's message library string for MSGID.
285 ** The default is to use gettext if available, and use MSGID otherwise.
286 */
287 
288 #ifndef _
289 #if HAVE_GETTEXT - 0
290 #define _(msgid) gettext(msgid)
291 #else /* !(HAVE_GETTEXT - 0) */
292 #define _(msgid) msgid
293 #endif /* !(HAVE_GETTEXT - 0) */
294 #endif /* !defined _ */
295 
296 #ifndef TZ_DOMAIN
297 #define TZ_DOMAIN "tz"
298 #endif /* !defined TZ_DOMAIN */
299 
300 #if HAVE_INCOMPATIBLE_CTIME_R
301 #undef asctime_r
302 #undef ctime_r
303 char *asctime_r P((struct tm const *, char *));
304 char *ctime_r P((time_t const *, char *));
305 #endif /* HAVE_INCOMPATIBLE_CTIME_R */
306 
307 /*
308 ** UNIX was a registered trademark of UNIX System Laboratories in 1993.
309 */
310 
311 #endif /* !defined PRIVATE_H */
312