private.h revision 1.42 1 1.42 christos /* $NetBSD: private.h,v 1.42 2015/06/22 17:43:23 christos Exp $ */
2 1.2 jtc
3 1.1 jtc #ifndef PRIVATE_H
4 1.1 jtc #define PRIVATE_H
5 1.3 jtc
6 1.3 jtc /* NetBSD defaults */
7 1.3 jtc #define TM_GMTOFF tm_gmtoff
8 1.3 jtc #define TM_ZONE tm_zone
9 1.3 jtc #define STD_INSPIRED 1
10 1.3 jtc #define HAVE_LONG_DOUBLE 1
11 1.21 bjh21
12 1.21 bjh21 /* For when we build zic as a host tool. */
13 1.23 lukem #if HAVE_NBTOOL_CONFIG_H
14 1.23 lukem #include "nbtool_config.h"
15 1.21 bjh21 #endif
16 1.1 jtc
17 1.1 jtc /*
18 1.6 jtc ** This file is in the public domain, so clarified as of
19 1.25 mlelstv ** 1996-06-05 by Arthur David Olson.
20 1.6 jtc */
21 1.6 jtc
22 1.6 jtc /*
23 1.1 jtc ** This header is for use ONLY with the time conversion code.
24 1.1 jtc ** There is no guarantee that it will remain unchanged,
25 1.1 jtc ** or that it will remain at all.
26 1.1 jtc ** Do NOT copy it to any system include directory.
27 1.1 jtc ** Thank you!
28 1.1 jtc */
29 1.1 jtc
30 1.25 mlelstv #define GRANDPARENTED "Local time zone must be set--see zic manual page"
31 1.25 mlelstv
32 1.1 jtc /*
33 1.1 jtc ** Defaults for preprocessor symbols.
34 1.34 christos ** You can override these in your C compiler options, e.g. '-DHAVE_ADJTIME=0'.
35 1.1 jtc */
36 1.1 jtc
37 1.1 jtc #ifndef HAVE_ADJTIME
38 1.1 jtc #define HAVE_ADJTIME 1
39 1.1 jtc #endif /* !defined HAVE_ADJTIME */
40 1.1 jtc
41 1.6 jtc #ifndef HAVE_GETTEXT
42 1.6 jtc #define HAVE_GETTEXT 0
43 1.6 jtc #endif /* !defined HAVE_GETTEXT */
44 1.6 jtc
45 1.17 kleink #ifndef HAVE_INCOMPATIBLE_CTIME_R
46 1.17 kleink #define HAVE_INCOMPATIBLE_CTIME_R 0
47 1.17 kleink #endif /* !defined INCOMPATIBLE_CTIME_R */
48 1.17 kleink
49 1.32 christos #ifndef HAVE_LINK
50 1.32 christos #define HAVE_LINK 1
51 1.32 christos #endif /* !defined HAVE_LINK */
52 1.32 christos
53 1.1 jtc #ifndef HAVE_SETTIMEOFDAY
54 1.1 jtc #define HAVE_SETTIMEOFDAY 3
55 1.1 jtc #endif /* !defined HAVE_SETTIMEOFDAY */
56 1.1 jtc
57 1.40 christos #ifndef HAVE_STRDUP
58 1.40 christos #define HAVE_STRDUP 1
59 1.40 christos #endif
60 1.40 christos
61 1.12 kleink #ifndef HAVE_SYMLINK
62 1.12 kleink #define HAVE_SYMLINK 1
63 1.12 kleink #endif /* !defined HAVE_SYMLINK */
64 1.6 jtc
65 1.20 kleink #ifndef HAVE_SYS_STAT_H
66 1.20 kleink #define HAVE_SYS_STAT_H 1
67 1.20 kleink #endif /* !defined HAVE_SYS_STAT_H */
68 1.20 kleink
69 1.14 kleink #ifndef HAVE_SYS_WAIT_H
70 1.14 kleink #define HAVE_SYS_WAIT_H 1
71 1.14 kleink #endif /* !defined HAVE_SYS_WAIT_H */
72 1.14 kleink
73 1.1 jtc #ifndef HAVE_UNISTD_H
74 1.1 jtc #define HAVE_UNISTD_H 1
75 1.1 jtc #endif /* !defined HAVE_UNISTD_H */
76 1.1 jtc
77 1.5 jtc #ifndef HAVE_UTMPX_H
78 1.5 jtc #define HAVE_UTMPX_H 0
79 1.5 jtc #endif /* !defined HAVE_UTMPX_H */
80 1.5 jtc
81 1.36 christos #ifndef NETBSD_INSPIRED
82 1.36 christos # define NETBSD_INSPIRED 1
83 1.36 christos #endif
84 1.1 jtc
85 1.17 kleink #if HAVE_INCOMPATIBLE_CTIME_R
86 1.17 kleink #define asctime_r _incompatible_asctime_r
87 1.17 kleink #define ctime_r _incompatible_ctime_r
88 1.17 kleink #endif /* HAVE_INCOMPATIBLE_CTIME_R */
89 1.17 kleink
90 1.36 christos /* Enable tm_gmtoff and tm_zone on GNUish systems. */
91 1.36 christos #define _GNU_SOURCE 1
92 1.36 christos /* Fix asctime_r on Solaris 10. */
93 1.36 christos #define _POSIX_PTHREAD_SEMANTICS 1
94 1.36 christos /* Enable strtoimax on Solaris 10. */
95 1.36 christos #define __EXTENSIONS__ 1
96 1.36 christos
97 1.1 jtc /*
98 1.1 jtc ** Nested includes
99 1.1 jtc */
100 1.1 jtc
101 1.36 christos #ifndef __NetBSD__
102 1.36 christos /* Avoid clashes with NetBSD by renaming NetBSD's declarations. */
103 1.36 christos #define localtime_rz sys_localtime_rz
104 1.36 christos #define mktime_z sys_mktime_z
105 1.36 christos #define posix2time_z sys_posix2time_z
106 1.36 christos #define time2posix_z sys_time2posix_z
107 1.36 christos #define timezone_t sys_timezone_t
108 1.36 christos #define tzalloc sys_tzalloc
109 1.36 christos #define tzfree sys_tzfree
110 1.36 christos #include <time.h>
111 1.36 christos #undef localtime_rz
112 1.36 christos #undef mktime_z
113 1.36 christos #undef posix2time_z
114 1.36 christos #undef time2posix_z
115 1.36 christos #undef timezone_t
116 1.36 christos #undef tzalloc
117 1.36 christos #undef tzfree
118 1.36 christos #else
119 1.36 christos #include "time.h"
120 1.36 christos #endif
121 1.36 christos
122 1.1 jtc #include "sys/types.h" /* for time_t */
123 1.1 jtc #include "stdio.h"
124 1.1 jtc #include "string.h"
125 1.25 mlelstv #include "limits.h" /* for CHAR_BIT et al. */
126 1.1 jtc #include "stdlib.h"
127 1.1 jtc
128 1.38 christos #include "errno.h"
129 1.38 christos
130 1.38 christos #ifndef ENAMETOOLONG
131 1.38 christos # define ENAMETOOLONG EINVAL
132 1.38 christos #endif
133 1.38 christos #ifndef EOVERFLOW
134 1.38 christos # define EOVERFLOW EINVAL
135 1.38 christos #endif
136 1.38 christos
137 1.25 mlelstv #if HAVE_GETTEXT
138 1.6 jtc #include "libintl.h"
139 1.25 mlelstv #endif /* HAVE_GETTEXT */
140 1.14 kleink
141 1.25 mlelstv #if HAVE_SYS_WAIT_H
142 1.14 kleink #include <sys/wait.h> /* for WIFEXITED and WEXITSTATUS */
143 1.25 mlelstv #endif /* HAVE_SYS_WAIT_H */
144 1.14 kleink
145 1.14 kleink #ifndef WIFEXITED
146 1.14 kleink #define WIFEXITED(status) (((status) & 0xff) == 0)
147 1.14 kleink #endif /* !defined WIFEXITED */
148 1.14 kleink #ifndef WEXITSTATUS
149 1.14 kleink #define WEXITSTATUS(status) (((status) >> 8) & 0xff)
150 1.14 kleink #endif /* !defined WEXITSTATUS */
151 1.6 jtc
152 1.25 mlelstv #if HAVE_UNISTD_H
153 1.25 mlelstv #include "unistd.h" /* for F_OK, R_OK, and other POSIX goodness */
154 1.25 mlelstv #endif /* HAVE_UNISTD_H */
155 1.1 jtc
156 1.36 christos #ifndef HAVE_STRFTIME_L
157 1.36 christos # if _POSIX_VERSION < 200809
158 1.36 christos # define HAVE_STRFTIME_L 0
159 1.36 christos # else
160 1.36 christos # define HAVE_STRFTIME_L 1
161 1.36 christos # endif
162 1.36 christos #endif
163 1.36 christos
164 1.1 jtc #ifndef F_OK
165 1.1 jtc #define F_OK 0
166 1.1 jtc #endif /* !defined F_OK */
167 1.1 jtc #ifndef R_OK
168 1.1 jtc #define R_OK 4
169 1.1 jtc #endif /* !defined R_OK */
170 1.1 jtc
171 1.25 mlelstv /* Unlike <ctype.h>'s isdigit, this also works if c < 0 | c > UCHAR_MAX. */
172 1.4 jtc #define is_digit(c) ((unsigned)(c) - '0' <= 9)
173 1.4 jtc
174 1.1 jtc /*
175 1.25 mlelstv ** Define HAVE_STDINT_H's default value here, rather than at the
176 1.25 mlelstv ** start, since __GLIBC__'s value depends on previously-included
177 1.25 mlelstv ** files.
178 1.25 mlelstv ** (glibc 2.1 and later have stdint.h, even with pre-C99 compilers.)
179 1.25 mlelstv */
180 1.25 mlelstv #ifndef HAVE_STDINT_H
181 1.25 mlelstv #define HAVE_STDINT_H \
182 1.33 christos (199901 <= __STDC_VERSION__ \
183 1.33 christos || 2 < __GLIBC__ + (1 <= __GLIBC_MINOR__) \
184 1.33 christos || __CYGWIN__)
185 1.25 mlelstv #endif /* !defined HAVE_STDINT_H */
186 1.25 mlelstv
187 1.25 mlelstv #if HAVE_STDINT_H
188 1.25 mlelstv #include "stdint.h"
189 1.25 mlelstv #endif /* !HAVE_STDINT_H */
190 1.25 mlelstv
191 1.29 christos #ifndef HAVE_INTTYPES_H
192 1.29 christos # define HAVE_INTTYPES_H HAVE_STDINT_H
193 1.29 christos #endif
194 1.29 christos #if HAVE_INTTYPES_H
195 1.29 christos # include <inttypes.h>
196 1.29 christos #endif
197 1.29 christos
198 1.36 christos /* Pre-C99 GCC compilers define __LONG_LONG_MAX__ instead of LLONG_MAX. */
199 1.36 christos #ifdef __LONG_LONG_MAX__
200 1.36 christos # ifndef LLONG_MAX
201 1.36 christos # define LLONG_MAX __LONG_LONG_MAX__
202 1.36 christos # endif
203 1.36 christos # ifndef LLONG_MIN
204 1.36 christos # define LLONG_MIN (-1 - LLONG_MAX)
205 1.36 christos # endif
206 1.36 christos #endif
207 1.36 christos
208 1.25 mlelstv #ifndef INT_FAST64_MAX
209 1.36 christos # ifdef LLONG_MAX
210 1.25 mlelstv typedef long long int_fast64_t;
211 1.29 christos # define INT_FAST64_MIN LLONG_MIN
212 1.29 christos # define INT_FAST64_MAX LLONG_MAX
213 1.29 christos # else
214 1.36 christos # if (LONG_MAX >> 31) < 0xffffffff
215 1.25 mlelstv Please use a compiler that supports a 64-bit integer type (or wider);
216 1.25 mlelstv you may need to compile with "-DHAVE_STDINT_H".
217 1.36 christos # endif
218 1.25 mlelstv typedef long int_fast64_t;
219 1.36 christos # define INT_FAST64_MIN LONG_MIN
220 1.36 christos # define INT_FAST64_MAX LONG_MAX
221 1.36 christos # endif
222 1.36 christos #endif
223 1.36 christos
224 1.36 christos #ifndef SCNdFAST64
225 1.36 christos # if INT_FAST64_MAX == LLONG_MAX
226 1.36 christos # define SCNdFAST64 "lld"
227 1.36 christos # else
228 1.36 christos # define SCNdFAST64 "ld"
229 1.36 christos # endif
230 1.36 christos #endif
231 1.25 mlelstv
232 1.29 christos #ifndef INT_FAST32_MAX
233 1.29 christos # if INT_MAX >> 31 == 0
234 1.29 christos typedef long int_fast32_t;
235 1.36 christos # define INT_FAST32_MAX LONG_MAX
236 1.36 christos # define INT_FAST32_MIN LONG_MIN
237 1.29 christos # else
238 1.29 christos typedef int int_fast32_t;
239 1.36 christos # define INT_FAST32_MAX INT_MAX
240 1.36 christos # define INT_FAST32_MIN INT_MIN
241 1.29 christos # endif
242 1.29 christos #endif
243 1.29 christos
244 1.29 christos #ifndef INTMAX_MAX
245 1.36 christos # ifdef LLONG_MAX
246 1.29 christos typedef long long intmax_t;
247 1.30 christos # define strtoimax strtoll
248 1.36 christos # define INTMAX_MAX LLONG_MAX
249 1.36 christos # define INTMAX_MIN LLONG_MIN
250 1.29 christos # else
251 1.29 christos typedef long intmax_t;
252 1.30 christos # define strtoimax strtol
253 1.30 christos # define INTMAX_MAX LONG_MAX
254 1.30 christos # define INTMAX_MIN LONG_MIN
255 1.29 christos # endif
256 1.29 christos #endif
257 1.29 christos
258 1.36 christos #ifndef PRIdMAX
259 1.36 christos # if INTMAX_MAX == LLONG_MAX
260 1.36 christos # define PRIdMAX "lld"
261 1.36 christos # else
262 1.36 christos # define PRIdMAX "ld"
263 1.36 christos # endif
264 1.36 christos #endif
265 1.36 christos
266 1.29 christos #ifndef UINTMAX_MAX
267 1.29 christos # if defined ULLONG_MAX || defined __LONG_LONG_MAX__
268 1.29 christos typedef unsigned long long uintmax_t;
269 1.36 christos # else
270 1.36 christos typedef unsigned long uintmax_t;
271 1.36 christos # endif
272 1.36 christos #endif
273 1.36 christos
274 1.36 christos #ifndef PRIuMAX
275 1.36 christos # if defined ULLONG_MAX || defined __LONG_LONG_MAX__
276 1.29 christos # define PRIuMAX "llu"
277 1.29 christos # else
278 1.29 christos # define PRIuMAX "lu"
279 1.29 christos # endif
280 1.29 christos #endif
281 1.29 christos
282 1.25 mlelstv #ifndef INT32_MAX
283 1.25 mlelstv #define INT32_MAX 0x7fffffff
284 1.25 mlelstv #endif /* !defined INT32_MAX */
285 1.25 mlelstv #ifndef INT32_MIN
286 1.25 mlelstv #define INT32_MIN (-1 - INT32_MAX)
287 1.25 mlelstv #endif /* !defined INT32_MIN */
288 1.1 jtc
289 1.33 christos #ifndef SIZE_MAX
290 1.33 christos #define SIZE_MAX ((size_t) -1)
291 1.33 christos #endif
292 1.33 christos
293 1.29 christos #if 2 < __GNUC__ + (96 <= __GNUC_MINOR__)
294 1.29 christos # define ATTRIBUTE_CONST __attribute__ ((__const__))
295 1.29 christos # define ATTRIBUTE_PURE __attribute__ ((__pure__))
296 1.30 christos # define ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
297 1.27 christos #else
298 1.29 christos # define ATTRIBUTE_CONST /* empty */
299 1.29 christos # define ATTRIBUTE_PURE /* empty */
300 1.30 christos # define ATTRIBUTE_FORMAT(spec) /* empty */
301 1.27 christos #endif
302 1.29 christos
303 1.29 christos #if !defined _Noreturn && __STDC_VERSION__ < 201112
304 1.29 christos # if 2 < __GNUC__ + (8 <= __GNUC_MINOR__)
305 1.29 christos # define _Noreturn __attribute__ ((__noreturn__))
306 1.29 christos # else
307 1.29 christos # define _Noreturn
308 1.29 christos # endif
309 1.29 christos #endif
310 1.29 christos
311 1.29 christos #if __STDC_VERSION__ < 199901 && !defined restrict
312 1.29 christos # define restrict /* empty */
313 1.27 christos #endif
314 1.27 christos
315 1.1 jtc /*
316 1.25 mlelstv ** Workarounds for compilers/systems.
317 1.1 jtc */
318 1.1 jtc
319 1.1 jtc /*
320 1.29 christos ** Compile with -Dtime_tz=T to build the tz package with a private
321 1.29 christos ** time_t type equivalent to T rather than the system-supplied time_t.
322 1.29 christos ** This debugging feature can test unusual design decisions
323 1.29 christos ** (e.g., time_t wider than 'long', or unsigned time_t) even on
324 1.29 christos ** typical platforms.
325 1.29 christos */
326 1.29 christos #ifdef time_tz
327 1.36 christos # ifdef LOCALTIME_IMPLEMENTATION
328 1.29 christos static time_t sys_time(time_t *x) { return time(x); }
329 1.36 christos # endif
330 1.29 christos
331 1.39 christos typedef time_tz tz_time_t;
332 1.39 christos
333 1.29 christos # undef ctime
334 1.29 christos # define ctime tz_ctime
335 1.29 christos # undef ctime_r
336 1.29 christos # define ctime_r tz_ctime_r
337 1.29 christos # undef difftime
338 1.29 christos # define difftime tz_difftime
339 1.29 christos # undef gmtime
340 1.29 christos # define gmtime tz_gmtime
341 1.29 christos # undef gmtime_r
342 1.29 christos # define gmtime_r tz_gmtime_r
343 1.29 christos # undef localtime
344 1.29 christos # define localtime tz_localtime
345 1.29 christos # undef localtime_r
346 1.29 christos # define localtime_r tz_localtime_r
347 1.39 christos # undef localtime_rz
348 1.39 christos # define localtime_rz tz_localtime_rz
349 1.29 christos # undef mktime
350 1.29 christos # define mktime tz_mktime
351 1.39 christos # undef mktime_z
352 1.39 christos # define mktime_z tz_mktime_z
353 1.36 christos # undef offtime
354 1.36 christos # define offtime tz_offtime
355 1.36 christos # undef posix2time
356 1.36 christos # define posix2time tz_posix2time
357 1.39 christos # undef posix2time_z
358 1.39 christos # define posix2time_z tz_posix2time_z
359 1.29 christos # undef time
360 1.29 christos # define time tz_time
361 1.36 christos # undef time2posix
362 1.36 christos # define time2posix tz_time2posix
363 1.39 christos # undef time2posix_z
364 1.39 christos # define time2posix_z tz_time2posix_z
365 1.29 christos # undef time_t
366 1.29 christos # define time_t tz_time_t
367 1.36 christos # undef timegm
368 1.36 christos # define timegm tz_timegm
369 1.36 christos # undef timelocal
370 1.36 christos # define timelocal tz_timelocal
371 1.36 christos # undef timeoff
372 1.36 christos # define timeoff tz_timeoff
373 1.39 christos # undef tzalloc
374 1.39 christos # define tzalloc tz_tzalloc
375 1.39 christos # undef tzfree
376 1.39 christos # define tzfree tz_tzfree
377 1.39 christos # undef tzset
378 1.39 christos # define tzset tz_tzset
379 1.39 christos # undef tzsetwall
380 1.39 christos # define tzsetwall tz_tzsetwall
381 1.29 christos
382 1.29 christos char *ctime(time_t const *);
383 1.29 christos char *ctime_r(time_t const *, char *);
384 1.29 christos double difftime(time_t, time_t);
385 1.29 christos struct tm *gmtime(time_t const *);
386 1.29 christos struct tm *gmtime_r(time_t const *restrict, struct tm *restrict);
387 1.29 christos struct tm *localtime(time_t const *);
388 1.29 christos struct tm *localtime_r(time_t const *restrict, struct tm *restrict);
389 1.29 christos time_t mktime(struct tm *);
390 1.36 christos time_t time(time_t *);
391 1.39 christos void tzset(void);
392 1.36 christos #endif
393 1.29 christos
394 1.36 christos /*
395 1.36 christos ** Some time.h implementations don't declare asctime_r.
396 1.36 christos ** Others might define it as a macro.
397 1.36 christos ** Fix the former without affecting the latter.
398 1.36 christos */
399 1.36 christos
400 1.36 christos #ifndef asctime_r
401 1.36 christos extern char * asctime_r(struct tm const *restrict, char *restrict);
402 1.36 christos #endif
403 1.36 christos
404 1.36 christos /*
405 1.36 christos ** The STD_INSPIRED functions are similar, but most also need
406 1.36 christos ** declarations if time_tz is defined.
407 1.36 christos */
408 1.36 christos
409 1.36 christos #ifdef STD_INSPIRED
410 1.39 christos # if !defined tzsetwall || defined time_tz
411 1.36 christos void tzsetwall(void);
412 1.36 christos # endif
413 1.36 christos # if !defined offtime || defined time_tz
414 1.36 christos struct tm *offtime(time_t const *, long);
415 1.36 christos # endif
416 1.36 christos # if !defined timegm || defined time_tz
417 1.36 christos time_t timegm(struct tm *);
418 1.36 christos # endif
419 1.36 christos # if !defined timelocal || defined time_tz
420 1.36 christos time_t timelocal(struct tm *);
421 1.36 christos # endif
422 1.36 christos # if !defined timeoff || defined time_tz
423 1.36 christos time_t timeoff(struct tm *, long);
424 1.36 christos # endif
425 1.36 christos # if !defined time2posix || defined time_tz
426 1.36 christos time_t time2posix(time_t);
427 1.36 christos # endif
428 1.36 christos # if !defined posix2time || defined time_tz
429 1.36 christos time_t posix2time(time_t);
430 1.36 christos # endif
431 1.36 christos #endif
432 1.36 christos
433 1.36 christos /* Infer TM_ZONE on systems where this information is known, but suppress
434 1.36 christos guessing if NO_TM_ZONE is defined. Similarly for TM_GMTOFF. */
435 1.36 christos #if (defined __GLIBC__ \
436 1.36 christos || defined __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__ \
437 1.36 christos || (defined __APPLE__ && defined __MACH__))
438 1.36 christos # if !defined TM_GMTOFF && !defined NO_TM_GMTOFF
439 1.36 christos # define TM_GMTOFF tm_gmtoff
440 1.36 christos # endif
441 1.36 christos # if !defined TM_ZONE && !defined NO_TM_ZONE
442 1.36 christos # define TM_ZONE tm_zone
443 1.36 christos # endif
444 1.36 christos #endif
445 1.36 christos
446 1.36 christos /*
447 1.36 christos ** Define functions that are ABI compatible with NetBSD but have
448 1.36 christos ** better prototypes. NetBSD 6.1.4 defines a pointer type timezone_t
449 1.36 christos ** and labors under the misconception that 'const timezone_t' is a
450 1.36 christos ** pointer to a constant. This use of 'const' is ineffective, so it
451 1.36 christos ** is not done here. What we call 'struct state' NetBSD calls
452 1.36 christos ** 'struct __state', but this is a private name so it doesn't matter.
453 1.36 christos */
454 1.37 christos #ifndef __NetBSD__
455 1.36 christos #if NETBSD_INSPIRED
456 1.36 christos typedef struct state *timezone_t;
457 1.36 christos struct tm *localtime_rz(timezone_t restrict, time_t const *restrict,
458 1.36 christos struct tm *restrict);
459 1.36 christos time_t mktime_z(timezone_t restrict, struct tm *restrict);
460 1.36 christos timezone_t tzalloc(char const *);
461 1.36 christos void tzfree(timezone_t);
462 1.36 christos # ifdef STD_INSPIRED
463 1.36 christos # if !defined posix2time_z || defined time_tz
464 1.36 christos time_t posix2time_z(timezone_t __restrict, time_t) ATTRIBUTE_PURE;
465 1.36 christos # endif
466 1.36 christos # if !defined time2posix_z || defined time_tz
467 1.36 christos time_t time2posix_z(timezone_t __restrict, time_t) ATTRIBUTE_PURE;
468 1.36 christos # endif
469 1.36 christos # endif
470 1.29 christos #endif
471 1.37 christos #endif
472 1.29 christos
473 1.29 christos /*
474 1.1 jtc ** Finally, some convenience items.
475 1.1 jtc */
476 1.1 jtc
477 1.36 christos #if __STDC_VERSION__ < 199901
478 1.36 christos # define true 1
479 1.36 christos # define false 0
480 1.36 christos # define bool int
481 1.36 christos #else
482 1.36 christos # include <stdbool.h>
483 1.36 christos #endif
484 1.1 jtc
485 1.5 jtc #ifndef TYPE_BIT
486 1.5 jtc #define TYPE_BIT(type) (sizeof (type) * CHAR_BIT)
487 1.5 jtc #endif /* !defined TYPE_BIT */
488 1.5 jtc
489 1.5 jtc #ifndef TYPE_SIGNED
490 1.28 christos #define TYPE_SIGNED(type) (/*CONSTCOND*/((type) -1) < 0)
491 1.5 jtc #endif /* !defined TYPE_SIGNED */
492 1.5 jtc
493 1.41 christos #define TWOS_COMPLEMENT(t) (/*CONSTCOND*/(t) ~ (t) 0 < 0)
494 1.41 christos
495 1.41 christos /* Max and min values of the integer type T, of which only the bottom
496 1.41 christos B bits are used, and where the highest-order used bit is considered
497 1.41 christos to be a sign bit if T is signed. */
498 1.41 christos #define MAXVAL(t, b) /*LINTED*/ \
499 1.41 christos ((t) (((t) 1 << ((b) - 1 - TYPE_SIGNED(t))) \
500 1.41 christos - 1 + ((t) 1 << ((b) - 1 - TYPE_SIGNED(t)))))
501 1.41 christos #define MINVAL(t, b) \
502 1.41 christos ((t) (TYPE_SIGNED(t) ? - TWOS_COMPLEMENT(t) - MAXVAL(t, b) : 0))
503 1.41 christos
504 1.42 christos #ifdef LOCALTIME_IMPLEMENTATION
505 1.41 christos /* The minimum and maximum finite time values. This assumes no padding. */
506 1.41 christos static time_t const time_t_min = MINVAL(time_t, TYPE_BIT(time_t));
507 1.41 christos static time_t const time_t_max = MAXVAL(time_t, TYPE_BIT(time_t));
508 1.42 christos #endif
509 1.36 christos
510 1.1 jtc #ifndef INT_STRLEN_MAXIMUM
511 1.1 jtc /*
512 1.1 jtc ** 302 / 1000 is log10(2.0) rounded up.
513 1.5 jtc ** Subtract one for the sign bit if the type is signed;
514 1.5 jtc ** add one for integer division truncation;
515 1.5 jtc ** add one more for a minus sign if the type is signed.
516 1.1 jtc */
517 1.1 jtc #define INT_STRLEN_MAXIMUM(type) \
518 1.25 mlelstv ((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + \
519 1.25 mlelstv 1 + TYPE_SIGNED(type))
520 1.1 jtc #endif /* !defined INT_STRLEN_MAXIMUM */
521 1.1 jtc
522 1.1 jtc /*
523 1.1 jtc ** INITIALIZE(x)
524 1.1 jtc */
525 1.1 jtc
526 1.35 christos #if defined(__GNUC__) || defined(__lint__)
527 1.34 christos # define INITIALIZE(x) ((x) = 0)
528 1.34 christos #else
529 1.34 christos # define INITIALIZE(x)
530 1.34 christos #endif
531 1.6 jtc
532 1.36 christos #ifndef UNINIT_TRAP
533 1.36 christos # define UNINIT_TRAP 0
534 1.36 christos #endif
535 1.36 christos
536 1.6 jtc /*
537 1.6 jtc ** For the benefit of GNU folk...
538 1.34 christos ** '_(MSGID)' uses the current locale's message library string for MSGID.
539 1.6 jtc ** The default is to use gettext if available, and use MSGID otherwise.
540 1.6 jtc */
541 1.6 jtc
542 1.6 jtc #ifndef _
543 1.25 mlelstv #if HAVE_GETTEXT
544 1.6 jtc #define _(msgid) gettext(msgid)
545 1.25 mlelstv #else /* !HAVE_GETTEXT */
546 1.6 jtc #define _(msgid) msgid
547 1.25 mlelstv #endif /* !HAVE_GETTEXT */
548 1.6 jtc #endif /* !defined _ */
549 1.6 jtc
550 1.34 christos #if !defined TZ_DOMAIN && defined HAVE_GETTEXT
551 1.34 christos # define TZ_DOMAIN "tz"
552 1.34 christos #endif
553 1.17 kleink
554 1.17 kleink #if HAVE_INCOMPATIBLE_CTIME_R
555 1.17 kleink #undef asctime_r
556 1.17 kleink #undef ctime_r
557 1.25 mlelstv char *asctime_r(struct tm const *, char *);
558 1.25 mlelstv char *ctime_r(time_t const *, char *);
559 1.17 kleink #endif /* HAVE_INCOMPATIBLE_CTIME_R */
560 1.1 jtc
561 1.25 mlelstv #ifndef YEARSPERREPEAT
562 1.25 mlelstv #define YEARSPERREPEAT 400 /* years before a Gregorian repeat */
563 1.25 mlelstv #endif /* !defined YEARSPERREPEAT */
564 1.25 mlelstv
565 1.25 mlelstv /*
566 1.25 mlelstv ** The Gregorian year averages 365.2425 days, which is 31556952 seconds.
567 1.25 mlelstv */
568 1.25 mlelstv
569 1.25 mlelstv #ifndef AVGSECSPERYEAR
570 1.25 mlelstv #define AVGSECSPERYEAR 31556952L
571 1.25 mlelstv #endif /* !defined AVGSECSPERYEAR */
572 1.25 mlelstv
573 1.25 mlelstv #ifndef SECSPERREPEAT
574 1.25 mlelstv #define SECSPERREPEAT ((int_fast64_t) YEARSPERREPEAT * (int_fast64_t) AVGSECSPERYEAR)
575 1.25 mlelstv #endif /* !defined SECSPERREPEAT */
576 1.25 mlelstv
577 1.25 mlelstv #ifndef SECSPERREPEAT_BITS
578 1.25 mlelstv #define SECSPERREPEAT_BITS 34 /* ceil(log2(SECSPERREPEAT)) */
579 1.25 mlelstv #endif /* !defined SECSPERREPEAT_BITS */
580 1.25 mlelstv
581 1.1 jtc #endif /* !defined PRIVATE_H */
582