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