Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame^] | 1 | /* Private header for tzdb code. */ |
| 2 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 3 | #ifndef PRIVATE_H |
| 4 | |
| 5 | #define PRIVATE_H |
| 6 | |
| 7 | /* |
| 8 | ** This file is in the public domain, so clarified as of |
| 9 | ** 1996-06-05 by Arthur David Olson. |
| 10 | */ |
| 11 | |
| 12 | /* |
| 13 | ** This header is for use ONLY with the time conversion code. |
| 14 | ** There is no guarantee that it will remain unchanged, |
| 15 | ** or that it will remain at all. |
| 16 | ** Do NOT copy it to any system include directory. |
| 17 | ** Thank you! |
| 18 | */ |
| 19 | |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame^] | 20 | /* |
| 21 | ** zdump has been made independent of the rest of the time |
| 22 | ** conversion package to increase confidence in the verification it provides. |
| 23 | ** You can use zdump to help in verifying other implementations. |
| 24 | ** To do this, compile with -DUSE_LTZ=0 and link without the tz library. |
| 25 | */ |
| 26 | #ifndef USE_LTZ |
| 27 | # define USE_LTZ 1 |
| 28 | #endif |
| 29 | |
| 30 | /* This string was in the Factory zone through version 2016f. */ |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 31 | #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] | 32 | |
| 33 | /* |
| 34 | ** Defaults for preprocessor symbols. |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 35 | ** 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] | 36 | */ |
| 37 | |
Elliott Hughes | 0a610d0 | 2016-07-29 14:04:17 -0700 | [diff] [blame] | 38 | #ifndef HAVE_DECL_ASCTIME_R |
| 39 | #define HAVE_DECL_ASCTIME_R 1 |
| 40 | #endif |
| 41 | |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame^] | 42 | #if !defined HAVE_GENERIC && defined __has_extension |
| 43 | # if __has_extension(c_generic_selections) |
| 44 | # define HAVE_GENERIC 1 |
| 45 | # else |
| 46 | # define HAVE_GENERIC 0 |
| 47 | # endif |
| 48 | #endif |
| 49 | /* _Generic is buggy in pre-4.9 GCC. */ |
| 50 | #if !defined HAVE_GENERIC && defined __GNUC__ |
| 51 | # define HAVE_GENERIC (4 < __GNUC__ + (9 <= __GNUC_MINOR__)) |
| 52 | #endif |
| 53 | #ifndef HAVE_GENERIC |
| 54 | # define HAVE_GENERIC (201112 <= __STDC_VERSION__) |
| 55 | #endif |
| 56 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 57 | #ifndef HAVE_GETTEXT |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 58 | #define HAVE_GETTEXT 0 |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 59 | #endif /* !defined HAVE_GETTEXT */ |
| 60 | |
| 61 | #ifndef HAVE_INCOMPATIBLE_CTIME_R |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 62 | #define HAVE_INCOMPATIBLE_CTIME_R 0 |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame^] | 63 | #endif |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 64 | |
Calin Juravle | 627d37c | 2014-02-28 11:46:03 +0000 | [diff] [blame] | 65 | #ifndef HAVE_LINK |
| 66 | #define HAVE_LINK 1 |
| 67 | #endif /* !defined HAVE_LINK */ |
| 68 | |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame^] | 69 | #ifndef HAVE_MALLOC_ERRNO |
| 70 | #define HAVE_MALLOC_ERRNO 1 |
| 71 | #endif |
| 72 | |
Elliott Hughes | 0a610d0 | 2016-07-29 14:04:17 -0700 | [diff] [blame] | 73 | #ifndef HAVE_POSIX_DECLS |
| 74 | #define HAVE_POSIX_DECLS 1 |
| 75 | #endif |
| 76 | |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame^] | 77 | #ifndef HAVE_STDBOOL_H |
| 78 | #define HAVE_STDBOOL_H (199901 <= __STDC_VERSION__) |
| 79 | #endif |
| 80 | |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 81 | #ifndef HAVE_STRDUP |
| 82 | #define HAVE_STRDUP 1 |
| 83 | #endif |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 84 | |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame^] | 85 | #ifndef HAVE_STRTOLL |
| 86 | #define HAVE_STRTOLL 1 |
| 87 | #endif |
| 88 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 89 | #ifndef HAVE_SYMLINK |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 90 | #define HAVE_SYMLINK 1 |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 91 | #endif /* !defined HAVE_SYMLINK */ |
| 92 | |
| 93 | #ifndef HAVE_SYS_STAT_H |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 94 | #define HAVE_SYS_STAT_H 1 |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 95 | #endif /* !defined HAVE_SYS_STAT_H */ |
| 96 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 97 | #ifndef HAVE_UNISTD_H |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 98 | #define HAVE_UNISTD_H 1 |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 99 | #endif /* !defined HAVE_UNISTD_H */ |
| 100 | |
| 101 | #ifndef HAVE_UTMPX_H |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 102 | #define HAVE_UTMPX_H 1 |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 103 | #endif /* !defined HAVE_UTMPX_H */ |
| 104 | |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 105 | #ifndef NETBSD_INSPIRED |
| 106 | # define NETBSD_INSPIRED 1 |
| 107 | #endif |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 108 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 109 | #if HAVE_INCOMPATIBLE_CTIME_R |
| 110 | #define asctime_r _incompatible_asctime_r |
| 111 | #define ctime_r _incompatible_ctime_r |
| 112 | #endif /* HAVE_INCOMPATIBLE_CTIME_R */ |
| 113 | |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame^] | 114 | /* Enable tm_gmtoff, tm_zone, and environ on GNUish systems. */ |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 115 | #define _GNU_SOURCE 1 |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame^] | 116 | /* Fix asctime_r on Solaris 11. */ |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 117 | #define _POSIX_PTHREAD_SEMANTICS 1 |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame^] | 118 | /* Enable strtoimax on pre-C99 Solaris 11. */ |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 119 | #define __EXTENSIONS__ 1 |
| 120 | |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame^] | 121 | /* To avoid having 'stat' fail unnecessarily with errno == EOVERFLOW, |
| 122 | enable large files on GNUish systems ... */ |
| 123 | #ifndef _FILE_OFFSET_BITS |
| 124 | # define _FILE_OFFSET_BITS 64 |
| 125 | #endif |
| 126 | /* ... and on AIX ... */ |
| 127 | #define _LARGE_FILES 1 |
| 128 | /* ... and enable large inode numbers on Mac OS X 10.5 and later. */ |
| 129 | #define _DARWIN_USE_64_BIT_INODE 1 |
| 130 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 131 | /* |
| 132 | ** Nested includes |
| 133 | */ |
| 134 | |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame^] | 135 | /* Avoid clashes with NetBSD by renaming NetBSD's declarations. |
| 136 | If defining the 'timezone' variable, avoid a clash with FreeBSD's |
| 137 | 'timezone' function by renaming its declaration. */ |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 138 | #define localtime_rz sys_localtime_rz |
| 139 | #define mktime_z sys_mktime_z |
| 140 | #define posix2time_z sys_posix2time_z |
| 141 | #define time2posix_z sys_time2posix_z |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame^] | 142 | #if defined USG_COMPAT && USG_COMPAT == 2 |
| 143 | # define timezone sys_timezone |
| 144 | #endif |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 145 | #define timezone_t sys_timezone_t |
| 146 | #define tzalloc sys_tzalloc |
| 147 | #define tzfree sys_tzfree |
| 148 | #include <time.h> |
| 149 | #undef localtime_rz |
| 150 | #undef mktime_z |
| 151 | #undef posix2time_z |
| 152 | #undef time2posix_z |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame^] | 153 | #if defined USG_COMPAT && USG_COMPAT == 2 |
| 154 | # undef timezone |
| 155 | #endif |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 156 | #undef timezone_t |
| 157 | #undef tzalloc |
| 158 | #undef tzfree |
| 159 | |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame^] | 160 | #include <sys/types.h> /* for time_t */ |
| 161 | #include <string.h> |
| 162 | #include <limits.h> /* for CHAR_BIT et al. */ |
| 163 | #include <stdlib.h> |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 164 | |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame^] | 165 | #include <errno.h> |
| 166 | |
| 167 | #ifndef EINVAL |
| 168 | # define EINVAL ERANGE |
| 169 | #endif |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 170 | |
| 171 | #ifndef ENAMETOOLONG |
| 172 | # define ENAMETOOLONG EINVAL |
| 173 | #endif |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame^] | 174 | #ifndef ENOMEM |
| 175 | # define ENOMEM EINVAL |
| 176 | #endif |
Elliott Hughes | 0a610d0 | 2016-07-29 14:04:17 -0700 | [diff] [blame] | 177 | #ifndef ENOTSUP |
| 178 | # define ENOTSUP EINVAL |
| 179 | #endif |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 180 | #ifndef EOVERFLOW |
| 181 | # define EOVERFLOW EINVAL |
| 182 | #endif |
| 183 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 184 | #if HAVE_GETTEXT |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame^] | 185 | #include <libintl.h> |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 186 | #endif /* HAVE_GETTEXT */ |
| 187 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 188 | #if HAVE_UNISTD_H |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame^] | 189 | #include <unistd.h> /* for R_OK, and other POSIX goodness */ |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 190 | #endif /* HAVE_UNISTD_H */ |
| 191 | |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 192 | #ifndef HAVE_STRFTIME_L |
| 193 | # if _POSIX_VERSION < 200809 |
| 194 | # define HAVE_STRFTIME_L 0 |
| 195 | # else |
| 196 | # define HAVE_STRFTIME_L 1 |
| 197 | # endif |
| 198 | #endif |
| 199 | |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame^] | 200 | #ifndef USG_COMPAT |
| 201 | # ifndef _XOPEN_VERSION |
| 202 | # define USG_COMPAT 0 |
| 203 | # else |
| 204 | # define USG_COMPAT 1 |
| 205 | # endif |
| 206 | #endif |
| 207 | |
| 208 | #ifndef HAVE_TZNAME |
| 209 | # if _POSIX_VERSION < 198808 && !USG_COMPAT |
| 210 | # define HAVE_TZNAME 0 |
| 211 | # else |
| 212 | # define HAVE_TZNAME 1 |
| 213 | # endif |
| 214 | #endif |
| 215 | |
| 216 | #ifndef ALTZONE |
| 217 | # if defined __sun || defined _M_XENIX |
| 218 | # define ALTZONE 1 |
| 219 | # else |
| 220 | # define ALTZONE 0 |
| 221 | # endif |
| 222 | #endif |
| 223 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 224 | #ifndef R_OK |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 225 | #define R_OK 4 |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 226 | #endif /* !defined R_OK */ |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 227 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 228 | /* |
| 229 | ** Define HAVE_STDINT_H's default value here, rather than at the |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame^] | 230 | ** start, since __GLIBC__ and INTMAX_MAX's values depend on |
| 231 | ** previously-included files. glibc 2.1 and Solaris 10 and later have |
| 232 | ** stdint.h, even with pre-C99 compilers. |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 233 | */ |
| 234 | #ifndef HAVE_STDINT_H |
| 235 | #define HAVE_STDINT_H \ |
Elliott Hughes | 5f56454 | 2014-06-19 13:54:10 -0700 | [diff] [blame] | 236 | (199901 <= __STDC_VERSION__ \ |
| 237 | || 2 < __GLIBC__ + (1 <= __GLIBC_MINOR__) \ |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame^] | 238 | || __CYGWIN__ || INTMAX_MAX) |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 239 | #endif /* !defined HAVE_STDINT_H */ |
| 240 | |
| 241 | #if HAVE_STDINT_H |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame^] | 242 | #include <stdint.h> |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 243 | #endif /* !HAVE_STDINT_H */ |
| 244 | |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 245 | #ifndef HAVE_INTTYPES_H |
| 246 | # define HAVE_INTTYPES_H HAVE_STDINT_H |
| 247 | #endif |
| 248 | #if HAVE_INTTYPES_H |
| 249 | # include <inttypes.h> |
| 250 | #endif |
| 251 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 252 | /* Pre-C99 GCC compilers define __LONG_LONG_MAX__ instead of LLONG_MAX. */ |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 253 | #ifdef __LONG_LONG_MAX__ |
| 254 | # ifndef LLONG_MAX |
| 255 | # define LLONG_MAX __LONG_LONG_MAX__ |
| 256 | # endif |
| 257 | # ifndef LLONG_MIN |
| 258 | # define LLONG_MIN (-1 - LLONG_MAX) |
| 259 | # endif |
| 260 | #endif |
| 261 | |
| 262 | #ifndef INT_FAST64_MAX |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 263 | # ifdef LLONG_MAX |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 264 | typedef long long int_fast64_t; |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 265 | # define INT_FAST64_MIN LLONG_MIN |
| 266 | # define INT_FAST64_MAX LLONG_MAX |
| 267 | # else |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 268 | # if LONG_MAX >> 31 < 0xffffffff |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 269 | Please use a compiler that supports a 64-bit integer type (or wider); |
| 270 | you may need to compile with "-DHAVE_STDINT_H". |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 271 | # endif |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 272 | typedef long int_fast64_t; |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 273 | # define INT_FAST64_MIN LONG_MIN |
| 274 | # define INT_FAST64_MAX LONG_MAX |
| 275 | # endif |
| 276 | #endif |
| 277 | |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame^] | 278 | #ifndef PRIdFAST64 |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 279 | # if INT_FAST64_MAX == LLONG_MAX |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame^] | 280 | # define PRIdFAST64 "lld" |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 281 | # else |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame^] | 282 | # define PRIdFAST64 "ld" |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 283 | # endif |
| 284 | #endif |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 285 | |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame^] | 286 | #ifndef SCNdFAST64 |
| 287 | # define SCNdFAST64 PRIdFAST64 |
| 288 | #endif |
| 289 | |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 290 | #ifndef INT_FAST32_MAX |
| 291 | # if INT_MAX >> 31 == 0 |
| 292 | typedef long int_fast32_t; |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 293 | # define INT_FAST32_MAX LONG_MAX |
| 294 | # define INT_FAST32_MIN LONG_MIN |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 295 | # else |
| 296 | typedef int int_fast32_t; |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 297 | # define INT_FAST32_MAX INT_MAX |
| 298 | # define INT_FAST32_MIN INT_MIN |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 299 | # endif |
| 300 | #endif |
| 301 | |
| 302 | #ifndef INTMAX_MAX |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 303 | # ifdef LLONG_MAX |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 304 | typedef long long intmax_t; |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame^] | 305 | # if HAVE_STRTOLL |
| 306 | # define strtoimax strtoll |
| 307 | # endif |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 308 | # define INTMAX_MAX LLONG_MAX |
| 309 | # define INTMAX_MIN LLONG_MIN |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 310 | # else |
| 311 | typedef long intmax_t; |
Elliott Hughes | e0d0b15 | 2013-09-27 00:04:30 -0700 | [diff] [blame] | 312 | # define INTMAX_MAX LONG_MAX |
| 313 | # define INTMAX_MIN LONG_MIN |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 314 | # endif |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame^] | 315 | # ifndef strtoimax |
| 316 | # define strtoimax strtol |
| 317 | # endif |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 318 | #endif |
| 319 | |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 320 | #ifndef PRIdMAX |
| 321 | # if INTMAX_MAX == LLONG_MAX |
| 322 | # define PRIdMAX "lld" |
| 323 | # else |
| 324 | # define PRIdMAX "ld" |
| 325 | # endif |
| 326 | #endif |
| 327 | |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame^] | 328 | #ifndef UINT_FAST32_MAX |
| 329 | typedef unsigned long uint_fast32_t; |
| 330 | #endif |
| 331 | |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 332 | #ifndef UINT_FAST64_MAX |
| 333 | # if defined ULLONG_MAX || defined __LONG_LONG_MAX__ |
| 334 | typedef unsigned long long uint_fast64_t; |
| 335 | # else |
| 336 | # if ULONG_MAX >> 31 >> 1 < 0xffffffff |
| 337 | Please use a compiler that supports a 64-bit integer type (or wider); |
| 338 | you may need to compile with "-DHAVE_STDINT_H". |
| 339 | # endif |
| 340 | typedef unsigned long uint_fast64_t; |
| 341 | # endif |
| 342 | #endif |
| 343 | |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 344 | #ifndef UINTMAX_MAX |
| 345 | # if defined ULLONG_MAX || defined __LONG_LONG_MAX__ |
| 346 | typedef unsigned long long uintmax_t; |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 347 | # else |
| 348 | typedef unsigned long uintmax_t; |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 349 | # endif |
| 350 | #endif |
| 351 | |
| 352 | #ifndef PRIuMAX |
| 353 | # if defined ULLONG_MAX || defined __LONG_LONG_MAX__ |
| 354 | # define PRIuMAX "llu" |
| 355 | # else |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 356 | # define PRIuMAX "lu" |
| 357 | # endif |
| 358 | #endif |
| 359 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 360 | #ifndef INT32_MAX |
| 361 | #define INT32_MAX 0x7fffffff |
| 362 | #endif /* !defined INT32_MAX */ |
| 363 | #ifndef INT32_MIN |
| 364 | #define INT32_MIN (-1 - INT32_MAX) |
| 365 | #endif /* !defined INT32_MIN */ |
| 366 | |
Elliott Hughes | 5f56454 | 2014-06-19 13:54:10 -0700 | [diff] [blame] | 367 | #ifndef SIZE_MAX |
| 368 | #define SIZE_MAX ((size_t) -1) |
| 369 | #endif |
| 370 | |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame^] | 371 | #if 3 <= __GNUC__ |
| 372 | # define ATTRIBUTE_CONST __attribute__((const)) |
| 373 | # define ATTRIBUTE_MALLOC __attribute__((__malloc__)) |
| 374 | # define ATTRIBUTE_PURE __attribute__((__pure__)) |
| 375 | # define ATTRIBUTE_FORMAT(spec) __attribute__((__format__ spec)) |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 376 | #else |
| 377 | # define ATTRIBUTE_CONST /* empty */ |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame^] | 378 | # define ATTRIBUTE_MALLOC /* empty */ |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 379 | # define ATTRIBUTE_PURE /* empty */ |
Elliott Hughes | e0d0b15 | 2013-09-27 00:04:30 -0700 | [diff] [blame] | 380 | # define ATTRIBUTE_FORMAT(spec) /* empty */ |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 381 | #endif |
| 382 | |
| 383 | #if !defined _Noreturn && __STDC_VERSION__ < 201112 |
| 384 | # if 2 < __GNUC__ + (8 <= __GNUC_MINOR__) |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame^] | 385 | # define _Noreturn __attribute__((__noreturn__)) |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 386 | # else |
| 387 | # define _Noreturn |
| 388 | # endif |
| 389 | #endif |
| 390 | |
| 391 | #if __STDC_VERSION__ < 199901 && !defined restrict |
| 392 | # define restrict /* empty */ |
| 393 | #endif |
| 394 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 395 | /* |
| 396 | ** Workarounds for compilers/systems. |
| 397 | */ |
| 398 | |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame^] | 399 | #ifndef EPOCH_LOCAL |
| 400 | # define EPOCH_LOCAL 0 |
| 401 | #endif |
| 402 | #ifndef EPOCH_OFFSET |
| 403 | # define EPOCH_OFFSET 0 |
| 404 | #endif |
| 405 | #ifndef RESERVE_STD_EXT_IDS |
| 406 | # define RESERVE_STD_EXT_IDS 0 |
| 407 | #endif |
| 408 | |
| 409 | /* If standard C identifiers with external linkage (e.g., localtime) |
| 410 | are reserved and are not already being renamed anyway, rename them |
| 411 | as if compiling with '-Dtime_tz=time_t'. */ |
| 412 | #if !defined time_tz && RESERVE_STD_EXT_IDS && USE_LTZ |
| 413 | # define time_tz time_t |
| 414 | #endif |
| 415 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 416 | /* |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 417 | ** Compile with -Dtime_tz=T to build the tz package with a private |
| 418 | ** time_t type equivalent to T rather than the system-supplied time_t. |
| 419 | ** This debugging feature can test unusual design decisions |
| 420 | ** (e.g., time_t wider than 'long', or unsigned time_t) even on |
| 421 | ** typical platforms. |
| 422 | */ |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame^] | 423 | #if defined time_tz || EPOCH_LOCAL || EPOCH_OFFSET != 0 |
| 424 | # define TZ_TIME_T 1 |
| 425 | #else |
| 426 | # define TZ_TIME_T 0 |
| 427 | #endif |
| 428 | |
| 429 | #if defined LOCALTIME_IMPLEMENTATION && TZ_TIME_T |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 430 | static time_t sys_time(time_t *x) { return time(x); } |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame^] | 431 | #endif |
| 432 | |
| 433 | #if TZ_TIME_T |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 434 | |
| 435 | typedef time_tz tz_time_t; |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 436 | |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame^] | 437 | # undef asctime |
| 438 | # define asctime tz_asctime |
| 439 | # undef asctime_r |
| 440 | # define asctime_r tz_asctime_r |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 441 | # undef ctime |
| 442 | # define ctime tz_ctime |
| 443 | # undef ctime_r |
| 444 | # define ctime_r tz_ctime_r |
| 445 | # undef difftime |
| 446 | # define difftime tz_difftime |
| 447 | # undef gmtime |
| 448 | # define gmtime tz_gmtime |
| 449 | # undef gmtime_r |
| 450 | # define gmtime_r tz_gmtime_r |
| 451 | # undef localtime |
| 452 | # define localtime tz_localtime |
| 453 | # undef localtime_r |
| 454 | # define localtime_r tz_localtime_r |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 455 | # undef localtime_rz |
| 456 | # define localtime_rz tz_localtime_rz |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 457 | # undef mktime |
| 458 | # define mktime tz_mktime |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 459 | # undef mktime_z |
| 460 | # define mktime_z tz_mktime_z |
| 461 | # undef offtime |
| 462 | # define offtime tz_offtime |
| 463 | # undef posix2time |
| 464 | # define posix2time tz_posix2time |
| 465 | # undef posix2time_z |
| 466 | # define posix2time_z tz_posix2time_z |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame^] | 467 | # undef strftime |
| 468 | # define strftime tz_strftime |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 469 | # undef time |
| 470 | # define time tz_time |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 471 | # undef time2posix |
| 472 | # define time2posix tz_time2posix |
| 473 | # undef time2posix_z |
| 474 | # define time2posix_z tz_time2posix_z |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 475 | # undef time_t |
| 476 | # define time_t tz_time_t |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 477 | # undef timegm |
| 478 | # define timegm tz_timegm |
| 479 | # undef timelocal |
| 480 | # define timelocal tz_timelocal |
| 481 | # undef timeoff |
| 482 | # define timeoff tz_timeoff |
| 483 | # undef tzalloc |
| 484 | # define tzalloc tz_tzalloc |
| 485 | # undef tzfree |
| 486 | # define tzfree tz_tzfree |
| 487 | # undef tzset |
| 488 | # define tzset tz_tzset |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame^] | 489 | # if HAVE_STRFTIME_L |
| 490 | # undef strftime_l |
| 491 | # define strftime_l tz_strftime_l |
| 492 | # endif |
| 493 | # if HAVE_TZNAME |
| 494 | # undef tzname |
| 495 | # define tzname tz_tzname |
| 496 | # endif |
| 497 | # if USG_COMPAT |
| 498 | # undef daylight |
| 499 | # define daylight tz_daylight |
| 500 | # undef timezone |
| 501 | # define timezone tz_timezone |
| 502 | # endif |
| 503 | # if ALTZONE |
| 504 | # undef altzone |
| 505 | # define altzone tz_altzone |
| 506 | # endif |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 507 | |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame^] | 508 | char *asctime(struct tm const *); |
| 509 | char *asctime_r(struct tm const *restrict, char *restrict); |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 510 | char *ctime(time_t const *); |
| 511 | char *ctime_r(time_t const *, char *); |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame^] | 512 | double difftime(time_t, time_t) ATTRIBUTE_CONST; |
| 513 | size_t strftime(char *restrict, size_t, char const *restrict, |
| 514 | struct tm const *restrict); |
| 515 | # if HAVE_STRFTIME_L |
| 516 | size_t strftime_l(char *restrict, size_t, char const *restrict, |
| 517 | struct tm const *restrict, locale_t); |
| 518 | # endif |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 519 | struct tm *gmtime(time_t const *); |
| 520 | struct tm *gmtime_r(time_t const *restrict, struct tm *restrict); |
| 521 | struct tm *localtime(time_t const *); |
| 522 | struct tm *localtime_r(time_t const *restrict, struct tm *restrict); |
| 523 | time_t mktime(struct tm *); |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 524 | time_t time(time_t *); |
| 525 | void tzset(void); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 526 | #endif |
| 527 | |
Elliott Hughes | 0a610d0 | 2016-07-29 14:04:17 -0700 | [diff] [blame] | 528 | #if !HAVE_DECL_ASCTIME_R && !defined asctime_r |
| 529 | extern char *asctime_r(struct tm const *restrict, char *restrict); |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 530 | #endif |
| 531 | |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame^] | 532 | #ifndef HAVE_DECL_ENVIRON |
| 533 | # if defined environ || defined __USE_GNU |
| 534 | # define HAVE_DECL_ENVIRON 1 |
| 535 | # else |
| 536 | # define HAVE_DECL_ENVIRON 0 |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 537 | # endif |
| 538 | #endif |
Elliott Hughes | 0a610d0 | 2016-07-29 14:04:17 -0700 | [diff] [blame] | 539 | |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame^] | 540 | #if !HAVE_DECL_ENVIRON |
| 541 | extern char **environ; |
| 542 | #endif |
| 543 | |
| 544 | #if 2 <= HAVE_TZNAME + (TZ_TIME_T || !HAVE_POSIX_DECLS) |
| 545 | extern char *tzname[]; |
| 546 | #endif |
| 547 | #if 2 <= USG_COMPAT + (TZ_TIME_T || !HAVE_POSIX_DECLS) |
| 548 | extern long timezone; |
| 549 | extern int daylight; |
| 550 | #endif |
| 551 | #if 2 <= ALTZONE + (TZ_TIME_T || !HAVE_POSIX_DECLS) |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 552 | extern long altzone; |
| 553 | #endif |
| 554 | |
| 555 | /* |
| 556 | ** The STD_INSPIRED functions are similar, but most also need |
| 557 | ** declarations if time_tz is defined. |
| 558 | */ |
| 559 | |
| 560 | #ifdef STD_INSPIRED |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame^] | 561 | # if TZ_TIME_T || !defined offtime |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 562 | struct tm *offtime(time_t const *, long); |
| 563 | # endif |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame^] | 564 | # if TZ_TIME_T || !defined timegm |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 565 | time_t timegm(struct tm *); |
| 566 | # endif |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame^] | 567 | # if TZ_TIME_T || !defined timelocal |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 568 | time_t timelocal(struct tm *); |
| 569 | # endif |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame^] | 570 | # if TZ_TIME_T || !defined timeoff |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 571 | time_t timeoff(struct tm *, long); |
| 572 | # endif |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame^] | 573 | # if TZ_TIME_T || !defined time2posix |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 574 | time_t time2posix(time_t); |
| 575 | # endif |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame^] | 576 | # if TZ_TIME_T || !defined posix2time |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 577 | time_t posix2time(time_t); |
| 578 | # endif |
| 579 | #endif |
| 580 | |
| 581 | /* Infer TM_ZONE on systems where this information is known, but suppress |
| 582 | guessing if NO_TM_ZONE is defined. Similarly for TM_GMTOFF. */ |
| 583 | #if (defined __GLIBC__ \ |
| 584 | || defined __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__ \ |
| 585 | || (defined __APPLE__ && defined __MACH__)) |
| 586 | # if !defined TM_GMTOFF && !defined NO_TM_GMTOFF |
| 587 | # define TM_GMTOFF tm_gmtoff |
| 588 | # endif |
| 589 | # if !defined TM_ZONE && !defined NO_TM_ZONE |
| 590 | # define TM_ZONE tm_zone |
| 591 | # endif |
| 592 | #endif |
| 593 | |
| 594 | /* |
| 595 | ** Define functions that are ABI compatible with NetBSD but have |
| 596 | ** better prototypes. NetBSD 6.1.4 defines a pointer type timezone_t |
| 597 | ** and labors under the misconception that 'const timezone_t' is a |
| 598 | ** pointer to a constant. This use of 'const' is ineffective, so it |
| 599 | ** is not done here. What we call 'struct state' NetBSD calls |
| 600 | ** 'struct __state', but this is a private name so it doesn't matter. |
| 601 | */ |
| 602 | #if NETBSD_INSPIRED |
| 603 | typedef struct state *timezone_t; |
| 604 | struct tm *localtime_rz(timezone_t restrict, time_t const *restrict, |
| 605 | struct tm *restrict); |
| 606 | time_t mktime_z(timezone_t restrict, struct tm *restrict); |
| 607 | timezone_t tzalloc(char const *); |
| 608 | void tzfree(timezone_t); |
| 609 | # ifdef STD_INSPIRED |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame^] | 610 | # if TZ_TIME_T || !defined posix2time_z |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 611 | time_t posix2time_z(timezone_t, time_t) ATTRIBUTE_PURE; |
| 612 | # endif |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame^] | 613 | # if TZ_TIME_T || !defined time2posix_z |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 614 | time_t time2posix_z(timezone_t, time_t) ATTRIBUTE_PURE; |
| 615 | # endif |
| 616 | # endif |
| 617 | #endif |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 618 | |
| 619 | /* |
| 620 | ** Finally, some convenience items. |
| 621 | */ |
| 622 | |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame^] | 623 | #if HAVE_STDBOOL_H |
| 624 | # include <stdbool.h> |
| 625 | #else |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 626 | # define true 1 |
| 627 | # define false 0 |
| 628 | # define bool int |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 629 | #endif |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 630 | |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame^] | 631 | #define TYPE_BIT(type) (sizeof(type) * CHAR_BIT) |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 632 | #define TYPE_SIGNED(type) (((type) -1) < 0) |
Stephen Hines | 23360cc | 2015-09-29 09:28:41 -0700 | [diff] [blame] | 633 | #define TWOS_COMPLEMENT(t) ((t) ~ (t) 0 < 0) |
| 634 | |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 635 | /* Max and min values of the integer type T, of which only the bottom |
| 636 | B bits are used, and where the highest-order used bit is considered |
| 637 | to be a sign bit if T is signed. */ |
| 638 | #define MAXVAL(t, b) \ |
| 639 | ((t) (((t) 1 << ((b) - 1 - TYPE_SIGNED(t))) \ |
| 640 | - 1 + ((t) 1 << ((b) - 1 - TYPE_SIGNED(t))))) |
| 641 | #define MINVAL(t, b) \ |
| 642 | ((t) (TYPE_SIGNED(t) ? - TWOS_COMPLEMENT(t) - MAXVAL(t, b) : 0)) |
Stephen Hines | 23360cc | 2015-09-29 09:28:41 -0700 | [diff] [blame] | 643 | |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame^] | 644 | /* The extreme time values, assuming no padding. */ |
| 645 | #define TIME_T_MIN_NO_PADDING MINVAL(time_t, TYPE_BIT(time_t)) |
| 646 | #define TIME_T_MAX_NO_PADDING MAXVAL(time_t, TYPE_BIT(time_t)) |
Elliott Hughes | 713fe64 | 2013-08-22 14:13:50 -0700 | [diff] [blame] | 647 | |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame^] | 648 | /* The extreme time values. These are macros, not constants, so that |
| 649 | any portability problems occur only when compiling .c files that use |
| 650 | the macros, which is safer for applications that need only zdump and zic. |
| 651 | This implementation assumes no padding if time_t is signed and |
| 652 | either the compiler lacks support for _Generic or time_t is not one |
| 653 | of the standard signed integer types. */ |
| 654 | #if HAVE_GENERIC |
| 655 | # define TIME_T_MIN \ |
| 656 | _Generic((time_t) 0, \ |
| 657 | signed char: SCHAR_MIN, short: SHRT_MIN, \ |
| 658 | int: INT_MIN, long: LONG_MIN, long long: LLONG_MIN, \ |
| 659 | default: TIME_T_MIN_NO_PADDING) |
| 660 | # define TIME_T_MAX \ |
| 661 | (TYPE_SIGNED(time_t) \ |
| 662 | ? _Generic((time_t) 0, \ |
| 663 | signed char: SCHAR_MAX, short: SHRT_MAX, \ |
| 664 | int: INT_MAX, long: LONG_MAX, long long: LLONG_MAX, \ |
| 665 | default: TIME_T_MAX_NO_PADDING) \ |
| 666 | : (time_t) -1) |
| 667 | #else |
| 668 | # define TIME_T_MIN TIME_T_MIN_NO_PADDING |
| 669 | # define TIME_T_MAX TIME_T_MAX_NO_PADDING |
| 670 | #endif |
| 671 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 672 | /* |
| 673 | ** 302 / 1000 is log10(2.0) rounded up. |
| 674 | ** Subtract one for the sign bit if the type is signed; |
| 675 | ** add one for integer division truncation; |
| 676 | ** add one more for a minus sign if the type is signed. |
| 677 | */ |
| 678 | #define INT_STRLEN_MAXIMUM(type) \ |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 679 | ((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + \ |
| 680 | 1 + TYPE_SIGNED(type)) |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 681 | |
| 682 | /* |
| 683 | ** INITIALIZE(x) |
| 684 | */ |
| 685 | |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame^] | 686 | #ifdef GCC_LINT |
Elliott Hughes | 5f56454 | 2014-06-19 13:54:10 -0700 | [diff] [blame] | 687 | # define INITIALIZE(x) ((x) = 0) |
| 688 | #else |
| 689 | # define INITIALIZE(x) |
| 690 | #endif |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 691 | |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 692 | #ifndef UNINIT_TRAP |
| 693 | # define UNINIT_TRAP 0 |
| 694 | #endif |
| 695 | |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame^] | 696 | #ifdef DEBUG |
| 697 | # define UNREACHABLE() abort() |
| 698 | #elif 4 < __GNUC__ + (5 <= __GNUC_MINOR__) |
| 699 | # define UNREACHABLE() __builtin_unreachable() |
| 700 | #elif defined __has_builtin |
| 701 | # if __has_builtin(__builtin_unreachable) |
| 702 | # define UNREACHABLE() __builtin_unreachable() |
| 703 | # endif |
| 704 | #endif |
| 705 | #ifndef UNREACHABLE |
| 706 | # define UNREACHABLE() ((void) 0) |
| 707 | #endif |
| 708 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 709 | /* |
| 710 | ** For the benefit of GNU folk... |
Elliott Hughes | 5f56454 | 2014-06-19 13:54:10 -0700 | [diff] [blame] | 711 | ** '_(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] | 712 | ** The default is to use gettext if available, and use MSGID otherwise. |
| 713 | */ |
| 714 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 715 | #if HAVE_GETTEXT |
| 716 | #define _(msgid) gettext(msgid) |
| 717 | #else /* !HAVE_GETTEXT */ |
| 718 | #define _(msgid) msgid |
| 719 | #endif /* !HAVE_GETTEXT */ |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 720 | |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 721 | #if !defined TZ_DOMAIN && defined HAVE_GETTEXT |
Elliott Hughes | 5f56454 | 2014-06-19 13:54:10 -0700 | [diff] [blame] | 722 | # define TZ_DOMAIN "tz" |
| 723 | #endif |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 724 | |
| 725 | #if HAVE_INCOMPATIBLE_CTIME_R |
| 726 | #undef asctime_r |
| 727 | #undef ctime_r |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 728 | char *asctime_r(struct tm const *, char *); |
| 729 | char *ctime_r(time_t const *, char *); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 730 | #endif /* HAVE_INCOMPATIBLE_CTIME_R */ |
| 731 | |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame^] | 732 | /* Handy macros that are independent of tzfile implementation. */ |
| 733 | |
| 734 | #define SECSPERMIN 60 |
| 735 | #define MINSPERHOUR 60 |
| 736 | #define HOURSPERDAY 24 |
| 737 | #define DAYSPERWEEK 7 |
| 738 | #define DAYSPERNYEAR 365 |
| 739 | #define DAYSPERLYEAR 366 |
| 740 | #define SECSPERHOUR (SECSPERMIN * MINSPERHOUR) |
| 741 | #define SECSPERDAY ((int_fast32_t) SECSPERHOUR * HOURSPERDAY) |
| 742 | #define MONSPERYEAR 12 |
| 743 | |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 744 | #define YEARSPERREPEAT 400 /* years before a Gregorian repeat */ |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame^] | 745 | #define DAYSPERREPEAT ((int_fast32_t) 400 * 365 + 100 - 4 + 1) |
| 746 | #define SECSPERREPEAT ((int_fast64_t) DAYSPERREPEAT * SECSPERDAY) |
| 747 | #define AVGSECSPERYEAR (SECSPERREPEAT / YEARSPERREPEAT) |
| 748 | |
| 749 | #define TM_SUNDAY 0 |
| 750 | #define TM_MONDAY 1 |
| 751 | #define TM_TUESDAY 2 |
| 752 | #define TM_WEDNESDAY 3 |
| 753 | #define TM_THURSDAY 4 |
| 754 | #define TM_FRIDAY 5 |
| 755 | #define TM_SATURDAY 6 |
| 756 | |
| 757 | #define TM_JANUARY 0 |
| 758 | #define TM_FEBRUARY 1 |
| 759 | #define TM_MARCH 2 |
| 760 | #define TM_APRIL 3 |
| 761 | #define TM_MAY 4 |
| 762 | #define TM_JUNE 5 |
| 763 | #define TM_JULY 6 |
| 764 | #define TM_AUGUST 7 |
| 765 | #define TM_SEPTEMBER 8 |
| 766 | #define TM_OCTOBER 9 |
| 767 | #define TM_NOVEMBER 10 |
| 768 | #define TM_DECEMBER 11 |
| 769 | |
| 770 | #define TM_YEAR_BASE 1900 |
| 771 | #define TM_WDAY_BASE TM_MONDAY |
| 772 | |
| 773 | #define EPOCH_YEAR 1970 |
| 774 | #define EPOCH_WDAY TM_THURSDAY |
| 775 | |
| 776 | #define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0)) |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 777 | |
| 778 | /* |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame^] | 779 | ** Since everything in isleap is modulo 400 (or a factor of 400), we know that |
| 780 | ** isleap(y) == isleap(y % 400) |
| 781 | ** and so |
| 782 | ** isleap(a + b) == isleap((a + b) % 400) |
| 783 | ** or |
| 784 | ** isleap(a + b) == isleap(a % 400 + b % 400) |
| 785 | ** This is true even if % means modulo rather than Fortran remainder |
| 786 | ** (which is allowed by C89 but not by C99 or later). |
| 787 | ** We use this to avoid addition overflow problems. |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 788 | */ |
| 789 | |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame^] | 790 | #define isleap_sum(a, b) isleap((a) % 400 + (b) % 400) |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 791 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 792 | #endif /* !defined PRIVATE_H */ |