00001
00002
00003
00004
00005
00006
00007
00008 #ifndef DEFINEH_H
00009 #define DEFINEH_H
00010
00011 #ifdef HAVE_CONFIG_H
00012 #include "config.h"
00013 #endif
00014
00015 #include "libpst.h"
00016 #include "timeconv.h"
00017 #include "libstrfunc.h"
00018 #include "vbuf.h"
00019
00020
00021 #ifdef HAVE_STRING_H
00022 #include <string.h>
00023 #endif
00024
00025 #ifdef HAVE_CTYPE_H
00026 #include <ctype.h>
00027 #endif
00028
00029 #ifdef HAVE_LIMITS_H
00030 #include <limits.h>
00031 #endif
00032
00033 #ifdef HAVE_WCHAR_H
00034 #include <wchar.h>
00035 #endif
00036
00037 #ifdef HAVE_SIGNAL_H
00038 #include <signal.h>
00039 #endif
00040
00041 #ifdef HAVE_ERRNO_H
00042 #include <errno.h>
00043 #endif
00044
00045 #ifdef HAVE_ICONV
00046 #include <iconv.h>
00047 #endif
00048
00049 #ifdef HAVE_REGEX_H
00050 #include <regex.h>
00051 #endif
00052
00053 #ifdef HAVE_GD_H
00054 #include <gd.h>
00055 #endif
00056
00057
00058 #define PERM_DIRS 0777
00059
00060 #ifdef _WIN32
00061 #include <direct.h>
00062
00063 #define D_MKDIR(x) mkdir(x)
00064 #define chdir _chdir
00065 #define strcasecmp _stricmp
00066 #define vsnprintf _vsnprintf
00067 #define snprintf _snprintf
00068 #ifdef _MSC_VER
00069 #define ftello _ftelli64
00070 #define fseeko _fseeki64
00071 #elif defined (__MINGW32__)
00072 #define ftello ftello64
00073 #define fseeko fseeko64
00074 #else
00075 #error Only MSC and mingw supported for Windows
00076 #endif
00077 #ifndef UINT64_MAX
00078 #define UINT64_MAX ((uint64_t)0xffffffffffffffff)
00079 #endif
00080 #ifndef PRIx64
00081 #define PRIx64 "I64x"
00082 #endif
00083 int __cdecl _fseeki64(FILE *, __int64, int);
00084 __int64 __cdecl _ftelli64(FILE *);
00085
00086 #ifdef __MINGW32__
00087 #include <getopt.h>
00088 #else
00089 #include "XGetopt.h"
00090 #endif
00091 #include <process.h>
00092 #undef gmtime_r
00093 #define gmtime_r(tp,tmp) (gmtime(tp)?(*(tmp)=*gmtime(tp),(tmp)):0)
00094 #define ctime_r(tp,tmp) (ctime(tp)?(strcpy((tmp),ctime((tp))),(tmp)):0)
00095 #else
00096 #ifdef __DJGPP__
00097 #define gmtime_r(tp,tmp) (gmtime(tp)?(*(tmp)=*gmtime(tp),(tmp)):0)
00098 #define ctime_r(tp,tmp) (ctime(tp)?(strcpy((tmp),ctime((tp))),(tmp)):0)
00099 #define fseeko(stream, offset, whence) fseek(stream, (long)offset, whence)
00100 #define ftello ftell
00101 #endif
00102 #ifdef HAVE_UNISTD_H
00103 #include <unistd.h>
00104 #else
00105 #include "XGetopt.h"
00106 #endif
00107 #define D_MKDIR(x) mkdir(x, PERM_DIRS)
00108 #endif
00109
00110 #ifdef HAVE_SYS_STAT_H
00111 #include <sys/stat.h>
00112 #endif
00113
00114 #ifdef HAVE_SYS_TYPES_H
00115 #include <sys/types.h>
00116 #endif
00117
00118 #ifdef HAVE_SYS_SHM_H
00119 #include <sys/shm.h>
00120 #endif
00121
00122 #ifdef HAVE_SYS_WAIT_H
00123 #include <sys/wait.h>
00124 #endif
00125
00126 #ifdef HAVE_DIRENT_H
00127 #include <dirent.h>
00128 #endif
00129
00130 #ifdef HAVE_SEMAPHORE_H
00131 #include <semaphore.h>
00132 #endif
00133
00134
00135 void pst_debug_lock();
00136 void pst_debug_unlock();
00137 void pst_debug_setlevel(int level);
00138 void pst_debug_init(const char* fname, void* output_mutex);
00139 void pst_debug_func(int level, const char* function);
00140 void pst_debug_func_ret(int level);
00141 void pst_debug(int level, int line, const char *file, const char *fmt, ...);
00142 void pst_debug_hexdump(int level, int line, const char *file, const char* buf, size_t size, int cols, int delta);
00143 void pst_debug_hexdumper(FILE* out, const char* buf, size_t size, int cols, int delta);
00144 void pst_debug_close();
00145 void* pst_malloc(size_t size);
00146 void *pst_realloc(void *ptr, size_t size);
00147
00148 #define MESSAGEPRINT1(...) pst_debug(1, __LINE__, __FILE__, __VA_ARGS__)
00149 #define MESSAGEPRINT2(...) pst_debug(2, __LINE__, __FILE__, __VA_ARGS__)
00150 #define MESSAGEPRINT3(...) pst_debug(3, __LINE__, __FILE__, __VA_ARGS__)
00151
00152 #define WARN(x) { \
00153 MESSAGEPRINT3 x; \
00154 pst_debug_lock(); \
00155 printf x; \
00156 fflush(stdout); \
00157 pst_debug_unlock(); \
00158 }
00159
00160 #define DIE(x) { \
00161 WARN(x); \
00162 exit(EXIT_FAILURE); \
00163 }
00164
00165 #define DEBUG_WARN(x) MESSAGEPRINT3 x
00166 #define DEBUG_INFO(x) MESSAGEPRINT2 x
00167 #define DEBUG_HEXDUMP(x, s) pst_debug_hexdump(1, __LINE__, __FILE__, (char*)x, s, 0x10, 0)
00168 #define DEBUG_HEXDUMPC(x, s, c) pst_debug_hexdump(1, __LINE__, __FILE__, (char*)x, s, c, 0)
00169
00170
00171 #define DEBUG_ENT(x) \
00172 { \
00173 pst_debug_func(1, x); \
00174 pst_debug(1, __LINE__, __FILE__, "Entering function\n"); \
00175 }
00176 #define DEBUG_RET() \
00177 { \
00178 pst_debug(1, __LINE__, __FILE__, "Leaving function\n"); \
00179 pst_debug_func_ret(1); \
00180 }
00181
00182 #define DEBUG_INIT(fname,mutex) {pst_debug_init(fname,mutex);}
00183 #define DEBUG_CLOSE() {pst_debug_close();}
00184 #define RET_DERROR(res, ret_val, x) if (res) { DIE(x);}
00185
00186
00187
00188 #if BYTE_ORDER == BIG_ENDIAN
00189 # define LE64_CPU(x) \
00190 x = ((((x) & UINT64_C(0xff00000000000000)) >> 56) | \
00191 (((x) & UINT64_C(0x00ff000000000000)) >> 40) | \
00192 (((x) & UINT64_C(0x0000ff0000000000)) >> 24) | \
00193 (((x) & UINT64_C(0x000000ff00000000)) >> 8 ) | \
00194 (((x) & UINT64_C(0x00000000ff000000)) << 8 ) | \
00195 (((x) & UINT64_C(0x0000000000ff0000)) << 24) | \
00196 (((x) & UINT64_C(0x000000000000ff00)) << 40) | \
00197 (((x) & UINT64_C(0x00000000000000ff)) << 56));
00198 # define LE32_CPU(x) \
00199 x = ((((x) & 0xff000000) >> 24) | \
00200 (((x) & 0x00ff0000) >> 8 ) | \
00201 (((x) & 0x0000ff00) << 8 ) | \
00202 (((x) & 0x000000ff) << 24));
00203 # define LE16_CPU(x) \
00204 x = ((((x) & 0xff00) >> 8) | \
00205 (((x) & 0x00ff) << 8));
00206 #elif BYTE_ORDER == LITTLE_ENDIAN
00207 # define LE64_CPU(x) {}
00208 # define LE32_CPU(x) {}
00209 # define LE16_CPU(x) {}
00210 #else
00211 # error "Byte order not supported by this library"
00212 #endif // BYTE_ORDER
00213
00214
00215 #define PST_LE_GET_UINT64(p) \
00216 (uint64_t)((((uint8_t const *)(p))[0] << 0) | \
00217 (((uint8_t const *)(p))[1] << 8) | \
00218 (((uint8_t const *)(p))[2] << 16) | \
00219 (((uint8_t const *)(p))[3] << 24) | \
00220 (((uint8_t const *)(p))[4] << 32) | \
00221 (((uint8_t const *)(p))[5] << 40) | \
00222 (((uint8_t const *)(p))[6] << 48) | \
00223 (((uint8_t const *)(p))[7] << 56))
00224
00225 #define PST_LE_GET_INT64(p) \
00226 (int64_t)((((uint8_t const *)(p))[0] << 0) | \
00227 (((uint8_t const *)(p))[1] << 8) | \
00228 (((uint8_t const *)(p))[2] << 16) | \
00229 (((uint8_t const *)(p))[3] << 24) | \
00230 (((uint8_t const *)(p))[4] << 32) | \
00231 (((uint8_t const *)(p))[5] << 40) | \
00232 (((uint8_t const *)(p))[6] << 48) | \
00233 (((uint8_t const *)(p))[7] << 56))
00234
00235 #define PST_LE_GET_UINT32(p) \
00236 (uint32_t)((((uint8_t const *)(p))[0] << 0) | \
00237 (((uint8_t const *)(p))[1] << 8) | \
00238 (((uint8_t const *)(p))[2] << 16) | \
00239 (((uint8_t const *)(p))[3] << 24))
00240
00241 #define PST_LE_GET_INT32(p) \
00242 (int32_t)((((uint8_t const *)(p))[0] << 0) | \
00243 (((uint8_t const *)(p))[1] << 8) | \
00244 (((uint8_t const *)(p))[2] << 16) | \
00245 (((uint8_t const *)(p))[3] << 24))
00246
00247 #define PST_LE_GET_UINT16(p) \
00248 (uint16_t)((((uint8_t const *)(p))[0] << 0) | \
00249 (((uint8_t const *)(p))[1] << 8))
00250
00251 #define PST_LE_GET_INT16(p) \
00252 (int16_t)((((uint8_t const *)(p))[0] << 0) | \
00253 (((uint8_t const *)(p))[1] << 8))
00254
00255 #define PST_LE_GET_UINT8(p) (*(uint8_t const *)(p))
00256
00257 #define PST_LE_GET_INT8(p) (*(int8_t const *)(p))
00258
00259 #define MAXDATEFMTLEN 40
00260
00261 #endif //DEFINEH_H