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 __MINGW32__
00078 #define size_t __int64
00079 #endif
00080 #ifndef UINT64_MAX
00081 #define UINT64_MAX ((uint64_t)0xffffffffffffffff)
00082 #endif
00083 #define PRIx64 "I64x"
00084 int __cdecl _fseeki64(FILE *, __int64, int);
00085 __int64 __cdecl _ftelli64(FILE *);
00086
00087 #ifdef __MINGW32__
00088 #include <getopt.h>
00089 #else
00090 #include "XGetopt.h"
00091 #endif
00092 #include <process.h>
00093 #undef gmtime_r
00094 #define gmtime_r(tp,tmp) (gmtime(tp)?(*(tmp)=*gmtime(tp),(tmp)):0)
00095 #define ctime_r(tp,tmp) (ctime(tp)?(strcpy((tmp),ctime((tp))),(tmp)):0)
00096 #else
00097 #ifdef HAVE_UNISTD_H
00098 #include <unistd.h>
00099 #else
00100 #include "XGetopt.h"
00101 #endif
00102 #define D_MKDIR(x) mkdir(x, PERM_DIRS)
00103 #endif
00104
00105 #ifdef HAVE_SYS_STAT_H
00106 #include <sys/stat.h>
00107 #endif
00108
00109 #ifdef HAVE_SYS_TYPES_H
00110 #include <sys/types.h>
00111 #endif
00112
00113 #ifdef HAVE_SYS_SHM_H
00114 #include <sys/shm.h>
00115 #endif
00116
00117 #ifdef HAVE_SYS_WAIT_H
00118 #include <sys/wait.h>
00119 #endif
00120
00121 #ifdef HAVE_DIRENT_H
00122 #include <dirent.h>
00123 #endif
00124
00125 #ifdef HAVE_SEMAPHORE_H
00126 #include <semaphore.h>
00127 #endif
00128
00129
00130 void pst_debug_lock();
00131 void pst_debug_unlock();
00132 void pst_debug_init(const char* fname, void* output_mutex);
00133 void pst_debug_func(const char* function);
00134 void pst_debug_func_ret();
00135 void pst_debug(int line, const char *file, const char *fmt, ...);
00136 void pst_debug_hexdump(int line, const char *file, const char* buf, size_t size, int cols, int delta);
00137 void pst_debug_hexdumper(FILE* out, const char* buf, size_t size, int cols, int delta);
00138 void pst_debug_close(void);
00139 void* pst_malloc(size_t size);
00140
00141 #define MESSAGEPRINT(...) pst_debug(__LINE__, __FILE__, __VA_ARGS__)
00142
00143 #define WARN(x) { \
00144 MESSAGEPRINT x; \
00145 pst_debug_lock(); \
00146 printf x; \
00147 fflush(stdout); \
00148 pst_debug_unlock(); \
00149 }
00150
00151 #define DIE(x) { \
00152 WARN(x); \
00153 exit(EXIT_FAILURE); \
00154 }
00155
00156 #define DEBUG_WARN(x) MESSAGEPRINT x
00157 #define DEBUG_INFO(x) MESSAGEPRINT x
00158 #define DEBUG_HEXDUMP(x, s) pst_debug_hexdump(__LINE__, __FILE__, (char*)x, s, 0x10, 0)
00159 #define DEBUG_HEXDUMPC(x, s, c) pst_debug_hexdump(__LINE__, __FILE__, (char*)x, s, c, 0)
00160
00161
00162 # define DEBUG_ENT(x) \
00163 { \
00164 pst_debug_func(x); \
00165 pst_debug(__LINE__, __FILE__, "Entering function\n"); \
00166 }
00167 # define DEBUG_RET() \
00168 { \
00169 pst_debug(__LINE__, __FILE__, "Leaving function\n"); \
00170 pst_debug_func_ret(); \
00171 }
00172
00173 #define DEBUG_INIT(fname,mutex) {pst_debug_init(fname,mutex);}
00174 #define DEBUG_CLOSE() {pst_debug_close();}
00175 #define RET_DERROR(res, ret_val, x) if (res) { DIE(x);}
00176
00177
00178
00179 #if BYTE_ORDER == BIG_ENDIAN
00180 # define LE64_CPU(x) \
00181 x = ((((x) & UINT64_C(0xff00000000000000)) >> 56) | \
00182 (((x) & UINT64_C(0x00ff000000000000)) >> 40) | \
00183 (((x) & UINT64_C(0x0000ff0000000000)) >> 24) | \
00184 (((x) & UINT64_C(0x000000ff00000000)) >> 8 ) | \
00185 (((x) & UINT64_C(0x00000000ff000000)) << 8 ) | \
00186 (((x) & UINT64_C(0x0000000000ff0000)) << 24) | \
00187 (((x) & UINT64_C(0x000000000000ff00)) << 40) | \
00188 (((x) & UINT64_C(0x00000000000000ff)) << 56));
00189 # define LE32_CPU(x) \
00190 x = ((((x) & 0xff000000) >> 24) | \
00191 (((x) & 0x00ff0000) >> 8 ) | \
00192 (((x) & 0x0000ff00) << 8 ) | \
00193 (((x) & 0x000000ff) << 24));
00194 # define LE16_CPU(x) \
00195 x = ((((x) & 0xff00) >> 8) | \
00196 (((x) & 0x00ff) << 8));
00197 #elif BYTE_ORDER == LITTLE_ENDIAN
00198 # define LE64_CPU(x) {}
00199 # define LE32_CPU(x) {}
00200 # define LE16_CPU(x) {}
00201 #else
00202 # error "Byte order not supported by this library"
00203 #endif // BYTE_ORDER
00204
00205
00206 #define PST_LE_GET_UINT64(p) \
00207 (uint64_t)((((uint8_t const *)(p))[0] << 0) | \
00208 (((uint8_t const *)(p))[1] << 8) | \
00209 (((uint8_t const *)(p))[2] << 16) | \
00210 (((uint8_t const *)(p))[3] << 24) | \
00211 (((uint8_t const *)(p))[4] << 32) | \
00212 (((uint8_t const *)(p))[5] << 40) | \
00213 (((uint8_t const *)(p))[6] << 48) | \
00214 (((uint8_t const *)(p))[7] << 56))
00215
00216 #define PST_LE_GET_INT64(p) \
00217 (int64_t)((((uint8_t const *)(p))[0] << 0) | \
00218 (((uint8_t const *)(p))[1] << 8) | \
00219 (((uint8_t const *)(p))[2] << 16) | \
00220 (((uint8_t const *)(p))[3] << 24) | \
00221 (((uint8_t const *)(p))[4] << 32) | \
00222 (((uint8_t const *)(p))[5] << 40) | \
00223 (((uint8_t const *)(p))[6] << 48) | \
00224 (((uint8_t const *)(p))[7] << 56))
00225
00226 #define PST_LE_GET_UINT32(p) \
00227 (uint32_t)((((uint8_t const *)(p))[0] << 0) | \
00228 (((uint8_t const *)(p))[1] << 8) | \
00229 (((uint8_t const *)(p))[2] << 16) | \
00230 (((uint8_t const *)(p))[3] << 24))
00231
00232 #define PST_LE_GET_INT32(p) \
00233 (int32_t)((((uint8_t const *)(p))[0] << 0) | \
00234 (((uint8_t const *)(p))[1] << 8) | \
00235 (((uint8_t const *)(p))[2] << 16) | \
00236 (((uint8_t const *)(p))[3] << 24))
00237
00238 #define PST_LE_GET_UINT16(p) \
00239 (uint16_t)((((uint8_t const *)(p))[0] << 0) | \
00240 (((uint8_t const *)(p))[1] << 8))
00241
00242 #define PST_LE_GET_INT16(p) \
00243 (int16_t)((((uint8_t const *)(p))[0] << 0) | \
00244 (((uint8_t const *)(p))[1] << 8))
00245
00246 #define PST_LE_GET_UINT8(p) (*(uint8_t const *)(p))
00247
00248 #define PST_LE_GET_INT8(p) (*(int8_t const *)(p))
00249
00250
00251 #endif //DEFINEH_H