1 /* $NetBSD: private.h,v 1.44 2015/10/09 17:21:45 christos Exp $ */
7 #define TM_GMTOFF tm_gmtoff
8 #define TM_ZONE tm_zone
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"
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.
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_GETTEXT=1'.
38 #define HAVE_GETTEXT 0
39 #endif /* !defined HAVE_GETTEXT */
41 #ifndef HAVE_INCOMPATIBLE_CTIME_R
42 #define HAVE_INCOMPATIBLE_CTIME_R 0
43 #endif /* !defined INCOMPATIBLE_CTIME_R */
47 #endif /* !defined HAVE_LINK */
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 */
66 #define HAVE_UNISTD_H 1
67 #endif /* !defined HAVE_UNISTD_H */
70 #define HAVE_UTMPX_H 1
71 #endif /* !defined HAVE_UTMPX_H */
73 #ifndef NETBSD_INSPIRED
74 # define NETBSD_INSPIRED 1
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 */
82 /* Enable tm_gmtoff and tm_zone on GNUish systems. */
84 /* Fix asctime_r on Solaris 10. */
85 #define _POSIX_PTHREAD_SEMANTICS 1
86 /* Enable strtoimax on Solaris 10. */
87 #define __EXTENSIONS__ 1
93 #if !defined(__NetBSD__) && !defined(__minix)
94 /* Avoid clashes with NetBSD by renaming NetBSD's declarations. */
95 #define localtime_rz sys_localtime_rz
96 #define mktime_z sys_mktime_z
97 #define posix2time_z sys_posix2time_z
98 #define time2posix_z sys_time2posix_z
99 #define timezone_t sys_timezone_t
100 #define tzalloc sys_tzalloc
101 #define tzfree sys_tzfree
114 #include "sys/types.h" /* for time_t */
117 #include "limits.h" /* for CHAR_BIT et al. */
123 # define ENAMETOOLONG EINVAL
126 # define EOVERFLOW EINVAL
131 #endif /* HAVE_GETTEXT */
134 #include <sys/wait.h> /* for WIFEXITED and WEXITSTATUS */
135 #endif /* HAVE_SYS_WAIT_H */
138 #define WIFEXITED(status) (((status) & 0xff) == 0)
139 #endif /* !defined WIFEXITED */
141 #define WEXITSTATUS(status) (((status) >> 8) & 0xff)
142 #endif /* !defined WEXITSTATUS */
145 #include "unistd.h" /* for F_OK, R_OK, and other POSIX goodness */
146 #endif /* HAVE_UNISTD_H */
148 #ifndef HAVE_STRFTIME_L
149 # if _POSIX_VERSION < 200809
150 # define HAVE_STRFTIME_L 0
152 # define HAVE_STRFTIME_L 1
158 #endif /* !defined F_OK */
161 #endif /* !defined R_OK */
163 /* Unlike <ctype.h>'s isdigit, this also works if c < 0 | c > UCHAR_MAX. */
164 #define is_digit(c) ((unsigned)(c) - '0' <= 9)
167 ** Define HAVE_STDINT_H's default value here, rather than at the
168 ** start, since __GLIBC__'s value depends on previously-included
170 ** (glibc 2.1 and later have stdint.h, even with pre-C99 compilers.)
172 #ifndef HAVE_STDINT_H
173 #define HAVE_STDINT_H \
174 (199901 <= __STDC_VERSION__ \
175 || 2 < __GLIBC__ + (1 <= __GLIBC_MINOR__) \
177 #endif /* !defined HAVE_STDINT_H */
181 #endif /* !HAVE_STDINT_H */
183 #ifndef HAVE_INTTYPES_H
184 # define HAVE_INTTYPES_H HAVE_STDINT_H
187 # include <inttypes.h>
190 /* Pre-C99 GCC compilers define __LONG_LONG_MAX__ instead of LLONG_MAX. */
191 #ifdef __LONG_LONG_MAX__
193 # define LLONG_MAX __LONG_LONG_MAX__
196 # define LLONG_MIN (-1 - LLONG_MAX)
200 #ifndef INT_FAST64_MAX
202 typedef long long int_fast64_t;
203 # define INT_FAST64_MIN LLONG_MIN
204 # define INT_FAST64_MAX LLONG_MAX
206 # if LONG_MAX >> 31 < 0xffffffff
207 Please use a compiler that supports a
64-bit integer
type (or wider
);
208 you may need to compile with
"-DHAVE_STDINT_H".
210 typedef long int_fast64_t;
211 # define INT_FAST64_MIN LONG_MIN
212 # define INT_FAST64_MAX LONG_MAX
217 # if INT_FAST64_MAX == LLONG_MAX
218 # define SCNdFAST64 "lld"
220 # define SCNdFAST64 "ld"
224 #ifndef INT_FAST32_MAX
225 # if INT_MAX >> 31 == 0
226 typedef long int_fast32_t;
227 # define INT_FAST32_MAX LONG_MAX
228 # define INT_FAST32_MIN LONG_MIN
230 typedef int int_fast32_t;
231 # define INT_FAST32_MAX INT_MAX
232 # define INT_FAST32_MIN INT_MIN
238 typedef long long intmax_t;
239 # define strtoimax strtoll
240 # define INTMAX_MAX LLONG_MAX
241 # define INTMAX_MIN LLONG_MIN
243 typedef long intmax_t;
244 # define strtoimax strtol
245 # define INTMAX_MAX LONG_MAX
246 # define INTMAX_MIN LONG_MIN
251 # if INTMAX_MAX == LLONG_MAX
252 # define PRIdMAX "lld"
254 # define PRIdMAX "ld"
258 #ifndef UINT_FAST64_MAX
259 # if defined ULLONG_MAX || defined __LONG_LONG_MAX__
260 typedef unsigned long long uint_fast64_t;
262 # if ULONG_MAX >> 31 >> 1 < 0xffffffff
263 Please use a compiler that supports a
64-bit integer
type (or wider
);
264 you may need to compile with
"-DHAVE_STDINT_H".
266 typedef unsigned long uint_fast64_t;
271 # if defined ULLONG_MAX || defined __LONG_LONG_MAX__
272 typedef unsigned long long uintmax_t;
274 typedef unsigned long uintmax_t;
279 # if defined ULLONG_MAX || defined __LONG_LONG_MAX__
280 # define PRIuMAX "llu"
282 # define PRIuMAX "lu"
287 #define INT32_MAX 0x7fffffff
288 #endif /* !defined INT32_MAX */
290 #define INT32_MIN (-1 - INT32_MAX)
291 #endif /* !defined INT32_MIN */
294 #define SIZE_MAX ((size_t) -1)
297 #if 2 < __GNUC__ + (96 <= __GNUC_MINOR__)
298 # define ATTRIBUTE_CONST __attribute__ ((__const__))
299 # define ATTRIBUTE_PURE __attribute__ ((__pure__))
300 # define ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
302 # define ATTRIBUTE_CONST /* empty */
303 # define ATTRIBUTE_PURE /* empty */
304 # define ATTRIBUTE_FORMAT(spec) /* empty */
307 #if !defined _Noreturn && __STDC_VERSION__ < 201112
308 # if 2 < __GNUC__ + (8 <= __GNUC_MINOR__)
309 # define _Noreturn __attribute__ ((__noreturn__))
315 #if __STDC_VERSION__ < 199901 && !defined restrict
316 # define restrict /* empty */
320 ** Workarounds for compilers/systems.
324 ** Compile with -Dtime_tz=T to build the tz package with a private
325 ** time_t type equivalent to T rather than the system-supplied time_t.
326 ** This debugging feature can test unusual design decisions
327 ** (e.g., time_t wider than 'long', or unsigned time_t) even on
328 ** typical platforms.
331 # ifdef LOCALTIME_IMPLEMENTATION
332 static time_t sys_time(time_t *x
) { return time(x
); }
335 typedef time_tz tz_time_t
;
338 # define ctime tz_ctime
340 # define ctime_r tz_ctime_r
342 # define difftime tz_difftime
344 # define gmtime tz_gmtime
346 # define gmtime_r tz_gmtime_r
348 # define localtime tz_localtime
350 # define localtime_r tz_localtime_r
352 # define localtime_rz tz_localtime_rz
354 # define mktime tz_mktime
356 # define mktime_z tz_mktime_z
358 # define offtime tz_offtime
360 # define posix2time tz_posix2time
362 # define posix2time_z tz_posix2time_z
364 # define time tz_time
366 # define time2posix tz_time2posix
368 # define time2posix_z tz_time2posix_z
370 # define time_t tz_time_t
372 # define timegm tz_timegm
374 # define timelocal tz_timelocal
376 # define timeoff tz_timeoff
378 # define tzalloc tz_tzalloc
380 # define tzfree tz_tzfree
382 # define tzset tz_tzset
384 # define tzsetwall tz_tzsetwall
386 char *ctime(time_t const *);
387 char *ctime_r(time_t const *, char *);
388 double difftime(time_t, time_t);
389 struct tm
*gmtime(time_t const *);
390 struct tm
*gmtime_r(time_t const *restrict
, struct tm
*restrict
);
391 struct tm
*localtime(time_t const *);
392 struct tm
*localtime_r(time_t const *restrict
, struct tm
*restrict
);
393 time_t mktime(struct tm
*);
394 time_t time(time_t *);
399 ** Some time.h implementations don't declare asctime_r.
400 ** Others might define it as a macro.
401 ** Fix the former without affecting the latter.
402 ** Similarly for timezone, daylight, and altzone.
406 extern char * asctime_r(struct tm
const *restrict
, char *restrict
);
409 #if defined(USG_COMPAT) && !defined(__NetBSD__) && !defined(__minix)
411 extern long timezone
;
417 #if defined ALTZONE && !defined altzone
422 ** The STD_INSPIRED functions are similar, but most also need
423 ** declarations if time_tz is defined.
427 # if !defined tzsetwall || defined time_tz
428 void tzsetwall(void);
430 # if !defined offtime || defined time_tz
431 struct tm
*offtime(time_t const *, long);
433 # if !defined timegm || defined time_tz
434 time_t timegm(struct tm
*);
436 # if !defined timelocal || defined time_tz
437 time_t timelocal(struct tm
*);
439 # if !defined timeoff || defined time_tz
440 time_t timeoff(struct tm
*, long);
442 # if !defined time2posix || defined time_tz
443 time_t time2posix(time_t);
445 # if !defined posix2time || defined time_tz
446 time_t posix2time(time_t);
450 /* Infer TM_ZONE on systems where this information is known, but suppress
451 guessing if NO_TM_ZONE is defined. Similarly for TM_GMTOFF. */
452 #if (defined __GLIBC__ \
453 || defined __FreeBSD__ || defined __minix || defined __NetBSD__ || defined __OpenBSD__ \
454 || (defined __APPLE__ && defined __MACH__))
455 # if !defined TM_GMTOFF && !defined NO_TM_GMTOFF
456 # define TM_GMTOFF tm_gmtoff
458 # if !defined TM_ZONE && !defined NO_TM_ZONE
459 # define TM_ZONE tm_zone
464 ** Define functions that are ABI compatible with NetBSD but have
465 ** better prototypes. NetBSD 6.1.4 defines a pointer type timezone_t
466 ** and labors under the misconception that 'const timezone_t' is a
467 ** pointer to a constant. This use of 'const' is ineffective, so it
468 ** is not done here. What we call 'struct state' NetBSD calls
469 ** 'struct __state', but this is a private name so it doesn't matter.
471 #if !defined(__NetBSD__) && !defined(__minix)
473 typedef struct state
*timezone_t
;
474 struct tm
*localtime_rz(timezone_t restrict
, time_t const *restrict
,
475 struct tm
*restrict
);
476 time_t mktime_z(timezone_t restrict
, struct tm
*restrict
);
477 timezone_t
tzalloc(char const *);
478 void tzfree(timezone_t
);
480 # if !defined posix2time_z || defined time_tz
481 time_t posix2time_z(timezone_t __restrict
, time_t) ATTRIBUTE_PURE
;
483 # if !defined time2posix_z || defined time_tz
484 time_t time2posix_z(timezone_t __restrict
, time_t) ATTRIBUTE_PURE
;
491 ** Finally, some convenience items.
494 #if __STDC_VERSION__ < 199901
499 # include <stdbool.h>
503 #define TYPE_BIT(type) (sizeof (type) * CHAR_BIT)
504 #endif /* !defined TYPE_BIT */
507 #define TYPE_SIGNED(type) (/*CONSTCOND*/((type) -1) < 0)
508 #endif /* !defined TYPE_SIGNED */
510 #define TWOS_COMPLEMENT(t) (/*CONSTCOND*/(t) ~ (t) 0 < 0)
512 /* Max and min values of the integer type T, of which only the bottom
513 B bits are used, and where the highest-order used bit is considered
514 to be a sign bit if T is signed. */
515 #define MAXVAL(t, b) /*LINTED*/ \
516 ((t) (((t) 1 << ((b) - 1 - TYPE_SIGNED(t))) \
517 - 1 + ((t) 1 << ((b) - 1 - TYPE_SIGNED(t)))))
518 #define MINVAL(t, b) \
519 ((t) (TYPE_SIGNED(t) ? - TWOS_COMPLEMENT(t) - MAXVAL(t, b) : 0))
521 #ifdef LOCALTIME_IMPLEMENTATION
522 /* The minimum and maximum finite time values. This assumes no padding. */
523 static time_t const time_t_min
= MINVAL(time_t, TYPE_BIT(time_t));
524 static time_t const time_t_max
= MAXVAL(time_t, TYPE_BIT(time_t));
527 #ifndef INT_STRLEN_MAXIMUM
529 ** 302 / 1000 is log10(2.0) rounded up.
530 ** Subtract one for the sign bit if the type is signed;
531 ** add one for integer division truncation;
532 ** add one more for a minus sign if the type is signed.
534 #define INT_STRLEN_MAXIMUM(type) \
535 ((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + \
536 1 + TYPE_SIGNED(type))
537 #endif /* !defined INT_STRLEN_MAXIMUM */
543 #if defined(__GNUC__) || defined(__lint__)
544 # define INITIALIZE(x) ((x) = 0)
546 # define INITIALIZE(x)
550 # define UNINIT_TRAP 0
554 ** For the benefit of GNU folk...
555 ** '_(MSGID)' uses the current locale's message library string for MSGID.
556 ** The default is to use gettext if available, and use MSGID otherwise.
561 #define _(msgid) gettext(msgid)
562 #else /* !HAVE_GETTEXT */
563 #define _(msgid) msgid
564 #endif /* !HAVE_GETTEXT */
565 #endif /* !defined _ */
567 #if !defined TZ_DOMAIN && defined HAVE_GETTEXT
568 # define TZ_DOMAIN "tz"
571 #if HAVE_INCOMPATIBLE_CTIME_R
574 char *asctime_r(struct tm
const *, char *);
575 char *ctime_r(time_t const *, char *);
576 #endif /* HAVE_INCOMPATIBLE_CTIME_R */
578 #ifndef YEARSPERREPEAT
579 #define YEARSPERREPEAT 400 /* years before a Gregorian repeat */
580 #endif /* !defined YEARSPERREPEAT */
583 ** The Gregorian year averages 365.2425 days, which is 31556952 seconds.
586 #ifndef AVGSECSPERYEAR
587 #define AVGSECSPERYEAR 31556952L
588 #endif /* !defined AVGSECSPERYEAR */
590 #ifndef SECSPERREPEAT
591 #define SECSPERREPEAT ((int_fast64_t) YEARSPERREPEAT * (int_fast64_t) AVGSECSPERYEAR)
592 #endif /* !defined SECSPERREPEAT */
594 #ifndef SECSPERREPEAT_BITS
595 #define SECSPERREPEAT_BITS 34 /* ceil(log2(SECSPERREPEAT)) */
596 #endif /* !defined SECSPERREPEAT_BITS */
598 #endif /* !defined PRIVATE_H */