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 18 /* 19 ** ID 20 */ 21 22 #ifndef lint 23 #ifndef NOID 24 static char privatehid[] = "@(#)private.h 8.2"; 25 #endif /* !defined NOID */ 26 #endif /* !defined lint */ 27 28 #define GRANDPARENTED "Local time zone must be set--see zic manual page" 29 30 /* 31 ** Defaults for preprocessor symbols. 32 ** You can override these in your C compiler options, e.g. `-DHAVE_ADJTIME=0'. 33 */ 34 35 #ifndef HAVE_ADJTIME 36 #define HAVE_ADJTIME 1 37 #endif /* !defined HAVE_ADJTIME */ 38 39 #ifndef HAVE_GETTEXT 40 #define HAVE_GETTEXT 0 41 #endif /* !defined HAVE_GETTEXT */ 42 43 #ifndef HAVE_INCOMPATIBLE_CTIME_R 44 #define HAVE_INCOMPATIBLE_CTIME_R 0 45 #endif /* !defined INCOMPATIBLE_CTIME_R */ 46 47 #ifndef HAVE_SETTIMEOFDAY 48 #define HAVE_SETTIMEOFDAY 3 49 #endif /* !defined HAVE_SETTIMEOFDAY */ 50 51 #ifndef HAVE_STRERROR 52 #define HAVE_STRERROR 1 53 #endif /* !defined HAVE_STRERROR */ 54 55 #ifndef HAVE_SYMLINK 56 #define HAVE_SYMLINK 1 57 #endif /* !defined HAVE_SYMLINK */ 58 59 #ifndef HAVE_SYS_STAT_H 60 #define HAVE_SYS_STAT_H 1 61 #endif /* !defined HAVE_SYS_STAT_H */ 62 63 #ifndef HAVE_SYS_WAIT_H 64 #define HAVE_SYS_WAIT_H 1 65 #endif /* !defined HAVE_SYS_WAIT_H */ 66 67 #ifndef HAVE_UNISTD_H 68 #define HAVE_UNISTD_H 1 69 #endif /* !defined HAVE_UNISTD_H */ 70 71 #ifndef HAVE_UTMPX_H 72 #define HAVE_UTMPX_H 0 73 #endif /* !defined HAVE_UTMPX_H */ 74 75 #ifndef LOCALE_HOME 76 #define LOCALE_HOME "/usr/lib/locale" 77 #endif /* !defined LOCALE_HOME */ 78 79 #if HAVE_INCOMPATIBLE_CTIME_R 80 #define asctime_r _incompatible_asctime_r 81 #define ctime_r _incompatible_ctime_r 82 #endif /* HAVE_INCOMPATIBLE_CTIME_R */ 83 84 /* 85 ** Nested includes 86 */ 87 88 #include "sys/types.h" /* for time_t */ 89 #include "stdio.h" 90 #include "errno.h" 91 #include "string.h" 92 #include "limits.h" /* for CHAR_BIT et al. */ 93 #include "time.h" 94 #include "stdlib.h" 95 96 #if HAVE_GETTEXT 97 #include "libintl.h" 98 #endif /* HAVE_GETTEXT */ 99 100 #if HAVE_SYS_WAIT_H 101 #include <sys/wait.h> /* for WIFEXITED and WEXITSTATUS */ 102 #endif /* HAVE_SYS_WAIT_H */ 103 104 #ifndef WIFEXITED 105 #define WIFEXITED(status) (((status) & 0xff) == 0) 106 #endif /* !defined WIFEXITED */ 107 #ifndef WEXITSTATUS 108 #define WEXITSTATUS(status) (((status) >> 8) & 0xff) 109 #endif /* !defined WEXITSTATUS */ 110 111 #if HAVE_UNISTD_H 112 #include "unistd.h" /* for F_OK and R_OK */ 113 #endif /* HAVE_UNISTD_H */ 114 115 #if !HAVE_UNISTD_H 116 #ifndef F_OK 117 #define F_OK 0 118 #endif /* !defined F_OK */ 119 #ifndef R_OK 120 #define R_OK 4 121 #endif /* !defined R_OK */ 122 #endif /* !HAVE_UNISTD_H */ 123 124 /* Unlike <ctype.h>'s isdigit, this also works if c < 0 | c > UCHAR_MAX. */ 125 #define is_digit(c) ((unsigned)(c) - '0' <= 9) 126 127 /* 128 ** Define HAVE_STDINT_H's default value here, rather than at the 129 ** start, since __GLIBC__'s value depends on previously-included 130 ** files. 131 ** (glibc 2.1 and later have stdint.h, even with pre-C99 compilers.) 132 */ 133 #ifndef HAVE_STDINT_H 134 #define HAVE_STDINT_H \ 135 (199901 <= __STDC_VERSION__ || \ 136 2 < (__GLIBC__ + (0 < __GLIBC_MINOR__))) 137 #endif /* !defined HAVE_STDINT_H */ 138 139 #if HAVE_STDINT_H 140 #include "stdint.h" 141 #endif /* !HAVE_STDINT_H */ 142 143 #ifndef INT_FAST64_MAX 144 /* Pre-C99 GCC compilers define __LONG_LONG_MAX__ instead of LLONG_MAX. */ 145 #if defined LLONG_MAX || defined __LONG_LONG_MAX__ 146 typedef long long int_fast64_t; 147 #else /* ! (defined LLONG_MAX || defined __LONG_LONG_MAX__) */ 148 #if (LONG_MAX >> 31) < 0xffffffff 149 Please use a compiler that supports a 64-bit integer type (or wider); 150 you may need to compile with "-DHAVE_STDINT_H". 151 #endif /* (LONG_MAX >> 31) < 0xffffffff */ 152 typedef long int_fast64_t; 153 #endif /* ! (defined LLONG_MAX || defined __LONG_LONG_MAX__) */ 154 #endif /* !defined INT_FAST64_MAX */ 155 156 #ifndef INT32_MAX 157 #define INT32_MAX 0x7fffffff 158 #endif /* !defined INT32_MAX */ 159 #ifndef INT32_MIN 160 #define INT32_MIN (-1 - INT32_MAX) 161 #endif /* !defined INT32_MIN */ 162 163 /* 164 ** Workarounds for compilers/systems. 165 */ 166 167 /* 168 ** If your compiler lacks prototypes, "#define P(x) ()". 169 */ 170 171 #ifndef P 172 #define P(x) x 173 #endif /* !defined P */ 174 175 /* 176 ** SunOS 4.1.1 headers lack EXIT_SUCCESS. 177 */ 178 179 #ifndef EXIT_SUCCESS 180 #define EXIT_SUCCESS 0 181 #endif /* !defined EXIT_SUCCESS */ 182 183 /* 184 ** SunOS 4.1.1 headers lack EXIT_FAILURE. 185 */ 186 187 #ifndef EXIT_FAILURE 188 #define EXIT_FAILURE 1 189 #endif /* !defined EXIT_FAILURE */ 190 191 /* 192 ** SunOS 4.1.1 headers lack FILENAME_MAX. 193 */ 194 195 #ifndef FILENAME_MAX 196 197 #ifndef MAXPATHLEN 198 #ifdef unix 199 #include "sys/param.h" 200 #endif /* defined unix */ 201 #endif /* !defined MAXPATHLEN */ 202 203 #ifdef MAXPATHLEN 204 #define FILENAME_MAX MAXPATHLEN 205 #endif /* defined MAXPATHLEN */ 206 #ifndef MAXPATHLEN 207 #define FILENAME_MAX 1024 /* Pure guesswork */ 208 #endif /* !defined MAXPATHLEN */ 209 210 #endif /* !defined FILENAME_MAX */ 211 212 /* 213 ** SunOS 4.1.1 libraries lack remove. 214 */ 215 216 #ifndef remove 217 extern int unlink P((const char * filename)); 218 #define remove unlink 219 #endif /* !defined remove */ 220 221 /* 222 ** Some ancient errno.h implementations don't declare errno. 223 ** But some newer errno.h implementations define it as a macro. 224 ** Fix the former without affecting the latter. 225 */ 226 227 #ifndef errno 228 extern int errno; 229 #endif /* !defined errno */ 230 231 /* 232 ** Some time.h implementations don't declare asctime_r. 233 ** Others might define it as a macro. 234 ** Fix the former without affecting the latter. 235 */ 236 237 #ifndef asctime_r 238 extern char * asctime_r(); 239 #endif 240 241 /* 242 ** Private function declarations. 243 */ 244 245 char * icalloc P((int nelem, int elsize)); 246 char * icatalloc P((char * old, const char * new)); 247 char * icpyalloc P((const char * string)); 248 char * imalloc P((int n)); 249 void * irealloc P((void * pointer, int size)); 250 void icfree P((char * pointer)); 251 void ifree P((char * pointer)); 252 const char * scheck P((const char * string, const char * format)); 253 254 /* 255 ** Finally, some convenience items. 256 */ 257 258 #ifndef TRUE 259 #define TRUE 1 260 #endif /* !defined TRUE */ 261 262 #ifndef FALSE 263 #define FALSE 0 264 #endif /* !defined FALSE */ 265 266 #ifndef TYPE_BIT 267 #define TYPE_BIT(type) (sizeof (type) * CHAR_BIT) 268 #endif /* !defined TYPE_BIT */ 269 270 #ifndef TYPE_SIGNED 271 #define TYPE_SIGNED(type) (((type) -1) < 0) 272 #endif /* !defined TYPE_SIGNED */ 273 274 /* 275 ** Since the definition of TYPE_INTEGRAL contains floating point numbers, 276 ** it cannot be used in preprocessor directives. 277 */ 278 279 #ifndef TYPE_INTEGRAL 280 #define TYPE_INTEGRAL(type) (((type) 0.5) != 0.5) 281 #endif /* !defined TYPE_INTEGRAL */ 282 283 #ifndef INT_STRLEN_MAXIMUM 284 /* 285 ** 302 / 1000 is log10(2.0) rounded up. 286 ** Subtract one for the sign bit if the type is signed; 287 ** add one for integer division truncation; 288 ** add one more for a minus sign if the type is signed. 289 */ 290 #define INT_STRLEN_MAXIMUM(type) \ 291 ((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + \ 292 1 + TYPE_SIGNED(type)) 293 #endif /* !defined INT_STRLEN_MAXIMUM */ 294 295 /* 296 ** INITIALIZE(x) 297 */ 298 299 #ifndef GNUC_or_lint 300 #ifdef lint 301 #define GNUC_or_lint 302 #endif /* defined lint */ 303 #ifndef lint 304 #ifdef __GNUC__ 305 #define GNUC_or_lint 306 #endif /* defined __GNUC__ */ 307 #endif /* !defined lint */ 308 #endif /* !defined GNUC_or_lint */ 309 310 #ifndef INITIALIZE 311 #ifdef GNUC_or_lint 312 #define INITIALIZE(x) ((x) = 0) 313 #endif /* defined GNUC_or_lint */ 314 #ifndef GNUC_or_lint 315 #define INITIALIZE(x) 316 #endif /* !defined GNUC_or_lint */ 317 #endif /* !defined INITIALIZE */ 318 319 /* 320 ** For the benefit of GNU folk... 321 ** `_(MSGID)' uses the current locale's message library string for MSGID. 322 ** The default is to use gettext if available, and use MSGID otherwise. 323 */ 324 325 #ifndef _ 326 #if HAVE_GETTEXT 327 #define _(msgid) gettext(msgid) 328 #else /* !HAVE_GETTEXT */ 329 #define _(msgid) msgid 330 #endif /* !HAVE_GETTEXT */ 331 #endif /* !defined _ */ 332 333 #ifndef TZ_DOMAIN 334 #define TZ_DOMAIN "tz" 335 #endif /* !defined TZ_DOMAIN */ 336 337 #if HAVE_INCOMPATIBLE_CTIME_R 338 #undef asctime_r 339 #undef ctime_r 340 char *asctime_r P((struct tm const *, char *)); 341 char *ctime_r P((time_t const *, char *)); 342 #endif /* HAVE_INCOMPATIBLE_CTIME_R */ 343 344 #ifndef YEARSPERREPEAT 345 #define YEARSPERREPEAT 400 /* years before a Gregorian repeat */ 346 #endif /* !defined YEARSPERREPEAT */ 347 348 /* 349 ** The Gregorian year averages 365.2425 days, which is 31556952 seconds. 350 */ 351 352 #ifndef AVGSECSPERYEAR 353 #define AVGSECSPERYEAR 31556952L 354 #endif /* !defined AVGSECSPERYEAR */ 355 356 #ifndef SECSPERREPEAT 357 #define SECSPERREPEAT ((int_fast64_t) YEARSPERREPEAT * (int_fast64_t) AVGSECSPERYEAR) 358 #endif /* !defined SECSPERREPEAT */ 359 360 #ifndef SECSPERREPEAT_BITS 361 #define SECSPERREPEAT_BITS 34 /* ceil(log2(SECSPERREPEAT)) */ 362 #endif /* !defined SECSPERREPEAT_BITS */ 363 364 /* 365 ** UNIX was a registered trademark of The Open Group in 2003. 366 */ 367 368 #endif /* !defined PRIVATE_H */ 369