blob: e82a655764abbbcecf0673b6b78a8ab022dcd54b [file] [log] [blame]
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08001#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
10/*
11** This header is for use ONLY with the time conversion code.
12** There is no guarantee that it will remain unchanged,
13** or that it will remain at all.
14** Do NOT copy it to any system include directory.
15** Thank you!
16*/
17
18/*
19** ID
20*/
21
22#ifndef lint
23#ifndef NOID
The Android Open Source Projectedbe7fc2009-03-18 22:20:24 -070024static char privatehid[] = "@(#)private.h 8.2";
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080025#endif /* !defined NOID */
26#endif /* !defined lint */
27
The Android Open Source Projectedbe7fc2009-03-18 22:20:24 -070028#define GRANDPARENTED "Local time zone must be set--see zic manual page"
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080029
30/*
31** Defaults for preprocessor symbols.
32** You can override these in your C compiler options, e.g. `-DHAVE_ADJTIME=0'.
33*/
34
35#ifndef HAVE_ADJTIME
The Android Open Source Projectedbe7fc2009-03-18 22:20:24 -070036#define HAVE_ADJTIME 1
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080037#endif /* !defined HAVE_ADJTIME */
38
39#ifndef HAVE_GETTEXT
The Android Open Source Projectedbe7fc2009-03-18 22:20:24 -070040#define HAVE_GETTEXT 0
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080041#endif /* !defined HAVE_GETTEXT */
42
43#ifndef HAVE_INCOMPATIBLE_CTIME_R
The Android Open Source Projectedbe7fc2009-03-18 22:20:24 -070044#define HAVE_INCOMPATIBLE_CTIME_R 0
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080045#endif /* !defined INCOMPATIBLE_CTIME_R */
46
47#ifndef HAVE_SETTIMEOFDAY
The Android Open Source Projectedbe7fc2009-03-18 22:20:24 -070048#define HAVE_SETTIMEOFDAY 3
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080049#endif /* !defined HAVE_SETTIMEOFDAY */
50
51#ifndef HAVE_STRERROR
The Android Open Source Projectedbe7fc2009-03-18 22:20:24 -070052#define HAVE_STRERROR 1
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080053#endif /* !defined HAVE_STRERROR */
54
55#ifndef HAVE_SYMLINK
The Android Open Source Projectedbe7fc2009-03-18 22:20:24 -070056#define HAVE_SYMLINK 1
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080057#endif /* !defined HAVE_SYMLINK */
58
59#ifndef HAVE_SYS_STAT_H
The Android Open Source Projectedbe7fc2009-03-18 22:20:24 -070060#define HAVE_SYS_STAT_H 1
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080061#endif /* !defined HAVE_SYS_STAT_H */
62
63#ifndef HAVE_SYS_WAIT_H
The Android Open Source Projectedbe7fc2009-03-18 22:20:24 -070064#define HAVE_SYS_WAIT_H 1
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080065#endif /* !defined HAVE_SYS_WAIT_H */
66
67#ifndef HAVE_UNISTD_H
The Android Open Source Projectedbe7fc2009-03-18 22:20:24 -070068#define HAVE_UNISTD_H 1
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080069#endif /* !defined HAVE_UNISTD_H */
70
71#ifndef HAVE_UTMPX_H
The Android Open Source Projectedbe7fc2009-03-18 22:20:24 -070072#define HAVE_UTMPX_H 0
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080073#endif /* !defined HAVE_UTMPX_H */
74
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080075#if HAVE_INCOMPATIBLE_CTIME_R
76#define asctime_r _incompatible_asctime_r
77#define ctime_r _incompatible_ctime_r
78#endif /* HAVE_INCOMPATIBLE_CTIME_R */
79
80/*
81** Nested includes
82*/
83
The Android Open Source Projectedbe7fc2009-03-18 22:20:24 -070084#include "sys/types.h" /* for time_t */
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080085#include "stdio.h"
86#include "errno.h"
87#include "string.h"
The Android Open Source Projectedbe7fc2009-03-18 22:20:24 -070088#include "limits.h" /* for CHAR_BIT et al. */
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080089#include "time.h"
90#include "stdlib.h"
91
92#if HAVE_GETTEXT
93#include "libintl.h"
94#endif /* HAVE_GETTEXT */
95
96#if HAVE_SYS_WAIT_H
The Android Open Source Projectedbe7fc2009-03-18 22:20:24 -070097#include <sys/wait.h> /* for WIFEXITED and WEXITSTATUS */
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080098#endif /* HAVE_SYS_WAIT_H */
99
100#ifndef WIFEXITED
The Android Open Source Projectedbe7fc2009-03-18 22:20:24 -0700101#define WIFEXITED(status) (((status) & 0xff) == 0)
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800102#endif /* !defined WIFEXITED */
103#ifndef WEXITSTATUS
The Android Open Source Projectedbe7fc2009-03-18 22:20:24 -0700104#define WEXITSTATUS(status) (((status) >> 8) & 0xff)
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800105#endif /* !defined WEXITSTATUS */
106
107#if HAVE_UNISTD_H
The Android Open Source Projectedbe7fc2009-03-18 22:20:24 -0700108#include "unistd.h" /* for F_OK and R_OK */
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800109#endif /* HAVE_UNISTD_H */
110
111#if !HAVE_UNISTD_H
112#ifndef F_OK
The Android Open Source Projectedbe7fc2009-03-18 22:20:24 -0700113#define F_OK 0
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800114#endif /* !defined F_OK */
115#ifndef R_OK
The Android Open Source Projectedbe7fc2009-03-18 22:20:24 -0700116#define R_OK 4
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800117#endif /* !defined R_OK */
118#endif /* !HAVE_UNISTD_H */
119
120/* Unlike <ctype.h>'s isdigit, this also works if c < 0 | c > UCHAR_MAX. */
121#define is_digit(c) ((unsigned)(c) - '0' <= 9)
122
123/*
124** Define HAVE_STDINT_H's default value here, rather than at the
125** start, since __GLIBC__'s value depends on previously-included
126** files.
127** (glibc 2.1 and later have stdint.h, even with pre-C99 compilers.)
128*/
129#ifndef HAVE_STDINT_H
130#define HAVE_STDINT_H \
The Android Open Source Projectedbe7fc2009-03-18 22:20:24 -0700131 (199901 <= __STDC_VERSION__ || \
132 2 < (__GLIBC__ + (0 < __GLIBC_MINOR__)))
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800133#endif /* !defined HAVE_STDINT_H */
134
135#if HAVE_STDINT_H
136#include "stdint.h"
137#endif /* !HAVE_STDINT_H */
138
139#ifndef INT_FAST64_MAX
140/* Pre-C99 GCC compilers define __LONG_LONG_MAX__ instead of LLONG_MAX. */
141#if defined LLONG_MAX || defined __LONG_LONG_MAX__
The Android Open Source Projectedbe7fc2009-03-18 22:20:24 -0700142typedef long long int_fast64_t;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800143#else /* ! (defined LLONG_MAX || defined __LONG_LONG_MAX__) */
144#if (LONG_MAX >> 31) < 0xffffffff
145Please use a compiler that supports a 64-bit integer type (or wider);
146you may need to compile with "-DHAVE_STDINT_H".
147#endif /* (LONG_MAX >> 31) < 0xffffffff */
The Android Open Source Projectedbe7fc2009-03-18 22:20:24 -0700148typedef long int_fast64_t;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800149#endif /* ! (defined LLONG_MAX || defined __LONG_LONG_MAX__) */
150#endif /* !defined INT_FAST64_MAX */
151
152#ifndef INT32_MAX
153#define INT32_MAX 0x7fffffff
154#endif /* !defined INT32_MAX */
155#ifndef INT32_MIN
156#define INT32_MIN (-1 - INT32_MAX)
157#endif /* !defined INT32_MIN */
158
159/*
160** Workarounds for compilers/systems.
161*/
162
163/*
164** If your compiler lacks prototypes, "#define P(x) ()".
165*/
166
167#ifndef P
The Android Open Source Projectedbe7fc2009-03-18 22:20:24 -0700168#define P(x) x
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800169#endif /* !defined P */
170
171/*
172** SunOS 4.1.1 headers lack EXIT_SUCCESS.
173*/
174
175#ifndef EXIT_SUCCESS
The Android Open Source Projectedbe7fc2009-03-18 22:20:24 -0700176#define EXIT_SUCCESS 0
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800177#endif /* !defined EXIT_SUCCESS */
178
179/*
180** SunOS 4.1.1 headers lack EXIT_FAILURE.
181*/
182
183#ifndef EXIT_FAILURE
The Android Open Source Projectedbe7fc2009-03-18 22:20:24 -0700184#define EXIT_FAILURE 1
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800185#endif /* !defined EXIT_FAILURE */
186
187/*
188** SunOS 4.1.1 headers lack FILENAME_MAX.
189*/
190
191#ifndef FILENAME_MAX
192
193#ifndef MAXPATHLEN
194#ifdef unix
195#include "sys/param.h"
196#endif /* defined unix */
197#endif /* !defined MAXPATHLEN */
198
199#ifdef MAXPATHLEN
The Android Open Source Projectedbe7fc2009-03-18 22:20:24 -0700200#define FILENAME_MAX MAXPATHLEN
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800201#endif /* defined MAXPATHLEN */
202#ifndef MAXPATHLEN
The Android Open Source Projectedbe7fc2009-03-18 22:20:24 -0700203#define FILENAME_MAX 1024 /* Pure guesswork */
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800204#endif /* !defined MAXPATHLEN */
205
206#endif /* !defined FILENAME_MAX */
207
208/*
209** SunOS 4.1.1 libraries lack remove.
210*/
211
212#ifndef remove
The Android Open Source Projectedbe7fc2009-03-18 22:20:24 -0700213extern int unlink P((const char * filename));
214#define remove unlink
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800215#endif /* !defined remove */
216
217/*
218** Some ancient errno.h implementations don't declare errno.
219** But some newer errno.h implementations define it as a macro.
220** Fix the former without affecting the latter.
221*/
222
223#ifndef errno
224extern int errno;
225#endif /* !defined errno */
226
227/*
228** Some time.h implementations don't declare asctime_r.
229** Others might define it as a macro.
230** Fix the former without affecting the latter.
231*/
232
233#ifndef asctime_r
The Android Open Source Projectedbe7fc2009-03-18 22:20:24 -0700234extern char * asctime_r();
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800235#endif
236
237/*
238** Private function declarations.
239*/
240
The Android Open Source Projectedbe7fc2009-03-18 22:20:24 -0700241char * icalloc P((int nelem, int elsize));
242char * icatalloc P((char * old, const char * new));
243char * icpyalloc P((const char * string));
244char * imalloc P((int n));
245void * irealloc P((void * pointer, int size));
246void icfree P((char * pointer));
247void ifree P((char * pointer));
248const char * scheck P((const char * string, const char * format));
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800249
250/*
251** Finally, some convenience items.
252*/
253
254#ifndef TRUE
The Android Open Source Projectedbe7fc2009-03-18 22:20:24 -0700255#define TRUE 1
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800256#endif /* !defined TRUE */
257
258#ifndef FALSE
The Android Open Source Projectedbe7fc2009-03-18 22:20:24 -0700259#define FALSE 0
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800260#endif /* !defined FALSE */
261
262#ifndef TYPE_BIT
The Android Open Source Projectedbe7fc2009-03-18 22:20:24 -0700263#define TYPE_BIT(type) (sizeof (type) * CHAR_BIT)
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800264#endif /* !defined TYPE_BIT */
265
266#ifndef TYPE_SIGNED
267#define TYPE_SIGNED(type) (((type) -1) < 0)
268#endif /* !defined TYPE_SIGNED */
269
270/*
271** Since the definition of TYPE_INTEGRAL contains floating point numbers,
272** it cannot be used in preprocessor directives.
273*/
274
275#ifndef TYPE_INTEGRAL
276#define TYPE_INTEGRAL(type) (((type) 0.5) != 0.5)
277#endif /* !defined TYPE_INTEGRAL */
278
279#ifndef INT_STRLEN_MAXIMUM
280/*
281** 302 / 1000 is log10(2.0) rounded up.
282** Subtract one for the sign bit if the type is signed;
283** add one for integer division truncation;
284** add one more for a minus sign if the type is signed.
285*/
286#define INT_STRLEN_MAXIMUM(type) \
The Android Open Source Projectedbe7fc2009-03-18 22:20:24 -0700287 ((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + \
288 1 + TYPE_SIGNED(type))
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800289#endif /* !defined INT_STRLEN_MAXIMUM */
290
291/*
292** INITIALIZE(x)
293*/
294
295#ifndef GNUC_or_lint
296#ifdef lint
297#define GNUC_or_lint
298#endif /* defined lint */
299#ifndef lint
300#ifdef __GNUC__
301#define GNUC_or_lint
302#endif /* defined __GNUC__ */
303#endif /* !defined lint */
304#endif /* !defined GNUC_or_lint */
305
306#ifndef INITIALIZE
307#ifdef GNUC_or_lint
The Android Open Source Projectedbe7fc2009-03-18 22:20:24 -0700308#define INITIALIZE(x) ((x) = 0)
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800309#endif /* defined GNUC_or_lint */
310#ifndef GNUC_or_lint
311#define INITIALIZE(x)
312#endif /* !defined GNUC_or_lint */
313#endif /* !defined INITIALIZE */
314
315/*
316** For the benefit of GNU folk...
317** `_(MSGID)' uses the current locale's message library string for MSGID.
318** The default is to use gettext if available, and use MSGID otherwise.
319*/
320
321#ifndef _
322#if HAVE_GETTEXT
323#define _(msgid) gettext(msgid)
324#else /* !HAVE_GETTEXT */
325#define _(msgid) msgid
326#endif /* !HAVE_GETTEXT */
327#endif /* !defined _ */
328
329#ifndef TZ_DOMAIN
330#define TZ_DOMAIN "tz"
331#endif /* !defined TZ_DOMAIN */
332
333#if HAVE_INCOMPATIBLE_CTIME_R
334#undef asctime_r
335#undef ctime_r
336char *asctime_r P((struct tm const *, char *));
337char *ctime_r P((time_t const *, char *));
338#endif /* HAVE_INCOMPATIBLE_CTIME_R */
339
340#ifndef YEARSPERREPEAT
The Android Open Source Projectedbe7fc2009-03-18 22:20:24 -0700341#define YEARSPERREPEAT 400 /* years before a Gregorian repeat */
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800342#endif /* !defined YEARSPERREPEAT */
343
344/*
345** The Gregorian year averages 365.2425 days, which is 31556952 seconds.
346*/
347
348#ifndef AVGSECSPERYEAR
The Android Open Source Projectedbe7fc2009-03-18 22:20:24 -0700349#define AVGSECSPERYEAR 31556952L
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800350#endif /* !defined AVGSECSPERYEAR */
351
352#ifndef SECSPERREPEAT
The Android Open Source Projectedbe7fc2009-03-18 22:20:24 -0700353#define SECSPERREPEAT ((int_fast64_t) YEARSPERREPEAT * (int_fast64_t) AVGSECSPERYEAR)
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800354#endif /* !defined SECSPERREPEAT */
355
356#ifndef SECSPERREPEAT_BITS
The Android Open Source Projectedbe7fc2009-03-18 22:20:24 -0700357#define SECSPERREPEAT_BITS 34 /* ceil(log2(SECSPERREPEAT)) */
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800358#endif /* !defined SECSPERREPEAT_BITS */
359
360/*
361** UNIX was a registered trademark of The Open Group in 2003.
362*/
363
364#endif /* !defined PRIVATE_H */