kernel, libc: signals fixes
[minix.git] / lib / libc / time / private.h
blobe493831a234702a3640d18bfa5ea48277e0a4c7c
1 /* $NetBSD: private.h,v 1.26 2012/08/09 12:38:25 christos Exp $ */
3 #ifndef PRIVATE_H
4 #define PRIVATE_H
6 /* NetBSD defaults */
7 #define TM_GMTOFF tm_gmtoff
8 #define TM_ZONE tm_zone
9 #define STD_INSPIRED 1
10 #define HAVE_LONG_DOUBLE 1
12 /* For when we build zic as a host tool. */
13 #if HAVE_NBTOOL_CONFIG_H
14 #include "nbtool_config.h"
15 #endif
18 ** This file is in the public domain, so clarified as of
19 ** 1996-06-05 by Arthur David Olson.
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!
30 #define GRANDPARENTED "Local time zone must be set--see zic manual page"
33 ** Defaults for preprocessor symbols.
34 ** You can override these in your C compiler options, e.g. `-DHAVE_ADJTIME=0'.
37 #ifndef HAVE_ADJTIME
38 #define HAVE_ADJTIME 1
39 #endif /* !defined HAVE_ADJTIME */
41 #ifndef HAVE_GETTEXT
42 #define HAVE_GETTEXT 0
43 #endif /* !defined HAVE_GETTEXT */
45 #ifndef HAVE_INCOMPATIBLE_CTIME_R
46 #define HAVE_INCOMPATIBLE_CTIME_R 0
47 #endif /* !defined INCOMPATIBLE_CTIME_R */
49 #ifndef HAVE_SETTIMEOFDAY
50 #define HAVE_SETTIMEOFDAY 3
51 #endif /* !defined HAVE_SETTIMEOFDAY */
53 #ifndef HAVE_SYMLINK
54 #define HAVE_SYMLINK 1
55 #endif /* !defined HAVE_SYMLINK */
57 #ifndef HAVE_SYS_STAT_H
58 #define HAVE_SYS_STAT_H 1
59 #endif /* !defined HAVE_SYS_STAT_H */
61 #ifndef HAVE_SYS_WAIT_H
62 #define HAVE_SYS_WAIT_H 1
63 #endif /* !defined HAVE_SYS_WAIT_H */
65 #ifndef HAVE_UNISTD_H
66 #define HAVE_UNISTD_H 1
67 #endif /* !defined HAVE_UNISTD_H */
69 #ifndef HAVE_UTMPX_H
70 #define HAVE_UTMPX_H 0
71 #endif /* !defined HAVE_UTMPX_H */
73 #ifdef LOCALE_HOME
74 #undef LOCALE_HOME /* not to be handled by tzcode itself */
75 #endif /* defined LOCALE_HOME */
77 #if HAVE_INCOMPATIBLE_CTIME_R
78 #define asctime_r _incompatible_asctime_r
79 #define ctime_r _incompatible_ctime_r
80 #endif /* HAVE_INCOMPATIBLE_CTIME_R */
83 ** Nested includes
86 #include "sys/types.h" /* for time_t */
87 #include "stdio.h"
88 #include "errno.h"
89 #include "string.h"
90 #include "limits.h" /* for CHAR_BIT et al. */
91 #include "time.h"
92 #include "stdlib.h"
94 #if HAVE_GETTEXT
95 #include "libintl.h"
96 #endif /* HAVE_GETTEXT */
98 #if HAVE_SYS_WAIT_H
99 #include <sys/wait.h> /* for WIFEXITED and WEXITSTATUS */
100 #endif /* HAVE_SYS_WAIT_H */
102 #ifndef WIFEXITED
103 #define WIFEXITED(status) (((status) & 0xff) == 0)
104 #endif /* !defined WIFEXITED */
105 #ifndef WEXITSTATUS
106 #define WEXITSTATUS(status) (((status) >> 8) & 0xff)
107 #endif /* !defined WEXITSTATUS */
109 #if HAVE_UNISTD_H
110 #include "unistd.h" /* for F_OK, R_OK, and other POSIX goodness */
111 #endif /* HAVE_UNISTD_H */
113 #ifndef F_OK
114 #define F_OK 0
115 #endif /* !defined F_OK */
116 #ifndef R_OK
117 #define R_OK 4
118 #endif /* !defined R_OK */
120 /* Unlike <ctype.h>'s isdigit, this also works if c < 0 | c > UCHAR_MAX. */
121 #define is_digit(c) ((unsigned)(c) - '0' <= 9)
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.)
129 #ifndef HAVE_STDINT_H
130 #define HAVE_STDINT_H \
131 (199901 <= __STDC_VERSION__ || \
132 2 < (__GLIBC__ + (0 < __GLIBC_MINOR__)))
133 #endif /* !defined HAVE_STDINT_H */
135 #if HAVE_STDINT_H
136 #include "stdint.h"
137 #endif /* !HAVE_STDINT_H */
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__
142 typedef long long int_fast64_t;
143 #else /* ! (defined LLONG_MAX || defined __LONG_LONG_MAX__) */
144 #if (LONG_MAX >> 31) < 0xffffffff
145 Please use a compiler that supports a 64-bit integer type (or wider);
146 you may need to compile with "-DHAVE_STDINT_H".
147 #endif /* (LONG_MAX >> 31) < 0xffffffff */
148 typedef long int_fast64_t;
149 #endif /* ! (defined LLONG_MAX || defined __LONG_LONG_MAX__) */
150 #endif /* !defined INT_FAST64_MAX */
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 */
160 ** Workarounds for compilers/systems.
164 ** Some time.h implementations don't declare asctime_r.
165 ** Others might define it as a macro.
166 ** Fix the former without affecting the latter.
169 #ifndef asctime_r
170 extern char * asctime_r(struct tm const *, char *);
171 #endif
174 ** Private function declarations.
177 char * icalloc(int nelem, int elsize);
178 char * icatalloc(char * old, const char * new);
179 char * icpyalloc(const char * string);
180 char * imalloc(int n);
181 void * irealloc(void * pointer, int size);
182 void icfree(char * pointer);
183 void ifree(char * pointer);
184 const char * scheck(const char * string, const char * format);
187 ** Finally, some convenience items.
190 #ifndef TRUE
191 #define TRUE 1
192 #endif /* !defined TRUE */
194 #ifndef FALSE
195 #define FALSE 0
196 #endif /* !defined FALSE */
198 #ifndef TYPE_BIT
199 #define TYPE_BIT(type) (sizeof (type) * CHAR_BIT)
200 #endif /* !defined TYPE_BIT */
202 #ifndef TYPE_SIGNED
203 #define TYPE_SIGNED(type) (((type) -1) < 0)
204 #endif /* !defined TYPE_SIGNED */
207 ** Since the definition of TYPE_INTEGRAL contains floating point numbers,
208 ** it cannot be used in preprocessor directives.
211 #ifndef TYPE_INTEGRAL
212 #define TYPE_INTEGRAL(type) (((type) 0.5) != 0.5)
213 #endif /* !defined TYPE_INTEGRAL */
215 #ifndef INT_STRLEN_MAXIMUM
217 ** 302 / 1000 is log10(2.0) rounded up.
218 ** Subtract one for the sign bit if the type is signed;
219 ** add one for integer division truncation;
220 ** add one more for a minus sign if the type is signed.
222 #define INT_STRLEN_MAXIMUM(type) \
223 ((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + \
224 1 + TYPE_SIGNED(type))
225 #endif /* !defined INT_STRLEN_MAXIMUM */
228 ** INITIALIZE(x)
231 #ifndef GNUC_or_lint
232 #ifdef lint
233 #define GNUC_or_lint
234 #endif /* defined lint */
235 #ifndef lint
236 #ifdef __GNUC__
237 #define GNUC_or_lint
238 #endif /* defined __GNUC__ */
239 #endif /* !defined lint */
240 #endif /* !defined GNUC_or_lint */
242 #ifndef INITIALIZE
243 #ifdef GNUC_or_lint
244 #define INITIALIZE(x) ((x) = 0)
245 #endif /* defined GNUC_or_lint */
246 #ifndef GNUC_or_lint
247 #define INITIALIZE(x)
248 #endif /* !defined GNUC_or_lint */
249 #endif /* !defined INITIALIZE */
252 ** For the benefit of GNU folk...
253 ** `_(MSGID)' uses the current locale's message library string for MSGID.
254 ** The default is to use gettext if available, and use MSGID otherwise.
257 #ifndef _
258 #if HAVE_GETTEXT
259 #define _(msgid) gettext(msgid)
260 #else /* !HAVE_GETTEXT */
261 #define _(msgid) msgid
262 #endif /* !HAVE_GETTEXT */
263 #endif /* !defined _ */
265 #ifndef TZ_DOMAIN
266 #define TZ_DOMAIN "tz"
267 #endif /* !defined TZ_DOMAIN */
269 #if HAVE_INCOMPATIBLE_CTIME_R
270 #undef asctime_r
271 #undef ctime_r
272 char *asctime_r(struct tm const *, char *);
273 char *ctime_r(time_t const *, char *);
274 #endif /* HAVE_INCOMPATIBLE_CTIME_R */
276 #ifndef YEARSPERREPEAT
277 #define YEARSPERREPEAT 400 /* years before a Gregorian repeat */
278 #endif /* !defined YEARSPERREPEAT */
281 ** The Gregorian year averages 365.2425 days, which is 31556952 seconds.
284 #ifndef AVGSECSPERYEAR
285 #define AVGSECSPERYEAR 31556952L
286 #endif /* !defined AVGSECSPERYEAR */
288 #ifndef SECSPERREPEAT
289 #define SECSPERREPEAT ((int_fast64_t) YEARSPERREPEAT * (int_fast64_t) AVGSECSPERYEAR)
290 #endif /* !defined SECSPERREPEAT */
292 #ifndef SECSPERREPEAT_BITS
293 #define SECSPERREPEAT_BITS 34 /* ceil(log2(SECSPERREPEAT)) */
294 #endif /* !defined SECSPERREPEAT_BITS */
297 ** UNIX was a registered trademark of The Open Group in 2003.
300 #endif /* !defined PRIVATE_H */