1 /* $NetBSD: private.h,v 1.28 2012/10/26 23:23:23 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 INT_FAST64_MAX 140 /* Pre-C99 GCC compilers define __LONG_LONG_MAX__ instead of LLONG_MAX. */ 141 #if defined LLONG_MAX || defined __LONG_LONG_MAX__ 142 typedef long long int_fast64_t; 143 #else /* ! (defined LLONG_MAX || defined __LONG_LONG_MAX__) */ 144 #if (LONG_MAX >> 31) < 0xffffffff 145 Please use a compiler that supports a 64-bit integer type (or wider); 146 you may need to compile with "-DHAVE_STDINT_H". 147 #endif /* (LONG_MAX >> 31) < 0xffffffff */ 148 typedef long int_fast64_t; 149 #endif /* ! (defined LLONG_MAX || defined __LONG_LONG_MAX__) */ 150 #endif /* !defined INT_FAST64_MAX */ 151 152 #ifndef INT32_MAX 153 #define INT32_MAX 0x7fffffff 154 #endif /* !defined INT32_MAX */ 155 #ifndef INT32_MIN 156 #define INT32_MIN (-1 - INT32_MAX) 157 #endif /* !defined INT32_MIN */ 158 159 #ifndef __pure 160 #if 2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__) 161 # define __pure __attribute__ ((__pure__)) 162 #else 163 # define __pure /* empty */ 164 #endif 165 #endif 166 167 /* 168 ** Workarounds for compilers/systems. 169 */ 170 171 /* 172 ** Some time.h implementations don't declare asctime_r. 173 ** Others might define it as a macro. 174 ** Fix the former without affecting the latter. 175 */ 176 177 #ifndef asctime_r 178 extern char * asctime_r(struct tm const *, char *); 179 #endif 180 181 /* 182 ** Private function declarations. 183 */ 184 185 char * icatalloc(char * old, const char * new); 186 char * icpyalloc(const char * string); 187 const char * scheck(const char * string, const char * format); 188 189 /* 190 ** Finally, some convenience items. 191 */ 192 193 #ifndef TRUE 194 #define TRUE 1 195 #endif /* !defined TRUE */ 196 197 #ifndef FALSE 198 #define FALSE 0 199 #endif /* !defined FALSE */ 200 201 #ifndef TYPE_BIT 202 #define TYPE_BIT(type) (sizeof (type) * CHAR_BIT) 203 #endif /* !defined TYPE_BIT */ 204 205 #ifndef TYPE_SIGNED 206 #define TYPE_SIGNED(type) (/*CONSTCOND*/((type) -1) < 0) 207 #endif /* !defined TYPE_SIGNED */ 208 209 /* 210 ** Since the definition of TYPE_INTEGRAL contains floating point numbers, 211 ** it cannot be used in preprocessor directives. 212 */ 213 214 #ifndef TYPE_INTEGRAL 215 #define TYPE_INTEGRAL(type) (/*CONSTCOND*/((type) 0.5) != 0.5) 216 #endif /* !defined TYPE_INTEGRAL */ 217 218 #ifndef INT_STRLEN_MAXIMUM 219 /* 220 ** 302 / 1000 is log10(2.0) rounded up. 221 ** Subtract one for the sign bit if the type is signed; 222 ** add one for integer division truncation; 223 ** add one more for a minus sign if the type is signed. 224 */ 225 #define INT_STRLEN_MAXIMUM(type) \ 226 ((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + \ 227 1 + TYPE_SIGNED(type)) 228 #endif /* !defined INT_STRLEN_MAXIMUM */ 229 230 /* 231 ** INITIALIZE(x) 232 */ 233 234 #ifndef GNUC_or_lint 235 #ifdef lint 236 #define GNUC_or_lint 237 #endif /* defined lint */ 238 #ifndef lint 239 #ifdef __GNUC__ 240 #define GNUC_or_lint 241 #endif /* defined __GNUC__ */ 242 #endif /* !defined lint */ 243 #endif /* !defined GNUC_or_lint */ 244 245 #ifndef INITIALIZE 246 #ifdef GNUC_or_lint 247 #define INITIALIZE(x) ((x) = 0) 248 #endif /* defined GNUC_or_lint */ 249 #ifndef GNUC_or_lint 250 #define INITIALIZE(x) 251 #endif /* !defined GNUC_or_lint */ 252 #endif /* !defined INITIALIZE */ 253 254 /* 255 ** For the benefit of GNU folk... 256 ** `_(MSGID)' uses the current locale's message library string for MSGID. 257 ** The default is to use gettext if available, and use MSGID otherwise. 258 */ 259 260 #ifndef _ 261 #if HAVE_GETTEXT 262 #define _(msgid) gettext(msgid) 263 #else /* !HAVE_GETTEXT */ 264 #define _(msgid) msgid 265 #endif /* !HAVE_GETTEXT */ 266 #endif /* !defined _ */ 267 268 #ifndef TZ_DOMAIN 269 #define TZ_DOMAIN "tz" 270 #endif /* !defined TZ_DOMAIN */ 271 272 #if HAVE_INCOMPATIBLE_CTIME_R 273 #undef asctime_r 274 #undef ctime_r 275 char *asctime_r(struct tm const *, char *); 276 char *ctime_r(time_t const *, char *); 277 #endif /* HAVE_INCOMPATIBLE_CTIME_R */ 278 279 #ifndef YEARSPERREPEAT 280 #define YEARSPERREPEAT 400 /* years before a Gregorian repeat */ 281 #endif /* !defined YEARSPERREPEAT */ 282 283 /* 284 ** The Gregorian year averages 365.2425 days, which is 31556952 seconds. 285 */ 286 287 #ifndef AVGSECSPERYEAR 288 #define AVGSECSPERYEAR 31556952L 289 #endif /* !defined AVGSECSPERYEAR */ 290 291 #ifndef SECSPERREPEAT 292 #define SECSPERREPEAT ((int_fast64_t) YEARSPERREPEAT * (int_fast64_t) AVGSECSPERYEAR) 293 #endif /* !defined SECSPERREPEAT */ 294 295 #ifndef SECSPERREPEAT_BITS 296 #define SECSPERREPEAT_BITS 34 /* ceil(log2(SECSPERREPEAT)) */ 297 #endif /* !defined SECSPERREPEAT_BITS */ 298 299 /* 300 ** UNIX was a registered trademark of The Open Group in 2003. 301 */ 302 303 #endif /* !defined PRIVATE_H */ 304