Back to index

glibc  2.9
private.h
Go to the documentation of this file.
00001 #ifndef PRIVATE_H
00002 
00003 #define PRIVATE_H
00004 
00005 /*
00006 ** This file is in the public domain, so clarified as of
00007 ** 1996-06-05 by Arthur David Olson.
00008 */
00009 
00010 /*
00011 ** This header is for use ONLY with the time conversion code.
00012 ** There is no guarantee that it will remain unchanged,
00013 ** or that it will remain at all.
00014 ** Do NOT copy it to any system include directory.
00015 ** Thank you!
00016 */
00017 
00018 /*
00019 ** ID
00020 */
00021 
00022 #ifndef lint
00023 #ifndef NOID
00024 static char   privatehid[] = "@(#)private.h      8.6";
00025 #endif /* !defined NOID */
00026 #endif /* !defined lint */
00027 
00028 #define GRANDPARENTED       "Local time zone must be set--see zic manual page"
00029 
00030 /*
00031 ** Defaults for preprocessor symbols.
00032 ** You can override these in your C compiler options, e.g. `-DHAVE_ADJTIME=0'.
00033 */
00034 
00035 #ifndef HAVE_ADJTIME
00036 #define HAVE_ADJTIME        1
00037 #endif /* !defined HAVE_ADJTIME */
00038 
00039 #ifndef HAVE_GETTEXT
00040 #define HAVE_GETTEXT        0
00041 #endif /* !defined HAVE_GETTEXT */
00042 
00043 #ifndef HAVE_INCOMPATIBLE_CTIME_R
00044 #define HAVE_INCOMPATIBLE_CTIME_R  0
00045 #endif /* !defined INCOMPATIBLE_CTIME_R */
00046 
00047 #ifndef HAVE_SETTIMEOFDAY
00048 #define HAVE_SETTIMEOFDAY   3
00049 #endif /* !defined HAVE_SETTIMEOFDAY */
00050 
00051 #ifndef HAVE_SYMLINK
00052 #define HAVE_SYMLINK        1
00053 #endif /* !defined HAVE_SYMLINK */
00054 
00055 #ifndef HAVE_SYS_STAT_H
00056 #define HAVE_SYS_STAT_H            1
00057 #endif /* !defined HAVE_SYS_STAT_H */
00058 
00059 #ifndef HAVE_SYS_WAIT_H
00060 #define HAVE_SYS_WAIT_H            1
00061 #endif /* !defined HAVE_SYS_WAIT_H */
00062 
00063 #ifndef HAVE_UNISTD_H
00064 #define HAVE_UNISTD_H              1
00065 #endif /* !defined HAVE_UNISTD_H */
00066 
00067 #ifndef HAVE_UTMPX_H
00068 #define HAVE_UTMPX_H        0
00069 #endif /* !defined HAVE_UTMPX_H */
00070 
00071 #ifndef LOCALE_HOME
00072 #define LOCALE_HOME         "/usr/lib/locale"
00073 #endif /* !defined LOCALE_HOME */
00074 
00075 #if HAVE_INCOMPATIBLE_CTIME_R
00076 #define asctime_r _incompatible_asctime_r
00077 #define ctime_r _incompatible_ctime_r
00078 #endif /* HAVE_INCOMPATIBLE_CTIME_R */
00079 
00080 /*
00081 ** Nested includes
00082 */
00083 
00084 #include "sys/types.h"      /* for time_t */
00085 #include "stdio.h"
00086 #include "errno.h"
00087 #include "string.h"
00088 #include "limits.h"  /* for CHAR_BIT et al. */
00089 #include "time.h"
00090 #include "stdlib.h"
00091 
00092 #if HAVE_GETTEXT
00093 #include "libintl.h"
00094 #endif /* HAVE_GETTEXT */
00095 
00096 #if HAVE_SYS_WAIT_H
00097 #include <sys/wait.h>       /* for WIFEXITED and WEXITSTATUS */
00098 #endif /* HAVE_SYS_WAIT_H */
00099 
00100 #ifndef WIFEXITED
00101 #define WIFEXITED(status)   (((status) & 0xff) == 0)
00102 #endif /* !defined WIFEXITED */
00103 #ifndef WEXITSTATUS
00104 #define WEXITSTATUS(status) (((status) >> 8) & 0xff)
00105 #endif /* !defined WEXITSTATUS */
00106 
00107 #if HAVE_UNISTD_H
00108 #include "unistd.h"  /* for F_OK, R_OK, and other POSIX goodness */
00109 #endif /* HAVE_UNISTD_H */
00110 
00111 #ifndef F_OK
00112 #define F_OK  0
00113 #endif /* !defined F_OK */
00114 #ifndef R_OK
00115 #define R_OK  4
00116 #endif /* !defined R_OK */
00117 
00118 /* Unlike <ctype.h>'s isdigit, this also works if c < 0 | c > UCHAR_MAX. */
00119 #define is_digit(c) ((unsigned)(c) - '0' <= 9)
00120 
00121 /*
00122 ** Define HAVE_STDINT_H's default value here, rather than at the
00123 ** start, since __GLIBC__'s value depends on previously-included
00124 ** files.
00125 ** (glibc 2.1 and later have stdint.h, even with pre-C99 compilers.)
00126 */
00127 #ifndef HAVE_STDINT_H
00128 #define HAVE_STDINT_H \
00129        (199901 <= __STDC_VERSION__ || \
00130        2 < (__GLIBC__ + (0 < __GLIBC_MINOR__)))
00131 #endif /* !defined HAVE_STDINT_H */
00132 
00133 #if HAVE_STDINT_H
00134 #include "stdint.h"
00135 #endif /* !HAVE_STDINT_H */
00136 
00137 #ifndef INT_FAST64_MAX
00138 /* Pre-C99 GCC compilers define __LONG_LONG_MAX__ instead of LLONG_MAX.  */
00139 #if defined LLONG_MAX || defined __LONG_LONG_MAX__
00140 typedef long long    int_fast64_t;
00141 #else /* ! (defined LLONG_MAX || defined __LONG_LONG_MAX__) */
00142 #if (LONG_MAX >> 31) < 0xffffffff
00143 Please use a compiler that supports a 64-bit integer type (or wider);
00144 you may need to compile with "-DHAVE_STDINT_H".
00145 #endif /* (LONG_MAX >> 31) < 0xffffffff */
00146 typedef long         int_fast64_t;
00147 #endif /* ! (defined LLONG_MAX || defined __LONG_LONG_MAX__) */
00148 #endif /* !defined INT_FAST64_MAX */
00149 
00150 #ifndef INT32_MAX
00151 #define INT32_MAX 0x7fffffff
00152 #endif /* !defined INT32_MAX */
00153 #ifndef INT32_MIN
00154 #define INT32_MIN (-1 - INT32_MAX)
00155 #endif /* !defined INT32_MIN */
00156 
00157 /*
00158 ** Workarounds for compilers/systems.
00159 */
00160 
00161 /*
00162 ** Some time.h implementations don't declare asctime_r.
00163 ** Others might define it as a macro.
00164 ** Fix the former without affecting the latter.
00165 */
00166 
00167 #ifndef asctime_r
00168 extern char * asctime_r(struct tm const *, char *);
00169 #endif
00170 
00171 /*
00172 ** Private function declarations.
00173 */
00174 
00175 char *        icalloc(int nelem, int elsize);
00176 char *        icatalloc(char * old, const char * new);
00177 char *        icpyalloc(const char * string);
00178 char *        imalloc(int n);
00179 void *        irealloc(void * pointer, int size);
00180 void          icfree(char * pointer);
00181 void          ifree(char * pointer);
00182 const char *  scheck(const char * string, const char * format);
00183 
00184 /*
00185 ** Finally, some convenience items.
00186 */
00187 
00188 #ifndef TRUE
00189 #define TRUE  1
00190 #endif /* !defined TRUE */
00191 
00192 #ifndef FALSE
00193 #define FALSE 0
00194 #endif /* !defined FALSE */
00195 
00196 #ifndef TYPE_BIT
00197 #define TYPE_BIT(type)      (sizeof (type) * CHAR_BIT)
00198 #endif /* !defined TYPE_BIT */
00199 
00200 #ifndef TYPE_SIGNED
00201 #define TYPE_SIGNED(type) (((type) -1) < 0)
00202 #endif /* !defined TYPE_SIGNED */
00203 
00204 /*
00205 ** Since the definition of TYPE_INTEGRAL contains floating point numbers,
00206 ** it cannot be used in preprocessor directives.
00207 */
00208 
00209 #ifndef TYPE_INTEGRAL
00210 #define TYPE_INTEGRAL(type) (((type) 0.5) != 0.5)
00211 #endif /* !defined TYPE_INTEGRAL */
00212 
00213 #ifndef INT_STRLEN_MAXIMUM
00214 /*
00215 ** 302 / 1000 is log10(2.0) rounded up.
00216 ** Subtract one for the sign bit if the type is signed;
00217 ** add one for integer division truncation;
00218 ** add one more for a minus sign if the type is signed.
00219 */
00220 #define INT_STRLEN_MAXIMUM(type) \
00221        ((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + \
00222        1 + TYPE_SIGNED(type))
00223 #endif /* !defined INT_STRLEN_MAXIMUM */
00224 
00225 /*
00226 ** INITIALIZE(x)
00227 */
00228 
00229 #ifndef GNUC_or_lint
00230 #ifdef lint
00231 #define GNUC_or_lint
00232 #endif /* defined lint */
00233 #ifndef lint
00234 #ifdef __GNUC__
00235 #define GNUC_or_lint
00236 #endif /* defined __GNUC__ */
00237 #endif /* !defined lint */
00238 #endif /* !defined GNUC_or_lint */
00239 
00240 #ifndef INITIALIZE
00241 #ifdef GNUC_or_lint
00242 #define INITIALIZE(x)       ((x) = 0)
00243 #endif /* defined GNUC_or_lint */
00244 #ifndef GNUC_or_lint
00245 #define INITIALIZE(x)
00246 #endif /* !defined GNUC_or_lint */
00247 #endif /* !defined INITIALIZE */
00248 
00249 /*
00250 ** For the benefit of GNU folk...
00251 ** `_(MSGID)' uses the current locale's message library string for MSGID.
00252 ** The default is to use gettext if available, and use MSGID otherwise.
00253 */
00254 
00255 #ifndef _
00256 #if HAVE_GETTEXT
00257 #define _(msgid) gettext(msgid)
00258 #else /* !HAVE_GETTEXT */
00259 #define _(msgid) msgid
00260 #endif /* !HAVE_GETTEXT */
00261 #endif /* !defined _ */
00262 
00263 #ifndef TZ_DOMAIN
00264 #define TZ_DOMAIN "tz"
00265 #endif /* !defined TZ_DOMAIN */
00266 
00267 #if HAVE_INCOMPATIBLE_CTIME_R
00268 #undef asctime_r
00269 #undef ctime_r
00270 char *asctime_r(struct tm const *, char *);
00271 char *ctime_r(time_t const *, char *);
00272 #endif /* HAVE_INCOMPATIBLE_CTIME_R */
00273 
00274 #ifndef YEARSPERREPEAT
00275 #define YEARSPERREPEAT             400    /* years before a Gregorian repeat */
00276 #endif /* !defined YEARSPERREPEAT */
00277 
00278 /*
00279 ** The Gregorian year averages 365.2425 days, which is 31556952 seconds.
00280 */
00281 
00282 #ifndef AVGSECSPERYEAR
00283 #define AVGSECSPERYEAR             31556952L
00284 #endif /* !defined AVGSECSPERYEAR */
00285 
00286 #ifndef SECSPERREPEAT
00287 #define SECSPERREPEAT              ((int_fast64_t) YEARSPERREPEAT * (int_fast64_t) AVGSECSPERYEAR)
00288 #endif /* !defined SECSPERREPEAT */
00289 
00290 #ifndef SECSPERREPEAT_BITS
00291 #define SECSPERREPEAT_BITS  34     /* ceil(log2(SECSPERREPEAT)) */
00292 #endif /* !defined SECSPERREPEAT_BITS */
00293 
00294 /*
00295 ** UNIX was a registered trademark of The Open Group in 2003.
00296 */
00297 
00298 #endif /* !defined PRIVATE_H */