Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
michael@0 | 1 | #ifndef PRIVATE_H |
michael@0 | 2 | |
michael@0 | 3 | #define PRIVATE_H |
michael@0 | 4 | |
michael@0 | 5 | /* |
michael@0 | 6 | ** This file is in the public domain, so clarified as of |
michael@0 | 7 | ** 1996-06-05 by Arthur David Olson. |
michael@0 | 8 | */ |
michael@0 | 9 | |
michael@0 | 10 | /* |
michael@0 | 11 | ** This header is for use ONLY with the time conversion code. |
michael@0 | 12 | ** There is no guarantee that it will remain unchanged, |
michael@0 | 13 | ** or that it will remain at all. |
michael@0 | 14 | ** Do NOT copy it to any system include directory. |
michael@0 | 15 | ** Thank you! |
michael@0 | 16 | */ |
michael@0 | 17 | |
michael@0 | 18 | /* |
michael@0 | 19 | ** ID |
michael@0 | 20 | */ |
michael@0 | 21 | |
michael@0 | 22 | #ifndef lint |
michael@0 | 23 | #ifndef NOID |
michael@0 | 24 | static char privatehid[] = "@(#)private.h 8.6"; |
michael@0 | 25 | #endif /* !defined NOID */ |
michael@0 | 26 | #endif /* !defined lint */ |
michael@0 | 27 | |
michael@0 | 28 | #define GRANDPARENTED "Local time zone must be set--see zic manual page" |
michael@0 | 29 | |
michael@0 | 30 | /* |
michael@0 | 31 | ** Defaults for preprocessor symbols. |
michael@0 | 32 | ** You can override these in your C compiler options, e.g. `-DHAVE_ADJTIME=0'. |
michael@0 | 33 | */ |
michael@0 | 34 | |
michael@0 | 35 | #ifndef HAVE_ADJTIME |
michael@0 | 36 | #define HAVE_ADJTIME 1 |
michael@0 | 37 | #endif /* !defined HAVE_ADJTIME */ |
michael@0 | 38 | |
michael@0 | 39 | #ifndef HAVE_GETTEXT |
michael@0 | 40 | #define HAVE_GETTEXT 0 |
michael@0 | 41 | #endif /* !defined HAVE_GETTEXT */ |
michael@0 | 42 | |
michael@0 | 43 | #ifndef HAVE_INCOMPATIBLE_CTIME_R |
michael@0 | 44 | #define HAVE_INCOMPATIBLE_CTIME_R 0 |
michael@0 | 45 | #endif /* !defined INCOMPATIBLE_CTIME_R */ |
michael@0 | 46 | |
michael@0 | 47 | #ifndef HAVE_SETTIMEOFDAY |
michael@0 | 48 | #define HAVE_SETTIMEOFDAY 3 |
michael@0 | 49 | #endif /* !defined HAVE_SETTIMEOFDAY */ |
michael@0 | 50 | |
michael@0 | 51 | #ifndef HAVE_SYMLINK |
michael@0 | 52 | #define HAVE_SYMLINK 1 |
michael@0 | 53 | #endif /* !defined HAVE_SYMLINK */ |
michael@0 | 54 | |
michael@0 | 55 | #ifndef HAVE_SYS_STAT_H |
michael@0 | 56 | #define HAVE_SYS_STAT_H 1 |
michael@0 | 57 | #endif /* !defined HAVE_SYS_STAT_H */ |
michael@0 | 58 | |
michael@0 | 59 | #ifndef HAVE_SYS_WAIT_H |
michael@0 | 60 | #define HAVE_SYS_WAIT_H 1 |
michael@0 | 61 | #endif /* !defined HAVE_SYS_WAIT_H */ |
michael@0 | 62 | |
michael@0 | 63 | #ifndef HAVE_UNISTD_H |
michael@0 | 64 | #define HAVE_UNISTD_H 1 |
michael@0 | 65 | #endif /* !defined HAVE_UNISTD_H */ |
michael@0 | 66 | |
michael@0 | 67 | #ifndef HAVE_UTMPX_H |
michael@0 | 68 | #define HAVE_UTMPX_H 0 |
michael@0 | 69 | #endif /* !defined HAVE_UTMPX_H */ |
michael@0 | 70 | |
michael@0 | 71 | #ifndef LOCALE_HOME |
michael@0 | 72 | #define LOCALE_HOME "/usr/lib/locale" |
michael@0 | 73 | #endif /* !defined LOCALE_HOME */ |
michael@0 | 74 | |
michael@0 | 75 | #if HAVE_INCOMPATIBLE_CTIME_R |
michael@0 | 76 | #define asctime_r _incompatible_asctime_r |
michael@0 | 77 | #define ctime_r _incompatible_ctime_r |
michael@0 | 78 | #endif /* HAVE_INCOMPATIBLE_CTIME_R */ |
michael@0 | 79 | |
michael@0 | 80 | /* |
michael@0 | 81 | ** Nested includes |
michael@0 | 82 | */ |
michael@0 | 83 | |
michael@0 | 84 | #include "sys/types.h" /* for time_t */ |
michael@0 | 85 | #include "stdio.h" |
michael@0 | 86 | #include "errno.h" |
michael@0 | 87 | #include "string.h" |
michael@0 | 88 | #include "limits.h" /* for CHAR_BIT et al. */ |
michael@0 | 89 | #include "time.h" |
michael@0 | 90 | #include "stdlib.h" |
michael@0 | 91 | |
michael@0 | 92 | #if HAVE_GETTEXT |
michael@0 | 93 | #include "libintl.h" |
michael@0 | 94 | #endif /* HAVE_GETTEXT */ |
michael@0 | 95 | |
michael@0 | 96 | #if HAVE_SYS_WAIT_H |
michael@0 | 97 | #include <sys/wait.h> /* for WIFEXITED and WEXITSTATUS */ |
michael@0 | 98 | #endif /* HAVE_SYS_WAIT_H */ |
michael@0 | 99 | |
michael@0 | 100 | #ifndef WIFEXITED |
michael@0 | 101 | #define WIFEXITED(status) (((status) & 0xff) == 0) |
michael@0 | 102 | #endif /* !defined WIFEXITED */ |
michael@0 | 103 | #ifndef WEXITSTATUS |
michael@0 | 104 | #define WEXITSTATUS(status) (((status) >> 8) & 0xff) |
michael@0 | 105 | #endif /* !defined WEXITSTATUS */ |
michael@0 | 106 | |
michael@0 | 107 | #if HAVE_UNISTD_H |
michael@0 | 108 | #include "unistd.h" /* for F_OK, R_OK, and other POSIX goodness */ |
michael@0 | 109 | #endif /* HAVE_UNISTD_H */ |
michael@0 | 110 | |
michael@0 | 111 | #ifndef F_OK |
michael@0 | 112 | #define F_OK 0 |
michael@0 | 113 | #endif /* !defined F_OK */ |
michael@0 | 114 | #ifndef R_OK |
michael@0 | 115 | #define R_OK 4 |
michael@0 | 116 | #endif /* !defined R_OK */ |
michael@0 | 117 | |
michael@0 | 118 | /* Unlike <ctype.h>'s isdigit, this also works if c < 0 | c > UCHAR_MAX. */ |
michael@0 | 119 | #define is_digit(c) ((unsigned)(c) - '0' <= 9) |
michael@0 | 120 | |
michael@0 | 121 | /* |
michael@0 | 122 | ** Define HAVE_STDINT_H's default value here, rather than at the |
michael@0 | 123 | ** start, since __GLIBC__'s value depends on previously-included |
michael@0 | 124 | ** files. |
michael@0 | 125 | ** (glibc 2.1 and later have stdint.h, even with pre-C99 compilers.) |
michael@0 | 126 | */ |
michael@0 | 127 | #ifndef HAVE_STDINT_H |
michael@0 | 128 | #define HAVE_STDINT_H \ |
michael@0 | 129 | (199901 <= __STDC_VERSION__ || \ |
michael@0 | 130 | 2 < (__GLIBC__ + (0 < __GLIBC_MINOR__))) |
michael@0 | 131 | #endif /* !defined HAVE_STDINT_H */ |
michael@0 | 132 | |
michael@0 | 133 | #if HAVE_STDINT_H |
michael@0 | 134 | #include "stdint.h" |
michael@0 | 135 | #endif /* !HAVE_STDINT_H */ |
michael@0 | 136 | |
michael@0 | 137 | #ifndef INT_FAST64_MAX |
michael@0 | 138 | /* Pre-C99 GCC compilers define __LONG_LONG_MAX__ instead of LLONG_MAX. */ |
michael@0 | 139 | #if defined LLONG_MAX || defined __LONG_LONG_MAX__ |
michael@0 | 140 | typedef long long int_fast64_t; |
michael@0 | 141 | #else /* ! (defined LLONG_MAX || defined __LONG_LONG_MAX__) */ |
michael@0 | 142 | #if (LONG_MAX >> 31) < 0xffffffff |
michael@0 | 143 | Please use a compiler that supports a 64-bit integer type (or wider); |
michael@0 | 144 | you may need to compile with "-DHAVE_STDINT_H". |
michael@0 | 145 | #endif /* (LONG_MAX >> 31) < 0xffffffff */ |
michael@0 | 146 | typedef long int_fast64_t; |
michael@0 | 147 | #endif /* ! (defined LLONG_MAX || defined __LONG_LONG_MAX__) */ |
michael@0 | 148 | #endif /* !defined INT_FAST64_MAX */ |
michael@0 | 149 | |
michael@0 | 150 | #ifndef INT32_MAX |
michael@0 | 151 | #define INT32_MAX 0x7fffffff |
michael@0 | 152 | #endif /* !defined INT32_MAX */ |
michael@0 | 153 | #ifndef INT32_MIN |
michael@0 | 154 | #define INT32_MIN (-1 - INT32_MAX) |
michael@0 | 155 | #endif /* !defined INT32_MIN */ |
michael@0 | 156 | |
michael@0 | 157 | /* |
michael@0 | 158 | ** Workarounds for compilers/systems. |
michael@0 | 159 | */ |
michael@0 | 160 | |
michael@0 | 161 | /* |
michael@0 | 162 | ** Some time.h implementations don't declare asctime_r. |
michael@0 | 163 | ** Others might define it as a macro. |
michael@0 | 164 | ** Fix the former without affecting the latter. |
michael@0 | 165 | */ |
michael@0 | 166 | |
michael@0 | 167 | #ifndef asctime_r |
michael@0 | 168 | extern char * asctime_r(struct tm const *, char *); |
michael@0 | 169 | #endif |
michael@0 | 170 | |
michael@0 | 171 | /* |
michael@0 | 172 | ** Private function declarations. |
michael@0 | 173 | */ |
michael@0 | 174 | |
michael@0 | 175 | char * icalloc(int nelem, int elsize); |
michael@0 | 176 | char * icatalloc(char * old, const char * new); |
michael@0 | 177 | char * icpyalloc(const char * string); |
michael@0 | 178 | char * imalloc(int n); |
michael@0 | 179 | void * irealloc(void * pointer, int size); |
michael@0 | 180 | void icfree(char * pointer); |
michael@0 | 181 | void ifree(char * pointer); |
michael@0 | 182 | const char * scheck(const char * string, const char * format); |
michael@0 | 183 | |
michael@0 | 184 | /* |
michael@0 | 185 | ** Finally, some convenience items. |
michael@0 | 186 | */ |
michael@0 | 187 | |
michael@0 | 188 | #ifndef TRUE |
michael@0 | 189 | #define TRUE 1 |
michael@0 | 190 | #endif /* !defined TRUE */ |
michael@0 | 191 | |
michael@0 | 192 | #ifndef FALSE |
michael@0 | 193 | #define FALSE 0 |
michael@0 | 194 | #endif /* !defined FALSE */ |
michael@0 | 195 | |
michael@0 | 196 | #ifndef TYPE_BIT |
michael@0 | 197 | #define TYPE_BIT(type) (sizeof (type) * CHAR_BIT) |
michael@0 | 198 | #endif /* !defined TYPE_BIT */ |
michael@0 | 199 | |
michael@0 | 200 | #ifndef TYPE_SIGNED |
michael@0 | 201 | #define TYPE_SIGNED(type) (((type) -1) < 0) |
michael@0 | 202 | #endif /* !defined TYPE_SIGNED */ |
michael@0 | 203 | |
michael@0 | 204 | /* |
michael@0 | 205 | ** Since the definition of TYPE_INTEGRAL contains floating point numbers, |
michael@0 | 206 | ** it cannot be used in preprocessor directives. |
michael@0 | 207 | */ |
michael@0 | 208 | |
michael@0 | 209 | #ifndef TYPE_INTEGRAL |
michael@0 | 210 | #define TYPE_INTEGRAL(type) (((type) 0.5) != 0.5) |
michael@0 | 211 | #endif /* !defined TYPE_INTEGRAL */ |
michael@0 | 212 | |
michael@0 | 213 | #ifndef INT_STRLEN_MAXIMUM |
michael@0 | 214 | /* |
michael@0 | 215 | ** 302 / 1000 is log10(2.0) rounded up. |
michael@0 | 216 | ** Subtract one for the sign bit if the type is signed; |
michael@0 | 217 | ** add one for integer division truncation; |
michael@0 | 218 | ** add one more for a minus sign if the type is signed. |
michael@0 | 219 | */ |
michael@0 | 220 | #define INT_STRLEN_MAXIMUM(type) \ |
michael@0 | 221 | ((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + \ |
michael@0 | 222 | 1 + TYPE_SIGNED(type)) |
michael@0 | 223 | #endif /* !defined INT_STRLEN_MAXIMUM */ |
michael@0 | 224 | |
michael@0 | 225 | /* |
michael@0 | 226 | ** INITIALIZE(x) |
michael@0 | 227 | */ |
michael@0 | 228 | |
michael@0 | 229 | #ifndef GNUC_or_lint |
michael@0 | 230 | #ifdef lint |
michael@0 | 231 | #define GNUC_or_lint |
michael@0 | 232 | #endif /* defined lint */ |
michael@0 | 233 | #ifndef lint |
michael@0 | 234 | #ifdef __GNUC__ |
michael@0 | 235 | #define GNUC_or_lint |
michael@0 | 236 | #endif /* defined __GNUC__ */ |
michael@0 | 237 | #endif /* !defined lint */ |
michael@0 | 238 | #endif /* !defined GNUC_or_lint */ |
michael@0 | 239 | |
michael@0 | 240 | #ifndef INITIALIZE |
michael@0 | 241 | #ifdef GNUC_or_lint |
michael@0 | 242 | #define INITIALIZE(x) ((x) = 0) |
michael@0 | 243 | #endif /* defined GNUC_or_lint */ |
michael@0 | 244 | #ifndef GNUC_or_lint |
michael@0 | 245 | #define INITIALIZE(x) |
michael@0 | 246 | #endif /* !defined GNUC_or_lint */ |
michael@0 | 247 | #endif /* !defined INITIALIZE */ |
michael@0 | 248 | |
michael@0 | 249 | /* |
michael@0 | 250 | ** For the benefit of GNU folk... |
michael@0 | 251 | ** `_(MSGID)' uses the current locale's message library string for MSGID. |
michael@0 | 252 | ** The default is to use gettext if available, and use MSGID otherwise. |
michael@0 | 253 | */ |
michael@0 | 254 | |
michael@0 | 255 | #ifndef _ |
michael@0 | 256 | #if HAVE_GETTEXT |
michael@0 | 257 | #define _(msgid) gettext(msgid) |
michael@0 | 258 | #else /* !HAVE_GETTEXT */ |
michael@0 | 259 | #define _(msgid) msgid |
michael@0 | 260 | #endif /* !HAVE_GETTEXT */ |
michael@0 | 261 | #endif /* !defined _ */ |
michael@0 | 262 | |
michael@0 | 263 | #ifndef TZ_DOMAIN |
michael@0 | 264 | #define TZ_DOMAIN "tz" |
michael@0 | 265 | #endif /* !defined TZ_DOMAIN */ |
michael@0 | 266 | |
michael@0 | 267 | #if HAVE_INCOMPATIBLE_CTIME_R |
michael@0 | 268 | #undef asctime_r |
michael@0 | 269 | #undef ctime_r |
michael@0 | 270 | char *asctime_r(struct tm const *, char *); |
michael@0 | 271 | char *ctime_r(time_t const *, char *); |
michael@0 | 272 | #endif /* HAVE_INCOMPATIBLE_CTIME_R */ |
michael@0 | 273 | |
michael@0 | 274 | #ifndef YEARSPERREPEAT |
michael@0 | 275 | #define YEARSPERREPEAT 400 /* years before a Gregorian repeat */ |
michael@0 | 276 | #endif /* !defined YEARSPERREPEAT */ |
michael@0 | 277 | |
michael@0 | 278 | /* |
michael@0 | 279 | ** The Gregorian year averages 365.2425 days, which is 31556952 seconds. |
michael@0 | 280 | */ |
michael@0 | 281 | |
michael@0 | 282 | #ifndef AVGSECSPERYEAR |
michael@0 | 283 | #define AVGSECSPERYEAR 31556952L |
michael@0 | 284 | #endif /* !defined AVGSECSPERYEAR */ |
michael@0 | 285 | |
michael@0 | 286 | #ifndef SECSPERREPEAT |
michael@0 | 287 | #define SECSPERREPEAT ((int_fast64_t) YEARSPERREPEAT * (int_fast64_t) AVGSECSPERYEAR) |
michael@0 | 288 | #endif /* !defined SECSPERREPEAT */ |
michael@0 | 289 | |
michael@0 | 290 | #ifndef SECSPERREPEAT_BITS |
michael@0 | 291 | #define SECSPERREPEAT_BITS 34 /* ceil(log2(SECSPERREPEAT)) */ |
michael@0 | 292 | #endif /* !defined SECSPERREPEAT_BITS */ |
michael@0 | 293 | |
michael@0 | 294 | /* |
michael@0 | 295 | ** UNIX was a registered trademark of The Open Group in 2003. |
michael@0 | 296 | */ |
michael@0 | 297 | |
michael@0 | 298 | #endif /* !defined PRIVATE_H */ |