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