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