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 | 5f56454 | 2014-06-19 13:54:10 -0700 | [diff] [blame] | 22 | ** You can override these in your C compiler options, e.g. '-DHAVE_ADJTIME=0'. |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 23 | */ |
| 24 | |
| 25 | #ifndef HAVE_ADJTIME |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 26 | #define HAVE_ADJTIME 1 |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 27 | #endif /* !defined HAVE_ADJTIME */ |
| 28 | |
| 29 | #ifndef HAVE_GETTEXT |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 30 | #define HAVE_GETTEXT 0 |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 31 | #endif /* !defined HAVE_GETTEXT */ |
| 32 | |
| 33 | #ifndef HAVE_INCOMPATIBLE_CTIME_R |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 34 | #define HAVE_INCOMPATIBLE_CTIME_R 0 |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 35 | #endif /* !defined INCOMPATIBLE_CTIME_R */ |
| 36 | |
Calin Juravle | 627d37c | 2014-02-28 11:46:03 +0000 | [diff] [blame] | 37 | #ifndef HAVE_LINK |
| 38 | #define HAVE_LINK 1 |
| 39 | #endif /* !defined HAVE_LINK */ |
| 40 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 41 | #ifndef HAVE_SETTIMEOFDAY |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 42 | #define HAVE_SETTIMEOFDAY 3 |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 43 | #endif /* !defined HAVE_SETTIMEOFDAY */ |
| 44 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 45 | #ifndef HAVE_SYMLINK |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 46 | #define HAVE_SYMLINK 1 |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 47 | #endif /* !defined HAVE_SYMLINK */ |
| 48 | |
| 49 | #ifndef HAVE_SYS_STAT_H |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 50 | #define HAVE_SYS_STAT_H 1 |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 51 | #endif /* !defined HAVE_SYS_STAT_H */ |
| 52 | |
| 53 | #ifndef HAVE_SYS_WAIT_H |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 54 | #define HAVE_SYS_WAIT_H 1 |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 55 | #endif /* !defined HAVE_SYS_WAIT_H */ |
| 56 | |
| 57 | #ifndef HAVE_UNISTD_H |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 58 | #define HAVE_UNISTD_H 1 |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 59 | #endif /* !defined HAVE_UNISTD_H */ |
| 60 | |
| 61 | #ifndef HAVE_UTMPX_H |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 62 | #define HAVE_UTMPX_H 0 |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 63 | #endif /* !defined HAVE_UTMPX_H */ |
| 64 | |
Elliott Hughes | 5f56454 | 2014-06-19 13:54:10 -0700 | [diff] [blame] | 65 | #if !defined(__ANDROID__) |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 66 | #ifndef LOCALE_HOME |
| 67 | #define LOCALE_HOME "/usr/lib/locale" |
| 68 | #endif /* !defined LOCALE_HOME */ |
Elliott Hughes | 5f56454 | 2014-06-19 13:54:10 -0700 | [diff] [blame] | 69 | #endif // __ANDROID__ |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 70 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 71 | #if HAVE_INCOMPATIBLE_CTIME_R |
| 72 | #define asctime_r _incompatible_asctime_r |
| 73 | #define ctime_r _incompatible_ctime_r |
| 74 | #endif /* HAVE_INCOMPATIBLE_CTIME_R */ |
| 75 | |
| 76 | /* |
| 77 | ** Nested includes |
| 78 | */ |
| 79 | |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 80 | #include "sys/types.h" /* for time_t */ |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 81 | #include "stdio.h" |
| 82 | #include "errno.h" |
| 83 | #include "string.h" |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 84 | #include "limits.h" /* for CHAR_BIT et al. */ |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 85 | #include "time.h" |
| 86 | #include "stdlib.h" |
| 87 | |
| 88 | #if HAVE_GETTEXT |
| 89 | #include "libintl.h" |
| 90 | #endif /* HAVE_GETTEXT */ |
| 91 | |
| 92 | #if HAVE_SYS_WAIT_H |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 93 | #include <sys/wait.h> /* for WIFEXITED and WEXITSTATUS */ |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 94 | #endif /* HAVE_SYS_WAIT_H */ |
| 95 | |
| 96 | #ifndef WIFEXITED |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 97 | #define WIFEXITED(status) (((status) & 0xff) == 0) |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 98 | #endif /* !defined WIFEXITED */ |
| 99 | #ifndef WEXITSTATUS |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 100 | #define WEXITSTATUS(status) (((status) >> 8) & 0xff) |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 101 | #endif /* !defined WEXITSTATUS */ |
| 102 | |
| 103 | #if HAVE_UNISTD_H |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 104 | #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] | 105 | #endif /* HAVE_UNISTD_H */ |
| 106 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 107 | #ifndef F_OK |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 108 | #define F_OK 0 |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 109 | #endif /* !defined F_OK */ |
| 110 | #ifndef R_OK |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 111 | #define R_OK 4 |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 112 | #endif /* !defined R_OK */ |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 113 | |
| 114 | /* Unlike <ctype.h>'s isdigit, this also works if c < 0 | c > UCHAR_MAX. */ |
| 115 | #define is_digit(c) ((unsigned)(c) - '0' <= 9) |
| 116 | |
| 117 | /* |
| 118 | ** Define HAVE_STDINT_H's default value here, rather than at the |
| 119 | ** start, since __GLIBC__'s value depends on previously-included |
| 120 | ** files. |
| 121 | ** (glibc 2.1 and later have stdint.h, even with pre-C99 compilers.) |
| 122 | */ |
| 123 | #ifndef HAVE_STDINT_H |
| 124 | #define HAVE_STDINT_H \ |
Elliott Hughes | 5f56454 | 2014-06-19 13:54:10 -0700 | [diff] [blame] | 125 | (199901 <= __STDC_VERSION__ \ |
| 126 | || 2 < __GLIBC__ + (1 <= __GLIBC_MINOR__) \ |
| 127 | || __CYGWIN__) |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 128 | #endif /* !defined HAVE_STDINT_H */ |
| 129 | |
| 130 | #if HAVE_STDINT_H |
| 131 | #include "stdint.h" |
| 132 | #endif /* !HAVE_STDINT_H */ |
| 133 | |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 134 | #ifndef HAVE_INTTYPES_H |
| 135 | # define HAVE_INTTYPES_H HAVE_STDINT_H |
| 136 | #endif |
| 137 | #if HAVE_INTTYPES_H |
| 138 | # include <inttypes.h> |
| 139 | #endif |
| 140 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 141 | #ifndef INT_FAST64_MAX |
| 142 | /* Pre-C99 GCC compilers define __LONG_LONG_MAX__ instead of LLONG_MAX. */ |
| 143 | #if defined LLONG_MAX || defined __LONG_LONG_MAX__ |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 144 | typedef long long int_fast64_t; |
| 145 | # ifdef LLONG_MAX |
| 146 | # define INT_FAST64_MIN LLONG_MIN |
| 147 | # define INT_FAST64_MAX LLONG_MAX |
| 148 | # else |
| 149 | # define INT_FAST64_MIN __LONG_LONG_MIN__ |
| 150 | # define INT_FAST64_MAX __LONG_LONG_MAX__ |
| 151 | # endif |
| 152 | # define SCNdFAST64 "lld" |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 153 | #else /* ! (defined LLONG_MAX || defined __LONG_LONG_MAX__) */ |
| 154 | #if (LONG_MAX >> 31) < 0xffffffff |
| 155 | Please use a compiler that supports a 64-bit integer type (or wider); |
| 156 | you may need to compile with "-DHAVE_STDINT_H". |
| 157 | #endif /* (LONG_MAX >> 31) < 0xffffffff */ |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 158 | typedef long int_fast64_t; |
| 159 | # define INT_FAST64_MIN LONG_MIN |
| 160 | # define INT_FAST64_MAX LONG_MAX |
| 161 | # define SCNdFAST64 "ld" |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 162 | #endif /* ! (defined LLONG_MAX || defined __LONG_LONG_MAX__) */ |
| 163 | #endif /* !defined INT_FAST64_MAX */ |
| 164 | |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 165 | #ifndef INT_FAST32_MAX |
| 166 | # if INT_MAX >> 31 == 0 |
| 167 | typedef long int_fast32_t; |
| 168 | # else |
| 169 | typedef int int_fast32_t; |
| 170 | # endif |
| 171 | #endif |
| 172 | |
| 173 | #ifndef INTMAX_MAX |
| 174 | # if defined LLONG_MAX || defined __LONG_LONG_MAX__ |
| 175 | typedef long long intmax_t; |
Elliott Hughes | e0d0b15 | 2013-09-27 00:04:30 -0700 | [diff] [blame] | 176 | # define strtoimax strtoll |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 177 | # define PRIdMAX "lld" |
Elliott Hughes | e0d0b15 | 2013-09-27 00:04:30 -0700 | [diff] [blame] | 178 | # ifdef LLONG_MAX |
| 179 | # define INTMAX_MAX LLONG_MAX |
| 180 | # define INTMAX_MIN LLONG_MIN |
| 181 | # else |
| 182 | # define INTMAX_MAX __LONG_LONG_MAX__ |
| 183 | # define INTMAX_MIN __LONG_LONG_MIN__ |
| 184 | # endif |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 185 | # else |
| 186 | typedef long intmax_t; |
Elliott Hughes | e0d0b15 | 2013-09-27 00:04:30 -0700 | [diff] [blame] | 187 | # define strtoimax strtol |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 188 | # define PRIdMAX "ld" |
Elliott Hughes | e0d0b15 | 2013-09-27 00:04:30 -0700 | [diff] [blame] | 189 | # define INTMAX_MAX LONG_MAX |
| 190 | # define INTMAX_MIN LONG_MIN |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 191 | # endif |
| 192 | #endif |
| 193 | |
| 194 | #ifndef UINTMAX_MAX |
| 195 | # if defined ULLONG_MAX || defined __LONG_LONG_MAX__ |
| 196 | typedef unsigned long long uintmax_t; |
| 197 | # define PRIuMAX "llu" |
| 198 | # else |
| 199 | typedef unsigned long uintmax_t; |
| 200 | # define PRIuMAX "lu" |
| 201 | # endif |
| 202 | #endif |
| 203 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 204 | #ifndef INT32_MAX |
| 205 | #define INT32_MAX 0x7fffffff |
| 206 | #endif /* !defined INT32_MAX */ |
| 207 | #ifndef INT32_MIN |
| 208 | #define INT32_MIN (-1 - INT32_MAX) |
| 209 | #endif /* !defined INT32_MIN */ |
| 210 | |
Elliott Hughes | 5f56454 | 2014-06-19 13:54:10 -0700 | [diff] [blame] | 211 | #ifndef SIZE_MAX |
| 212 | #define SIZE_MAX ((size_t) -1) |
| 213 | #endif |
| 214 | |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 215 | #if 2 < __GNUC__ + (96 <= __GNUC_MINOR__) |
| 216 | # define ATTRIBUTE_CONST __attribute__ ((const)) |
| 217 | # define ATTRIBUTE_PURE __attribute__ ((__pure__)) |
Elliott Hughes | e0d0b15 | 2013-09-27 00:04:30 -0700 | [diff] [blame] | 218 | # define ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec)) |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 219 | #else |
| 220 | # define ATTRIBUTE_CONST /* empty */ |
| 221 | # define ATTRIBUTE_PURE /* empty */ |
Elliott Hughes | e0d0b15 | 2013-09-27 00:04:30 -0700 | [diff] [blame] | 222 | # define ATTRIBUTE_FORMAT(spec) /* empty */ |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 223 | #endif |
| 224 | |
| 225 | #if !defined _Noreturn && __STDC_VERSION__ < 201112 |
| 226 | # if 2 < __GNUC__ + (8 <= __GNUC_MINOR__) |
| 227 | # define _Noreturn __attribute__ ((__noreturn__)) |
| 228 | # else |
| 229 | # define _Noreturn |
| 230 | # endif |
| 231 | #endif |
| 232 | |
| 233 | #if __STDC_VERSION__ < 199901 && !defined restrict |
| 234 | # define restrict /* empty */ |
| 235 | #endif |
| 236 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 237 | /* |
| 238 | ** Workarounds for compilers/systems. |
| 239 | */ |
| 240 | |
| 241 | /* |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 242 | ** Some time.h implementations don't declare asctime_r. |
| 243 | ** Others might define it as a macro. |
| 244 | ** Fix the former without affecting the latter. |
| 245 | */ |
| 246 | |
| 247 | #ifndef asctime_r |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 248 | extern char * asctime_r(struct tm const *, char *); |
| 249 | #endif |
| 250 | |
| 251 | /* |
| 252 | ** Compile with -Dtime_tz=T to build the tz package with a private |
| 253 | ** time_t type equivalent to T rather than the system-supplied time_t. |
| 254 | ** This debugging feature can test unusual design decisions |
| 255 | ** (e.g., time_t wider than 'long', or unsigned time_t) even on |
| 256 | ** typical platforms. |
| 257 | */ |
| 258 | #ifdef time_tz |
| 259 | static time_t sys_time(time_t *x) { return time(x); } |
| 260 | |
| 261 | # undef ctime |
| 262 | # define ctime tz_ctime |
| 263 | # undef ctime_r |
| 264 | # define ctime_r tz_ctime_r |
| 265 | # undef difftime |
| 266 | # define difftime tz_difftime |
| 267 | # undef gmtime |
| 268 | # define gmtime tz_gmtime |
| 269 | # undef gmtime_r |
| 270 | # define gmtime_r tz_gmtime_r |
| 271 | # undef localtime |
| 272 | # define localtime tz_localtime |
| 273 | # undef localtime_r |
| 274 | # define localtime_r tz_localtime_r |
| 275 | # undef mktime |
| 276 | # define mktime tz_mktime |
| 277 | # undef time |
| 278 | # define time tz_time |
| 279 | # undef time_t |
| 280 | # define time_t tz_time_t |
| 281 | |
| 282 | typedef time_tz time_t; |
| 283 | |
| 284 | char *ctime(time_t const *); |
| 285 | char *ctime_r(time_t const *, char *); |
| 286 | double difftime(time_t, time_t); |
| 287 | struct tm *gmtime(time_t const *); |
| 288 | struct tm *gmtime_r(time_t const *restrict, struct tm *restrict); |
| 289 | struct tm *localtime(time_t const *); |
| 290 | struct tm *localtime_r(time_t const *restrict, struct tm *restrict); |
| 291 | time_t mktime(struct tm *); |
| 292 | |
| 293 | static time_t |
| 294 | time(time_t *p) |
| 295 | { |
| 296 | time_t r = sys_time(0); |
| 297 | if (p) |
| 298 | *p = r; |
| 299 | return r; |
| 300 | } |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 301 | #endif |
| 302 | |
| 303 | /* |
| 304 | ** Private function declarations. |
| 305 | */ |
| 306 | |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 307 | char * icatalloc(char * old, const char * new); |
| 308 | char * icpyalloc(const char * string); |
| 309 | const char * scheck(const char * string, const char * format); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 310 | |
| 311 | /* |
| 312 | ** Finally, some convenience items. |
| 313 | */ |
| 314 | |
| 315 | #ifndef TRUE |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 316 | #define TRUE 1 |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 317 | #endif /* !defined TRUE */ |
| 318 | |
| 319 | #ifndef FALSE |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 320 | #define FALSE 0 |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 321 | #endif /* !defined FALSE */ |
| 322 | |
| 323 | #ifndef TYPE_BIT |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 324 | #define TYPE_BIT(type) (sizeof (type) * CHAR_BIT) |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 325 | #endif /* !defined TYPE_BIT */ |
| 326 | |
| 327 | #ifndef TYPE_SIGNED |
| 328 | #define TYPE_SIGNED(type) (((type) -1) < 0) |
| 329 | #endif /* !defined TYPE_SIGNED */ |
| 330 | |
Elliott Hughes | 713fe64 | 2013-08-22 14:13:50 -0700 | [diff] [blame] | 331 | /* The minimum and maximum finite time values. */ |
| 332 | static time_t const time_t_min = |
| 333 | (TYPE_SIGNED(time_t) |
| 334 | ? (time_t) -1 << (CHAR_BIT * sizeof (time_t) - 1) |
| 335 | : 0); |
| 336 | static time_t const time_t_max = |
| 337 | (TYPE_SIGNED(time_t) |
| 338 | ? - (~ 0 < 0) - ((time_t) -1 << (CHAR_BIT * sizeof (time_t) - 1)) |
| 339 | : -1); |
| 340 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 341 | #ifndef INT_STRLEN_MAXIMUM |
| 342 | /* |
| 343 | ** 302 / 1000 is log10(2.0) rounded up. |
| 344 | ** Subtract one for the sign bit if the type is signed; |
| 345 | ** add one for integer division truncation; |
| 346 | ** add one more for a minus sign if the type is signed. |
| 347 | */ |
| 348 | #define INT_STRLEN_MAXIMUM(type) \ |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 349 | ((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + \ |
| 350 | 1 + TYPE_SIGNED(type)) |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 351 | #endif /* !defined INT_STRLEN_MAXIMUM */ |
| 352 | |
| 353 | /* |
| 354 | ** INITIALIZE(x) |
| 355 | */ |
| 356 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 357 | #ifdef lint |
Elliott Hughes | 5f56454 | 2014-06-19 13:54:10 -0700 | [diff] [blame] | 358 | # define INITIALIZE(x) ((x) = 0) |
| 359 | #else |
| 360 | # define INITIALIZE(x) |
| 361 | #endif |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 362 | |
| 363 | /* |
| 364 | ** For the benefit of GNU folk... |
Elliott Hughes | 5f56454 | 2014-06-19 13:54:10 -0700 | [diff] [blame] | 365 | ** '_(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] | 366 | ** The default is to use gettext if available, and use MSGID otherwise. |
| 367 | */ |
| 368 | |
| 369 | #ifndef _ |
| 370 | #if HAVE_GETTEXT |
| 371 | #define _(msgid) gettext(msgid) |
| 372 | #else /* !HAVE_GETTEXT */ |
| 373 | #define _(msgid) msgid |
| 374 | #endif /* !HAVE_GETTEXT */ |
| 375 | #endif /* !defined _ */ |
| 376 | |
Elliott Hughes | 5f56454 | 2014-06-19 13:54:10 -0700 | [diff] [blame] | 377 | #if !defined TZ_DOMAIN && defined TZ_DOMAINDIR |
| 378 | # define TZ_DOMAIN "tz" |
| 379 | #endif |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 380 | |
| 381 | #if HAVE_INCOMPATIBLE_CTIME_R |
| 382 | #undef asctime_r |
| 383 | #undef ctime_r |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 384 | char *asctime_r(struct tm const *, char *); |
| 385 | char *ctime_r(time_t const *, char *); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 386 | #endif /* HAVE_INCOMPATIBLE_CTIME_R */ |
| 387 | |
| 388 | #ifndef YEARSPERREPEAT |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 389 | #define YEARSPERREPEAT 400 /* years before a Gregorian repeat */ |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 390 | #endif /* !defined YEARSPERREPEAT */ |
| 391 | |
| 392 | /* |
| 393 | ** The Gregorian year averages 365.2425 days, which is 31556952 seconds. |
| 394 | */ |
| 395 | |
| 396 | #ifndef AVGSECSPERYEAR |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 397 | #define AVGSECSPERYEAR 31556952L |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 398 | #endif /* !defined AVGSECSPERYEAR */ |
| 399 | |
| 400 | #ifndef SECSPERREPEAT |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 401 | #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] | 402 | #endif /* !defined SECSPERREPEAT */ |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 403 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 404 | #ifndef SECSPERREPEAT_BITS |
Elliott Hughes | ce4783c | 2013-07-12 17:31:11 -0700 | [diff] [blame] | 405 | #define SECSPERREPEAT_BITS 34 /* ceil(log2(SECSPERREPEAT)) */ |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 406 | #endif /* !defined SECSPERREPEAT_BITS */ |
| 407 | |
| 408 | /* |
| 409 | ** UNIX was a registered trademark of The Open Group in 2003. |
| 410 | */ |
| 411 | |
| 412 | #endif /* !defined PRIVATE_H */ |