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