xref: /openbsd-src/lib/libc/time/private.h (revision d13be5d47e4149db2549a9828e244d59dbc43f15)
1 /*	$OpenBSD: private.h,v 1.23 2011/07/01 13:34:18 millert Exp $	*/
2 #ifndef PRIVATE_H
3 
4 #define PRIVATE_H
5 
6 /*
7 ** This file is in the public domain, so clarified as of
8 ** 1996-06-05 by Arthur David Olson.
9 */
10 
11 /* OpenBSD defaults */
12 #define TM_GMTOFF		tm_gmtoff
13 #define TM_ZONE			tm_zone
14 #define PCTS			1
15 #define XPG4_1994_04_09		1
16 #define ALL_STATE		1
17 #define STD_INSPIRED		1
18 #define HAVE_STRERROR		1
19 #define HAVE_STDINT_H		1
20 #define NO_RUN_TIME_WARNINGS_ABOUT_YEAR_2000_PROBLEMS_THANK_YOU	1
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 #if 0
35 #ifndef lint
36 #ifndef NOID
37 static char	privatehid[] = "@(#)private.h	8.6";
38 #endif /* !defined NOID */
39 #endif /* !defined lint */
40 #endif
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 #if 0
86 #ifndef LOCALE_HOME
87 #define LOCALE_HOME		"/usr/share/locale"
88 #endif /* !defined LOCALE_HOME */
89 #endif
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 et al. */
105 #include "time.h"
106 #include "stdlib.h"
107 
108 #if HAVE_GETTEXT
109 #include "libintl.h"
110 #endif /* HAVE_GETTEXT */
111 
112 #if HAVE_SYS_WAIT_H
113 #include <sys/wait.h>	/* for WIFEXITED and WEXITSTATUS */
114 #endif /* HAVE_SYS_WAIT_H */
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
124 #include "unistd.h"	/* for F_OK, R_OK, and other POSIX goodness */
125 #endif /* HAVE_UNISTD_H */
126 
127 #ifndef F_OK
128 #define F_OK	0
129 #endif /* !defined F_OK */
130 #ifndef R_OK
131 #define R_OK	4
132 #endif /* !defined R_OK */
133 
134 /* Unlike <ctype.h>'s isdigit, this also works if c < 0 | c > UCHAR_MAX. */
135 #define is_digit(c) ((unsigned)(c) - '0' <= 9)
136 
137 #if HAVE_STDINT_H
138 #include "stdint.h"
139 #endif /* !HAVE_STDINT_H */
140 
141 #ifndef INT_FAST64_MAX
142 /* Pre-C99 GCC compilers define __LONG_LONG_MAX__ instead of LLONG_MAX.  */
143 #if defined LLONG_MAX || defined __LONG_LONG_MAX__
144 typedef long long	int_fast64_t;
145 #else /* ! (defined LLONG_MAX || defined __LONG_LONG_MAX__) */
146 #if (LONG_MAX >> 31) < 0xffffffff
147 Please use a compiler that supports a 64-bit integer type (or wider);
148 you may need to compile with "-DHAVE_STDINT_H".
149 #endif /* (LONG_MAX >> 31) < 0xffffffff */
150 typedef long		int_fast64_t;
151 #endif /* ! (defined LLONG_MAX || defined __LONG_LONG_MAX__) */
152 #endif /* !defined INT_FAST64_MAX */
153 
154 #ifndef INT32_MAX
155 #define INT32_MAX 0x7fffffff
156 #endif /* !defined INT32_MAX */
157 #ifndef INT32_MIN
158 #define INT32_MIN (-1 - INT32_MAX)
159 #endif /* !defined INT32_MIN */
160 
161 /*
162 ** Workarounds for compilers/systems.
163 */
164 
165 #if 0
166 /*
167 ** Some time.h implementations don't declare asctime_r.
168 ** Others might define it as a macro.
169 ** Fix the former without affecting the latter.
170 */
171 
172 #ifndef asctime_r
173 extern char *	asctime_r(struct tm const *, char *);
174 #endif
175 #endif
176 
177 /*
178 ** Private function declarations.
179 */
180 
181 char *		icalloc(int nelem, int elsize);
182 char *		icatalloc(char * old, const char * new);
183 char *		icpyalloc(const char * string);
184 char *		imalloc(int n);
185 void *		irealloc(void * pointer, int size);
186 void		icfree(char * pointer);
187 void		ifree(char * pointer);
188 const char *	scheck(const char * string, const char * format);
189 
190 /*
191 ** Finally, some convenience items.
192 */
193 
194 #ifndef TRUE
195 #define TRUE	1
196 #endif /* !defined TRUE */
197 
198 #ifndef FALSE
199 #define FALSE	0
200 #endif /* !defined FALSE */
201 
202 #ifndef TYPE_BIT
203 #define TYPE_BIT(type)	(sizeof (type) * CHAR_BIT)
204 #endif /* !defined TYPE_BIT */
205 
206 #ifndef TYPE_SIGNED
207 #define TYPE_SIGNED(type) (((type) -1) < 0)
208 #endif /* !defined TYPE_SIGNED */
209 
210 /*
211 ** Since the definition of TYPE_INTEGRAL contains floating point numbers,
212 ** it cannot be used in preprocessor directives.
213 */
214 
215 #ifndef TYPE_INTEGRAL
216 #define TYPE_INTEGRAL(type) (((type) 0.5) != 0.5)
217 #endif /* !defined TYPE_INTEGRAL */
218 
219 #ifndef INT_STRLEN_MAXIMUM
220 /*
221 ** 302 / 1000 is log10(2.0) rounded up.
222 ** Subtract one for the sign bit if the type is signed;
223 ** add one for integer division truncation;
224 ** add one more for a minus sign if the type is signed.
225 */
226 #define INT_STRLEN_MAXIMUM(type) \
227 	((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + \
228 	1 + TYPE_SIGNED(type))
229 #endif /* !defined INT_STRLEN_MAXIMUM */
230 
231 /*
232 ** INITIALIZE(x)
233 */
234 
235 #ifndef GNUC_or_lint
236 #ifdef lint
237 #define GNUC_or_lint
238 #endif /* defined lint */
239 #ifndef lint
240 #ifdef __GNUC__
241 #define GNUC_or_lint
242 #endif /* defined __GNUC__ */
243 #endif /* !defined lint */
244 #endif /* !defined GNUC_or_lint */
245 
246 #ifndef INITIALIZE
247 #ifdef GNUC_or_lint
248 #define INITIALIZE(x)	((x) = 0)
249 #endif /* defined GNUC_or_lint */
250 #ifndef GNUC_or_lint
251 #define INITIALIZE(x)
252 #endif /* !defined GNUC_or_lint */
253 #endif /* !defined INITIALIZE */
254 
255 /*
256 ** For the benefit of GNU folk...
257 ** `_(MSGID)' uses the current locale's message library string for MSGID.
258 ** The default is to use gettext if available, and use MSGID otherwise.
259 */
260 
261 #ifndef _
262 #if HAVE_GETTEXT
263 #define _(msgid) gettext(msgid)
264 #else /* !HAVE_GETTEXT */
265 #define _(msgid) msgid
266 #endif /* !HAVE_GETTEXT */
267 #endif /* !defined _ */
268 
269 #ifndef TZ_DOMAIN
270 #define TZ_DOMAIN "tz"
271 #endif /* !defined TZ_DOMAIN */
272 
273 #if HAVE_INCOMPATIBLE_CTIME_R
274 #undef asctime_r
275 #undef ctime_r
276 char *asctime_r(struct tm const *, char *);
277 char *ctime_r(time_t const *, char *);
278 #endif /* HAVE_INCOMPATIBLE_CTIME_R */
279 
280 #ifndef YEARSPERREPEAT
281 #define YEARSPERREPEAT		400	/* years before a Gregorian repeat */
282 #endif /* !defined YEARSPERREPEAT */
283 
284 /*
285 ** The Gregorian year averages 365.2425 days, which is 31556952 seconds.
286 */
287 
288 #ifndef AVGSECSPERYEAR
289 #define AVGSECSPERYEAR		31556952L
290 #endif /* !defined AVGSECSPERYEAR */
291 
292 #ifndef SECSPERREPEAT
293 #define SECSPERREPEAT		((int_fast64_t) YEARSPERREPEAT * (int_fast64_t) AVGSECSPERYEAR)
294 #endif /* !defined SECSPERREPEAT */
295 
296 #ifndef SECSPERREPEAT_BITS
297 #define SECSPERREPEAT_BITS	34	/* ceil(log2(SECSPERREPEAT)) */
298 #endif /* !defined SECSPERREPEAT_BITS */
299 
300 /*
301 ** UNIX was a registered trademark of The Open Group in 2003.
302 */
303 
304 #endif /* !defined PRIVATE_H */
305