1*0a6a1f1dSLionel Sambuc /* $NetBSD: private.h,v 1.44 2015/10/09 17:21:45 christos Exp $ */
22fe8fb19SBen Gras
32fe8fb19SBen Gras #ifndef PRIVATE_H
42fe8fb19SBen Gras #define PRIVATE_H
52fe8fb19SBen Gras
62fe8fb19SBen Gras /* NetBSD defaults */
72fe8fb19SBen Gras #define TM_GMTOFF tm_gmtoff
82fe8fb19SBen Gras #define TM_ZONE tm_zone
92fe8fb19SBen Gras #define STD_INSPIRED 1
102fe8fb19SBen Gras #define HAVE_LONG_DOUBLE 1
112fe8fb19SBen Gras
122fe8fb19SBen Gras /* For when we build zic as a host tool. */
132fe8fb19SBen Gras #if HAVE_NBTOOL_CONFIG_H
142fe8fb19SBen Gras #include "nbtool_config.h"
152fe8fb19SBen Gras #endif
162fe8fb19SBen Gras
172fe8fb19SBen Gras /*
182fe8fb19SBen Gras ** This file is in the public domain, so clarified as of
192fe8fb19SBen Gras ** 1996-06-05 by Arthur David Olson.
202fe8fb19SBen Gras */
212fe8fb19SBen Gras
222fe8fb19SBen Gras /*
232fe8fb19SBen Gras ** This header is for use ONLY with the time conversion code.
242fe8fb19SBen Gras ** There is no guarantee that it will remain unchanged,
252fe8fb19SBen Gras ** or that it will remain at all.
262fe8fb19SBen Gras ** Do NOT copy it to any system include directory.
272fe8fb19SBen Gras ** Thank you!
282fe8fb19SBen Gras */
292fe8fb19SBen Gras
302fe8fb19SBen Gras #define GRANDPARENTED "Local time zone must be set--see zic manual page"
312fe8fb19SBen Gras
322fe8fb19SBen Gras /*
332fe8fb19SBen Gras ** Defaults for preprocessor symbols.
34*0a6a1f1dSLionel Sambuc ** You can override these in your C compiler options, e.g. '-DHAVE_GETTEXT=1'.
352fe8fb19SBen Gras */
362fe8fb19SBen Gras
372fe8fb19SBen Gras #ifndef HAVE_GETTEXT
382fe8fb19SBen Gras #define HAVE_GETTEXT 0
392fe8fb19SBen Gras #endif /* !defined HAVE_GETTEXT */
402fe8fb19SBen Gras
412fe8fb19SBen Gras #ifndef HAVE_INCOMPATIBLE_CTIME_R
422fe8fb19SBen Gras #define HAVE_INCOMPATIBLE_CTIME_R 0
432fe8fb19SBen Gras #endif /* !defined INCOMPATIBLE_CTIME_R */
442fe8fb19SBen Gras
45*0a6a1f1dSLionel Sambuc #ifndef HAVE_LINK
46*0a6a1f1dSLionel Sambuc #define HAVE_LINK 1
47*0a6a1f1dSLionel Sambuc #endif /* !defined HAVE_LINK */
48*0a6a1f1dSLionel Sambuc
49*0a6a1f1dSLionel Sambuc #ifndef HAVE_STRDUP
50*0a6a1f1dSLionel Sambuc #define HAVE_STRDUP 1
51*0a6a1f1dSLionel Sambuc #endif
522fe8fb19SBen Gras
532fe8fb19SBen Gras #ifndef HAVE_SYMLINK
542fe8fb19SBen Gras #define HAVE_SYMLINK 1
552fe8fb19SBen Gras #endif /* !defined HAVE_SYMLINK */
562fe8fb19SBen Gras
572fe8fb19SBen Gras #ifndef HAVE_SYS_STAT_H
582fe8fb19SBen Gras #define HAVE_SYS_STAT_H 1
592fe8fb19SBen Gras #endif /* !defined HAVE_SYS_STAT_H */
602fe8fb19SBen Gras
612fe8fb19SBen Gras #ifndef HAVE_SYS_WAIT_H
622fe8fb19SBen Gras #define HAVE_SYS_WAIT_H 1
632fe8fb19SBen Gras #endif /* !defined HAVE_SYS_WAIT_H */
642fe8fb19SBen Gras
652fe8fb19SBen Gras #ifndef HAVE_UNISTD_H
662fe8fb19SBen Gras #define HAVE_UNISTD_H 1
672fe8fb19SBen Gras #endif /* !defined HAVE_UNISTD_H */
682fe8fb19SBen Gras
692fe8fb19SBen Gras #ifndef HAVE_UTMPX_H
70*0a6a1f1dSLionel Sambuc #define HAVE_UTMPX_H 1
712fe8fb19SBen Gras #endif /* !defined HAVE_UTMPX_H */
722fe8fb19SBen Gras
73*0a6a1f1dSLionel Sambuc #ifndef NETBSD_INSPIRED
74*0a6a1f1dSLionel Sambuc # define NETBSD_INSPIRED 1
75*0a6a1f1dSLionel Sambuc #endif
762fe8fb19SBen Gras
772fe8fb19SBen Gras #if HAVE_INCOMPATIBLE_CTIME_R
782fe8fb19SBen Gras #define asctime_r _incompatible_asctime_r
792fe8fb19SBen Gras #define ctime_r _incompatible_ctime_r
802fe8fb19SBen Gras #endif /* HAVE_INCOMPATIBLE_CTIME_R */
812fe8fb19SBen Gras
82*0a6a1f1dSLionel Sambuc /* Enable tm_gmtoff and tm_zone on GNUish systems. */
83*0a6a1f1dSLionel Sambuc #define _GNU_SOURCE 1
84*0a6a1f1dSLionel Sambuc /* Fix asctime_r on Solaris 10. */
85*0a6a1f1dSLionel Sambuc #define _POSIX_PTHREAD_SEMANTICS 1
86*0a6a1f1dSLionel Sambuc /* Enable strtoimax on Solaris 10. */
87*0a6a1f1dSLionel Sambuc #define __EXTENSIONS__ 1
88*0a6a1f1dSLionel Sambuc
892fe8fb19SBen Gras /*
902fe8fb19SBen Gras ** Nested includes
912fe8fb19SBen Gras */
922fe8fb19SBen Gras
93*0a6a1f1dSLionel Sambuc #if !defined(__NetBSD__) && !defined(__minix)
94*0a6a1f1dSLionel Sambuc /* Avoid clashes with NetBSD by renaming NetBSD's declarations. */
95*0a6a1f1dSLionel Sambuc #define localtime_rz sys_localtime_rz
96*0a6a1f1dSLionel Sambuc #define mktime_z sys_mktime_z
97*0a6a1f1dSLionel Sambuc #define posix2time_z sys_posix2time_z
98*0a6a1f1dSLionel Sambuc #define time2posix_z sys_time2posix_z
99*0a6a1f1dSLionel Sambuc #define timezone_t sys_timezone_t
100*0a6a1f1dSLionel Sambuc #define tzalloc sys_tzalloc
101*0a6a1f1dSLionel Sambuc #define tzfree sys_tzfree
102*0a6a1f1dSLionel Sambuc #include <time.h>
103*0a6a1f1dSLionel Sambuc #undef localtime_rz
104*0a6a1f1dSLionel Sambuc #undef mktime_z
105*0a6a1f1dSLionel Sambuc #undef posix2time_z
106*0a6a1f1dSLionel Sambuc #undef time2posix_z
107*0a6a1f1dSLionel Sambuc #undef timezone_t
108*0a6a1f1dSLionel Sambuc #undef tzalloc
109*0a6a1f1dSLionel Sambuc #undef tzfree
110*0a6a1f1dSLionel Sambuc #else
111*0a6a1f1dSLionel Sambuc #include "time.h"
112*0a6a1f1dSLionel Sambuc #endif
113*0a6a1f1dSLionel Sambuc
1142fe8fb19SBen Gras #include "sys/types.h" /* for time_t */
1152fe8fb19SBen Gras #include "stdio.h"
1162fe8fb19SBen Gras #include "string.h"
1172fe8fb19SBen Gras #include "limits.h" /* for CHAR_BIT et al. */
1182fe8fb19SBen Gras #include "stdlib.h"
1192fe8fb19SBen Gras
120*0a6a1f1dSLionel Sambuc #include "errno.h"
121*0a6a1f1dSLionel Sambuc
122*0a6a1f1dSLionel Sambuc #ifndef ENAMETOOLONG
123*0a6a1f1dSLionel Sambuc # define ENAMETOOLONG EINVAL
124*0a6a1f1dSLionel Sambuc #endif
125*0a6a1f1dSLionel Sambuc #ifndef EOVERFLOW
126*0a6a1f1dSLionel Sambuc # define EOVERFLOW EINVAL
127*0a6a1f1dSLionel Sambuc #endif
128*0a6a1f1dSLionel Sambuc
1292fe8fb19SBen Gras #if HAVE_GETTEXT
1302fe8fb19SBen Gras #include "libintl.h"
1312fe8fb19SBen Gras #endif /* HAVE_GETTEXT */
1322fe8fb19SBen Gras
1332fe8fb19SBen Gras #if HAVE_SYS_WAIT_H
1342fe8fb19SBen Gras #include <sys/wait.h> /* for WIFEXITED and WEXITSTATUS */
1352fe8fb19SBen Gras #endif /* HAVE_SYS_WAIT_H */
1362fe8fb19SBen Gras
1372fe8fb19SBen Gras #ifndef WIFEXITED
1382fe8fb19SBen Gras #define WIFEXITED(status) (((status) & 0xff) == 0)
1392fe8fb19SBen Gras #endif /* !defined WIFEXITED */
1402fe8fb19SBen Gras #ifndef WEXITSTATUS
1412fe8fb19SBen Gras #define WEXITSTATUS(status) (((status) >> 8) & 0xff)
1422fe8fb19SBen Gras #endif /* !defined WEXITSTATUS */
1432fe8fb19SBen Gras
1442fe8fb19SBen Gras #if HAVE_UNISTD_H
1452fe8fb19SBen Gras #include "unistd.h" /* for F_OK, R_OK, and other POSIX goodness */
1462fe8fb19SBen Gras #endif /* HAVE_UNISTD_H */
1472fe8fb19SBen Gras
148*0a6a1f1dSLionel Sambuc #ifndef HAVE_STRFTIME_L
149*0a6a1f1dSLionel Sambuc # if _POSIX_VERSION < 200809
150*0a6a1f1dSLionel Sambuc # define HAVE_STRFTIME_L 0
151*0a6a1f1dSLionel Sambuc # else
152*0a6a1f1dSLionel Sambuc # define HAVE_STRFTIME_L 1
153*0a6a1f1dSLionel Sambuc # endif
154*0a6a1f1dSLionel Sambuc #endif
155*0a6a1f1dSLionel Sambuc
1562fe8fb19SBen Gras #ifndef F_OK
1572fe8fb19SBen Gras #define F_OK 0
1582fe8fb19SBen Gras #endif /* !defined F_OK */
1592fe8fb19SBen Gras #ifndef R_OK
1602fe8fb19SBen Gras #define R_OK 4
1612fe8fb19SBen Gras #endif /* !defined R_OK */
1622fe8fb19SBen Gras
1632fe8fb19SBen Gras /* Unlike <ctype.h>'s isdigit, this also works if c < 0 | c > UCHAR_MAX. */
1642fe8fb19SBen Gras #define is_digit(c) ((unsigned)(c) - '0' <= 9)
1652fe8fb19SBen Gras
1662fe8fb19SBen Gras /*
1672fe8fb19SBen Gras ** Define HAVE_STDINT_H's default value here, rather than at the
1682fe8fb19SBen Gras ** start, since __GLIBC__'s value depends on previously-included
1692fe8fb19SBen Gras ** files.
1702fe8fb19SBen Gras ** (glibc 2.1 and later have stdint.h, even with pre-C99 compilers.)
1712fe8fb19SBen Gras */
1722fe8fb19SBen Gras #ifndef HAVE_STDINT_H
1732fe8fb19SBen Gras #define HAVE_STDINT_H \
174*0a6a1f1dSLionel Sambuc (199901 <= __STDC_VERSION__ \
175*0a6a1f1dSLionel Sambuc || 2 < __GLIBC__ + (1 <= __GLIBC_MINOR__) \
176*0a6a1f1dSLionel Sambuc || __CYGWIN__)
1772fe8fb19SBen Gras #endif /* !defined HAVE_STDINT_H */
1782fe8fb19SBen Gras
1792fe8fb19SBen Gras #if HAVE_STDINT_H
1802fe8fb19SBen Gras #include "stdint.h"
1812fe8fb19SBen Gras #endif /* !HAVE_STDINT_H */
1822fe8fb19SBen Gras
18384d9c625SLionel Sambuc #ifndef HAVE_INTTYPES_H
18484d9c625SLionel Sambuc # define HAVE_INTTYPES_H HAVE_STDINT_H
18584d9c625SLionel Sambuc #endif
18684d9c625SLionel Sambuc #if HAVE_INTTYPES_H
18784d9c625SLionel Sambuc # include <inttypes.h>
18884d9c625SLionel Sambuc #endif
18984d9c625SLionel Sambuc
1902fe8fb19SBen Gras /* Pre-C99 GCC compilers define __LONG_LONG_MAX__ instead of LLONG_MAX. */
191*0a6a1f1dSLionel Sambuc #ifdef __LONG_LONG_MAX__
192*0a6a1f1dSLionel Sambuc # ifndef LLONG_MAX
193*0a6a1f1dSLionel Sambuc # define LLONG_MAX __LONG_LONG_MAX__
194*0a6a1f1dSLionel Sambuc # endif
195*0a6a1f1dSLionel Sambuc # ifndef LLONG_MIN
196*0a6a1f1dSLionel Sambuc # define LLONG_MIN (-1 - LLONG_MAX)
197*0a6a1f1dSLionel Sambuc # endif
198*0a6a1f1dSLionel Sambuc #endif
199*0a6a1f1dSLionel Sambuc
200*0a6a1f1dSLionel Sambuc #ifndef INT_FAST64_MAX
20184d9c625SLionel Sambuc # ifdef LLONG_MAX
202*0a6a1f1dSLionel Sambuc typedef long long int_fast64_t;
20384d9c625SLionel Sambuc # define INT_FAST64_MIN LLONG_MIN
20484d9c625SLionel Sambuc # define INT_FAST64_MAX LLONG_MAX
20584d9c625SLionel Sambuc # else
206*0a6a1f1dSLionel Sambuc # if LONG_MAX >> 31 < 0xffffffff
2072fe8fb19SBen Gras Please use a compiler that supports a 64-bit integer type (or wider);
2082fe8fb19SBen Gras you may need to compile with "-DHAVE_STDINT_H".
209*0a6a1f1dSLionel Sambuc # endif
2102fe8fb19SBen Gras typedef long int_fast64_t;
21184d9c625SLionel Sambuc # define INT_FAST64_MIN LONG_MIN
21284d9c625SLionel Sambuc # define INT_FAST64_MAX LONG_MAX
213*0a6a1f1dSLionel Sambuc # endif
214*0a6a1f1dSLionel Sambuc #endif
215*0a6a1f1dSLionel Sambuc
216*0a6a1f1dSLionel Sambuc #ifndef SCNdFAST64
217*0a6a1f1dSLionel Sambuc # if INT_FAST64_MAX == LLONG_MAX
218*0a6a1f1dSLionel Sambuc # define SCNdFAST64 "lld"
219*0a6a1f1dSLionel Sambuc # else
22084d9c625SLionel Sambuc # define SCNdFAST64 "ld"
221*0a6a1f1dSLionel Sambuc # endif
222*0a6a1f1dSLionel Sambuc #endif
2232fe8fb19SBen Gras
22484d9c625SLionel Sambuc #ifndef INT_FAST32_MAX
22584d9c625SLionel Sambuc # if INT_MAX >> 31 == 0
22684d9c625SLionel Sambuc typedef long int_fast32_t;
227*0a6a1f1dSLionel Sambuc # define INT_FAST32_MAX LONG_MAX
228*0a6a1f1dSLionel Sambuc # define INT_FAST32_MIN LONG_MIN
22984d9c625SLionel Sambuc # else
23084d9c625SLionel Sambuc typedef int int_fast32_t;
231*0a6a1f1dSLionel Sambuc # define INT_FAST32_MAX INT_MAX
232*0a6a1f1dSLionel Sambuc # define INT_FAST32_MIN INT_MIN
23384d9c625SLionel Sambuc # endif
23484d9c625SLionel Sambuc #endif
23584d9c625SLionel Sambuc
23684d9c625SLionel Sambuc #ifndef INTMAX_MAX
237*0a6a1f1dSLionel Sambuc # ifdef LLONG_MAX
23884d9c625SLionel Sambuc typedef long long intmax_t;
23984d9c625SLionel Sambuc # define strtoimax strtoll
24084d9c625SLionel Sambuc # define INTMAX_MAX LLONG_MAX
24184d9c625SLionel Sambuc # define INTMAX_MIN LLONG_MIN
24284d9c625SLionel Sambuc # else
24384d9c625SLionel Sambuc typedef long intmax_t;
24484d9c625SLionel Sambuc # define strtoimax strtol
24584d9c625SLionel Sambuc # define INTMAX_MAX LONG_MAX
24684d9c625SLionel Sambuc # define INTMAX_MIN LONG_MIN
24784d9c625SLionel Sambuc # endif
24884d9c625SLionel Sambuc #endif
24984d9c625SLionel Sambuc
250*0a6a1f1dSLionel Sambuc #ifndef PRIdMAX
251*0a6a1f1dSLionel Sambuc # if INTMAX_MAX == LLONG_MAX
252*0a6a1f1dSLionel Sambuc # define PRIdMAX "lld"
253*0a6a1f1dSLionel Sambuc # else
254*0a6a1f1dSLionel Sambuc # define PRIdMAX "ld"
255*0a6a1f1dSLionel Sambuc # endif
256*0a6a1f1dSLionel Sambuc #endif
257*0a6a1f1dSLionel Sambuc
258*0a6a1f1dSLionel Sambuc #ifndef UINT_FAST64_MAX
259*0a6a1f1dSLionel Sambuc # if defined ULLONG_MAX || defined __LONG_LONG_MAX__
260*0a6a1f1dSLionel Sambuc typedef unsigned long long uint_fast64_t;
261*0a6a1f1dSLionel Sambuc # else
262*0a6a1f1dSLionel Sambuc # if ULONG_MAX >> 31 >> 1 < 0xffffffff
263*0a6a1f1dSLionel Sambuc Please use a compiler that supports a 64-bit integer type (or wider);
264*0a6a1f1dSLionel Sambuc you may need to compile with "-DHAVE_STDINT_H".
265*0a6a1f1dSLionel Sambuc # endif
266*0a6a1f1dSLionel Sambuc typedef unsigned long uint_fast64_t;
267*0a6a1f1dSLionel Sambuc # endif
268*0a6a1f1dSLionel Sambuc #endif
269*0a6a1f1dSLionel Sambuc
27084d9c625SLionel Sambuc #ifndef UINTMAX_MAX
27184d9c625SLionel Sambuc # if defined ULLONG_MAX || defined __LONG_LONG_MAX__
27284d9c625SLionel Sambuc typedef unsigned long long uintmax_t;
27384d9c625SLionel Sambuc # else
27484d9c625SLionel Sambuc typedef unsigned long uintmax_t;
275*0a6a1f1dSLionel Sambuc # endif
276*0a6a1f1dSLionel Sambuc #endif
277*0a6a1f1dSLionel Sambuc
278*0a6a1f1dSLionel Sambuc #ifndef PRIuMAX
279*0a6a1f1dSLionel Sambuc # if defined ULLONG_MAX || defined __LONG_LONG_MAX__
280*0a6a1f1dSLionel Sambuc # define PRIuMAX "llu"
281*0a6a1f1dSLionel Sambuc # else
28284d9c625SLionel Sambuc # define PRIuMAX "lu"
28384d9c625SLionel Sambuc # endif
28484d9c625SLionel Sambuc #endif
28584d9c625SLionel Sambuc
2862fe8fb19SBen Gras #ifndef INT32_MAX
2872fe8fb19SBen Gras #define INT32_MAX 0x7fffffff
2882fe8fb19SBen Gras #endif /* !defined INT32_MAX */
2892fe8fb19SBen Gras #ifndef INT32_MIN
2902fe8fb19SBen Gras #define INT32_MIN (-1 - INT32_MAX)
2912fe8fb19SBen Gras #endif /* !defined INT32_MIN */
2922fe8fb19SBen Gras
293*0a6a1f1dSLionel Sambuc #ifndef SIZE_MAX
294*0a6a1f1dSLionel Sambuc #define SIZE_MAX ((size_t) -1)
295*0a6a1f1dSLionel Sambuc #endif
296*0a6a1f1dSLionel Sambuc
29784d9c625SLionel Sambuc #if 2 < __GNUC__ + (96 <= __GNUC_MINOR__)
29884d9c625SLionel Sambuc # define ATTRIBUTE_CONST __attribute__ ((__const__))
29984d9c625SLionel Sambuc # define ATTRIBUTE_PURE __attribute__ ((__pure__))
30084d9c625SLionel Sambuc # define ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
30184d9c625SLionel Sambuc #else
30284d9c625SLionel Sambuc # define ATTRIBUTE_CONST /* empty */
30384d9c625SLionel Sambuc # define ATTRIBUTE_PURE /* empty */
30484d9c625SLionel Sambuc # define ATTRIBUTE_FORMAT(spec) /* empty */
30584d9c625SLionel Sambuc #endif
30684d9c625SLionel Sambuc
30784d9c625SLionel Sambuc #if !defined _Noreturn && __STDC_VERSION__ < 201112
30884d9c625SLionel Sambuc # if 2 < __GNUC__ + (8 <= __GNUC_MINOR__)
30984d9c625SLionel Sambuc # define _Noreturn __attribute__ ((__noreturn__))
31084d9c625SLionel Sambuc # else
31184d9c625SLionel Sambuc # define _Noreturn
31284d9c625SLionel Sambuc # endif
31384d9c625SLionel Sambuc #endif
31484d9c625SLionel Sambuc
31584d9c625SLionel Sambuc #if __STDC_VERSION__ < 199901 && !defined restrict
31684d9c625SLionel Sambuc # define restrict /* empty */
31784d9c625SLionel Sambuc #endif
31884d9c625SLionel Sambuc
3192fe8fb19SBen Gras /*
3202fe8fb19SBen Gras ** Workarounds for compilers/systems.
3212fe8fb19SBen Gras */
3222fe8fb19SBen Gras
3232fe8fb19SBen Gras /*
32484d9c625SLionel Sambuc ** Compile with -Dtime_tz=T to build the tz package with a private
32584d9c625SLionel Sambuc ** time_t type equivalent to T rather than the system-supplied time_t.
32684d9c625SLionel Sambuc ** This debugging feature can test unusual design decisions
32784d9c625SLionel Sambuc ** (e.g., time_t wider than 'long', or unsigned time_t) even on
32884d9c625SLionel Sambuc ** typical platforms.
32984d9c625SLionel Sambuc */
33084d9c625SLionel Sambuc #ifdef time_tz
331*0a6a1f1dSLionel Sambuc # ifdef LOCALTIME_IMPLEMENTATION
sys_time(time_t * x)33284d9c625SLionel Sambuc static time_t sys_time(time_t *x) { return time(x); }
333*0a6a1f1dSLionel Sambuc # endif
334*0a6a1f1dSLionel Sambuc
335*0a6a1f1dSLionel Sambuc typedef time_tz tz_time_t;
33684d9c625SLionel Sambuc
33784d9c625SLionel Sambuc # undef ctime
33884d9c625SLionel Sambuc # define ctime tz_ctime
33984d9c625SLionel Sambuc # undef ctime_r
34084d9c625SLionel Sambuc # define ctime_r tz_ctime_r
34184d9c625SLionel Sambuc # undef difftime
34284d9c625SLionel Sambuc # define difftime tz_difftime
34384d9c625SLionel Sambuc # undef gmtime
34484d9c625SLionel Sambuc # define gmtime tz_gmtime
34584d9c625SLionel Sambuc # undef gmtime_r
34684d9c625SLionel Sambuc # define gmtime_r tz_gmtime_r
34784d9c625SLionel Sambuc # undef localtime
34884d9c625SLionel Sambuc # define localtime tz_localtime
34984d9c625SLionel Sambuc # undef localtime_r
35084d9c625SLionel Sambuc # define localtime_r tz_localtime_r
351*0a6a1f1dSLionel Sambuc # undef localtime_rz
352*0a6a1f1dSLionel Sambuc # define localtime_rz tz_localtime_rz
35384d9c625SLionel Sambuc # undef mktime
35484d9c625SLionel Sambuc # define mktime tz_mktime
355*0a6a1f1dSLionel Sambuc # undef mktime_z
356*0a6a1f1dSLionel Sambuc # define mktime_z tz_mktime_z
357*0a6a1f1dSLionel Sambuc # undef offtime
358*0a6a1f1dSLionel Sambuc # define offtime tz_offtime
359*0a6a1f1dSLionel Sambuc # undef posix2time
360*0a6a1f1dSLionel Sambuc # define posix2time tz_posix2time
361*0a6a1f1dSLionel Sambuc # undef posix2time_z
362*0a6a1f1dSLionel Sambuc # define posix2time_z tz_posix2time_z
36384d9c625SLionel Sambuc # undef time
36484d9c625SLionel Sambuc # define time tz_time
365*0a6a1f1dSLionel Sambuc # undef time2posix
366*0a6a1f1dSLionel Sambuc # define time2posix tz_time2posix
367*0a6a1f1dSLionel Sambuc # undef time2posix_z
368*0a6a1f1dSLionel Sambuc # define time2posix_z tz_time2posix_z
36984d9c625SLionel Sambuc # undef time_t
37084d9c625SLionel Sambuc # define time_t tz_time_t
371*0a6a1f1dSLionel Sambuc # undef timegm
372*0a6a1f1dSLionel Sambuc # define timegm tz_timegm
373*0a6a1f1dSLionel Sambuc # undef timelocal
374*0a6a1f1dSLionel Sambuc # define timelocal tz_timelocal
375*0a6a1f1dSLionel Sambuc # undef timeoff
376*0a6a1f1dSLionel Sambuc # define timeoff tz_timeoff
377*0a6a1f1dSLionel Sambuc # undef tzalloc
378*0a6a1f1dSLionel Sambuc # define tzalloc tz_tzalloc
379*0a6a1f1dSLionel Sambuc # undef tzfree
380*0a6a1f1dSLionel Sambuc # define tzfree tz_tzfree
381*0a6a1f1dSLionel Sambuc # undef tzset
382*0a6a1f1dSLionel Sambuc # define tzset tz_tzset
383*0a6a1f1dSLionel Sambuc # undef tzsetwall
384*0a6a1f1dSLionel Sambuc # define tzsetwall tz_tzsetwall
38584d9c625SLionel Sambuc
38684d9c625SLionel Sambuc char *ctime(time_t const *);
38784d9c625SLionel Sambuc char *ctime_r(time_t const *, char *);
38884d9c625SLionel Sambuc double difftime(time_t, time_t);
38984d9c625SLionel Sambuc struct tm *gmtime(time_t const *);
39084d9c625SLionel Sambuc struct tm *gmtime_r(time_t const *restrict, struct tm *restrict);
39184d9c625SLionel Sambuc struct tm *localtime(time_t const *);
39284d9c625SLionel Sambuc struct tm *localtime_r(time_t const *restrict, struct tm *restrict);
39384d9c625SLionel Sambuc time_t mktime(struct tm *);
394*0a6a1f1dSLionel Sambuc time_t time(time_t *);
395*0a6a1f1dSLionel Sambuc void tzset(void);
39684d9c625SLionel Sambuc #endif
39784d9c625SLionel Sambuc
39884d9c625SLionel Sambuc /*
399*0a6a1f1dSLionel Sambuc ** Some time.h implementations don't declare asctime_r.
400*0a6a1f1dSLionel Sambuc ** Others might define it as a macro.
401*0a6a1f1dSLionel Sambuc ** Fix the former without affecting the latter.
402*0a6a1f1dSLionel Sambuc ** Similarly for timezone, daylight, and altzone.
4032fe8fb19SBen Gras */
4042fe8fb19SBen Gras
405*0a6a1f1dSLionel Sambuc #ifndef asctime_r
406*0a6a1f1dSLionel Sambuc extern char * asctime_r(struct tm const *restrict, char *restrict);
407*0a6a1f1dSLionel Sambuc #endif
408*0a6a1f1dSLionel Sambuc
409*0a6a1f1dSLionel Sambuc #if defined(USG_COMPAT) && !defined(__NetBSD__) && !defined(__minix)
410*0a6a1f1dSLionel Sambuc # ifndef timezone
411*0a6a1f1dSLionel Sambuc extern long timezone;
412*0a6a1f1dSLionel Sambuc # endif
413*0a6a1f1dSLionel Sambuc # ifndef daylight
414*0a6a1f1dSLionel Sambuc extern int daylight;
415*0a6a1f1dSLionel Sambuc # endif
416*0a6a1f1dSLionel Sambuc #endif
417*0a6a1f1dSLionel Sambuc #if defined ALTZONE && !defined altzone
418*0a6a1f1dSLionel Sambuc extern long altzone;
419*0a6a1f1dSLionel Sambuc #endif
420*0a6a1f1dSLionel Sambuc
421*0a6a1f1dSLionel Sambuc /*
422*0a6a1f1dSLionel Sambuc ** The STD_INSPIRED functions are similar, but most also need
423*0a6a1f1dSLionel Sambuc ** declarations if time_tz is defined.
424*0a6a1f1dSLionel Sambuc */
425*0a6a1f1dSLionel Sambuc
426*0a6a1f1dSLionel Sambuc #ifdef STD_INSPIRED
427*0a6a1f1dSLionel Sambuc # if !defined tzsetwall || defined time_tz
428*0a6a1f1dSLionel Sambuc void tzsetwall(void);
429*0a6a1f1dSLionel Sambuc # endif
430*0a6a1f1dSLionel Sambuc # if !defined offtime || defined time_tz
431*0a6a1f1dSLionel Sambuc struct tm *offtime(time_t const *, long);
432*0a6a1f1dSLionel Sambuc # endif
433*0a6a1f1dSLionel Sambuc # if !defined timegm || defined time_tz
434*0a6a1f1dSLionel Sambuc time_t timegm(struct tm *);
435*0a6a1f1dSLionel Sambuc # endif
436*0a6a1f1dSLionel Sambuc # if !defined timelocal || defined time_tz
437*0a6a1f1dSLionel Sambuc time_t timelocal(struct tm *);
438*0a6a1f1dSLionel Sambuc # endif
439*0a6a1f1dSLionel Sambuc # if !defined timeoff || defined time_tz
440*0a6a1f1dSLionel Sambuc time_t timeoff(struct tm *, long);
441*0a6a1f1dSLionel Sambuc # endif
442*0a6a1f1dSLionel Sambuc # if !defined time2posix || defined time_tz
443*0a6a1f1dSLionel Sambuc time_t time2posix(time_t);
444*0a6a1f1dSLionel Sambuc # endif
445*0a6a1f1dSLionel Sambuc # if !defined posix2time || defined time_tz
446*0a6a1f1dSLionel Sambuc time_t posix2time(time_t);
447*0a6a1f1dSLionel Sambuc # endif
448*0a6a1f1dSLionel Sambuc #endif
449*0a6a1f1dSLionel Sambuc
450*0a6a1f1dSLionel Sambuc /* Infer TM_ZONE on systems where this information is known, but suppress
451*0a6a1f1dSLionel Sambuc guessing if NO_TM_ZONE is defined. Similarly for TM_GMTOFF. */
452*0a6a1f1dSLionel Sambuc #if (defined __GLIBC__ \
453*0a6a1f1dSLionel Sambuc || defined __FreeBSD__ || defined __minix || defined __NetBSD__ || defined __OpenBSD__ \
454*0a6a1f1dSLionel Sambuc || (defined __APPLE__ && defined __MACH__))
455*0a6a1f1dSLionel Sambuc # if !defined TM_GMTOFF && !defined NO_TM_GMTOFF
456*0a6a1f1dSLionel Sambuc # define TM_GMTOFF tm_gmtoff
457*0a6a1f1dSLionel Sambuc # endif
458*0a6a1f1dSLionel Sambuc # if !defined TM_ZONE && !defined NO_TM_ZONE
459*0a6a1f1dSLionel Sambuc # define TM_ZONE tm_zone
460*0a6a1f1dSLionel Sambuc # endif
461*0a6a1f1dSLionel Sambuc #endif
462*0a6a1f1dSLionel Sambuc
463*0a6a1f1dSLionel Sambuc /*
464*0a6a1f1dSLionel Sambuc ** Define functions that are ABI compatible with NetBSD but have
465*0a6a1f1dSLionel Sambuc ** better prototypes. NetBSD 6.1.4 defines a pointer type timezone_t
466*0a6a1f1dSLionel Sambuc ** and labors under the misconception that 'const timezone_t' is a
467*0a6a1f1dSLionel Sambuc ** pointer to a constant. This use of 'const' is ineffective, so it
468*0a6a1f1dSLionel Sambuc ** is not done here. What we call 'struct state' NetBSD calls
469*0a6a1f1dSLionel Sambuc ** 'struct __state', but this is a private name so it doesn't matter.
470*0a6a1f1dSLionel Sambuc */
471*0a6a1f1dSLionel Sambuc #if !defined(__NetBSD__) && !defined(__minix)
472*0a6a1f1dSLionel Sambuc #if NETBSD_INSPIRED
473*0a6a1f1dSLionel Sambuc typedef struct state *timezone_t;
474*0a6a1f1dSLionel Sambuc struct tm *localtime_rz(timezone_t restrict, time_t const *restrict,
475*0a6a1f1dSLionel Sambuc struct tm *restrict);
476*0a6a1f1dSLionel Sambuc time_t mktime_z(timezone_t restrict, struct tm *restrict);
477*0a6a1f1dSLionel Sambuc timezone_t tzalloc(char const *);
478*0a6a1f1dSLionel Sambuc void tzfree(timezone_t);
479*0a6a1f1dSLionel Sambuc # ifdef STD_INSPIRED
480*0a6a1f1dSLionel Sambuc # if !defined posix2time_z || defined time_tz
481*0a6a1f1dSLionel Sambuc time_t posix2time_z(timezone_t __restrict, time_t) ATTRIBUTE_PURE;
482*0a6a1f1dSLionel Sambuc # endif
483*0a6a1f1dSLionel Sambuc # if !defined time2posix_z || defined time_tz
484*0a6a1f1dSLionel Sambuc time_t time2posix_z(timezone_t __restrict, time_t) ATTRIBUTE_PURE;
485*0a6a1f1dSLionel Sambuc # endif
486*0a6a1f1dSLionel Sambuc # endif
487*0a6a1f1dSLionel Sambuc #endif
488*0a6a1f1dSLionel Sambuc #endif
4892fe8fb19SBen Gras
4902fe8fb19SBen Gras /*
4912fe8fb19SBen Gras ** Finally, some convenience items.
4922fe8fb19SBen Gras */
4932fe8fb19SBen Gras
494*0a6a1f1dSLionel Sambuc #if __STDC_VERSION__ < 199901
495*0a6a1f1dSLionel Sambuc # define true 1
496*0a6a1f1dSLionel Sambuc # define false 0
497*0a6a1f1dSLionel Sambuc # define bool int
498*0a6a1f1dSLionel Sambuc #else
499*0a6a1f1dSLionel Sambuc # include <stdbool.h>
500*0a6a1f1dSLionel Sambuc #endif
5012fe8fb19SBen Gras
5022fe8fb19SBen Gras #ifndef TYPE_BIT
5032fe8fb19SBen Gras #define TYPE_BIT(type) (sizeof (type) * CHAR_BIT)
5042fe8fb19SBen Gras #endif /* !defined TYPE_BIT */
5052fe8fb19SBen Gras
5062fe8fb19SBen Gras #ifndef TYPE_SIGNED
50784d9c625SLionel Sambuc #define TYPE_SIGNED(type) (/*CONSTCOND*/((type) -1) < 0)
5082fe8fb19SBen Gras #endif /* !defined TYPE_SIGNED */
5092fe8fb19SBen Gras
510*0a6a1f1dSLionel Sambuc #define TWOS_COMPLEMENT(t) (/*CONSTCOND*/(t) ~ (t) 0 < 0)
511*0a6a1f1dSLionel Sambuc
512*0a6a1f1dSLionel Sambuc /* Max and min values of the integer type T, of which only the bottom
513*0a6a1f1dSLionel Sambuc B bits are used, and where the highest-order used bit is considered
514*0a6a1f1dSLionel Sambuc to be a sign bit if T is signed. */
515*0a6a1f1dSLionel Sambuc #define MAXVAL(t, b) /*LINTED*/ \
516*0a6a1f1dSLionel Sambuc ((t) (((t) 1 << ((b) - 1 - TYPE_SIGNED(t))) \
517*0a6a1f1dSLionel Sambuc - 1 + ((t) 1 << ((b) - 1 - TYPE_SIGNED(t)))))
518*0a6a1f1dSLionel Sambuc #define MINVAL(t, b) \
519*0a6a1f1dSLionel Sambuc ((t) (TYPE_SIGNED(t) ? - TWOS_COMPLEMENT(t) - MAXVAL(t, b) : 0))
520*0a6a1f1dSLionel Sambuc
521*0a6a1f1dSLionel Sambuc #ifdef LOCALTIME_IMPLEMENTATION
522*0a6a1f1dSLionel Sambuc /* The minimum and maximum finite time values. This assumes no padding. */
523*0a6a1f1dSLionel Sambuc static time_t const time_t_min = MINVAL(time_t, TYPE_BIT(time_t));
524*0a6a1f1dSLionel Sambuc static time_t const time_t_max = MAXVAL(time_t, TYPE_BIT(time_t));
525*0a6a1f1dSLionel Sambuc #endif
5262fe8fb19SBen Gras
5272fe8fb19SBen Gras #ifndef INT_STRLEN_MAXIMUM
5282fe8fb19SBen Gras /*
5292fe8fb19SBen Gras ** 302 / 1000 is log10(2.0) rounded up.
5302fe8fb19SBen Gras ** Subtract one for the sign bit if the type is signed;
5312fe8fb19SBen Gras ** add one for integer division truncation;
5322fe8fb19SBen Gras ** add one more for a minus sign if the type is signed.
5332fe8fb19SBen Gras */
5342fe8fb19SBen Gras #define INT_STRLEN_MAXIMUM(type) \
5352fe8fb19SBen Gras ((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + \
5362fe8fb19SBen Gras 1 + TYPE_SIGNED(type))
5372fe8fb19SBen Gras #endif /* !defined INT_STRLEN_MAXIMUM */
5382fe8fb19SBen Gras
5392fe8fb19SBen Gras /*
5402fe8fb19SBen Gras ** INITIALIZE(x)
5412fe8fb19SBen Gras */
5422fe8fb19SBen Gras
543*0a6a1f1dSLionel Sambuc #if defined(__GNUC__) || defined(__lint__)
5442fe8fb19SBen Gras # define INITIALIZE(x) ((x) = 0)
545*0a6a1f1dSLionel Sambuc #else
5462fe8fb19SBen Gras # define INITIALIZE(x)
547*0a6a1f1dSLionel Sambuc #endif
548*0a6a1f1dSLionel Sambuc
549*0a6a1f1dSLionel Sambuc #ifndef UNINIT_TRAP
550*0a6a1f1dSLionel Sambuc # define UNINIT_TRAP 0
551*0a6a1f1dSLionel Sambuc #endif
5522fe8fb19SBen Gras
5532fe8fb19SBen Gras /*
5542fe8fb19SBen Gras ** For the benefit of GNU folk...
555*0a6a1f1dSLionel Sambuc ** '_(MSGID)' uses the current locale's message library string for MSGID.
5562fe8fb19SBen Gras ** The default is to use gettext if available, and use MSGID otherwise.
5572fe8fb19SBen Gras */
5582fe8fb19SBen Gras
5592fe8fb19SBen Gras #ifndef _
5602fe8fb19SBen Gras #if HAVE_GETTEXT
5612fe8fb19SBen Gras #define _(msgid) gettext(msgid)
5622fe8fb19SBen Gras #else /* !HAVE_GETTEXT */
5632fe8fb19SBen Gras #define _(msgid) msgid
5642fe8fb19SBen Gras #endif /* !HAVE_GETTEXT */
5652fe8fb19SBen Gras #endif /* !defined _ */
5662fe8fb19SBen Gras
567*0a6a1f1dSLionel Sambuc #if !defined TZ_DOMAIN && defined HAVE_GETTEXT
5682fe8fb19SBen Gras # define TZ_DOMAIN "tz"
569*0a6a1f1dSLionel Sambuc #endif
5702fe8fb19SBen Gras
5712fe8fb19SBen Gras #if HAVE_INCOMPATIBLE_CTIME_R
5722fe8fb19SBen Gras #undef asctime_r
5732fe8fb19SBen Gras #undef ctime_r
5742fe8fb19SBen Gras char *asctime_r(struct tm const *, char *);
5752fe8fb19SBen Gras char *ctime_r(time_t const *, char *);
5762fe8fb19SBen Gras #endif /* HAVE_INCOMPATIBLE_CTIME_R */
5772fe8fb19SBen Gras
5782fe8fb19SBen Gras #ifndef YEARSPERREPEAT
5792fe8fb19SBen Gras #define YEARSPERREPEAT 400 /* years before a Gregorian repeat */
5802fe8fb19SBen Gras #endif /* !defined YEARSPERREPEAT */
5812fe8fb19SBen Gras
5822fe8fb19SBen Gras /*
5832fe8fb19SBen Gras ** The Gregorian year averages 365.2425 days, which is 31556952 seconds.
5842fe8fb19SBen Gras */
5852fe8fb19SBen Gras
5862fe8fb19SBen Gras #ifndef AVGSECSPERYEAR
5872fe8fb19SBen Gras #define AVGSECSPERYEAR 31556952L
5882fe8fb19SBen Gras #endif /* !defined AVGSECSPERYEAR */
5892fe8fb19SBen Gras
5902fe8fb19SBen Gras #ifndef SECSPERREPEAT
5912fe8fb19SBen Gras #define SECSPERREPEAT ((int_fast64_t) YEARSPERREPEAT * (int_fast64_t) AVGSECSPERYEAR)
5922fe8fb19SBen Gras #endif /* !defined SECSPERREPEAT */
5932fe8fb19SBen Gras
5942fe8fb19SBen Gras #ifndef SECSPERREPEAT_BITS
5952fe8fb19SBen Gras #define SECSPERREPEAT_BITS 34 /* ceil(log2(SECSPERREPEAT)) */
5962fe8fb19SBen Gras #endif /* !defined SECSPERREPEAT_BITS */
5972fe8fb19SBen Gras
5982fe8fb19SBen Gras #endif /* !defined PRIVATE_H */
599