Home | History | Annotate | Line # | Download | only in time
private.h revision 1.24
      1 /*	$NetBSD: private.h,v 1.24 2003/12/20 00:12:05 kleink 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 (arthur_david_olson (at) nih.gov).
     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 /*
     31 ** ID
     32 */
     33 
     34 #ifndef lint
     35 #ifndef NOID
     36 #if 0
     37 static char	privatehid[] = "@(#)private.h	7.53";
     38 #endif
     39 #endif /* !defined NOID */
     40 #endif /* !defined lint */
     41 
     42 /*
     43 ** Defaults for preprocessor symbols.
     44 ** You can override these in your C compiler options, e.g. `-DHAVE_ADJTIME=0'.
     45 */
     46 
     47 #ifndef HAVE_ADJTIME
     48 #define HAVE_ADJTIME		1
     49 #endif /* !defined HAVE_ADJTIME */
     50 
     51 #ifndef HAVE_GETTEXT
     52 #define HAVE_GETTEXT		0
     53 #endif /* !defined HAVE_GETTEXT */
     54 
     55 #ifndef HAVE_INCOMPATIBLE_CTIME_R
     56 #define HAVE_INCOMPATIBLE_CTIME_R	0
     57 #endif /* !defined INCOMPATIBLE_CTIME_R */
     58 
     59 #ifndef HAVE_SETTIMEOFDAY
     60 #define HAVE_SETTIMEOFDAY	3
     61 #endif /* !defined HAVE_SETTIMEOFDAY */
     62 
     63 #ifndef HAVE_STRERROR
     64 #define HAVE_STRERROR		1
     65 #endif /* !defined HAVE_STRERROR */
     66 
     67 #ifndef HAVE_SYMLINK
     68 #define HAVE_SYMLINK		1
     69 #endif /* !defined HAVE_SYMLINK */
     70 
     71 #ifndef HAVE_SYS_STAT_H
     72 #define HAVE_SYS_STAT_H		1
     73 #endif /* !defined HAVE_SYS_STAT_H */
     74 
     75 #ifndef HAVE_SYS_WAIT_H
     76 #define HAVE_SYS_WAIT_H		1
     77 #endif /* !defined HAVE_SYS_WAIT_H */
     78 
     79 #ifndef HAVE_UNISTD_H
     80 #define HAVE_UNISTD_H		1
     81 #endif /* !defined HAVE_UNISTD_H */
     82 
     83 #ifndef HAVE_UTMPX_H
     84 #define HAVE_UTMPX_H		0
     85 #endif /* !defined HAVE_UTMPX_H */
     86 
     87 #ifdef LOCALE_HOME
     88 #undef LOCALE_HOME		/* not to be handled by tzcode itself */
     89 #endif /* defined LOCALE_HOME */
     90 
     91 #if HAVE_INCOMPATIBLE_CTIME_R
     92 #define asctime_r _incompatible_asctime_r
     93 #define ctime_r _incompatible_ctime_r
     94 #endif /* HAVE_INCOMPATIBLE_CTIME_R */
     95 
     96 /*
     97 ** Nested includes
     98 */
     99 
    100 #include "sys/types.h"	/* for time_t */
    101 #include "stdio.h"
    102 #include "errno.h"
    103 #include "string.h"
    104 #include "limits.h"	/* for CHAR_BIT */
    105 #include "time.h"
    106 #include "stdlib.h"
    107 
    108 #if HAVE_GETTEXT - 0
    109 #include "libintl.h"
    110 #endif /* HAVE_GETTEXT - 0 */
    111 
    112 #if HAVE_SYS_WAIT_H - 0
    113 #include <sys/wait.h>	/* for WIFEXITED and WEXITSTATUS */
    114 #endif /* HAVE_SYS_WAIT_H - 0 */
    115 
    116 #ifndef WIFEXITED
    117 #define WIFEXITED(status)	(((status) & 0xff) == 0)
    118 #endif /* !defined WIFEXITED */
    119 #ifndef WEXITSTATUS
    120 #define WEXITSTATUS(status)	(((status) >> 8) & 0xff)
    121 #endif /* !defined WEXITSTATUS */
    122 
    123 #if HAVE_UNISTD_H - 0
    124 #include "unistd.h"	/* for F_OK and R_OK */
    125 #endif /* HAVE_UNISTD_H - 0 */
    126 
    127 #if !(HAVE_UNISTD_H - 0)
    128 #ifndef F_OK
    129 #define F_OK	0
    130 #endif /* !defined F_OK */
    131 #ifndef R_OK
    132 #define R_OK	4
    133 #endif /* !defined R_OK */
    134 #endif /* !(HAVE_UNISTD_H - 0) */
    135 
    136 /* Unlike <ctype.h>'s isdigit, this also works if c < 0 | c > UCHAR_MAX.  */
    137 #define is_digit(c) ((unsigned)(c) - '0' <= 9)
    138 
    139 /*
    140 ** Workarounds for compilers/systems.
    141 */
    142 
    143 /*
    144 ** SunOS 4.1.1 cc lacks prototypes.
    145 */
    146 
    147 #ifndef P
    148 #define P(x)	x
    149 #endif /* !defined P */
    150 
    151 /*
    152 ** SunOS 4.1.1 headers lack EXIT_SUCCESS.
    153 */
    154 
    155 #ifndef EXIT_SUCCESS
    156 #define EXIT_SUCCESS	0
    157 #endif /* !defined EXIT_SUCCESS */
    158 
    159 /*
    160 ** SunOS 4.1.1 headers lack EXIT_FAILURE.
    161 */
    162 
    163 #ifndef EXIT_FAILURE
    164 #define EXIT_FAILURE	1
    165 #endif /* !defined EXIT_FAILURE */
    166 
    167 /*
    168 ** SunOS 4.1.1 headers lack FILENAME_MAX.
    169 */
    170 
    171 #ifndef FILENAME_MAX
    172 
    173 #ifndef MAXPATHLEN
    174 #ifdef unix
    175 #include "sys/param.h"
    176 #endif /* defined unix */
    177 #endif /* !defined MAXPATHLEN */
    178 
    179 #ifdef MAXPATHLEN
    180 #define FILENAME_MAX	MAXPATHLEN
    181 #endif /* defined MAXPATHLEN */
    182 #ifndef MAXPATHLEN
    183 #define FILENAME_MAX	1024		/* Pure guesswork */
    184 #endif /* !defined MAXPATHLEN */
    185 
    186 #endif /* !defined FILENAME_MAX */
    187 
    188 /*
    189 ** SunOS 4.1.1 libraries lack remove.
    190 */
    191 
    192 #ifndef __NetBSD__
    193 #ifndef remove
    194 extern int	unlink P((const char * filename));
    195 #define remove	unlink
    196 #endif /* !defined remove */
    197 #endif
    198 
    199 /*
    200 ** Some ancient errno.h implementations don't declare errno.
    201 ** But some newer errno.h implementations define it as a macro.
    202 ** Fix the former without affecting the latter.
    203 */
    204 #ifndef errno
    205 extern int errno;
    206 #endif /* !defined errno */
    207 
    208 /*
    209 ** Private function declarations.
    210 */
    211 char *	icalloc P((int nelem, int elsize));
    212 char *	icatalloc P((char * old, const char * new));
    213 char *	icpyalloc P((const char * string));
    214 char *	imalloc P((int n));
    215 void *	irealloc P((void * pointer, int size));
    216 void	icfree P((char * pointer));
    217 void	ifree P((char * pointer));
    218 char *	scheck P((const char *string, const char *format))
    219 	__attribute__((__format_arg__(2)));
    220 
    221 
    222 /*
    223 ** Finally, some convenience items.
    224 */
    225 
    226 #ifndef TRUE
    227 #define TRUE	1
    228 #endif /* !defined TRUE */
    229 
    230 #ifndef FALSE
    231 #define FALSE	0
    232 #endif /* !defined FALSE */
    233 
    234 #ifndef TYPE_BIT
    235 #define TYPE_BIT(type)	(sizeof (type) * CHAR_BIT)
    236 #endif /* !defined TYPE_BIT */
    237 
    238 #ifndef TYPE_SIGNED
    239 #define TYPE_SIGNED(type) (((type) -1) < 0)
    240 #endif /* !defined TYPE_SIGNED */
    241 
    242 #ifndef INT_STRLEN_MAXIMUM
    243 /*
    244 ** 302 / 1000 is log10(2.0) rounded up.
    245 ** Subtract one for the sign bit if the type is signed;
    246 ** add one for integer division truncation;
    247 ** add one more for a minus sign if the type is signed.
    248 */
    249 #define INT_STRLEN_MAXIMUM(type) \
    250     ((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + 1 + TYPE_SIGNED(type))
    251 #endif /* !defined INT_STRLEN_MAXIMUM */
    252 
    253 /*
    254 ** INITIALIZE(x)
    255 */
    256 
    257 #ifndef GNUC_or_lint
    258 #ifdef lint
    259 #define GNUC_or_lint
    260 #endif /* defined lint */
    261 #ifndef lint
    262 #ifdef __GNUC__
    263 #define GNUC_or_lint
    264 #endif /* defined __GNUC__ */
    265 #endif /* !defined lint */
    266 #endif /* !defined GNUC_or_lint */
    267 
    268 #ifndef INITIALIZE
    269 #ifdef GNUC_or_lint
    270 #define INITIALIZE(x)	((x) = 0)
    271 #endif /* defined GNUC_or_lint */
    272 #ifndef GNUC_or_lint
    273 #define INITIALIZE(x)
    274 #endif /* !defined GNUC_or_lint */
    275 #endif /* !defined INITIALIZE */
    276 
    277 /*
    278 ** For the benefit of GNU folk...
    279 ** `_(MSGID)' uses the current locale's message library string for MSGID.
    280 ** The default is to use gettext if available, and use MSGID otherwise.
    281 */
    282 
    283 #ifndef _
    284 #if HAVE_GETTEXT - 0
    285 #define _(msgid) gettext(msgid)
    286 #else /* !(HAVE_GETTEXT - 0) */
    287 #define _(msgid) msgid
    288 #endif /* !(HAVE_GETTEXT - 0) */
    289 #endif /* !defined _ */
    290 
    291 #ifndef TZ_DOMAIN
    292 #define TZ_DOMAIN "tz"
    293 #endif /* !defined TZ_DOMAIN */
    294 
    295 #if HAVE_INCOMPATIBLE_CTIME_R
    296 #undef asctime_r
    297 #undef ctime_r
    298 char *asctime_r P((struct tm const *, char *));
    299 char *ctime_r P((time_t const *, char *));
    300 #endif /* HAVE_INCOMPATIBLE_CTIME_R */
    301 
    302 /*
    303 ** UNIX was a registered trademark of The Open Group in 2003.
    304 */
    305 
    306 #endif /* !defined PRIVATE_H */
    307