Home | History | Annotate | Line # | Download | only in time
private.h revision 1.26
      1 /*	$NetBSD: private.h,v 1.26 2012/08/09 12:38:25 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 /*
    160 ** Workarounds for compilers/systems.
    161 */
    162 
    163 /*
    164 ** Some time.h implementations don't declare asctime_r.
    165 ** Others might define it as a macro.
    166 ** Fix the former without affecting the latter.
    167 */
    168 
    169 #ifndef asctime_r
    170 extern char *	asctime_r(struct tm const *, char *);
    171 #endif
    172 
    173 /*
    174 ** Private function declarations.
    175 */
    176 
    177 char *		icalloc(int nelem, int elsize);
    178 char *		icatalloc(char * old, const char * new);
    179 char *		icpyalloc(const char * string);
    180 char *		imalloc(int n);
    181 void *		irealloc(void * pointer, int size);
    182 void		icfree(char * pointer);
    183 void		ifree(char * pointer);
    184 const char *	scheck(const char * string, const char * format);
    185 
    186 /*
    187 ** Finally, some convenience items.
    188 */
    189 
    190 #ifndef TRUE
    191 #define TRUE	1
    192 #endif /* !defined TRUE */
    193 
    194 #ifndef FALSE
    195 #define FALSE	0
    196 #endif /* !defined FALSE */
    197 
    198 #ifndef TYPE_BIT
    199 #define TYPE_BIT(type)	(sizeof (type) * CHAR_BIT)
    200 #endif /* !defined TYPE_BIT */
    201 
    202 #ifndef TYPE_SIGNED
    203 #define TYPE_SIGNED(type) (((type) -1) < 0)
    204 #endif /* !defined TYPE_SIGNED */
    205 
    206 /*
    207 ** Since the definition of TYPE_INTEGRAL contains floating point numbers,
    208 ** it cannot be used in preprocessor directives.
    209 */
    210 
    211 #ifndef TYPE_INTEGRAL
    212 #define TYPE_INTEGRAL(type) (((type) 0.5) != 0.5)
    213 #endif /* !defined TYPE_INTEGRAL */
    214 
    215 #ifndef INT_STRLEN_MAXIMUM
    216 /*
    217 ** 302 / 1000 is log10(2.0) rounded up.
    218 ** Subtract one for the sign bit if the type is signed;
    219 ** add one for integer division truncation;
    220 ** add one more for a minus sign if the type is signed.
    221 */
    222 #define INT_STRLEN_MAXIMUM(type) \
    223 	((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + \
    224 	1 + TYPE_SIGNED(type))
    225 #endif /* !defined INT_STRLEN_MAXIMUM */
    226 
    227 /*
    228 ** INITIALIZE(x)
    229 */
    230 
    231 #ifndef GNUC_or_lint
    232 #ifdef lint
    233 #define GNUC_or_lint
    234 #endif /* defined lint */
    235 #ifndef lint
    236 #ifdef __GNUC__
    237 #define GNUC_or_lint
    238 #endif /* defined __GNUC__ */
    239 #endif /* !defined lint */
    240 #endif /* !defined GNUC_or_lint */
    241 
    242 #ifndef INITIALIZE
    243 #ifdef GNUC_or_lint
    244 #define INITIALIZE(x)	((x) = 0)
    245 #endif /* defined GNUC_or_lint */
    246 #ifndef GNUC_or_lint
    247 #define INITIALIZE(x)
    248 #endif /* !defined GNUC_or_lint */
    249 #endif /* !defined INITIALIZE */
    250 
    251 /*
    252 ** For the benefit of GNU folk...
    253 ** `_(MSGID)' uses the current locale's message library string for MSGID.
    254 ** The default is to use gettext if available, and use MSGID otherwise.
    255 */
    256 
    257 #ifndef _
    258 #if HAVE_GETTEXT
    259 #define _(msgid) gettext(msgid)
    260 #else /* !HAVE_GETTEXT */
    261 #define _(msgid) msgid
    262 #endif /* !HAVE_GETTEXT */
    263 #endif /* !defined _ */
    264 
    265 #ifndef TZ_DOMAIN
    266 #define TZ_DOMAIN "tz"
    267 #endif /* !defined TZ_DOMAIN */
    268 
    269 #if HAVE_INCOMPATIBLE_CTIME_R
    270 #undef asctime_r
    271 #undef ctime_r
    272 char *asctime_r(struct tm const *, char *);
    273 char *ctime_r(time_t const *, char *);
    274 #endif /* HAVE_INCOMPATIBLE_CTIME_R */
    275 
    276 #ifndef YEARSPERREPEAT
    277 #define YEARSPERREPEAT		400	/* years before a Gregorian repeat */
    278 #endif /* !defined YEARSPERREPEAT */
    279 
    280 /*
    281 ** The Gregorian year averages 365.2425 days, which is 31556952 seconds.
    282 */
    283 
    284 #ifndef AVGSECSPERYEAR
    285 #define AVGSECSPERYEAR		31556952L
    286 #endif /* !defined AVGSECSPERYEAR */
    287 
    288 #ifndef SECSPERREPEAT
    289 #define SECSPERREPEAT		((int_fast64_t) YEARSPERREPEAT * (int_fast64_t) AVGSECSPERYEAR)
    290 #endif /* !defined SECSPERREPEAT */
    291 
    292 #ifndef SECSPERREPEAT_BITS
    293 #define SECSPERREPEAT_BITS	34	/* ceil(log2(SECSPERREPEAT)) */
    294 #endif /* !defined SECSPERREPEAT_BITS */
    295 
    296 /*
    297 ** UNIX was a registered trademark of The Open Group in 2003.
    298 */
    299 
    300 #endif /* !defined PRIVATE_H */
    301