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