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