11dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#ifndef PRIVATE_H
21dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
31dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define PRIVATE_H
41dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
51dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/*
61dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project** This file is in the public domain, so clarified as of
71dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project** 1996-06-05 by Arthur David Olson.
81dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project*/
91dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
101dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/*
111dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project** This header is for use ONLY with the time conversion code.
121dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project** There is no guarantee that it will remain unchanged,
131dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project** or that it will remain at all.
141dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project** Do NOT copy it to any system include directory.
151dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project** Thank you!
161dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project*/
171dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
18ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes#define GRANDPARENTED	"Local time zone must be set--see zic manual page"
191dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
201dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/*
211dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project** Defaults for preprocessor symbols.
229fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes** You can override these in your C compiler options, e.g. '-DHAVE_GETTEXT=1'.
231dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project*/
241dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
251dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#ifndef HAVE_GETTEXT
26ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes#define HAVE_GETTEXT		0
271dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif /* !defined HAVE_GETTEXT */
281dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
291dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#ifndef HAVE_INCOMPATIBLE_CTIME_R
30ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes#define HAVE_INCOMPATIBLE_CTIME_R	0
311dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif /* !defined INCOMPATIBLE_CTIME_R */
321dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
33627d37cd1f7bb6680f611dbe5f28b74a086567a7Calin Juravle#ifndef HAVE_LINK
34627d37cd1f7bb6680f611dbe5f28b74a086567a7Calin Juravle#define HAVE_LINK		1
35627d37cd1f7bb6680f611dbe5f28b74a086567a7Calin Juravle#endif /* !defined HAVE_LINK */
36627d37cd1f7bb6680f611dbe5f28b74a086567a7Calin Juravle
379fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#ifndef HAVE_STRDUP
389fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#define HAVE_STRDUP 1
399fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#endif
401dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
411dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#ifndef HAVE_SYMLINK
42ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes#define HAVE_SYMLINK		1
431dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif /* !defined HAVE_SYMLINK */
441dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
451dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#ifndef HAVE_SYS_STAT_H
46ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes#define HAVE_SYS_STAT_H		1
471dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif /* !defined HAVE_SYS_STAT_H */
481dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
491dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#ifndef HAVE_SYS_WAIT_H
50ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes#define HAVE_SYS_WAIT_H		1
511dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif /* !defined HAVE_SYS_WAIT_H */
521dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
531dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#ifndef HAVE_UNISTD_H
54ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes#define HAVE_UNISTD_H		1
551dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif /* !defined HAVE_UNISTD_H */
561dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
571dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#ifndef HAVE_UTMPX_H
589fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#define HAVE_UTMPX_H		1
591dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif /* !defined HAVE_UTMPX_H */
601dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
619fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#ifndef NETBSD_INSPIRED
629fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# define NETBSD_INSPIRED 1
639fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#endif
64ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes
651dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#if HAVE_INCOMPATIBLE_CTIME_R
661dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define asctime_r _incompatible_asctime_r
671dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define ctime_r _incompatible_ctime_r
681dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif /* HAVE_INCOMPATIBLE_CTIME_R */
691dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
709fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes/* Enable tm_gmtoff and tm_zone on GNUish systems.  */
719fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#define _GNU_SOURCE 1
729fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes/* Fix asctime_r on Solaris 10.  */
739fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#define _POSIX_PTHREAD_SEMANTICS 1
749fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes/* Enable strtoimax on Solaris 10.  */
759fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#define __EXTENSIONS__ 1
769fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes
771dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/*
781dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project** Nested includes
791dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project*/
801dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
819fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes/* Avoid clashes with NetBSD by renaming NetBSD's declarations.  */
829fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#define localtime_rz sys_localtime_rz
839fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#define mktime_z sys_mktime_z
849fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#define posix2time_z sys_posix2time_z
859fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#define time2posix_z sys_time2posix_z
869fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#define timezone_t sys_timezone_t
879fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#define tzalloc sys_tzalloc
889fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#define tzfree sys_tzfree
899fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#include <time.h>
909fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#undef localtime_rz
919fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#undef mktime_z
929fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#undef posix2time_z
939fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#undef time2posix_z
949fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#undef timezone_t
959fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#undef tzalloc
969fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#undef tzfree
979fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes
98ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes#include "sys/types.h"	/* for time_t */
991dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#include "stdio.h"
1001dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#include "string.h"
101ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes#include "limits.h"	/* for CHAR_BIT et al. */
1021dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#include "stdlib.h"
1031dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
1049fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#include "errno.h"
1059fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes
1069fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#ifndef ENAMETOOLONG
1079fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# define ENAMETOOLONG EINVAL
1089fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#endif
1099fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#ifndef EOVERFLOW
1109fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# define EOVERFLOW EINVAL
1119fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#endif
1129fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes
1131dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#if HAVE_GETTEXT
1141dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#include "libintl.h"
1151dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif /* HAVE_GETTEXT */
1161dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
1171dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#if HAVE_SYS_WAIT_H
118ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes#include <sys/wait.h>	/* for WIFEXITED and WEXITSTATUS */
1191dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif /* HAVE_SYS_WAIT_H */
1201dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
1211dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#ifndef WIFEXITED
122ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes#define WIFEXITED(status)	(((status) & 0xff) == 0)
1231dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif /* !defined WIFEXITED */
1241dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#ifndef WEXITSTATUS
125ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes#define WEXITSTATUS(status)	(((status) >> 8) & 0xff)
1261dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif /* !defined WEXITSTATUS */
1271dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
1281dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#if HAVE_UNISTD_H
129ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes#include "unistd.h"	/* for F_OK, R_OK, and other POSIX goodness */
1301dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif /* HAVE_UNISTD_H */
1311dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
1329fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#ifndef HAVE_STRFTIME_L
1339fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# if _POSIX_VERSION < 200809
1349fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#  define HAVE_STRFTIME_L 0
1359fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# else
1369fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#  define HAVE_STRFTIME_L 1
1379fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# endif
1389fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#endif
1399fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes
1401dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#ifndef F_OK
141ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes#define F_OK	0
1421dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif /* !defined F_OK */
1431dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#ifndef R_OK
144ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes#define R_OK	4
1451dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif /* !defined R_OK */
1461dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
1471dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/* Unlike <ctype.h>'s isdigit, this also works if c < 0 | c > UCHAR_MAX. */
1481dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define is_digit(c) ((unsigned)(c) - '0' <= 9)
1491dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
1501dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/*
1511dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project** Define HAVE_STDINT_H's default value here, rather than at the
1521dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project** start, since __GLIBC__'s value depends on previously-included
1531dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project** files.
1541dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project** (glibc 2.1 and later have stdint.h, even with pre-C99 compilers.)
1551dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project*/
1561dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#ifndef HAVE_STDINT_H
1571dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define HAVE_STDINT_H \
1585f564540a953a670925e058dabc521f68ffb997cElliott Hughes   (199901 <= __STDC_VERSION__ \
1595f564540a953a670925e058dabc521f68ffb997cElliott Hughes    || 2 < __GLIBC__ + (1 <= __GLIBC_MINOR__)	\
1605f564540a953a670925e058dabc521f68ffb997cElliott Hughes    || __CYGWIN__)
1611dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif /* !defined HAVE_STDINT_H */
1621dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
1631dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#if HAVE_STDINT_H
1641dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#include "stdint.h"
1651dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif /* !HAVE_STDINT_H */
1661dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
167ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes#ifndef HAVE_INTTYPES_H
168ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes# define HAVE_INTTYPES_H HAVE_STDINT_H
169ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes#endif
170ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes#if HAVE_INTTYPES_H
171ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes# include <inttypes.h>
172ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes#endif
173ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes
1741dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/* Pre-C99 GCC compilers define __LONG_LONG_MAX__ instead of LLONG_MAX.  */
1759fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#ifdef __LONG_LONG_MAX__
1769fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# ifndef LLONG_MAX
1779fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#  define LLONG_MAX __LONG_LONG_MAX__
1789fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# endif
1799fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# ifndef LLONG_MIN
1809fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#  define LLONG_MIN (-1 - LLONG_MAX)
1819fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# endif
1829fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#endif
1839fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes
1849fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#ifndef INT_FAST64_MAX
185ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes# ifdef LLONG_MAX
1869fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughestypedef long long	int_fast64_t;
187ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes#  define INT_FAST64_MIN LLONG_MIN
188ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes#  define INT_FAST64_MAX LLONG_MAX
189ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes# else
1909fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#  if LONG_MAX >> 31 < 0xffffffff
1911dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source ProjectPlease use a compiler that supports a 64-bit integer type (or wider);
1921dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectyou may need to compile with "-DHAVE_STDINT_H".
1939fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#  endif
194ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughestypedef long		int_fast64_t;
1959fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#  define INT_FAST64_MIN LONG_MIN
1969fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#  define INT_FAST64_MAX LONG_MAX
1979fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# endif
1989fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#endif
1999fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes
2009fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#ifndef SCNdFAST64
2019fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# if INT_FAST64_MAX == LLONG_MAX
2029fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#  define SCNdFAST64 "lld"
2039fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# else
2049fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#  define SCNdFAST64 "ld"
2059fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# endif
2069fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#endif
2071dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
208ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes#ifndef INT_FAST32_MAX
209ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes# if INT_MAX >> 31 == 0
210ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughestypedef long int_fast32_t;
2119fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#  define INT_FAST32_MAX LONG_MAX
2129fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#  define INT_FAST32_MIN LONG_MIN
213ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes# else
214ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughestypedef int int_fast32_t;
2159fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#  define INT_FAST32_MAX INT_MAX
2169fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#  define INT_FAST32_MIN INT_MIN
217ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes# endif
218ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes#endif
219ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes
220ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes#ifndef INTMAX_MAX
2219fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# ifdef LLONG_MAX
222ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughestypedef long long intmax_t;
223e0d0b15de6eaee6c3975e13ad2b0e1238d0fdd8fElliott Hughes#  define strtoimax strtoll
2249fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#  define INTMAX_MAX LLONG_MAX
2259fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#  define INTMAX_MIN LLONG_MIN
226ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes# else
227ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughestypedef long intmax_t;
228e0d0b15de6eaee6c3975e13ad2b0e1238d0fdd8fElliott Hughes#  define strtoimax strtol
229e0d0b15de6eaee6c3975e13ad2b0e1238d0fdd8fElliott Hughes#  define INTMAX_MAX LONG_MAX
230e0d0b15de6eaee6c3975e13ad2b0e1238d0fdd8fElliott Hughes#  define INTMAX_MIN LONG_MIN
231ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes# endif
232ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes#endif
233ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes
2349fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#ifndef PRIdMAX
2359fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# if INTMAX_MAX == LLONG_MAX
2369fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#  define PRIdMAX "lld"
2379fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# else
2389fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#  define PRIdMAX "ld"
2399fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# endif
2409fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#endif
2419fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes
2429fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#ifndef UINT_FAST64_MAX
2439fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# if defined ULLONG_MAX || defined __LONG_LONG_MAX__
2449fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughestypedef unsigned long long uint_fast64_t;
2459fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# else
2469fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#  if ULONG_MAX >> 31 >> 1 < 0xffffffff
2479fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott HughesPlease use a compiler that supports a 64-bit integer type (or wider);
2489fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughesyou may need to compile with "-DHAVE_STDINT_H".
2499fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#  endif
2509fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughestypedef unsigned long	uint_fast64_t;
2519fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# endif
2529fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#endif
2539fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes
254ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes#ifndef UINTMAX_MAX
255ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes# if defined ULLONG_MAX || defined __LONG_LONG_MAX__
256ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughestypedef unsigned long long uintmax_t;
257ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes# else
258ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughestypedef unsigned long uintmax_t;
2599fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# endif
2609fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#endif
2619fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes
2629fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#ifndef PRIuMAX
2639fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# if defined ULLONG_MAX || defined __LONG_LONG_MAX__
2649fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#  define PRIuMAX "llu"
2659fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# else
266ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes#  define PRIuMAX "lu"
267ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes# endif
268ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes#endif
269ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes
2701dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#ifndef INT32_MAX
2711dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define INT32_MAX 0x7fffffff
2721dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif /* !defined INT32_MAX */
2731dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#ifndef INT32_MIN
2741dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define INT32_MIN (-1 - INT32_MAX)
2751dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif /* !defined INT32_MIN */
2761dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
2775f564540a953a670925e058dabc521f68ffb997cElliott Hughes#ifndef SIZE_MAX
2785f564540a953a670925e058dabc521f68ffb997cElliott Hughes#define SIZE_MAX ((size_t) -1)
2795f564540a953a670925e058dabc521f68ffb997cElliott Hughes#endif
2805f564540a953a670925e058dabc521f68ffb997cElliott Hughes
281ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes#if 2 < __GNUC__ + (96 <= __GNUC_MINOR__)
282ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes# define ATTRIBUTE_CONST __attribute__ ((const))
283ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes# define ATTRIBUTE_PURE __attribute__ ((__pure__))
284e0d0b15de6eaee6c3975e13ad2b0e1238d0fdd8fElliott Hughes# define ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
285ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes#else
286ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes# define ATTRIBUTE_CONST /* empty */
287ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes# define ATTRIBUTE_PURE /* empty */
288e0d0b15de6eaee6c3975e13ad2b0e1238d0fdd8fElliott Hughes# define ATTRIBUTE_FORMAT(spec) /* empty */
289ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes#endif
2901dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
291ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes#if !defined _Noreturn && __STDC_VERSION__ < 201112
292ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes# if 2 < __GNUC__ + (8 <= __GNUC_MINOR__)
293ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes#  define _Noreturn __attribute__ ((__noreturn__))
294ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes# else
295ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes#  define _Noreturn
296ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes# endif
297ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes#endif
2981dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
299ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes#if __STDC_VERSION__ < 199901 && !defined restrict
300ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes# define restrict /* empty */
301ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes#endif
3021dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
3031dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/*
304ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes** Workarounds for compilers/systems.
3051dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project*/
3061dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
3071dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/*
308ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes** Compile with -Dtime_tz=T to build the tz package with a private
309ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes** time_t type equivalent to T rather than the system-supplied time_t.
310ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes** This debugging feature can test unusual design decisions
311ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes** (e.g., time_t wider than 'long', or unsigned time_t) even on
312ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes** typical platforms.
313ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes*/
314ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes#ifdef time_tz
3159fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# ifdef LOCALTIME_IMPLEMENTATION
316ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughesstatic time_t sys_time(time_t *x) { return time(x); }
3179fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# endif
3189fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes
3199fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughestypedef time_tz tz_time_t;
320ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes
321ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes# undef  ctime
322ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes# define ctime tz_ctime
323ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes# undef  ctime_r
324ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes# define ctime_r tz_ctime_r
325ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes# undef  difftime
326ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes# define difftime tz_difftime
327ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes# undef  gmtime
328ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes# define gmtime tz_gmtime
329ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes# undef  gmtime_r
330ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes# define gmtime_r tz_gmtime_r
331ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes# undef  localtime
332ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes# define localtime tz_localtime
333ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes# undef  localtime_r
334ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes# define localtime_r tz_localtime_r
3359fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# undef  localtime_rz
3369fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# define localtime_rz tz_localtime_rz
337ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes# undef  mktime
338ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes# define mktime tz_mktime
3399fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# undef  mktime_z
3409fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# define mktime_z tz_mktime_z
3419fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# undef  offtime
3429fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# define offtime tz_offtime
3439fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# undef  posix2time
3449fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# define posix2time tz_posix2time
3459fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# undef  posix2time_z
3469fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# define posix2time_z tz_posix2time_z
347ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes# undef  time
348ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes# define time tz_time
3499fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# undef  time2posix
3509fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# define time2posix tz_time2posix
3519fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# undef  time2posix_z
3529fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# define time2posix_z tz_time2posix_z
353ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes# undef  time_t
354ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes# define time_t tz_time_t
3559fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# undef  timegm
3569fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# define timegm tz_timegm
3579fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# undef  timelocal
3589fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# define timelocal tz_timelocal
3599fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# undef  timeoff
3609fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# define timeoff tz_timeoff
3619fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# undef  tzalloc
3629fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# define tzalloc tz_tzalloc
3639fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# undef  tzfree
3649fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# define tzfree tz_tzfree
3659fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# undef  tzset
3669fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# define tzset tz_tzset
3679fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# undef  tzsetwall
3689fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# define tzsetwall tz_tzsetwall
369ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes
370ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hugheschar *ctime(time_t const *);
371ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hugheschar *ctime_r(time_t const *, char *);
372ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughesdouble difftime(time_t, time_t);
373ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughesstruct tm *gmtime(time_t const *);
374ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughesstruct tm *gmtime_r(time_t const *restrict, struct tm *restrict);
375ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughesstruct tm *localtime(time_t const *);
376ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughesstruct tm *localtime_r(time_t const *restrict, struct tm *restrict);
377ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughestime_t mktime(struct tm *);
3789fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughestime_t time(time_t *);
3799fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughesvoid tzset(void);
3809fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#endif
3819fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes
3829fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes/*
3839fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes** Some time.h implementations don't declare asctime_r.
3849fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes** Others might define it as a macro.
3859fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes** Fix the former without affecting the latter.
3869fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes** Similarly for timezone, daylight, and altzone.
3879fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes*/
388ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes
3899fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#ifndef asctime_r
3909fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughesextern char *	asctime_r(struct tm const *restrict, char *restrict);
3919fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#endif
3929fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes
3939fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#ifdef USG_COMPAT
3949fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# ifndef timezone
3959fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughesextern long timezone;
3969fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# endif
3979fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# ifndef daylight
3989fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughesextern int daylight;
3999fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# endif
4009fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#endif
4019fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#if defined ALTZONE && !defined altzone
4029fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughesextern long altzone;
4031dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif
4041dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
4051dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/*
4069fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes** The STD_INSPIRED functions are similar, but most also need
4079fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes** declarations if time_tz is defined.
4081dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project*/
4091dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
4109fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#ifdef STD_INSPIRED
4119fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# if !defined tzsetwall || defined time_tz
4129fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughesvoid tzsetwall(void);
4139fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# endif
4149fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# if !defined offtime || defined time_tz
4159fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughesstruct tm *offtime(time_t const *, long);
4169fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# endif
4179fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# if !defined timegm || defined time_tz
4189fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughestime_t timegm(struct tm *);
4199fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# endif
4209fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# if !defined timelocal || defined time_tz
4219fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughestime_t timelocal(struct tm *);
4229fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# endif
4239fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# if !defined timeoff || defined time_tz
4249fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughestime_t timeoff(struct tm *, long);
4259fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# endif
4269fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# if !defined time2posix || defined time_tz
4279fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughestime_t time2posix(time_t);
4289fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# endif
4299fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# if !defined posix2time || defined time_tz
4309fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughestime_t posix2time(time_t);
4319fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# endif
4329fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#endif
4339fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes
4349fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes/* Infer TM_ZONE on systems where this information is known, but suppress
4359fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes   guessing if NO_TM_ZONE is defined.  Similarly for TM_GMTOFF.  */
4369fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#if (defined __GLIBC__ \
4379fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes     || defined __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__ \
4389fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes     || (defined __APPLE__ && defined __MACH__))
4399fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# if !defined TM_GMTOFF && !defined NO_TM_GMTOFF
4409fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#  define TM_GMTOFF tm_gmtoff
4419fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# endif
4429fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# if !defined TM_ZONE && !defined NO_TM_ZONE
4439fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#  define TM_ZONE tm_zone
4449fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# endif
4459fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#endif
4461dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
4471dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/*
4489fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes** Define functions that are ABI compatible with NetBSD but have
4499fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes** better prototypes.  NetBSD 6.1.4 defines a pointer type timezone_t
4509fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes** and labors under the misconception that 'const timezone_t' is a
4519fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes** pointer to a constant.  This use of 'const' is ineffective, so it
4529fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes** is not done here.  What we call 'struct state' NetBSD calls
4539fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes** 'struct __state', but this is a private name so it doesn't matter.
4541dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project*/
4559fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#if NETBSD_INSPIRED
4569fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughestypedef struct state *timezone_t;
4579fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughesstruct tm *localtime_rz(timezone_t restrict, time_t const *restrict,
4589fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes			struct tm *restrict);
4599fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughestime_t mktime_z(timezone_t restrict, struct tm *restrict);
4609fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughestimezone_t tzalloc(char const *);
4619fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughesvoid tzfree(timezone_t);
4629fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# ifdef STD_INSPIRED
4639fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#  if !defined posix2time_z || defined time_tz
4649fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughestime_t posix2time_z(timezone_t, time_t) ATTRIBUTE_PURE;
4659fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#  endif
4669fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#  if !defined time2posix_z || defined time_tz
4679fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughestime_t time2posix_z(timezone_t, time_t) ATTRIBUTE_PURE;
4689fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#  endif
4699fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# endif
4709fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#endif
4711dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
4729fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes/*
4739fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes** Finally, some convenience items.
4749fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes*/
4751dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
4769fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#if __STDC_VERSION__ < 199901
4779fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# define true 1
4789fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# define false 0
4799fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# define bool int
4809fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#else
4819fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# include <stdbool.h>
4829fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#endif
4831dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
4841dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#ifndef TYPE_BIT
485ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes#define TYPE_BIT(type)	(sizeof (type) * CHAR_BIT)
4861dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif /* !defined TYPE_BIT */
4871dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
4881dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#ifndef TYPE_SIGNED
4891dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define TYPE_SIGNED(type) (((type) -1) < 0)
4901dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif /* !defined TYPE_SIGNED */
4911dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
49223360cc4980213d375718b7c124ecc0a21a1b1b7Stephen Hines#define TWOS_COMPLEMENT(t) ((t) ~ (t) 0 < 0)
49323360cc4980213d375718b7c124ecc0a21a1b1b7Stephen Hines
4949fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes/* Max and min values of the integer type T, of which only the bottom
4959fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes   B bits are used, and where the highest-order used bit is considered
4969fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes   to be a sign bit if T is signed.  */
4979fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#define MAXVAL(t, b)						\
4989fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes  ((t) (((t) 1 << ((b) - 1 - TYPE_SIGNED(t)))			\
4999fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes	- 1 + ((t) 1 << ((b) - 1 - TYPE_SIGNED(t)))))
5009fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#define MINVAL(t, b)						\
5019fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes  ((t) (TYPE_SIGNED(t) ? - TWOS_COMPLEMENT(t) - MAXVAL(t, b) : 0))
50223360cc4980213d375718b7c124ecc0a21a1b1b7Stephen Hines
50323360cc4980213d375718b7c124ecc0a21a1b1b7Stephen Hines/* The minimum and maximum finite time values.  This assumes no padding.  */
50423360cc4980213d375718b7c124ecc0a21a1b1b7Stephen Hinesstatic time_t const time_t_min = MINVAL(time_t, TYPE_BIT(time_t));
50523360cc4980213d375718b7c124ecc0a21a1b1b7Stephen Hinesstatic time_t const time_t_max = MAXVAL(time_t, TYPE_BIT(time_t));
506713fe6463e6ff8cb9689aa8ead88c885d25d03aaElliott Hughes
5071dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#ifndef INT_STRLEN_MAXIMUM
5081dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/*
5091dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project** 302 / 1000 is log10(2.0) rounded up.
5101dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project** Subtract one for the sign bit if the type is signed;
5111dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project** add one for integer division truncation;
5121dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project** add one more for a minus sign if the type is signed.
5131dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project*/
5141dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define INT_STRLEN_MAXIMUM(type) \
515ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes	((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + \
516ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes	1 + TYPE_SIGNED(type))
5171dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif /* !defined INT_STRLEN_MAXIMUM */
5181dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
5191dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/*
5201dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project** INITIALIZE(x)
5211dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project*/
5221dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
5231dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#ifdef lint
5245f564540a953a670925e058dabc521f68ffb997cElliott Hughes# define INITIALIZE(x)	((x) = 0)
5255f564540a953a670925e058dabc521f68ffb997cElliott Hughes#else
5265f564540a953a670925e058dabc521f68ffb997cElliott Hughes# define INITIALIZE(x)
5275f564540a953a670925e058dabc521f68ffb997cElliott Hughes#endif
5281dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
5299fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#ifndef UNINIT_TRAP
5309fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes# define UNINIT_TRAP 0
5319fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#endif
5329fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes
5331dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/*
5341dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project** For the benefit of GNU folk...
5355f564540a953a670925e058dabc521f68ffb997cElliott Hughes** '_(MSGID)' uses the current locale's message library string for MSGID.
5361dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project** The default is to use gettext if available, and use MSGID otherwise.
5371dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project*/
5381dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
5391dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#ifndef _
5401dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#if HAVE_GETTEXT
5411dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define _(msgid) gettext(msgid)
5421dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#else /* !HAVE_GETTEXT */
5431dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define _(msgid) msgid
5441dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif /* !HAVE_GETTEXT */
5451dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif /* !defined _ */
5461dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
5479fb22a3ec4ec5217fc29bb3ee3a0f1076098151fElliott Hughes#if !defined TZ_DOMAIN && defined HAVE_GETTEXT
5485f564540a953a670925e058dabc521f68ffb997cElliott Hughes# define TZ_DOMAIN "tz"
5495f564540a953a670925e058dabc521f68ffb997cElliott Hughes#endif
5501dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
5511dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#if HAVE_INCOMPATIBLE_CTIME_R
5521dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#undef asctime_r
5531dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#undef ctime_r
554ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hugheschar *asctime_r(struct tm const *, char *);
555ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hugheschar *ctime_r(time_t const *, char *);
5561dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif /* HAVE_INCOMPATIBLE_CTIME_R */
5571dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
5581dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#ifndef YEARSPERREPEAT
559ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes#define YEARSPERREPEAT		400	/* years before a Gregorian repeat */
5601dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif /* !defined YEARSPERREPEAT */
5611dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
5621dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/*
5631dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project** The Gregorian year averages 365.2425 days, which is 31556952 seconds.
5641dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project*/
5651dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
5661dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#ifndef AVGSECSPERYEAR
567ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes#define AVGSECSPERYEAR		31556952L
5681dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif /* !defined AVGSECSPERYEAR */
5691dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
5701dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#ifndef SECSPERREPEAT
571ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes#define SECSPERREPEAT		((int_fast64_t) YEARSPERREPEAT * (int_fast64_t) AVGSECSPERYEAR)
5721dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif /* !defined SECSPERREPEAT */
573ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes
5741dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#ifndef SECSPERREPEAT_BITS
575ce4783ce76a4ef888466e02e4c6f3a0a3910bce8Elliott Hughes#define SECSPERREPEAT_BITS	34	/* ceil(log2(SECSPERREPEAT)) */
5761dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif /* !defined SECSPERREPEAT_BITS */
5771dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
5781dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif /* !defined PRIVATE_H */
579