michael@0: #ifndef PRIVATE_H michael@0: michael@0: #define PRIVATE_H michael@0: michael@0: /* michael@0: ** This file is in the public domain, so clarified as of michael@0: ** 1996-06-05 by Arthur David Olson. michael@0: */ michael@0: michael@0: /* michael@0: ** This header is for use ONLY with the time conversion code. michael@0: ** There is no guarantee that it will remain unchanged, michael@0: ** or that it will remain at all. michael@0: ** Do NOT copy it to any system include directory. michael@0: ** Thank you! michael@0: */ michael@0: michael@0: /* michael@0: ** ID michael@0: */ michael@0: michael@0: #ifndef lint michael@0: #ifndef NOID michael@0: static char privatehid[] = "@(#)private.h 8.6"; michael@0: #endif /* !defined NOID */ michael@0: #endif /* !defined lint */ michael@0: michael@0: #define GRANDPARENTED "Local time zone must be set--see zic manual page" michael@0: michael@0: /* michael@0: ** Defaults for preprocessor symbols. michael@0: ** You can override these in your C compiler options, e.g. `-DHAVE_ADJTIME=0'. michael@0: */ michael@0: michael@0: #ifndef HAVE_ADJTIME michael@0: #define HAVE_ADJTIME 1 michael@0: #endif /* !defined HAVE_ADJTIME */ michael@0: michael@0: #ifndef HAVE_GETTEXT michael@0: #define HAVE_GETTEXT 0 michael@0: #endif /* !defined HAVE_GETTEXT */ michael@0: michael@0: #ifndef HAVE_INCOMPATIBLE_CTIME_R michael@0: #define HAVE_INCOMPATIBLE_CTIME_R 0 michael@0: #endif /* !defined INCOMPATIBLE_CTIME_R */ michael@0: michael@0: #ifndef HAVE_SETTIMEOFDAY michael@0: #define HAVE_SETTIMEOFDAY 3 michael@0: #endif /* !defined HAVE_SETTIMEOFDAY */ michael@0: michael@0: #ifndef HAVE_SYMLINK michael@0: #define HAVE_SYMLINK 1 michael@0: #endif /* !defined HAVE_SYMLINK */ michael@0: michael@0: #ifndef HAVE_SYS_STAT_H michael@0: #define HAVE_SYS_STAT_H 1 michael@0: #endif /* !defined HAVE_SYS_STAT_H */ michael@0: michael@0: #ifndef HAVE_SYS_WAIT_H michael@0: #define HAVE_SYS_WAIT_H 1 michael@0: #endif /* !defined HAVE_SYS_WAIT_H */ michael@0: michael@0: #ifndef HAVE_UNISTD_H michael@0: #define HAVE_UNISTD_H 1 michael@0: #endif /* !defined HAVE_UNISTD_H */ michael@0: michael@0: #ifndef HAVE_UTMPX_H michael@0: #define HAVE_UTMPX_H 0 michael@0: #endif /* !defined HAVE_UTMPX_H */ michael@0: michael@0: #ifndef LOCALE_HOME michael@0: #define LOCALE_HOME "/usr/lib/locale" michael@0: #endif /* !defined LOCALE_HOME */ michael@0: michael@0: #if HAVE_INCOMPATIBLE_CTIME_R michael@0: #define asctime_r _incompatible_asctime_r michael@0: #define ctime_r _incompatible_ctime_r michael@0: #endif /* HAVE_INCOMPATIBLE_CTIME_R */ michael@0: michael@0: /* michael@0: ** Nested includes michael@0: */ michael@0: michael@0: #include "sys/types.h" /* for time_t */ michael@0: #include "stdio.h" michael@0: #include "errno.h" michael@0: #include "string.h" michael@0: #include "limits.h" /* for CHAR_BIT et al. */ michael@0: #include "time.h" michael@0: #include "stdlib.h" michael@0: michael@0: #if HAVE_GETTEXT michael@0: #include "libintl.h" michael@0: #endif /* HAVE_GETTEXT */ michael@0: michael@0: #if HAVE_SYS_WAIT_H michael@0: #include /* for WIFEXITED and WEXITSTATUS */ michael@0: #endif /* HAVE_SYS_WAIT_H */ michael@0: michael@0: #ifndef WIFEXITED michael@0: #define WIFEXITED(status) (((status) & 0xff) == 0) michael@0: #endif /* !defined WIFEXITED */ michael@0: #ifndef WEXITSTATUS michael@0: #define WEXITSTATUS(status) (((status) >> 8) & 0xff) michael@0: #endif /* !defined WEXITSTATUS */ michael@0: michael@0: #if HAVE_UNISTD_H michael@0: #include "unistd.h" /* for F_OK, R_OK, and other POSIX goodness */ michael@0: #endif /* HAVE_UNISTD_H */ michael@0: michael@0: #ifndef F_OK michael@0: #define F_OK 0 michael@0: #endif /* !defined F_OK */ michael@0: #ifndef R_OK michael@0: #define R_OK 4 michael@0: #endif /* !defined R_OK */ michael@0: michael@0: /* Unlike 's isdigit, this also works if c < 0 | c > UCHAR_MAX. */ michael@0: #define is_digit(c) ((unsigned)(c) - '0' <= 9) michael@0: michael@0: /* michael@0: ** Define HAVE_STDINT_H's default value here, rather than at the michael@0: ** start, since __GLIBC__'s value depends on previously-included michael@0: ** files. michael@0: ** (glibc 2.1 and later have stdint.h, even with pre-C99 compilers.) michael@0: */ michael@0: #ifndef HAVE_STDINT_H michael@0: #define HAVE_STDINT_H \ michael@0: (199901 <= __STDC_VERSION__ || \ michael@0: 2 < (__GLIBC__ + (0 < __GLIBC_MINOR__))) michael@0: #endif /* !defined HAVE_STDINT_H */ michael@0: michael@0: #if HAVE_STDINT_H michael@0: #include "stdint.h" michael@0: #endif /* !HAVE_STDINT_H */ michael@0: michael@0: #ifndef INT_FAST64_MAX michael@0: /* Pre-C99 GCC compilers define __LONG_LONG_MAX__ instead of LLONG_MAX. */ michael@0: #if defined LLONG_MAX || defined __LONG_LONG_MAX__ michael@0: typedef long long int_fast64_t; michael@0: #else /* ! (defined LLONG_MAX || defined __LONG_LONG_MAX__) */ michael@0: #if (LONG_MAX >> 31) < 0xffffffff michael@0: Please use a compiler that supports a 64-bit integer type (or wider); michael@0: you may need to compile with "-DHAVE_STDINT_H". michael@0: #endif /* (LONG_MAX >> 31) < 0xffffffff */ michael@0: typedef long int_fast64_t; michael@0: #endif /* ! (defined LLONG_MAX || defined __LONG_LONG_MAX__) */ michael@0: #endif /* !defined INT_FAST64_MAX */ michael@0: michael@0: #ifndef INT32_MAX michael@0: #define INT32_MAX 0x7fffffff michael@0: #endif /* !defined INT32_MAX */ michael@0: #ifndef INT32_MIN michael@0: #define INT32_MIN (-1 - INT32_MAX) michael@0: #endif /* !defined INT32_MIN */ michael@0: michael@0: /* michael@0: ** Workarounds for compilers/systems. michael@0: */ michael@0: michael@0: /* michael@0: ** Some time.h implementations don't declare asctime_r. michael@0: ** Others might define it as a macro. michael@0: ** Fix the former without affecting the latter. michael@0: */ michael@0: michael@0: #ifndef asctime_r michael@0: extern char * asctime_r(struct tm const *, char *); michael@0: #endif michael@0: michael@0: /* michael@0: ** Private function declarations. michael@0: */ michael@0: michael@0: char * icalloc(int nelem, int elsize); michael@0: char * icatalloc(char * old, const char * new); michael@0: char * icpyalloc(const char * string); michael@0: char * imalloc(int n); michael@0: void * irealloc(void * pointer, int size); michael@0: void icfree(char * pointer); michael@0: void ifree(char * pointer); michael@0: const char * scheck(const char * string, const char * format); michael@0: michael@0: /* michael@0: ** Finally, some convenience items. michael@0: */ michael@0: michael@0: #ifndef TRUE michael@0: #define TRUE 1 michael@0: #endif /* !defined TRUE */ michael@0: michael@0: #ifndef FALSE michael@0: #define FALSE 0 michael@0: #endif /* !defined FALSE */ michael@0: michael@0: #ifndef TYPE_BIT michael@0: #define TYPE_BIT(type) (sizeof (type) * CHAR_BIT) michael@0: #endif /* !defined TYPE_BIT */ michael@0: michael@0: #ifndef TYPE_SIGNED michael@0: #define TYPE_SIGNED(type) (((type) -1) < 0) michael@0: #endif /* !defined TYPE_SIGNED */ michael@0: michael@0: /* michael@0: ** Since the definition of TYPE_INTEGRAL contains floating point numbers, michael@0: ** it cannot be used in preprocessor directives. michael@0: */ michael@0: michael@0: #ifndef TYPE_INTEGRAL michael@0: #define TYPE_INTEGRAL(type) (((type) 0.5) != 0.5) michael@0: #endif /* !defined TYPE_INTEGRAL */ michael@0: michael@0: #ifndef INT_STRLEN_MAXIMUM michael@0: /* michael@0: ** 302 / 1000 is log10(2.0) rounded up. michael@0: ** Subtract one for the sign bit if the type is signed; michael@0: ** add one for integer division truncation; michael@0: ** add one more for a minus sign if the type is signed. michael@0: */ michael@0: #define INT_STRLEN_MAXIMUM(type) \ michael@0: ((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + \ michael@0: 1 + TYPE_SIGNED(type)) michael@0: #endif /* !defined INT_STRLEN_MAXIMUM */ michael@0: michael@0: /* michael@0: ** INITIALIZE(x) michael@0: */ michael@0: michael@0: #ifndef GNUC_or_lint michael@0: #ifdef lint michael@0: #define GNUC_or_lint michael@0: #endif /* defined lint */ michael@0: #ifndef lint michael@0: #ifdef __GNUC__ michael@0: #define GNUC_or_lint michael@0: #endif /* defined __GNUC__ */ michael@0: #endif /* !defined lint */ michael@0: #endif /* !defined GNUC_or_lint */ michael@0: michael@0: #ifndef INITIALIZE michael@0: #ifdef GNUC_or_lint michael@0: #define INITIALIZE(x) ((x) = 0) michael@0: #endif /* defined GNUC_or_lint */ michael@0: #ifndef GNUC_or_lint michael@0: #define INITIALIZE(x) michael@0: #endif /* !defined GNUC_or_lint */ michael@0: #endif /* !defined INITIALIZE */ michael@0: michael@0: /* michael@0: ** For the benefit of GNU folk... michael@0: ** `_(MSGID)' uses the current locale's message library string for MSGID. michael@0: ** The default is to use gettext if available, and use MSGID otherwise. michael@0: */ michael@0: michael@0: #ifndef _ michael@0: #if HAVE_GETTEXT michael@0: #define _(msgid) gettext(msgid) michael@0: #else /* !HAVE_GETTEXT */ michael@0: #define _(msgid) msgid michael@0: #endif /* !HAVE_GETTEXT */ michael@0: #endif /* !defined _ */ michael@0: michael@0: #ifndef TZ_DOMAIN michael@0: #define TZ_DOMAIN "tz" michael@0: #endif /* !defined TZ_DOMAIN */ michael@0: michael@0: #if HAVE_INCOMPATIBLE_CTIME_R michael@0: #undef asctime_r michael@0: #undef ctime_r michael@0: char *asctime_r(struct tm const *, char *); michael@0: char *ctime_r(time_t const *, char *); michael@0: #endif /* HAVE_INCOMPATIBLE_CTIME_R */ michael@0: michael@0: #ifndef YEARSPERREPEAT michael@0: #define YEARSPERREPEAT 400 /* years before a Gregorian repeat */ michael@0: #endif /* !defined YEARSPERREPEAT */ michael@0: michael@0: /* michael@0: ** The Gregorian year averages 365.2425 days, which is 31556952 seconds. michael@0: */ michael@0: michael@0: #ifndef AVGSECSPERYEAR michael@0: #define AVGSECSPERYEAR 31556952L michael@0: #endif /* !defined AVGSECSPERYEAR */ michael@0: michael@0: #ifndef SECSPERREPEAT michael@0: #define SECSPERREPEAT ((int_fast64_t) YEARSPERREPEAT * (int_fast64_t) AVGSECSPERYEAR) michael@0: #endif /* !defined SECSPERREPEAT */ michael@0: michael@0: #ifndef SECSPERREPEAT_BITS michael@0: #define SECSPERREPEAT_BITS 34 /* ceil(log2(SECSPERREPEAT)) */ michael@0: #endif /* !defined SECSPERREPEAT_BITS */ michael@0: michael@0: /* michael@0: ** UNIX was a registered trademark of The Open Group in 2003. michael@0: */ michael@0: michael@0: #endif /* !defined PRIVATE_H */