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