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