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