1 /*----------------------------------------------------------------------------
  2 Name:      basicDefs.h
  3 Project:   xmlBlaster.org
  4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
  5 Author:    "Marcel Ruff" <xmlBlaster@marcelruff.info>
  6 Note:      The gcc and icc (>=8) both define __GNUC__
  7 Note:      cl.exe (Windows) always defines _WIN32
  8            __cplusplus    Defined for C++ programs only.
  9            _CHAR_UNSIGNED Defined when /J is specified.
 10            _CPPRTTI  Defined for code compiled with the /GR (Enable Run-Time Type Information) option.
 11            _CPPUNWIND  Defined for code compiled with the /GX (Enable Exception Handling) option.
 12                           _DLL      Defined when /MD or /MDd - Multithread DLL is specified.
 13            _M_IX86   (x86 specific) Defined as 500 for Blend (/GB), 300 for 80386 (/G3), 400 for 80486 (/G4), 500 for Pentium (/G5), and 600 for Pentium Pro (/G6).
 14            _MSC_VER  Defines the compiler version. Always defined.
 15                      1200: VC++ 6.0 Microsoft Visual C++ version 6.0 or later
 16                                                         1310: VC++ 7.1 2003 Microsoft (R) 32-bit C/C++ 13.10.3077 for 80x86 1984-2002
 17                      1400: VC++ 8.0 2005 14.00.50727.42
 18            _WIN32    (x86 specific) Defined for applications for WIN32. Always defined.
 19            _MT       Defined when /MD or /MT is specified.
 20            http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/HTML/_core_.2f.u.2c_2f.u.asp
 21            http://msdn.microsoft.com/en-us/library/b0084kay(VS.80).aspx
 22 -----------------------------------------------------------------------------*/
 23 #ifndef XMLBLASTER_basicDefs_H
 24 #define XMLBLASTER_basicDefs_H
 25 
 26 /*
 27   __IPhoneOS__ is used for Apple iPhone
 28   __MacOSX__   (__OBJC__ __APPLE__ are predefined)
 29   __FreeBSD__
 30   __hpux__
 31   __linux__
 32   _WINDOWS
 33   WINCE
 34  e.g. #if defined(_WINDOWS) || defined(WINCE)
 35  */
 36 
 37 #if defined(_WIN32)
 38 #  if !defined(_WINDOWS)
 39 #     define _WINDOWS /* We work with _WINDOWS and _MSC_VER in our code */
 40 #  endif
 41 #else  /* UNIX */
 42 /*#  define _MSC_VER 0 not possible as #ifdefs will return true!*/ /* Dummy for UNIX to avoid compiler warnings at: #if _MSC_VER >= 1400 */
 43 #endif
 44 
 45 #if defined(_WINDOWS)
 46 # define Blaster_Export_Flag __declspec (dllexport)
 47 # define Blaster_Import_Flag __declspec (dllimport)
 48 # if defined(_WINDLL)
 49 #   define Dll_Export Blaster_Export_Flag
 50 # elif defined(DLL_IGNORE)
 51 #   define Dll_Export
 52 # else
 53 #   define Dll_Export Blaster_Import_Flag
 54 #endif
 55 #else
 56 # define Dll_Export
 57 #endif
 58 
 59 /* Note: cast int to bool like this: i!=0 which is true or false depending on i */
 60 /* Windows Note for bool:
 61 The bool type participates in integral promotions. An r-value of type bool can be converted to an r-value of type int, with false becoming zero and true becoming one.
 62 Microsoft Specific:
 63 In Visual C++4.2, the Standard C++ header files contained a typedef that equated bool with int.
 64 In Visual C++ 5.0 and later, bool is implemented as a built-in type with a size of 1 byte.
 65 That means that for Visual C++ 4.2, a call of sizeof(bool) yields 4, while in Visual C++ 5.0 and later, the same call yields 1.
 66 This can cause memory corruption problems if you have defined structure members of type bool in Visual C++ 4.2 and are mixing object files (OBJ) and/or
 67 DLLs built with the 4.2 and 5.0 or later compilers. 
 68 */
 69 #ifndef __cplusplus
 70 #  if !defined(__sun) && !defined(_WINDOWS)  /* __GNUC_MINOR__=85 : gcc 2.85 does not like it either: how to define? */
 71 #    include <stdbool.h>
 72 #  endif
 73 #  ifndef __bool_true_false_are_defined
 74 #    define bool char   /* Can Windows CE P/Invoke handle this? */
 75 #    define true (char)1
 76 #    define false (char)0
 77 /*#    define bool int   Not possible if used with C++ as a bool is 1byte and struct alignement broken, savest ist probably: build -DXMLBLASTER_C_COMPILE_AS_CPP=1 c cpp
 78 #    define true 1
 79 #    define false 0*/
 80 #  endif
 81 #  define XMLBLASTER_C_bool bool
 82 #else  /* __cplusplus */
 83 #  define XMLBLASTER_C_bool bool
 84 #endif
 85 
 86 #if defined(_WINDOWS)
 87 #  if _MSC_VER >= 1400  /* _WINDOWS: 1200->VC++6.0, 1310->VC++7.1 (2003), 1400->VC++8.0 (2005) */
 88 #    define SNPRINTF snprintf0
 89      /* sscanf_s( tokenstring, "%s", s, sizeof(s) );   !! for %s: two args, the second with size !! */
 90 #    define VSNPRINTF _vsnprintf
 91 #  else
 92 #    define SNPRINTF _snprintf
 93 #    define VSNPRINTF _vsnprintf
 94 #  endif
 95 #else
 96 #  define SNPRINTF snprintf
 97 #  define VSNPRINTF vsnprintf    /* stdarg.h */
 98 #endif
 99 
100 #if defined(_WINDOWS)
101   typedef unsigned __int64 uint64_t;
102   typedef __int64 int64_t;
103 # define PRINTF_PREFIX_INT64_T "%I64d"
104 # define PRINTF_PREFIX_UINT64_T "%I64u"
105   /*typedef long long int64_t;*/
106   typedef unsigned __int32 uint32_t;
107   typedef __int32 int32_t;
108   typedef unsigned __int16 uint16_t;
109   typedef __int16 int16_t;
110 #else
111 
112 /* FreeBSD uses inttypes.h, not stdint.h.  Boost's lib suggests
113    this should read  defined(__FreeBSD__) || defined(__IBMCPP__)
114 */
115 # if defined(__FreeBSD__)
116 #   include <inttypes.h>
117 # elif defined(__sun)
118     /*#   include <int_types.h>*/ /* /usr/include/sys/int_types.h */
119 # elif defined(__hpux)
120   /*typedef long long int64_t;*/
121   /*#   include <int_types.h>*/ /* /usr/include/sys/int_types.h */
122 # else
123 #   include <stdint.h>  /*-> C99:  uint64_t etc. */
124 # endif
125 
126   /* TODO: Change to inttypes.h: PRId64 (ld or lld) instead of PRINTF_PREFIX_INT64_T */
127   /* unfortunately PRId64 is missing on Windows and if we do C++ instead of C compile */
128   /* PRId64 as 32bit system need "%lld" and 64 bit systems need "%ld" */
129 
130   /* __unix __WIN64 __WIN32 */
131 # if __LP64__
132    /* For example a Xeon processor with UNIX */
133 #  define PRINTF_PREFIX_INT64_T "%ld"
134 #  define PRINTF_PREFIX_UINT64_T "%lu"
135    /*#elif __ILP64__ __LLP64__ */
136 # else
137 #  define PRINTF_PREFIX_INT64_T "%lld"
138 #  define PRINTF_PREFIX_UINT64_T "%llu"
139 # endif
140 
141 #endif
142 /*#define INT64_DIGITLEN_MAX 19  Size of a max int64_t dumped to a string: LLONG_MAX from limits.h 9223372036854775807 */
143 #define INT64_STRLEN_MAX 22 /**< Size of a max int64_t dumped to a string including an optional LL and termination '\0': LLONG_MAX from limits.h 9223372036854775807LL */
144 
145 
146 #ifdef GCC_ANSI  /**< Set -DGCC_ANSI on command line if you use the 'gcc --ansi' flag */
147 #ifndef __USE_BSD /**< gcc -ansi on Linux: */
148    typedef unsigned short u_short;
149 #endif
150 #endif
151 
152 #ifdef _WINDOWS
153 #  define _INLINE_FUNC        /* C99 allows to declare functions as 'inline', not supported on WIN cl */
154 #else
155 #  ifdef __cplusplus
156 #    define _INLINE_FUNC      /* 'inline' does not compile with g++ */
157 #  elif __GNUC__
158 #    define _INLINE_FUNC __inline__ /* http://gcc.gnu.org/onlinedocs/gcc/Alternate-Keywords.html */
159 #  else
160 #    define _INLINE_FUNC inline /* C99 allows to declare functions as 'inline', it has internal linkage -> code to be in same file as call */
161 #  endif
162 #endif
163 
164 #if defined(_WINDOWS)
165 #  define socklen_t int
166 #  define ssize_t signed int
167 #elif defined(__alpha)
168 #  define socklen_t int
169 #else
170 #  include <unistd.h>
171 #endif
172 
173 #ifndef XB_NO_PTHREADS
174 #  define XB_USE_PTHREADS 1 /**< Used to dump thread ID in default logging output, undef it if you run single threaded */
175 #endif
176 
177 /**
178  * Declare function callback pointer about how many bytes are read from socket.
179  * @param userP A user pointer
180  * @param currBytesRead The currently number of bytes read
181  * @param nbytes Totally expected bytes
182  */
183 typedef void ( * XmlBlasterNumReadFunc)(void *xb, const size_t currBytesRead, const size_t nbytes);
184 
185 #endif /* XMLBLASTER_basicDefs_H */


syntax highlighted by Code2HTML, v. 0.9.1