zic(8) & libc/stdtime: Reduce #ifdefs a bit.
[dragonfly.git] / lib / libc / stdtime / private.h
1 /*
2  * @(#)private.h        8.6
3  * $FreeBSD: src/lib/libc/stdtime/private.h,v 1.6.8.1 2000/08/23 00:19:15 jhb Exp $
4  * $DragonFly: src/lib/libc/stdtime/private.h,v 1.3 2008/10/19 20:15:58 swildner Exp $
5  */
6
7 #ifndef PRIVATE_H
8
9 #define PRIVATE_H
10 /*
11 ** This file is in the public domain, so clarified as of
12 ** 1996-06-05 by Arthur David Olson.
13 */
14
15 /* Stuff moved from Makefile.inc to reduce clutter */
16 #ifndef TM_GMTOFF
17 #define TM_GMTOFF       tm_gmtoff
18 #define TM_ZONE         tm_zone
19 #define PCTS            1
20 #define TZDIR           "/usr/share/zoneinfo"
21 #endif /* ndef TM_GMTOFF */
22
23 /*
24 ** This header is for use ONLY with the time conversion code.
25 ** There is no guarantee that it will remain unchanged,
26 ** or that it will remain at all.
27 ** Do NOT copy it to any system include directory.
28 ** Thank you!
29 */
30
31 #define GRANDPARENTED   "Local time zone must be set--see zic manual page"
32
33 /*
34 ** Nested includes
35 */
36
37 #include "sys/types.h"  /* for time_t */
38 #include "stdio.h"
39 #include "errno.h"
40 #include "string.h"
41 #include "limits.h"     /* for CHAR_BIT et al. */
42 #include "time.h"
43 #include "stdlib.h"
44
45 #include <sys/wait.h>   /* for WIFEXITED and WEXITSTATUS */
46
47 #ifndef WIFEXITED
48 #define WIFEXITED(status)       (((status) & 0xff) == 0)
49 #endif /* !defined WIFEXITED */
50 #ifndef WEXITSTATUS
51 #define WEXITSTATUS(status)     (((status) >> 8) & 0xff)
52 #endif /* !defined WEXITSTATUS */
53
54 #include "unistd.h"     /* for F_OK, R_OK, and other POSIX goodness */
55
56 #ifndef F_OK
57 #define F_OK    0
58 #endif /* !defined F_OK */
59 #ifndef R_OK
60 #define R_OK    4
61 #endif /* !defined R_OK */
62
63 /* Unlike <ctype.h>'s isdigit, this also works if c < 0 | c > UCHAR_MAX. */
64 #define is_digit(c) ((unsigned)(c) - '0' <= 9)
65
66 #include "stdint.h"
67
68 /*
69 ** Workarounds for compilers/systems.
70 */
71
72 /*
73 ** Some time.h implementations don't declare asctime_r.
74 ** Others might define it as a macro.
75 ** Fix the former without affecting the latter.
76 */
77
78 #ifndef asctime_r
79 extern char *   asctime_r(struct tm const *, char *);
80 #endif
81
82 /*
83 ** Private function declarations.
84 */
85
86 char *          icalloc(int nelem, int elsize);
87 char *          icatalloc(char * old, const char * new);
88 char *          icpyalloc(const char * string);
89 char *          imalloc(int n);
90 void *          irealloc(void * pointer, int size);
91 void            icfree(char * pointer);
92 void            ifree(char * pointer);
93 const char *    scheck(const char * string, const char * format);
94
95 /*
96 ** Finally, some convenience items.
97 */
98
99 #ifndef TRUE
100 #define TRUE    1
101 #endif /* !defined TRUE */
102
103 #ifndef FALSE
104 #define FALSE   0
105 #endif /* !defined FALSE */
106
107 #ifndef TYPE_BIT
108 #define TYPE_BIT(type)  (sizeof (type) * CHAR_BIT)
109 #endif /* !defined TYPE_BIT */
110
111 #ifndef TYPE_SIGNED
112 #define TYPE_SIGNED(type) (((type) -1) < 0)
113 #endif /* !defined TYPE_SIGNED */
114
115 /*
116 ** Since the definition of TYPE_INTEGRAL contains floating point numbers,
117 ** it cannot be used in preprocessor directives.
118 */
119
120 #ifndef TYPE_INTEGRAL
121 #define TYPE_INTEGRAL(type) (((type) 0.5) != 0.5)
122 #endif /* !defined TYPE_INTEGRAL */
123
124 #ifndef INT_STRLEN_MAXIMUM
125 /*
126 ** 302 / 1000 is log10(2.0) rounded up.
127 ** Subtract one for the sign bit if the type is signed;
128 ** add one for integer division truncation;
129 ** add one more for a minus sign if the type is signed.
130 */
131 #define INT_STRLEN_MAXIMUM(type) \
132         ((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + \
133         1 + TYPE_SIGNED(type))
134 #endif /* !defined INT_STRLEN_MAXIMUM */
135
136 /*
137 ** INITIALIZE(x)
138 */
139
140 #ifndef GNUC_or_lint
141 #ifdef lint
142 #define GNUC_or_lint
143 #endif /* defined lint */
144 #ifndef lint
145 #ifdef __GNUC__
146 #define GNUC_or_lint
147 #endif /* defined __GNUC__ */
148 #endif /* !defined lint */
149 #endif /* !defined GNUC_or_lint */
150
151 #ifndef INITIALIZE
152 #ifdef GNUC_or_lint
153 #define INITIALIZE(x)   ((x) = 0)
154 #endif /* defined GNUC_or_lint */
155 #ifndef GNUC_or_lint
156 #define INITIALIZE(x)
157 #endif /* !defined GNUC_or_lint */
158 #endif /* !defined INITIALIZE */
159
160 /*
161 ** For the benefit of GNU folk...
162 ** `_(MSGID)' uses the current locale's message library string for MSGID.
163 ** The default is to use gettext if available, and use MSGID otherwise.
164 */
165
166 #ifndef _
167 #define _(msgid) msgid
168 #endif /* !defined _ */
169
170 #ifndef TZ_DOMAIN
171 #define TZ_DOMAIN "tz"
172 #endif /* !defined TZ_DOMAIN */
173
174 #ifndef YEARSPERREPEAT
175 #define YEARSPERREPEAT          400     /* years before a Gregorian repeat */
176 #endif /* !defined YEARSPERREPEAT */
177
178 /*
179 ** The Gregorian year averages 365.2425 days, which is 31556952 seconds.
180 */
181
182 #ifndef AVGSECSPERYEAR
183 #define AVGSECSPERYEAR          31556952L
184 #endif /* !defined AVGSECSPERYEAR */
185
186 #ifndef SECSPERREPEAT
187 #define SECSPERREPEAT           ((int_fast64_t) YEARSPERREPEAT * (int_fast64_t) AVGSECSPERYEAR)
188 #endif /* !defined SECSPERREPEAT */
189
190 #ifndef SECSPERREPEAT_BITS
191 #define SECSPERREPEAT_BITS      34      /* ceil(log2(SECSPERREPEAT)) */
192 #endif /* !defined SECSPERREPEAT_BITS */
193
194 /*
195 ** UNIX was a registered trademark of The Open Group in 2003.
196 */
197
198 #endif /* !defined PRIVATE_H */