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 | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 20 | /* PORT_TO_C89 means the code should work even if the underlying |
| 21 | compiler and library support only C89. SUPPORT_C89 means the |
| 22 | tzcode library should support C89 callers in addition to the usual |
| 23 | support for C99-and-later callers. These macros are obsolescent, |
| 24 | and the plan is to remove them along with any code needed only when |
| 25 | they are nonzero. */ |
| 26 | #ifndef PORT_TO_C89 |
| 27 | # define PORT_TO_C89 0 |
| 28 | #endif |
| 29 | #ifndef SUPPORT_C89 |
| 30 | # define SUPPORT_C89 0 |
| 31 | #endif |
| 32 | |
| 33 | #ifndef __STDC_VERSION__ |
| 34 | # define __STDC_VERSION__ 0 |
| 35 | #endif |
| 36 | |
| 37 | /* Define true, false and bool if they don't work out of the box. */ |
| 38 | #if PORT_TO_C89 && __STDC_VERSION__ < 199901 |
| 39 | # define true 1 |
| 40 | # define false 0 |
| 41 | # define bool int |
| 42 | #elif __STDC_VERSION__ < 202311 |
| 43 | # include <stdbool.h> |
| 44 | #endif |
| 45 | |
| 46 | #if __STDC_VERSION__ < 202311 |
| 47 | # define static_assert(cond) extern int static_assert_check[(cond) ? 1 : -1] |
| 48 | #endif |
| 49 | |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 50 | /* |
| 51 | ** zdump has been made independent of the rest of the time |
| 52 | ** conversion package to increase confidence in the verification it provides. |
| 53 | ** You can use zdump to help in verifying other implementations. |
| 54 | ** To do this, compile with -DUSE_LTZ=0 and link without the tz library. |
| 55 | */ |
| 56 | #ifndef USE_LTZ |
| 57 | # define USE_LTZ 1 |
| 58 | #endif |
| 59 | |
| 60 | /* This string was in the Factory zone through version 2016f. */ |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 61 | #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] | 62 | |
| 63 | /* |
| 64 | ** Defaults for preprocessor symbols. |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 65 | ** 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] | 66 | */ |
| 67 | |
Elliott Hughes | 0a610d0 | 2016-07-29 14:04:17 -0700 | [diff] [blame] | 68 | #ifndef HAVE_DECL_ASCTIME_R |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 69 | # define HAVE_DECL_ASCTIME_R 1 |
Elliott Hughes | 0a610d0 | 2016-07-29 14:04:17 -0700 | [diff] [blame] | 70 | #endif |
| 71 | |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 72 | #if !defined HAVE__GENERIC && defined __has_extension |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 73 | # if __has_extension(c_generic_selections) |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 74 | # define HAVE__GENERIC 1 |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 75 | # else |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 76 | # define HAVE__GENERIC 0 |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 77 | # endif |
| 78 | #endif |
| 79 | /* _Generic is buggy in pre-4.9 GCC. */ |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 80 | #if !defined HAVE__GENERIC && defined __GNUC__ && !defined __STRICT_ANSI__ |
| 81 | # define HAVE__GENERIC (4 < __GNUC__ + (9 <= __GNUC_MINOR__)) |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 82 | #endif |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 83 | #ifndef HAVE__GENERIC |
| 84 | # define HAVE__GENERIC (201112 <= __STDC_VERSION__) |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 85 | #endif |
| 86 | |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 87 | #if !defined HAVE_GETTEXT && defined __has_include |
| 88 | # if __has_include(<libintl.h>) |
| 89 | # define HAVE_GETTEXT true |
| 90 | # endif |
| 91 | #endif |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 92 | #ifndef HAVE_GETTEXT |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 93 | # define HAVE_GETTEXT false |
| 94 | #endif |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 95 | |
| 96 | #ifndef HAVE_INCOMPATIBLE_CTIME_R |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 97 | # define HAVE_INCOMPATIBLE_CTIME_R 0 |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 98 | #endif |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 99 | |
Calin Juravle | 627d37c | 2014-02-28 11:46:03 +0000 | [diff] [blame] | 100 | #ifndef HAVE_LINK |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 101 | # define HAVE_LINK 1 |
Calin Juravle | 627d37c | 2014-02-28 11:46:03 +0000 | [diff] [blame] | 102 | #endif /* !defined HAVE_LINK */ |
| 103 | |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 104 | #ifndef HAVE_MALLOC_ERRNO |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 105 | # define HAVE_MALLOC_ERRNO 1 |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 106 | #endif |
| 107 | |
Elliott Hughes | 0a610d0 | 2016-07-29 14:04:17 -0700 | [diff] [blame] | 108 | #ifndef HAVE_POSIX_DECLS |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 109 | # define HAVE_POSIX_DECLS 1 |
Elliott Hughes | 0a610d0 | 2016-07-29 14:04:17 -0700 | [diff] [blame] | 110 | #endif |
| 111 | |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 112 | #ifndef HAVE_SETENV |
| 113 | # define HAVE_SETENV 1 |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 114 | #endif |
| 115 | |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 116 | #ifndef HAVE_STRDUP |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 117 | # define HAVE_STRDUP 1 |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 118 | #endif |
| 119 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 120 | #ifndef HAVE_SYMLINK |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 121 | # define HAVE_SYMLINK 1 |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 122 | #endif /* !defined HAVE_SYMLINK */ |
| 123 | |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 124 | #if !defined HAVE_SYS_STAT_H && defined __has_include |
| 125 | # if !__has_include(<sys/stat.h>) |
| 126 | # define HAVE_SYS_STAT_H false |
| 127 | # endif |
| 128 | #endif |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 129 | #ifndef HAVE_SYS_STAT_H |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 130 | # define HAVE_SYS_STAT_H true |
| 131 | #endif |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 132 | |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 133 | #if !defined HAVE_UNISTD_H && defined __has_include |
| 134 | # if !__has_include(<unistd.h>) |
| 135 | # define HAVE_UNISTD_H false |
| 136 | # endif |
| 137 | #endif |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 138 | #ifndef HAVE_UNISTD_H |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 139 | # define HAVE_UNISTD_H true |
| 140 | #endif |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 141 | |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 142 | #ifndef NETBSD_INSPIRED |
| 143 | # define NETBSD_INSPIRED 1 |
| 144 | #endif |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 145 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 146 | #if HAVE_INCOMPATIBLE_CTIME_R |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 147 | # define asctime_r _incompatible_asctime_r |
| 148 | # define ctime_r _incompatible_ctime_r |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 149 | #endif /* HAVE_INCOMPATIBLE_CTIME_R */ |
| 150 | |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 151 | /* Enable tm_gmtoff, tm_zone, and environ on GNUish systems. */ |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 152 | #define _GNU_SOURCE 1 |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 153 | /* Fix asctime_r on Solaris 11. */ |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 154 | #define _POSIX_PTHREAD_SEMANTICS 1 |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 155 | /* Enable strtoimax on pre-C99 Solaris 11. */ |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 156 | #define __EXTENSIONS__ 1 |
| 157 | |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 158 | /* On GNUish systems where time_t might be 32 or 64 bits, use 64. |
| 159 | On these platforms _FILE_OFFSET_BITS must also be 64; otherwise |
| 160 | setting _TIME_BITS to 64 does not work. The code does not |
| 161 | otherwise rely on _FILE_OFFSET_BITS being 64, since it does not |
| 162 | use off_t or functions like 'stat' that depend on off_t. */ |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 163 | #ifndef _FILE_OFFSET_BITS |
| 164 | # define _FILE_OFFSET_BITS 64 |
| 165 | #endif |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 166 | #if !defined _TIME_BITS && _FILE_OFFSET_BITS == 64 |
| 167 | # define _TIME_BITS 64 |
| 168 | #endif |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 169 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 170 | /* |
| 171 | ** Nested includes |
| 172 | */ |
| 173 | |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 174 | /* Avoid clashes with NetBSD by renaming NetBSD's declarations. |
| 175 | If defining the 'timezone' variable, avoid a clash with FreeBSD's |
| 176 | 'timezone' function by renaming its declaration. */ |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 177 | #define localtime_rz sys_localtime_rz |
| 178 | #define mktime_z sys_mktime_z |
| 179 | #define posix2time_z sys_posix2time_z |
| 180 | #define time2posix_z sys_time2posix_z |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 181 | #if defined USG_COMPAT && USG_COMPAT == 2 |
| 182 | # define timezone sys_timezone |
| 183 | #endif |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 184 | #define timezone_t sys_timezone_t |
| 185 | #define tzalloc sys_tzalloc |
| 186 | #define tzfree sys_tzfree |
| 187 | #include <time.h> |
| 188 | #undef localtime_rz |
| 189 | #undef mktime_z |
| 190 | #undef posix2time_z |
| 191 | #undef time2posix_z |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 192 | #if defined USG_COMPAT && USG_COMPAT == 2 |
| 193 | # undef timezone |
| 194 | #endif |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 195 | #undef timezone_t |
| 196 | #undef tzalloc |
| 197 | #undef tzfree |
| 198 | |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 199 | #include <stddef.h> |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 200 | #include <string.h> |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 201 | #if !PORT_TO_C89 |
| 202 | # include <inttypes.h> |
| 203 | #endif |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 204 | #include <limits.h> /* for CHAR_BIT et al. */ |
| 205 | #include <stdlib.h> |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 206 | |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 207 | #include <errno.h> |
| 208 | |
| 209 | #ifndef EINVAL |
| 210 | # define EINVAL ERANGE |
| 211 | #endif |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 212 | |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 213 | #ifndef ELOOP |
| 214 | # define ELOOP EINVAL |
| 215 | #endif |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 216 | #ifndef ENAMETOOLONG |
| 217 | # define ENAMETOOLONG EINVAL |
| 218 | #endif |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 219 | #ifndef ENOMEM |
| 220 | # define ENOMEM EINVAL |
| 221 | #endif |
Elliott Hughes | 0a610d0 | 2016-07-29 14:04:17 -0700 | [diff] [blame] | 222 | #ifndef ENOTSUP |
| 223 | # define ENOTSUP EINVAL |
| 224 | #endif |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 225 | #ifndef EOVERFLOW |
| 226 | # define EOVERFLOW EINVAL |
| 227 | #endif |
| 228 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 229 | #if HAVE_GETTEXT |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 230 | # include <libintl.h> |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 231 | #endif /* HAVE_GETTEXT */ |
| 232 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 233 | #if HAVE_UNISTD_H |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 234 | # 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] | 235 | #endif /* HAVE_UNISTD_H */ |
| 236 | |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 237 | #ifndef HAVE_STRFTIME_L |
| 238 | # if _POSIX_VERSION < 200809 |
| 239 | # define HAVE_STRFTIME_L 0 |
| 240 | # else |
| 241 | # define HAVE_STRFTIME_L 1 |
| 242 | # endif |
| 243 | #endif |
| 244 | |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 245 | #ifndef USG_COMPAT |
| 246 | # ifndef _XOPEN_VERSION |
| 247 | # define USG_COMPAT 0 |
| 248 | # else |
| 249 | # define USG_COMPAT 1 |
| 250 | # endif |
| 251 | #endif |
| 252 | |
| 253 | #ifndef HAVE_TZNAME |
| 254 | # if _POSIX_VERSION < 198808 && !USG_COMPAT |
| 255 | # define HAVE_TZNAME 0 |
| 256 | # else |
| 257 | # define HAVE_TZNAME 1 |
| 258 | # endif |
| 259 | #endif |
| 260 | |
| 261 | #ifndef ALTZONE |
| 262 | # if defined __sun || defined _M_XENIX |
| 263 | # define ALTZONE 1 |
| 264 | # else |
| 265 | # define ALTZONE 0 |
| 266 | # endif |
| 267 | #endif |
| 268 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 269 | #ifndef R_OK |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 270 | # define R_OK 4 |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 271 | #endif /* !defined R_OK */ |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 272 | |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 273 | #if PORT_TO_C89 |
| 274 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 275 | /* |
| 276 | ** Define HAVE_STDINT_H's default value here, rather than at the |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 277 | ** start, since __GLIBC__ and INTMAX_MAX's values depend on |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 278 | ** previously included files. glibc 2.1 and Solaris 10 and later have |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 279 | ** stdint.h, even with pre-C99 compilers. |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 280 | */ |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 281 | #if !defined HAVE_STDINT_H && defined __has_include |
| 282 | # define HAVE_STDINT_H true /* C23 __has_include implies C99 stdint.h. */ |
| 283 | #endif |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 284 | #ifndef HAVE_STDINT_H |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 285 | # define HAVE_STDINT_H \ |
Elliott Hughes | 5f56454 | 2014-06-19 13:54:10 -0700 | [diff] [blame] | 286 | (199901 <= __STDC_VERSION__ \ |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 287 | || 2 < __GLIBC__ + (1 <= __GLIBC_MINOR__) \ |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 288 | || __CYGWIN__ || INTMAX_MAX) |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 289 | #endif /* !defined HAVE_STDINT_H */ |
| 290 | |
| 291 | #if HAVE_STDINT_H |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 292 | # include <stdint.h> |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 293 | #endif /* !HAVE_STDINT_H */ |
| 294 | |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 295 | #ifndef HAVE_INTTYPES_H |
| 296 | # define HAVE_INTTYPES_H HAVE_STDINT_H |
| 297 | #endif |
| 298 | #if HAVE_INTTYPES_H |
| 299 | # include <inttypes.h> |
| 300 | #endif |
| 301 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 302 | /* Pre-C99 GCC compilers define __LONG_LONG_MAX__ instead of LLONG_MAX. */ |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 303 | #if defined __LONG_LONG_MAX__ && !defined __STRICT_ANSI__ |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 304 | # ifndef LLONG_MAX |
| 305 | # define LLONG_MAX __LONG_LONG_MAX__ |
| 306 | # endif |
| 307 | # ifndef LLONG_MIN |
| 308 | # define LLONG_MIN (-1 - LLONG_MAX) |
| 309 | # endif |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 310 | # ifndef ULLONG_MAX |
| 311 | # define ULLONG_MAX (LLONG_MAX * 2ull + 1) |
| 312 | # endif |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 313 | #endif |
| 314 | |
| 315 | #ifndef INT_FAST64_MAX |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 316 | # if 1 <= LONG_MAX >> 31 >> 31 |
| 317 | typedef long int_fast64_t; |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 318 | # define INT_FAST64_MIN LONG_MIN |
| 319 | # define INT_FAST64_MAX LONG_MAX |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 320 | # else |
| 321 | /* If this fails, compile with -DHAVE_STDINT_H or with a better compiler. */ |
| 322 | typedef long long int_fast64_t; |
| 323 | # define INT_FAST64_MIN LLONG_MIN |
| 324 | # define INT_FAST64_MAX LLONG_MAX |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 325 | # endif |
| 326 | #endif |
| 327 | |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 328 | #ifndef PRIdFAST64 |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 329 | # if INT_FAST64_MAX == LONG_MAX |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 330 | # define PRIdFAST64 "ld" |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 331 | # else |
| 332 | # define PRIdFAST64 "lld" |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 333 | # endif |
| 334 | #endif |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 335 | |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 336 | #ifndef SCNdFAST64 |
| 337 | # define SCNdFAST64 PRIdFAST64 |
| 338 | #endif |
| 339 | |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 340 | #ifndef INT_FAST32_MAX |
| 341 | # if INT_MAX >> 31 == 0 |
| 342 | typedef long int_fast32_t; |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 343 | # define INT_FAST32_MAX LONG_MAX |
| 344 | # define INT_FAST32_MIN LONG_MIN |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 345 | # else |
| 346 | typedef int int_fast32_t; |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 347 | # define INT_FAST32_MAX INT_MAX |
| 348 | # define INT_FAST32_MIN INT_MIN |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 349 | # endif |
| 350 | #endif |
| 351 | |
| 352 | #ifndef INTMAX_MAX |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 353 | # ifdef LLONG_MAX |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 354 | typedef long long intmax_t; |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 355 | # ifndef HAVE_STRTOLL |
| 356 | # define HAVE_STRTOLL true |
| 357 | # endif |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 358 | # if HAVE_STRTOLL |
| 359 | # define strtoimax strtoll |
| 360 | # endif |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 361 | # define INTMAX_MAX LLONG_MAX |
| 362 | # define INTMAX_MIN LLONG_MIN |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 363 | # else |
| 364 | typedef long intmax_t; |
Elliott Hughes | e0d0b15 | 2013-09-27 00:04:30 -0700 | [diff] [blame] | 365 | # define INTMAX_MAX LONG_MAX |
| 366 | # define INTMAX_MIN LONG_MIN |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 367 | # endif |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 368 | # ifndef strtoimax |
| 369 | # define strtoimax strtol |
| 370 | # endif |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 371 | #endif |
| 372 | |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 373 | #ifndef PRIdMAX |
| 374 | # if INTMAX_MAX == LLONG_MAX |
| 375 | # define PRIdMAX "lld" |
| 376 | # else |
| 377 | # define PRIdMAX "ld" |
| 378 | # endif |
| 379 | #endif |
| 380 | |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 381 | #ifndef PTRDIFF_MAX |
| 382 | # define PTRDIFF_MAX MAXVAL(ptrdiff_t, TYPE_BIT(ptrdiff_t)) |
| 383 | #endif |
| 384 | |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 385 | #ifndef UINT_FAST32_MAX |
| 386 | typedef unsigned long uint_fast32_t; |
| 387 | #endif |
| 388 | |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 389 | #ifndef UINT_FAST64_MAX |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 390 | # if 3 <= ULONG_MAX >> 31 >> 31 |
| 391 | typedef unsigned long uint_fast64_t; |
| 392 | # define UINT_FAST64_MAX ULONG_MAX |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 393 | # else |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 394 | /* If this fails, compile with -DHAVE_STDINT_H or with a better compiler. */ |
| 395 | typedef unsigned long long uint_fast64_t; |
| 396 | # define UINT_FAST64_MAX ULLONG_MAX |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 397 | # endif |
| 398 | #endif |
| 399 | |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 400 | #ifndef UINTMAX_MAX |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 401 | # ifdef ULLONG_MAX |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 402 | typedef unsigned long long uintmax_t; |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 403 | # define UINTMAX_MAX ULLONG_MAX |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 404 | # else |
| 405 | typedef unsigned long uintmax_t; |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 406 | # define UINTMAX_MAX ULONG_MAX |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 407 | # endif |
| 408 | #endif |
| 409 | |
| 410 | #ifndef PRIuMAX |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 411 | # ifdef ULLONG_MAX |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 412 | # define PRIuMAX "llu" |
| 413 | # else |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 414 | # define PRIuMAX "lu" |
| 415 | # endif |
| 416 | #endif |
| 417 | |
Elliott Hughes | 5f56454 | 2014-06-19 13:54:10 -0700 | [diff] [blame] | 418 | #ifndef SIZE_MAX |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 419 | # define SIZE_MAX ((size_t) -1) |
| 420 | #endif |
| 421 | |
| 422 | #endif /* PORT_TO_C89 */ |
| 423 | |
| 424 | /* The maximum size of any created object, as a signed integer. |
| 425 | Although the C standard does not outright prohibit larger objects, |
| 426 | behavior is undefined if the result of pointer subtraction does not |
| 427 | fit into ptrdiff_t, and the code assumes in several places that |
| 428 | pointer subtraction works. As a practical matter it's OK to not |
| 429 | support objects larger than this. */ |
| 430 | #define INDEX_MAX ((ptrdiff_t) min(PTRDIFF_MAX, SIZE_MAX)) |
| 431 | |
| 432 | /* Support ckd_add, ckd_sub, ckd_mul on C23 or recent-enough GCC-like |
| 433 | hosts, unless compiled with -DHAVE_STDCKDINT_H=0 or with pre-C23 EDG. */ |
| 434 | #if !defined HAVE_STDCKDINT_H && defined __has_include |
| 435 | # if __has_include(<stdckdint.h>) |
| 436 | # define HAVE_STDCKDINT_H true |
| 437 | # endif |
| 438 | #endif |
| 439 | #ifdef HAVE_STDCKDINT_H |
| 440 | # if HAVE_STDCKDINT_H |
| 441 | # include <stdckdint.h> |
| 442 | # endif |
| 443 | #elif defined __EDG__ |
| 444 | /* Do nothing, to work around EDG bug <https://bugs.gnu.org/53256>. */ |
| 445 | #elif defined __has_builtin |
| 446 | # if __has_builtin(__builtin_add_overflow) |
| 447 | # define ckd_add(r, a, b) __builtin_add_overflow(a, b, r) |
| 448 | # endif |
| 449 | # if __has_builtin(__builtin_sub_overflow) |
| 450 | # define ckd_sub(r, a, b) __builtin_sub_overflow(a, b, r) |
| 451 | # endif |
| 452 | # if __has_builtin(__builtin_mul_overflow) |
| 453 | # define ckd_mul(r, a, b) __builtin_mul_overflow(a, b, r) |
| 454 | # endif |
| 455 | #elif 7 <= __GNUC__ |
| 456 | # define ckd_add(r, a, b) __builtin_add_overflow(a, b, r) |
| 457 | # define ckd_sub(r, a, b) __builtin_sub_overflow(a, b, r) |
| 458 | # define ckd_mul(r, a, b) __builtin_mul_overflow(a, b, r) |
Elliott Hughes | 5f56454 | 2014-06-19 13:54:10 -0700 | [diff] [blame] | 459 | #endif |
| 460 | |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 461 | #if 3 <= __GNUC__ |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 462 | # define ATTRIBUTE_MALLOC __attribute__((malloc)) |
| 463 | # define ATTRIBUTE_FORMAT(spec) __attribute__((format spec)) |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 464 | #else |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 465 | # define ATTRIBUTE_MALLOC /* empty */ |
Elliott Hughes | e0d0b15 | 2013-09-27 00:04:30 -0700 | [diff] [blame] | 466 | # define ATTRIBUTE_FORMAT(spec) /* empty */ |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 467 | #endif |
| 468 | |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 469 | #if (defined __has_c_attribute \ |
| 470 | && (202311 <= __STDC_VERSION__ || !defined __STRICT_ANSI__)) |
| 471 | # define HAVE___HAS_C_ATTRIBUTE true |
| 472 | #else |
| 473 | # define HAVE___HAS_C_ATTRIBUTE false |
| 474 | #endif |
| 475 | |
| 476 | #if HAVE___HAS_C_ATTRIBUTE |
| 477 | # if __has_c_attribute(deprecated) |
| 478 | # define ATTRIBUTE_DEPRECATED [[deprecated]] |
| 479 | # endif |
| 480 | #endif |
| 481 | #ifndef ATTRIBUTE_DEPRECATED |
| 482 | # if 3 < __GNUC__ + (2 <= __GNUC_MINOR__) |
| 483 | # define ATTRIBUTE_DEPRECATED __attribute__((deprecated)) |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 484 | # else |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 485 | # define ATTRIBUTE_DEPRECATED /* empty */ |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 486 | # endif |
| 487 | #endif |
| 488 | |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 489 | #if HAVE___HAS_C_ATTRIBUTE |
| 490 | # if __has_c_attribute(fallthrough) |
| 491 | # define ATTRIBUTE_FALLTHROUGH [[fallthrough]] |
| 492 | # endif |
| 493 | #endif |
| 494 | #ifndef ATTRIBUTE_FALLTHROUGH |
| 495 | # if 7 <= __GNUC__ |
| 496 | # define ATTRIBUTE_FALLTHROUGH __attribute__((fallthrough)) |
| 497 | # else |
| 498 | # define ATTRIBUTE_FALLTHROUGH ((void) 0) |
| 499 | # endif |
| 500 | #endif |
| 501 | |
| 502 | #if HAVE___HAS_C_ATTRIBUTE |
| 503 | # if __has_c_attribute(maybe_unused) |
| 504 | # define ATTRIBUTE_MAYBE_UNUSED [[maybe_unused]] |
| 505 | # endif |
| 506 | #endif |
| 507 | #ifndef ATTRIBUTE_MAYBE_UNUSED |
| 508 | # if 2 < __GNUC__ + (7 <= __GNUC_MINOR__) |
| 509 | # define ATTRIBUTE_MAYBE_UNUSED __attribute__((unused)) |
| 510 | # else |
| 511 | # define ATTRIBUTE_MAYBE_UNUSED /* empty */ |
| 512 | # endif |
| 513 | #endif |
| 514 | |
| 515 | #if HAVE___HAS_C_ATTRIBUTE |
| 516 | # if __has_c_attribute(noreturn) |
| 517 | # define ATTRIBUTE_NORETURN [[noreturn]] |
| 518 | # endif |
| 519 | #endif |
| 520 | #ifndef ATTRIBUTE_NORETURN |
| 521 | # if 201112 <= __STDC_VERSION__ |
| 522 | # define ATTRIBUTE_NORETURN _Noreturn |
| 523 | # elif 2 < __GNUC__ + (8 <= __GNUC_MINOR__) |
| 524 | # define ATTRIBUTE_NORETURN __attribute__((noreturn)) |
| 525 | # else |
| 526 | # define ATTRIBUTE_NORETURN /* empty */ |
| 527 | # endif |
| 528 | #endif |
| 529 | |
| 530 | #if HAVE___HAS_C_ATTRIBUTE |
| 531 | # if __has_c_attribute(reproducible) |
| 532 | # define ATTRIBUTE_REPRODUCIBLE [[reproducible]] |
| 533 | # endif |
| 534 | #endif |
| 535 | #ifndef ATTRIBUTE_REPRODUCIBLE |
| 536 | # if 3 <= __GNUC__ |
| 537 | # define ATTRIBUTE_REPRODUCIBLE __attribute__((pure)) |
| 538 | # else |
| 539 | # define ATTRIBUTE_REPRODUCIBLE /* empty */ |
| 540 | # endif |
| 541 | #endif |
| 542 | |
| 543 | #if HAVE___HAS_C_ATTRIBUTE |
| 544 | # if __has_c_attribute(unsequenced) |
| 545 | # define ATTRIBUTE_UNSEQUENCED [[unsequenced]] |
| 546 | # endif |
| 547 | #endif |
| 548 | #ifndef ATTRIBUTE_UNSEQUENCED |
| 549 | # if 3 <= __GNUC__ |
| 550 | # define ATTRIBUTE_UNSEQUENCED __attribute__((const)) |
| 551 | # else |
| 552 | # define ATTRIBUTE_UNSEQUENCED /* empty */ |
| 553 | # endif |
| 554 | #endif |
| 555 | |
| 556 | #if (__STDC_VERSION__ < 199901 && !defined restrict \ |
| 557 | && (PORT_TO_C89 || defined _MSC_VER)) |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 558 | # define restrict /* empty */ |
| 559 | #endif |
| 560 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 561 | /* |
| 562 | ** Workarounds for compilers/systems. |
| 563 | */ |
| 564 | |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 565 | #ifndef EPOCH_LOCAL |
| 566 | # define EPOCH_LOCAL 0 |
| 567 | #endif |
| 568 | #ifndef EPOCH_OFFSET |
| 569 | # define EPOCH_OFFSET 0 |
| 570 | #endif |
| 571 | #ifndef RESERVE_STD_EXT_IDS |
| 572 | # define RESERVE_STD_EXT_IDS 0 |
| 573 | #endif |
| 574 | |
| 575 | /* If standard C identifiers with external linkage (e.g., localtime) |
| 576 | are reserved and are not already being renamed anyway, rename them |
| 577 | as if compiling with '-Dtime_tz=time_t'. */ |
| 578 | #if !defined time_tz && RESERVE_STD_EXT_IDS && USE_LTZ |
| 579 | # define time_tz time_t |
| 580 | #endif |
| 581 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 582 | /* |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 583 | ** Compile with -Dtime_tz=T to build the tz package with a private |
| 584 | ** time_t type equivalent to T rather than the system-supplied time_t. |
| 585 | ** This debugging feature can test unusual design decisions |
| 586 | ** (e.g., time_t wider than 'long', or unsigned time_t) even on |
| 587 | ** typical platforms. |
| 588 | */ |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 589 | #if defined time_tz || EPOCH_LOCAL || EPOCH_OFFSET != 0 |
| 590 | # define TZ_TIME_T 1 |
| 591 | #else |
| 592 | # define TZ_TIME_T 0 |
| 593 | #endif |
| 594 | |
| 595 | #if defined LOCALTIME_IMPLEMENTATION && TZ_TIME_T |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 596 | static time_t sys_time(time_t *x) { return time(x); } |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 597 | #endif |
| 598 | |
| 599 | #if TZ_TIME_T |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 600 | |
| 601 | typedef time_tz tz_time_t; |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 602 | |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 603 | # undef asctime |
| 604 | # define asctime tz_asctime |
| 605 | # undef asctime_r |
| 606 | # define asctime_r tz_asctime_r |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 607 | # undef ctime |
| 608 | # define ctime tz_ctime |
| 609 | # undef ctime_r |
| 610 | # define ctime_r tz_ctime_r |
| 611 | # undef difftime |
| 612 | # define difftime tz_difftime |
| 613 | # undef gmtime |
| 614 | # define gmtime tz_gmtime |
| 615 | # undef gmtime_r |
| 616 | # define gmtime_r tz_gmtime_r |
| 617 | # undef localtime |
| 618 | # define localtime tz_localtime |
| 619 | # undef localtime_r |
| 620 | # define localtime_r tz_localtime_r |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 621 | # undef localtime_rz |
| 622 | # define localtime_rz tz_localtime_rz |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 623 | # undef mktime |
| 624 | # define mktime tz_mktime |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 625 | # undef mktime_z |
| 626 | # define mktime_z tz_mktime_z |
| 627 | # undef offtime |
| 628 | # define offtime tz_offtime |
| 629 | # undef posix2time |
| 630 | # define posix2time tz_posix2time |
| 631 | # undef posix2time_z |
| 632 | # define posix2time_z tz_posix2time_z |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 633 | # undef strftime |
| 634 | # define strftime tz_strftime |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 635 | # undef time |
| 636 | # define time tz_time |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 637 | # undef time2posix |
| 638 | # define time2posix tz_time2posix |
| 639 | # undef time2posix_z |
| 640 | # define time2posix_z tz_time2posix_z |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 641 | # undef time_t |
| 642 | # define time_t tz_time_t |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 643 | # undef timegm |
| 644 | # define timegm tz_timegm |
| 645 | # undef timelocal |
| 646 | # define timelocal tz_timelocal |
| 647 | # undef timeoff |
| 648 | # define timeoff tz_timeoff |
| 649 | # undef tzalloc |
| 650 | # define tzalloc tz_tzalloc |
| 651 | # undef tzfree |
| 652 | # define tzfree tz_tzfree |
| 653 | # undef tzset |
| 654 | # define tzset tz_tzset |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 655 | # if HAVE_STRFTIME_L |
| 656 | # undef strftime_l |
| 657 | # define strftime_l tz_strftime_l |
| 658 | # endif |
| 659 | # if HAVE_TZNAME |
| 660 | # undef tzname |
| 661 | # define tzname tz_tzname |
| 662 | # endif |
| 663 | # if USG_COMPAT |
| 664 | # undef daylight |
| 665 | # define daylight tz_daylight |
| 666 | # undef timezone |
| 667 | # define timezone tz_timezone |
| 668 | # endif |
| 669 | # if ALTZONE |
| 670 | # undef altzone |
| 671 | # define altzone tz_altzone |
| 672 | # endif |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 673 | |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 674 | # if __STDC_VERSION__ < 202311 |
| 675 | # define DEPRECATED_IN_C23 /* empty */ |
| 676 | # else |
| 677 | # define DEPRECATED_IN_C23 ATTRIBUTE_DEPRECATED |
| 678 | # endif |
| 679 | DEPRECATED_IN_C23 char *asctime(struct tm const *); |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 680 | char *asctime_r(struct tm const *restrict, char *restrict); |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 681 | DEPRECATED_IN_C23 char *ctime(time_t const *); |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 682 | char *ctime_r(time_t const *, char *); |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 683 | ATTRIBUTE_UNSEQUENCED double difftime(time_t, time_t); |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 684 | size_t strftime(char *restrict, size_t, char const *restrict, |
| 685 | struct tm const *restrict); |
| 686 | # if HAVE_STRFTIME_L |
| 687 | size_t strftime_l(char *restrict, size_t, char const *restrict, |
| 688 | struct tm const *restrict, locale_t); |
| 689 | # endif |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 690 | struct tm *gmtime(time_t const *); |
| 691 | struct tm *gmtime_r(time_t const *restrict, struct tm *restrict); |
| 692 | struct tm *localtime(time_t const *); |
| 693 | struct tm *localtime_r(time_t const *restrict, struct tm *restrict); |
| 694 | time_t mktime(struct tm *); |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 695 | time_t time(time_t *); |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 696 | time_t timegm(struct tm *); |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 697 | void tzset(void); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 698 | #endif |
| 699 | |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 700 | #ifndef HAVE_DECL_TIMEGM |
| 701 | # if (202311 <= __STDC_VERSION__ \ |
| 702 | || defined __GLIBC__ || defined __tm_zone /* musl */ \ |
| 703 | || defined __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__ \ |
| 704 | || (defined __APPLE__ && defined __MACH__)) |
| 705 | # define HAVE_DECL_TIMEGM true |
| 706 | # else |
| 707 | # define HAVE_DECL_TIMEGM false |
| 708 | # endif |
| 709 | #endif |
| 710 | #if !HAVE_DECL_TIMEGM && !defined timegm |
| 711 | time_t timegm(struct tm *); |
| 712 | #endif |
| 713 | |
Elliott Hughes | 0a610d0 | 2016-07-29 14:04:17 -0700 | [diff] [blame] | 714 | #if !HAVE_DECL_ASCTIME_R && !defined asctime_r |
| 715 | extern char *asctime_r(struct tm const *restrict, char *restrict); |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 716 | #endif |
| 717 | |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 718 | #ifndef HAVE_DECL_ENVIRON |
| 719 | # if defined environ || defined __USE_GNU |
| 720 | # define HAVE_DECL_ENVIRON 1 |
| 721 | # else |
| 722 | # define HAVE_DECL_ENVIRON 0 |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 723 | # endif |
| 724 | #endif |
Elliott Hughes | 0a610d0 | 2016-07-29 14:04:17 -0700 | [diff] [blame] | 725 | |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 726 | #if !HAVE_DECL_ENVIRON |
| 727 | extern char **environ; |
| 728 | #endif |
| 729 | |
| 730 | #if 2 <= HAVE_TZNAME + (TZ_TIME_T || !HAVE_POSIX_DECLS) |
| 731 | extern char *tzname[]; |
| 732 | #endif |
| 733 | #if 2 <= USG_COMPAT + (TZ_TIME_T || !HAVE_POSIX_DECLS) |
| 734 | extern long timezone; |
| 735 | extern int daylight; |
| 736 | #endif |
| 737 | #if 2 <= ALTZONE + (TZ_TIME_T || !HAVE_POSIX_DECLS) |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 738 | extern long altzone; |
| 739 | #endif |
| 740 | |
| 741 | /* |
| 742 | ** The STD_INSPIRED functions are similar, but most also need |
| 743 | ** declarations if time_tz is defined. |
| 744 | */ |
| 745 | |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 746 | #ifndef STD_INSPIRED |
| 747 | # define STD_INSPIRED 0 |
| 748 | #endif |
| 749 | #if STD_INSPIRED |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 750 | # if TZ_TIME_T || !defined offtime |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 751 | struct tm *offtime(time_t const *, long); |
| 752 | # endif |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 753 | # if TZ_TIME_T || !defined timelocal |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 754 | time_t timelocal(struct tm *); |
| 755 | # endif |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 756 | # if TZ_TIME_T || !defined timeoff |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 757 | time_t timeoff(struct tm *, long); |
| 758 | # endif |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 759 | # if TZ_TIME_T || !defined time2posix |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 760 | time_t time2posix(time_t); |
| 761 | # endif |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 762 | # if TZ_TIME_T || !defined posix2time |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 763 | time_t posix2time(time_t); |
| 764 | # endif |
| 765 | #endif |
| 766 | |
| 767 | /* Infer TM_ZONE on systems where this information is known, but suppress |
| 768 | guessing if NO_TM_ZONE is defined. Similarly for TM_GMTOFF. */ |
| 769 | #if (defined __GLIBC__ \ |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 770 | || defined __tm_zone /* musl */ \ |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 771 | || defined __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__ \ |
| 772 | || (defined __APPLE__ && defined __MACH__)) |
| 773 | # if !defined TM_GMTOFF && !defined NO_TM_GMTOFF |
| 774 | # define TM_GMTOFF tm_gmtoff |
| 775 | # endif |
| 776 | # if !defined TM_ZONE && !defined NO_TM_ZONE |
| 777 | # define TM_ZONE tm_zone |
| 778 | # endif |
| 779 | #endif |
| 780 | |
| 781 | /* |
| 782 | ** Define functions that are ABI compatible with NetBSD but have |
| 783 | ** better prototypes. NetBSD 6.1.4 defines a pointer type timezone_t |
| 784 | ** and labors under the misconception that 'const timezone_t' is a |
| 785 | ** pointer to a constant. This use of 'const' is ineffective, so it |
| 786 | ** is not done here. What we call 'struct state' NetBSD calls |
| 787 | ** 'struct __state', but this is a private name so it doesn't matter. |
| 788 | */ |
| 789 | #if NETBSD_INSPIRED |
| 790 | typedef struct state *timezone_t; |
| 791 | struct tm *localtime_rz(timezone_t restrict, time_t const *restrict, |
| 792 | struct tm *restrict); |
| 793 | time_t mktime_z(timezone_t restrict, struct tm *restrict); |
| 794 | timezone_t tzalloc(char const *); |
| 795 | void tzfree(timezone_t); |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 796 | # if STD_INSPIRED |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 797 | # if TZ_TIME_T || !defined posix2time_z |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 798 | ATTRIBUTE_REPRODUCIBLE time_t posix2time_z(timezone_t, time_t); |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 799 | # endif |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 800 | # if TZ_TIME_T || !defined time2posix_z |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 801 | ATTRIBUTE_REPRODUCIBLE time_t time2posix_z(timezone_t, time_t); |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 802 | # endif |
| 803 | # endif |
| 804 | #endif |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 805 | |
| 806 | /* |
| 807 | ** Finally, some convenience items. |
| 808 | */ |
| 809 | |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 810 | #define TYPE_BIT(type) (CHAR_BIT * (ptrdiff_t) sizeof(type)) |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 811 | #define TYPE_SIGNED(type) (((type) -1) < 0) |
Stephen Hines | 23360cc | 2015-09-29 09:28:41 -0700 | [diff] [blame] | 812 | #define TWOS_COMPLEMENT(t) ((t) ~ (t) 0 < 0) |
| 813 | |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 814 | /* Minimum and maximum of two values. Use lower case to avoid |
| 815 | naming clashes with standard include files. */ |
| 816 | #define max(a, b) ((a) > (b) ? (a) : (b)) |
| 817 | #define min(a, b) ((a) < (b) ? (a) : (b)) |
| 818 | |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 819 | /* Max and min values of the integer type T, of which only the bottom |
| 820 | B bits are used, and where the highest-order used bit is considered |
| 821 | to be a sign bit if T is signed. */ |
| 822 | #define MAXVAL(t, b) \ |
| 823 | ((t) (((t) 1 << ((b) - 1 - TYPE_SIGNED(t))) \ |
| 824 | - 1 + ((t) 1 << ((b) - 1 - TYPE_SIGNED(t))))) |
| 825 | #define MINVAL(t, b) \ |
| 826 | ((t) (TYPE_SIGNED(t) ? - TWOS_COMPLEMENT(t) - MAXVAL(t, b) : 0)) |
Stephen Hines | 23360cc | 2015-09-29 09:28:41 -0700 | [diff] [blame] | 827 | |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 828 | /* The extreme time values, assuming no padding. */ |
| 829 | #define TIME_T_MIN_NO_PADDING MINVAL(time_t, TYPE_BIT(time_t)) |
| 830 | #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] | 831 | |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 832 | /* The extreme time values. These are macros, not constants, so that |
| 833 | any portability problems occur only when compiling .c files that use |
| 834 | the macros, which is safer for applications that need only zdump and zic. |
| 835 | This implementation assumes no padding if time_t is signed and |
| 836 | either the compiler lacks support for _Generic or time_t is not one |
| 837 | of the standard signed integer types. */ |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 838 | #if HAVE__GENERIC |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 839 | # define TIME_T_MIN \ |
| 840 | _Generic((time_t) 0, \ |
| 841 | signed char: SCHAR_MIN, short: SHRT_MIN, \ |
| 842 | int: INT_MIN, long: LONG_MIN, long long: LLONG_MIN, \ |
| 843 | default: TIME_T_MIN_NO_PADDING) |
| 844 | # define TIME_T_MAX \ |
| 845 | (TYPE_SIGNED(time_t) \ |
| 846 | ? _Generic((time_t) 0, \ |
| 847 | signed char: SCHAR_MAX, short: SHRT_MAX, \ |
| 848 | int: INT_MAX, long: LONG_MAX, long long: LLONG_MAX, \ |
| 849 | default: TIME_T_MAX_NO_PADDING) \ |
| 850 | : (time_t) -1) |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 851 | enum { SIGNED_PADDING_CHECK_NEEDED |
| 852 | = _Generic((time_t) 0, |
| 853 | signed char: false, short: false, |
| 854 | int: false, long: false, long long: false, |
| 855 | default: true) }; |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 856 | #else |
| 857 | # define TIME_T_MIN TIME_T_MIN_NO_PADDING |
| 858 | # define TIME_T_MAX TIME_T_MAX_NO_PADDING |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 859 | enum { SIGNED_PADDING_CHECK_NEEDED = true }; |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 860 | #endif |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 861 | /* Try to check the padding assumptions. Although TIME_T_MAX and the |
| 862 | following check can both have undefined behavior on oddball |
| 863 | platforms due to shifts exceeding widths of signed integers, these |
| 864 | platforms' compilers are likely to diagnose these issues in integer |
| 865 | constant expressions, so it shouldn't hurt to check statically. */ |
| 866 | static_assert(! TYPE_SIGNED(time_t) || ! SIGNED_PADDING_CHECK_NEEDED |
| 867 | || TIME_T_MAX >> (TYPE_BIT(time_t) - 2) == 1); |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 868 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 869 | /* |
| 870 | ** 302 / 1000 is log10(2.0) rounded up. |
| 871 | ** Subtract one for the sign bit if the type is signed; |
| 872 | ** add one for integer division truncation; |
| 873 | ** add one more for a minus sign if the type is signed. |
| 874 | */ |
| 875 | #define INT_STRLEN_MAXIMUM(type) \ |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 876 | ((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + \ |
| 877 | 1 + TYPE_SIGNED(type)) |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 878 | |
| 879 | /* |
| 880 | ** INITIALIZE(x) |
| 881 | */ |
| 882 | |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 883 | #ifdef GCC_LINT |
Elliott Hughes | 5f56454 | 2014-06-19 13:54:10 -0700 | [diff] [blame] | 884 | # define INITIALIZE(x) ((x) = 0) |
| 885 | #else |
| 886 | # define INITIALIZE(x) |
| 887 | #endif |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 888 | |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 889 | /* Whether memory access must strictly follow the C standard. |
| 890 | If 0, it's OK to read uninitialized storage so long as the value is |
| 891 | not relied upon. Defining it to 0 lets mktime access parts of |
| 892 | struct tm that might be uninitialized, as a heuristic when the |
| 893 | standard doesn't say what to return and when tm_gmtoff can help |
| 894 | mktime likely infer a better value. */ |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 895 | #ifndef UNINIT_TRAP |
| 896 | # define UNINIT_TRAP 0 |
| 897 | #endif |
| 898 | |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 899 | #ifdef DEBUG |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 900 | # undef unreachable |
| 901 | # define unreachable() abort() |
| 902 | #elif !defined unreachable |
| 903 | # ifdef __has_builtin |
| 904 | # if __has_builtin(__builtin_unreachable) |
| 905 | # define unreachable() __builtin_unreachable() |
| 906 | # endif |
| 907 | # elif 4 < __GNUC__ + (5 <= __GNUC_MINOR__) |
| 908 | # define unreachable() __builtin_unreachable() |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 909 | # endif |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 910 | # ifndef unreachable |
| 911 | # define unreachable() ((void) 0) |
| 912 | # endif |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 913 | #endif |
| 914 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 915 | /* |
| 916 | ** For the benefit of GNU folk... |
Elliott Hughes | 5f56454 | 2014-06-19 13:54:10 -0700 | [diff] [blame] | 917 | ** '_(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] | 918 | ** The default is to use gettext if available, and use MSGID otherwise. |
| 919 | */ |
| 920 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 921 | #if HAVE_GETTEXT |
| 922 | #define _(msgid) gettext(msgid) |
| 923 | #else /* !HAVE_GETTEXT */ |
| 924 | #define _(msgid) msgid |
| 925 | #endif /* !HAVE_GETTEXT */ |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 926 | |
Elliott Hughes | 9fb22a3 | 2015-10-07 17:13:40 -0700 | [diff] [blame] | 927 | #if !defined TZ_DOMAIN && defined HAVE_GETTEXT |
Elliott Hughes | 5f56454 | 2014-06-19 13:54:10 -0700 | [diff] [blame] | 928 | # define TZ_DOMAIN "tz" |
| 929 | #endif |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 930 | |
| 931 | #if HAVE_INCOMPATIBLE_CTIME_R |
| 932 | #undef asctime_r |
| 933 | #undef ctime_r |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 934 | char *asctime_r(struct tm const *restrict, char *restrict); |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 935 | char *ctime_r(time_t const *, char *); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 936 | #endif /* HAVE_INCOMPATIBLE_CTIME_R */ |
| 937 | |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 938 | /* Handy macros that are independent of tzfile implementation. */ |
| 939 | |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 940 | enum { |
| 941 | SECSPERMIN = 60, |
| 942 | MINSPERHOUR = 60, |
| 943 | SECSPERHOUR = SECSPERMIN * MINSPERHOUR, |
| 944 | HOURSPERDAY = 24, |
| 945 | DAYSPERWEEK = 7, |
| 946 | DAYSPERNYEAR = 365, |
| 947 | DAYSPERLYEAR = DAYSPERNYEAR + 1, |
| 948 | MONSPERYEAR = 12, |
| 949 | YEARSPERREPEAT = 400 /* years before a Gregorian repeat */ |
| 950 | }; |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 951 | |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 952 | #define SECSPERDAY ((int_fast32_t) SECSPERHOUR * HOURSPERDAY) |
| 953 | |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 954 | #define DAYSPERREPEAT ((int_fast32_t) 400 * 365 + 100 - 4 + 1) |
| 955 | #define SECSPERREPEAT ((int_fast64_t) DAYSPERREPEAT * SECSPERDAY) |
| 956 | #define AVGSECSPERYEAR (SECSPERREPEAT / YEARSPERREPEAT) |
| 957 | |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 958 | enum { |
| 959 | TM_SUNDAY, |
| 960 | TM_MONDAY, |
| 961 | TM_TUESDAY, |
| 962 | TM_WEDNESDAY, |
| 963 | TM_THURSDAY, |
| 964 | TM_FRIDAY, |
| 965 | TM_SATURDAY |
| 966 | }; |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 967 | |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 968 | enum { |
| 969 | TM_JANUARY, |
| 970 | TM_FEBRUARY, |
| 971 | TM_MARCH, |
| 972 | TM_APRIL, |
| 973 | TM_MAY, |
| 974 | TM_JUNE, |
| 975 | TM_JULY, |
| 976 | TM_AUGUST, |
| 977 | TM_SEPTEMBER, |
| 978 | TM_OCTOBER, |
| 979 | TM_NOVEMBER, |
| 980 | TM_DECEMBER |
| 981 | }; |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 982 | |
Almaz Mingaleev | d86a3ab | 2023-04-27 11:24:48 +0100 | [diff] [blame] | 983 | enum { |
| 984 | TM_YEAR_BASE = 1900, |
| 985 | TM_WDAY_BASE = TM_MONDAY, |
| 986 | EPOCH_YEAR = 1970, |
| 987 | EPOCH_WDAY = TM_THURSDAY |
| 988 | }; |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 989 | |
| 990 | #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] | 991 | |
| 992 | /* |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 993 | ** Since everything in isleap is modulo 400 (or a factor of 400), we know that |
| 994 | ** isleap(y) == isleap(y % 400) |
| 995 | ** and so |
| 996 | ** isleap(a + b) == isleap((a + b) % 400) |
| 997 | ** or |
| 998 | ** isleap(a + b) == isleap(a % 400 + b % 400) |
| 999 | ** This is true even if % means modulo rather than Fortran remainder |
| 1000 | ** (which is allowed by C89 but not by C99 or later). |
| 1001 | ** We use this to avoid addition overflow problems. |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 1002 | */ |
| 1003 | |
Almaz Mingaleev | 5411aff | 2022-02-11 12:27:12 +0000 | [diff] [blame] | 1004 | #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] | 1005 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 1006 | #endif /* !defined PRIVATE_H */ |