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