| OLD | NEW |
| 1 #ifndef PRIVATE_H | 1 #ifndef PRIVATE_H |
| 2 | 2 |
| 3 #define PRIVATE_H | 3 #define PRIVATE_H |
| 4 | 4 |
| 5 /* | 5 /* |
| 6 ** This file is in the public domain, so clarified as of | 6 ** This file is in the public domain, so clarified as of |
| 7 ** 1996-06-05 by Arthur David Olson. | 7 ** 1996-06-05 by Arthur David Olson. |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 /* | 10 /* |
| 11 ** This header is for use ONLY with the time conversion code. | 11 ** This header is for use ONLY with the time conversion code. |
| 12 ** There is no guarantee that it will remain unchanged, | 12 ** There is no guarantee that it will remain unchanged, |
| 13 ** or that it will remain at all. | 13 ** or that it will remain at all. |
| 14 ** Do NOT copy it to any system include directory. | 14 ** Do NOT copy it to any system include directory. |
| 15 ** Thank you! | 15 ** Thank you! |
| 16 */ | 16 */ |
| 17 | 17 |
| 18 /* | |
| 19 ** ID | |
| 20 */ | |
| 21 | |
| 22 #ifndef lint | |
| 23 #ifndef NOID | |
| 24 static char privatehid[] = "@(#)private.h 8.6"; | |
| 25 #endif /* !defined NOID */ | |
| 26 #endif /* !defined lint */ | |
| 27 | |
| 28 #define GRANDPARENTED "Local time zone must be set--see zic manual page" | 18 #define GRANDPARENTED "Local time zone must be set--see zic manual page" |
| 29 | 19 |
| 30 /* | 20 /* |
| 31 ** Defaults for preprocessor symbols. | 21 ** Defaults for preprocessor symbols. |
| 32 ** You can override these in your C compiler options, e.g. `-DHAVE_ADJTIME=0'. | 22 ** You can override these in your C compiler options, e.g. `-DHAVE_ADJTIME=0'. |
| 33 */ | 23 */ |
| 34 | 24 |
| 35 #ifndef HAVE_ADJTIME | 25 #ifndef HAVE_ADJTIME |
| 36 #define HAVE_ADJTIME 1 | 26 #define HAVE_ADJTIME 1 |
| 37 #endif /* !defined HAVE_ADJTIME */ | 27 #endif /* !defined HAVE_ADJTIME */ |
| 38 | 28 |
| 39 #ifndef HAVE_GETTEXT | 29 #ifndef HAVE_GETTEXT |
| 40 #define HAVE_GETTEXT 0 | 30 #define HAVE_GETTEXT 0 |
| 41 #endif /* !defined HAVE_GETTEXT */ | 31 #endif /* !defined HAVE_GETTEXT */ |
| 42 | 32 |
| 43 #ifndef HAVE_INCOMPATIBLE_CTIME_R | 33 #ifndef HAVE_INCOMPATIBLE_CTIME_R |
| 44 #define HAVE_INCOMPATIBLE_CTIME_R 0 | 34 #define HAVE_INCOMPATIBLE_CTIME_R 0 |
| 45 #endif /* !defined INCOMPATIBLE_CTIME_R */ | 35 #endif /* !defined INCOMPATIBLE_CTIME_R */ |
| 46 | 36 |
| 37 #ifndef HAVE_LINK |
| 38 #define HAVE_LINK 1 |
| 39 #endif /* !defined HAVE_LINK */ |
| 40 |
| 47 #ifndef HAVE_SETTIMEOFDAY | 41 #ifndef HAVE_SETTIMEOFDAY |
| 48 #define HAVE_SETTIMEOFDAY 3 | 42 #define HAVE_SETTIMEOFDAY 3 |
| 49 #endif /* !defined HAVE_SETTIMEOFDAY */ | 43 #endif /* !defined HAVE_SETTIMEOFDAY */ |
| 50 | 44 |
| 51 #ifndef HAVE_SYMLINK | 45 #ifndef HAVE_SYMLINK |
| 52 #define HAVE_SYMLINK 1 | 46 #define HAVE_SYMLINK 1 |
| 53 #endif /* !defined HAVE_SYMLINK */ | 47 #endif /* !defined HAVE_SYMLINK */ |
| 54 | 48 |
| 55 #ifndef HAVE_SYS_STAT_H | 49 #ifndef HAVE_SYS_STAT_H |
| 56 #define HAVE_SYS_STAT_H 1 | 50 #define HAVE_SYS_STAT_H 1 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 #ifndef HAVE_STDINT_H | 121 #ifndef HAVE_STDINT_H |
| 128 #define HAVE_STDINT_H \ | 122 #define HAVE_STDINT_H \ |
| 129 (199901 <= __STDC_VERSION__ || \ | 123 (199901 <= __STDC_VERSION__ || \ |
| 130 2 < (__GLIBC__ + (0 < __GLIBC_MINOR__))) | 124 2 < (__GLIBC__ + (0 < __GLIBC_MINOR__))) |
| 131 #endif /* !defined HAVE_STDINT_H */ | 125 #endif /* !defined HAVE_STDINT_H */ |
| 132 | 126 |
| 133 #if HAVE_STDINT_H | 127 #if HAVE_STDINT_H |
| 134 #include "stdint.h" | 128 #include "stdint.h" |
| 135 #endif /* !HAVE_STDINT_H */ | 129 #endif /* !HAVE_STDINT_H */ |
| 136 | 130 |
| 131 #ifndef HAVE_INTTYPES_H |
| 132 # define HAVE_INTTYPES_H HAVE_STDINT_H |
| 133 #endif |
| 134 #if HAVE_INTTYPES_H |
| 135 # include <inttypes.h> |
| 136 #endif |
| 137 |
| 137 #ifndef INT_FAST64_MAX | 138 #ifndef INT_FAST64_MAX |
| 138 /* Pre-C99 GCC compilers define __LONG_LONG_MAX__ instead of LLONG_MAX. */ | 139 /* Pre-C99 GCC compilers define __LONG_LONG_MAX__ instead of LLONG_MAX. */ |
| 139 #if defined LLONG_MAX || defined __LONG_LONG_MAX__ | 140 #if defined LLONG_MAX || defined __LONG_LONG_MAX__ |
| 140 typedef long long int_fast64_t; | 141 typedef long long int_fast64_t; |
| 142 # ifdef LLONG_MAX |
| 143 # define INT_FAST64_MIN LLONG_MIN |
| 144 # define INT_FAST64_MAX LLONG_MAX |
| 145 # else |
| 146 # define INT_FAST64_MIN __LONG_LONG_MIN__ |
| 147 # define INT_FAST64_MAX __LONG_LONG_MAX__ |
| 148 # endif |
| 149 # define SCNdFAST64 "lld" |
| 141 #else /* ! (defined LLONG_MAX || defined __LONG_LONG_MAX__) */ | 150 #else /* ! (defined LLONG_MAX || defined __LONG_LONG_MAX__) */ |
| 142 #if (LONG_MAX >> 31) < 0xffffffff | 151 #if (LONG_MAX >> 31) < 0xffffffff |
| 143 Please use a compiler that supports a 64-bit integer type (or wider); | 152 Please use a compiler that supports a 64-bit integer type (or wider); |
| 144 you may need to compile with "-DHAVE_STDINT_H". | 153 you may need to compile with "-DHAVE_STDINT_H". |
| 145 #endif /* (LONG_MAX >> 31) < 0xffffffff */ | 154 #endif /* (LONG_MAX >> 31) < 0xffffffff */ |
| 146 typedef long int_fast64_t; | 155 typedef long int_fast64_t; |
| 156 # define INT_FAST64_MIN LONG_MIN |
| 157 # define INT_FAST64_MAX LONG_MAX |
| 158 # define SCNdFAST64 "ld" |
| 147 #endif /* ! (defined LLONG_MAX || defined __LONG_LONG_MAX__) */ | 159 #endif /* ! (defined LLONG_MAX || defined __LONG_LONG_MAX__) */ |
| 148 #endif /* !defined INT_FAST64_MAX */ | 160 #endif /* !defined INT_FAST64_MAX */ |
| 149 | 161 |
| 162 #ifndef INT_FAST32_MAX |
| 163 # if INT_MAX >> 31 == 0 |
| 164 typedef long int_fast32_t; |
| 165 # else |
| 166 typedef int int_fast32_t; |
| 167 # endif |
| 168 #endif |
| 169 |
| 170 #ifndef INTMAX_MAX |
| 171 # if defined LLONG_MAX || defined __LONG_LONG_MAX__ |
| 172 typedef long long intmax_t; |
| 173 # define strtoimax strtoll |
| 174 # define PRIdMAX "lld" |
| 175 # ifdef LLONG_MAX |
| 176 # define INTMAX_MAX LLONG_MAX |
| 177 # define INTMAX_MIN LLONG_MIN |
| 178 # else |
| 179 # define INTMAX_MAX __LONG_LONG_MAX__ |
| 180 # define INTMAX_MIN __LONG_LONG_MIN__ |
| 181 # endif |
| 182 # else |
| 183 typedef long intmax_t; |
| 184 # define strtoimax strtol |
| 185 # define PRIdMAX "ld" |
| 186 # define INTMAX_MAX LONG_MAX |
| 187 # define INTMAX_MIN LONG_MIN |
| 188 # endif |
| 189 #endif |
| 190 |
| 191 #ifndef UINTMAX_MAX |
| 192 # if defined ULLONG_MAX || defined __LONG_LONG_MAX__ |
| 193 typedef unsigned long long uintmax_t; |
| 194 # define PRIuMAX "llu" |
| 195 # else |
| 196 typedef unsigned long uintmax_t; |
| 197 # define PRIuMAX "lu" |
| 198 # endif |
| 199 #endif |
| 200 |
| 150 #ifndef INT32_MAX | 201 #ifndef INT32_MAX |
| 151 #define INT32_MAX 0x7fffffff | 202 #define INT32_MAX 0x7fffffff |
| 152 #endif /* !defined INT32_MAX */ | 203 #endif /* !defined INT32_MAX */ |
| 153 #ifndef INT32_MIN | 204 #ifndef INT32_MIN |
| 154 #define INT32_MIN (-1 - INT32_MAX) | 205 #define INT32_MIN (-1 - INT32_MAX) |
| 155 #endif /* !defined INT32_MIN */ | 206 #endif /* !defined INT32_MIN */ |
| 156 | 207 |
| 208 #ifndef SIZE_MAX |
| 209 #define SIZE_MAX ((size_t) -1) |
| 210 #endif |
| 211 |
| 212 #if 2 < __GNUC__ + (96 <= __GNUC_MINOR__) |
| 213 # define ATTRIBUTE_CONST __attribute__ ((const)) |
| 214 # define ATTRIBUTE_PURE __attribute__ ((__pure__)) |
| 215 # define ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec)) |
| 216 #else |
| 217 # define ATTRIBUTE_CONST /* empty */ |
| 218 # define ATTRIBUTE_PURE /* empty */ |
| 219 # define ATTRIBUTE_FORMAT(spec) /* empty */ |
| 220 #endif |
| 221 |
| 222 #if !defined _Noreturn && __STDC_VERSION__ < 201112 |
| 223 # if 2 < __GNUC__ + (8 <= __GNUC_MINOR__) |
| 224 # define _Noreturn __attribute__ ((__noreturn__)) |
| 225 # else |
| 226 # define _Noreturn |
| 227 # endif |
| 228 #endif |
| 229 |
| 230 #if __STDC_VERSION__ < 199901 && !defined restrict |
| 231 # define restrict /* empty */ |
| 232 #endif |
| 233 |
| 157 /* | 234 /* |
| 158 ** Workarounds for compilers/systems. | 235 ** Workarounds for compilers/systems. |
| 159 */ | 236 */ |
| 160 | 237 |
| 161 /* | 238 /* |
| 162 ** Some time.h implementations don't declare asctime_r. | 239 ** Some time.h implementations don't declare asctime_r. |
| 163 ** Others might define it as a macro. | 240 ** Others might define it as a macro. |
| 164 ** Fix the former without affecting the latter. | 241 ** Fix the former without affecting the latter. |
| 165 */ | 242 */ |
| 166 | 243 |
| 167 #ifndef asctime_r | 244 #ifndef asctime_r |
| 168 extern char * asctime_r(struct tm const *, char *); | 245 extern char * asctime_r(struct tm const *, char *); |
| 169 #endif | 246 #endif |
| 170 | 247 |
| 171 /* | 248 /* |
| 249 ** Compile with -Dtime_tz=T to build the tz package with a private |
| 250 ** time_t type equivalent to T rather than the system-supplied time_t. |
| 251 ** This debugging feature can test unusual design decisions |
| 252 ** (e.g., time_t wider than 'long', or unsigned time_t) even on |
| 253 ** typical platforms. |
| 254 */ |
| 255 #ifdef time_tz |
| 256 static time_t sys_time(time_t *x) { return time(x); } |
| 257 |
| 258 # undef ctime |
| 259 # define ctime tz_ctime |
| 260 # undef ctime_r |
| 261 # define ctime_r tz_ctime_r |
| 262 # undef difftime |
| 263 # define difftime tz_difftime |
| 264 # undef gmtime |
| 265 # define gmtime tz_gmtime |
| 266 # undef gmtime_r |
| 267 # define gmtime_r tz_gmtime_r |
| 268 # undef localtime |
| 269 # define localtime tz_localtime |
| 270 # undef localtime_r |
| 271 # define localtime_r tz_localtime_r |
| 272 # undef mktime |
| 273 # define mktime tz_mktime |
| 274 # undef time |
| 275 # define time tz_time |
| 276 # undef time_t |
| 277 # define time_t tz_time_t |
| 278 |
| 279 typedef time_tz time_t; |
| 280 |
| 281 char *ctime(time_t const *); |
| 282 char *ctime_r(time_t const *, char *); |
| 283 double difftime(time_t, time_t); |
| 284 struct tm *gmtime(time_t const *); |
| 285 struct tm *gmtime_r(time_t const *restrict, struct tm *restrict); |
| 286 struct tm *localtime(time_t const *); |
| 287 struct tm *localtime_r(time_t const *restrict, struct tm *restrict); |
| 288 time_t mktime(struct tm *); |
| 289 |
| 290 static time_t |
| 291 time(time_t *p) |
| 292 { |
| 293 time_t r = sys_time(0); |
| 294 if (p) |
| 295 *p = r; |
| 296 return r; |
| 297 } |
| 298 #endif |
| 299 |
| 300 /* |
| 172 ** Private function declarations. | 301 ** Private function declarations. |
| 173 */ | 302 */ |
| 174 | 303 |
| 175 char * icalloc(int nelem, int elsize); | |
| 176 char * icatalloc(char * old, const char * new); | 304 char * icatalloc(char * old, const char * new); |
| 177 char * icpyalloc(const char * string); | 305 char * icpyalloc(const char * string); |
| 178 char * imalloc(int n); | |
| 179 void * irealloc(void * pointer, int size); | |
| 180 void icfree(char * pointer); | |
| 181 void ifree(char * pointer); | |
| 182 const char * scheck(const char * string, const char * format); | 306 const char * scheck(const char * string, const char * format); |
| 183 | 307 |
| 184 /* | 308 /* |
| 185 ** Finally, some convenience items. | 309 ** Finally, some convenience items. |
| 186 */ | 310 */ |
| 187 | 311 |
| 188 #ifndef TRUE | 312 #ifndef TRUE |
| 189 #define TRUE 1 | 313 #define TRUE 1 |
| 190 #endif /* !defined TRUE */ | 314 #endif /* !defined TRUE */ |
| 191 | 315 |
| 192 #ifndef FALSE | 316 #ifndef FALSE |
| 193 #define FALSE 0 | 317 #define FALSE 0 |
| 194 #endif /* !defined FALSE */ | 318 #endif /* !defined FALSE */ |
| 195 | 319 |
| 196 #ifndef TYPE_BIT | 320 #ifndef TYPE_BIT |
| 197 #define TYPE_BIT(type) (sizeof (type) * CHAR_BIT) | 321 #define TYPE_BIT(type) (sizeof (type) * CHAR_BIT) |
| 198 #endif /* !defined TYPE_BIT */ | 322 #endif /* !defined TYPE_BIT */ |
| 199 | 323 |
| 200 #ifndef TYPE_SIGNED | 324 #ifndef TYPE_SIGNED |
| 201 #define TYPE_SIGNED(type) (((type) -1) < 0) | 325 #define TYPE_SIGNED(type) (((type) -1) < 0) |
| 202 #endif /* !defined TYPE_SIGNED */ | 326 #endif /* !defined TYPE_SIGNED */ |
| 203 | 327 |
| 204 /* | 328 /* The minimum and maximum finite time values. */ |
| 205 ** Since the definition of TYPE_INTEGRAL contains floating point numbers, | 329 static time_t const time_t_min = |
| 206 ** it cannot be used in preprocessor directives. | 330 (TYPE_SIGNED(time_t) |
| 207 */ | 331 ? (time_t) -1 << (CHAR_BIT * sizeof (time_t) - 1) |
| 208 | 332 : 0); |
| 209 #ifndef TYPE_INTEGRAL | 333 static time_t const time_t_max = |
| 210 #define TYPE_INTEGRAL(type) (((type) 0.5) != 0.5) | 334 (TYPE_SIGNED(time_t) |
| 211 #endif /* !defined TYPE_INTEGRAL */ | 335 ? - (~ 0 < 0) - ((time_t) -1 << (CHAR_BIT * sizeof (time_t) - 1)) |
| 336 : -1); |
| 212 | 337 |
| 213 #ifndef INT_STRLEN_MAXIMUM | 338 #ifndef INT_STRLEN_MAXIMUM |
| 214 /* | 339 /* |
| 215 ** 302 / 1000 is log10(2.0) rounded up. | 340 ** 302 / 1000 is log10(2.0) rounded up. |
| 216 ** Subtract one for the sign bit if the type is signed; | 341 ** Subtract one for the sign bit if the type is signed; |
| 217 ** add one for integer division truncation; | 342 ** add one for integer division truncation; |
| 218 ** add one more for a minus sign if the type is signed. | 343 ** add one more for a minus sign if the type is signed. |
| 219 */ | 344 */ |
| 220 #define INT_STRLEN_MAXIMUM(type) \ | 345 #define INT_STRLEN_MAXIMUM(type) \ |
| 221 ((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + \ | 346 ((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + \ |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 | 414 |
| 290 #ifndef SECSPERREPEAT_BITS | 415 #ifndef SECSPERREPEAT_BITS |
| 291 #define SECSPERREPEAT_BITS 34 /* ceil(log2(SECSPERREPEAT)) */ | 416 #define SECSPERREPEAT_BITS 34 /* ceil(log2(SECSPERREPEAT)) */ |
| 292 #endif /* !defined SECSPERREPEAT_BITS */ | 417 #endif /* !defined SECSPERREPEAT_BITS */ |
| 293 | 418 |
| 294 /* | 419 /* |
| 295 ** UNIX was a registered trademark of The Open Group in 2003. | 420 ** UNIX was a registered trademark of The Open Group in 2003. |
| 296 */ | 421 */ |
| 297 | 422 |
| 298 #endif /* !defined PRIVATE_H */ | 423 #endif /* !defined PRIVATE_H */ |
| OLD | NEW |