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