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