define.h

Go to the documentation of this file.
00001 /***
00002  * define.h
00003  * Part of the LibPST project
00004  * Written by David Smith
00005  *            dave.s@earthcorp.com
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 void *pst_realloc(void *ptr, size_t size);
00147 
00148 #define MESSAGEPRINT(...) pst_debug(__LINE__, __FILE__,  __VA_ARGS__)
00149 
00150 #define WARN(x) {           \
00151     MESSAGEPRINT x;         \
00152     pst_debug_lock();       \
00153         printf x;           \
00154         fflush(stdout);     \
00155     pst_debug_unlock();     \
00156 }
00157 
00158 #define DIE(x) {            \
00159     WARN(x);                \
00160     exit(EXIT_FAILURE);     \
00161 }
00162 
00163 #define DEBUG_WARN(x)           MESSAGEPRINT x
00164 #define DEBUG_INFO(x)           MESSAGEPRINT x
00165 #define DEBUG_HEXDUMP(x, s)     pst_debug_hexdump(__LINE__, __FILE__, (char*)x, s, 0x10, 0)
00166 #define DEBUG_HEXDUMPC(x, s, c) pst_debug_hexdump(__LINE__, __FILE__, (char*)x, s, c, 0)
00167 
00168 
00169 #define DEBUG_ENT(x)                                            \
00170     {                                                           \
00171         pst_debug_func(x);                                      \
00172         pst_debug(__LINE__, __FILE__, "Entering function\n");   \
00173     }
00174 #define DEBUG_RET()                                             \
00175     {                                                           \
00176         pst_debug(__LINE__, __FILE__, "Leaving function\n");    \
00177         pst_debug_func_ret();                                   \
00178     }
00179 
00180 #define DEBUG_INIT(fname,mutex) {pst_debug_init(fname,mutex);}
00181 #define DEBUG_CLOSE()           {pst_debug_close();}
00182 #define RET_DERROR(res, ret_val, x) if (res) { DIE(x);}
00183 
00184 
00185 
00186 #if BYTE_ORDER == BIG_ENDIAN
00187 #  define LE64_CPU(x) \
00188   x = ((((x) & UINT64_C(0xff00000000000000)) >> 56) | \
00189        (((x) & UINT64_C(0x00ff000000000000)) >> 40) | \
00190        (((x) & UINT64_C(0x0000ff0000000000)) >> 24) | \
00191        (((x) & UINT64_C(0x000000ff00000000)) >> 8 ) | \
00192        (((x) & UINT64_C(0x00000000ff000000)) << 8 ) | \
00193        (((x) & UINT64_C(0x0000000000ff0000)) << 24) | \
00194        (((x) & UINT64_C(0x000000000000ff00)) << 40) | \
00195        (((x) & UINT64_C(0x00000000000000ff)) << 56));
00196 #  define LE32_CPU(x) \
00197   x = ((((x) & 0xff000000) >> 24) | \
00198        (((x) & 0x00ff0000) >> 8 ) | \
00199        (((x) & 0x0000ff00) << 8 ) | \
00200        (((x) & 0x000000ff) << 24));
00201 #  define LE16_CPU(x) \
00202   x = ((((x) & 0xff00) >> 8) | \
00203        (((x) & 0x00ff) << 8));
00204 #elif BYTE_ORDER == LITTLE_ENDIAN
00205 #  define LE64_CPU(x) {}
00206 #  define LE32_CPU(x) {}
00207 #  define LE16_CPU(x) {}
00208 #else
00209 #  error "Byte order not supported by this library"
00210 #endif // BYTE_ORDER
00211 
00212 
00213 #define PST_LE_GET_UINT64(p) \
00214         (uint64_t)((((uint8_t const *)(p))[0] << 0)  |    \
00215                    (((uint8_t const *)(p))[1] << 8)  |    \
00216                    (((uint8_t const *)(p))[2] << 16) |    \
00217                    (((uint8_t const *)(p))[3] << 24) |    \
00218                    (((uint8_t const *)(p))[4] << 32) |    \
00219                    (((uint8_t const *)(p))[5] << 40) |    \
00220                    (((uint8_t const *)(p))[6] << 48) |    \
00221                    (((uint8_t const *)(p))[7] << 56))
00222 
00223 #define PST_LE_GET_INT64(p) \
00224         (int64_t)((((uint8_t const *)(p))[0] << 0)  |    \
00225                   (((uint8_t const *)(p))[1] << 8)  |    \
00226                   (((uint8_t const *)(p))[2] << 16) |    \
00227                   (((uint8_t const *)(p))[3] << 24) |    \
00228                   (((uint8_t const *)(p))[4] << 32) |    \
00229                   (((uint8_t const *)(p))[5] << 40) |    \
00230                   (((uint8_t const *)(p))[6] << 48) |    \
00231                   (((uint8_t const *)(p))[7] << 56))
00232 
00233 #define PST_LE_GET_UINT32(p) \
00234         (uint32_t)((((uint8_t const *)(p))[0] << 0)  |    \
00235                    (((uint8_t const *)(p))[1] << 8)  |    \
00236                    (((uint8_t const *)(p))[2] << 16) |    \
00237                    (((uint8_t const *)(p))[3] << 24))
00238 
00239 #define PST_LE_GET_INT32(p) \
00240         (int32_t)((((uint8_t const *)(p))[0] << 0)  |    \
00241                   (((uint8_t const *)(p))[1] << 8)  |    \
00242                   (((uint8_t const *)(p))[2] << 16) |    \
00243                   (((uint8_t const *)(p))[3] << 24))
00244 
00245 #define PST_LE_GET_UINT16(p)                  \
00246         (uint16_t)((((uint8_t const *)(p))[0] << 0)  |    \
00247                    (((uint8_t const *)(p))[1] << 8))
00248 
00249 #define PST_LE_GET_INT16(p)               \
00250         (int16_t)((((uint8_t const *)(p))[0] << 0)  |    \
00251                    (((uint8_t const *)(p))[1] << 8))
00252 
00253 #define PST_LE_GET_UINT8(p) (*(uint8_t const *)(p))
00254 
00255 #define PST_LE_GET_INT8(p) (*(int8_t const *)(p))
00256 
00257 
00258 #endif //DEFINEH_H

Generated on 27 Dec 2013 for 'LibPst' by  doxygen 1.6.1