Home | History | Annotate | Download | only in tzcode
      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 #if HAVE_INCOMPATIBLE_CTIME_R
     76 #define asctime_r _incompatible_asctime_r
     77 #define ctime_r _incompatible_ctime_r
     78 #endif /* HAVE_INCOMPATIBLE_CTIME_R */
     79 
     80 /*
     81 ** Nested includes
     82 */
     83 
     84 #include "sys/types.h"  /* for time_t */
     85 #include "stdio.h"
     86 #include "errno.h"
     87 #include "string.h"
     88 #include "limits.h" /* for CHAR_BIT et al. */
     89 #include "time.h"
     90 #include "stdlib.h"
     91 
     92 #if HAVE_GETTEXT
     93 #include "libintl.h"
     94 #endif /* HAVE_GETTEXT */
     95 
     96 #if HAVE_SYS_WAIT_H
     97 #include <sys/wait.h>   /* for WIFEXITED and WEXITSTATUS */
     98 #endif /* HAVE_SYS_WAIT_H */
     99 
    100 #ifndef WIFEXITED
    101 #define WIFEXITED(status)   (((status) & 0xff) == 0)
    102 #endif /* !defined WIFEXITED */
    103 #ifndef WEXITSTATUS
    104 #define WEXITSTATUS(status) (((status) >> 8) & 0xff)
    105 #endif /* !defined WEXITSTATUS */
    106 
    107 #if HAVE_UNISTD_H
    108 #include "unistd.h" /* for F_OK and R_OK */
    109 #endif /* HAVE_UNISTD_H */
    110 
    111 #if !HAVE_UNISTD_H
    112 #ifndef F_OK
    113 #define F_OK    0
    114 #endif /* !defined F_OK */
    115 #ifndef R_OK
    116 #define R_OK    4
    117 #endif /* !defined R_OK */
    118 #endif /* !HAVE_UNISTD_H */
    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 /*
    160 ** Workarounds for compilers/systems.
    161 */
    162 
    163 /*
    164 ** If your compiler lacks prototypes, "#define P(x) ()".
    165 */
    166 
    167 #ifndef P
    168 #define P(x)    x
    169 #endif /* !defined P */
    170 
    171 /*
    172 ** SunOS 4.1.1 headers lack EXIT_SUCCESS.
    173 */
    174 
    175 #ifndef EXIT_SUCCESS
    176 #define EXIT_SUCCESS    0
    177 #endif /* !defined EXIT_SUCCESS */
    178 
    179 /*
    180 ** SunOS 4.1.1 headers lack EXIT_FAILURE.
    181 */
    182 
    183 #ifndef EXIT_FAILURE
    184 #define EXIT_FAILURE    1
    185 #endif /* !defined EXIT_FAILURE */
    186 
    187 /*
    188 ** SunOS 4.1.1 headers lack FILENAME_MAX.
    189 */
    190 
    191 #ifndef FILENAME_MAX
    192 
    193 #ifndef MAXPATHLEN
    194 #ifdef unix
    195 #include "sys/param.h"
    196 #endif /* defined unix */
    197 #endif /* !defined MAXPATHLEN */
    198 
    199 #ifdef MAXPATHLEN
    200 #define FILENAME_MAX    MAXPATHLEN
    201 #endif /* defined MAXPATHLEN */
    202 #ifndef MAXPATHLEN
    203 #define FILENAME_MAX    1024        /* Pure guesswork */
    204 #endif /* !defined MAXPATHLEN */
    205 
    206 #endif /* !defined FILENAME_MAX */
    207 
    208 /*
    209 ** SunOS 4.1.1 libraries lack remove.
    210 */
    211 
    212 #ifndef remove
    213 extern int  unlink P((const char * filename));
    214 #define remove  unlink
    215 #endif /* !defined remove */
    216 
    217 /*
    218 ** Some ancient errno.h implementations don't declare errno.
    219 ** But some newer errno.h implementations define it as a macro.
    220 ** Fix the former without affecting the latter.
    221 */
    222 
    223 #ifndef errno
    224 extern int errno;
    225 #endif /* !defined errno */
    226 
    227 /*
    228 ** Some time.h implementations don't declare asctime_r.
    229 ** Others might define it as a macro.
    230 ** Fix the former without affecting the latter.
    231 */
    232 
    233 #ifndef asctime_r
    234 extern char *   asctime_r();
    235 #endif
    236 
    237 /*
    238 ** Private function declarations.
    239 */
    240 
    241 char *      icalloc P((int nelem, int elsize));
    242 char *      icatalloc P((char * old, const char * new));
    243 char *      icpyalloc P((const char * string));
    244 char *      imalloc P((int n));
    245 void *      irealloc P((void * pointer, int size));
    246 void        icfree P((char * pointer));
    247 void        ifree P((char * pointer));
    248 const char *    scheck P((const char * string, const char * format));
    249 
    250 /*
    251 ** Finally, some convenience items.
    252 */
    253 
    254 #ifndef TRUE
    255 #define TRUE    1
    256 #endif /* !defined TRUE */
    257 
    258 #ifndef FALSE
    259 #define FALSE   0
    260 #endif /* !defined FALSE */
    261 
    262 #ifndef TYPE_BIT
    263 #define TYPE_BIT(type)  (sizeof (type) * CHAR_BIT)
    264 #endif /* !defined TYPE_BIT */
    265 
    266 #ifndef TYPE_SIGNED
    267 #define TYPE_SIGNED(type) (((type) -1) < 0)
    268 #endif /* !defined TYPE_SIGNED */
    269 
    270 /*
    271 ** Since the definition of TYPE_INTEGRAL contains floating point numbers,
    272 ** it cannot be used in preprocessor directives.
    273 */
    274 
    275 #ifndef TYPE_INTEGRAL
    276 #define TYPE_INTEGRAL(type) (((type) 0.5) != 0.5)
    277 #endif /* !defined TYPE_INTEGRAL */
    278 
    279 #ifndef INT_STRLEN_MAXIMUM
    280 /*
    281 ** 302 / 1000 is log10(2.0) rounded up.
    282 ** Subtract one for the sign bit if the type is signed;
    283 ** add one for integer division truncation;
    284 ** add one more for a minus sign if the type is signed.
    285 */
    286 #define INT_STRLEN_MAXIMUM(type) \
    287     ((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + \
    288     1 + TYPE_SIGNED(type))
    289 #endif /* !defined INT_STRLEN_MAXIMUM */
    290 
    291 /*
    292 ** INITIALIZE(x)
    293 */
    294 
    295 #ifndef GNUC_or_lint
    296 #ifdef lint
    297 #define GNUC_or_lint
    298 #endif /* defined lint */
    299 #ifndef lint
    300 #ifdef __GNUC__
    301 #define GNUC_or_lint
    302 #endif /* defined __GNUC__ */
    303 #endif /* !defined lint */
    304 #endif /* !defined GNUC_or_lint */
    305 
    306 #ifndef INITIALIZE
    307 #ifdef GNUC_or_lint
    308 #define INITIALIZE(x)   ((x) = 0)
    309 #endif /* defined GNUC_or_lint */
    310 #ifndef GNUC_or_lint
    311 #define INITIALIZE(x)
    312 #endif /* !defined GNUC_or_lint */
    313 #endif /* !defined INITIALIZE */
    314 
    315 /*
    316 ** For the benefit of GNU folk...
    317 ** `_(MSGID)' uses the current locale's message library string for MSGID.
    318 ** The default is to use gettext if available, and use MSGID otherwise.
    319 */
    320 
    321 #ifndef _
    322 #if HAVE_GETTEXT
    323 #define _(msgid) gettext(msgid)
    324 #else /* !HAVE_GETTEXT */
    325 #define _(msgid) msgid
    326 #endif /* !HAVE_GETTEXT */
    327 #endif /* !defined _ */
    328 
    329 #ifndef TZ_DOMAIN
    330 #define TZ_DOMAIN "tz"
    331 #endif /* !defined TZ_DOMAIN */
    332 
    333 #if HAVE_INCOMPATIBLE_CTIME_R
    334 #undef asctime_r
    335 #undef ctime_r
    336 char *asctime_r P((struct tm const *, char *));
    337 char *ctime_r P((time_t const *, char *));
    338 #endif /* HAVE_INCOMPATIBLE_CTIME_R */
    339 
    340 #ifndef YEARSPERREPEAT
    341 #define YEARSPERREPEAT      400 /* years before a Gregorian repeat */
    342 #endif /* !defined YEARSPERREPEAT */
    343 
    344 /*
    345 ** The Gregorian year averages 365.2425 days, which is 31556952 seconds.
    346 */
    347 
    348 #ifndef AVGSECSPERYEAR
    349 #define AVGSECSPERYEAR      31556952L
    350 #endif /* !defined AVGSECSPERYEAR */
    351 
    352 #ifndef SECSPERREPEAT
    353 #define SECSPERREPEAT       ((int_fast64_t) YEARSPERREPEAT * (int_fast64_t) AVGSECSPERYEAR)
    354 #endif /* !defined SECSPERREPEAT */
    355 
    356 #ifndef SECSPERREPEAT_BITS
    357 #define SECSPERREPEAT_BITS  34  /* ceil(log2(SECSPERREPEAT)) */
    358 #endif /* !defined SECSPERREPEAT_BITS */
    359 
    360 /*
    361 ** UNIX was a registered trademark of The Open Group in 2003.
    362 */
    363 
    364 #endif /* !defined PRIVATE_H */
    365