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