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