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