GlobalDef.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. /*
  2. * Copyright: JessMA Open Source (ldcsaa@gmail.com)
  3. *
  4. * Author : Bruce Liang
  5. * Website : https://github.com/ldcsaa
  6. * Project : https://github.com/ldcsaa/HP-Socket
  7. * Blog : http://www.cnblogs.com/ldcsaa
  8. * Wiki : http://www.oschina.net/p/hp-socket
  9. * QQ Group : 44636872, 75375912
  10. *
  11. * Licensed under the Apache License, Version 2.0 (the "License");
  12. * you may not use this file except in compliance with the License.
  13. * You may obtain a copy of the License at
  14. *
  15. * http://www.apache.org/licenses/LICENSE-2.0
  16. *
  17. * Unless required by applicable law or agreed to in writing, software
  18. * distributed under the License is distributed on an "AS IS" BASIS,
  19. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  20. * See the License for the specific language governing permissions and
  21. * limitations under the License.
  22. */
  23. #pragma once
  24. #include <sys/types.h>
  25. typedef int BOOL;
  26. typedef float FLOAT;
  27. typedef FLOAT *PFLOAT, *LPFLOAT;
  28. typedef double DOUBLE;
  29. typedef DOUBLE *PDOUBLE, *LPDOUBLE;
  30. typedef short SHORT, INT16;
  31. typedef SHORT *PSHORT, *LPSHORT;
  32. typedef unsigned short USHORT, UINT16;
  33. typedef USHORT *PUSHORT, *LPUSHORT;
  34. typedef unsigned short WORD;
  35. typedef WORD *PWORD, *LPWORD;
  36. typedef unsigned int DWORD;
  37. typedef DWORD *PDWORD, *LPDWORD;
  38. typedef long LONG, LID;
  39. typedef LONG *PLONG, *LPLONG;
  40. typedef unsigned long ULONG, ULID;
  41. typedef ULONG *PULONG, *LPULONG;
  42. typedef long long LONGLONG, LLONG, INT64;
  43. typedef LONGLONG *PLONGLONG, *LPLONGLONG, *PLLONG, *LPLLONG;
  44. typedef unsigned long long ULONGLONG, ULLONG, UINT64;
  45. typedef ULONGLONG *PULONGLONG, *LPULONGLONG, *PULLONG, *LPULLONG;
  46. typedef int INT, IID, INT32;
  47. typedef INT *PINT, *LPINT;
  48. typedef unsigned int UINT, UIID, UINT32;
  49. typedef UINT *PUINT, *LPUINT;
  50. typedef void VOID;
  51. typedef VOID *PVOID, *LPVOID;
  52. typedef char CHAR, INT8;
  53. typedef CHAR *PCHAR, *LPCHAR, *PSTR, *LPSTR;
  54. typedef const char *PCSTR, *LPCSTR;
  55. typedef unsigned char BYTE, UINT8;
  56. typedef BYTE *PBYTE, *LPBYTE;
  57. typedef const BYTE *PCBYTE, *LPCBYTE;
  58. typedef wchar_t WCHAR;
  59. typedef WCHAR *PWSTR, *LPWSTR;
  60. typedef const WCHAR *PCWSTR, *LPCWSTR;
  61. typedef LONG INT_PTR, LONG_PTR, LPARAM;
  62. typedef ULONG UINT_PTR, ULONG_PTR, DWORD_PTR, WPARAM;
  63. typedef IID FD, HANDLE, SOCKET;
  64. typedef INT LRESULT, HRESULT;
  65. typedef LLONG __time64_t;
  66. typedef INT __time32_t;
  67. typedef LID NTHR_ID;
  68. #ifdef __ANDROID__
  69. typedef LID THR_ID;
  70. #else
  71. typedef ULID THR_ID;
  72. #endif
  73. typedef size_t SIZE_T;
  74. typedef ssize_t SSIZE_T;
  75. #ifdef _UNICODE
  76. typedef WCHAR TCHAR;
  77. #else
  78. typedef CHAR TCHAR;
  79. #endif
  80. typedef TCHAR *PTSTR, *LPTSTR;
  81. typedef const TCHAR *PCTSTR, *LPCTSTR;
  82. #define MAXUINT8 ((UINT8)~((UINT8)0))
  83. #define MAXINT8 ((INT8)(MAXUINT8 >> 1))
  84. #define MININT8 ((INT8)~MAXINT8)
  85. #define MAXUINT16 ((UINT16)~((UINT16)0))
  86. #define MAXINT16 ((INT16)(MAXUINT16 >> 1))
  87. #define MININT16 ((INT16)~MAXINT16)
  88. #define MAXUINT32 ((UINT32)~((UINT32)0))
  89. #define MAXINT32 ((INT32)(MAXUINT32 >> 1))
  90. #define MININT32 ((INT32)~MAXINT32)
  91. #define MAXUINT64 ((UINT64)~((UINT64)0))
  92. #define MAXINT64 ((INT64)(MAXUINT64 >> 1))
  93. #define MININT64 ((INT64)~MAXINT64)
  94. #define MAXULONG ((ULONG)~((ULONG)0))
  95. #define MAXLONG ((LONG)(MAXULONG >> 1))
  96. #define MINLONG ((LONG)~MAXLONG)
  97. #define MAXULONGLONG ((ULONGLONG)~((ULONGLONG)0))
  98. #define MINLONGLONG ((LONGLONG)~MAXLONGLONG)
  99. #define MAXSIZE_T ((SIZE_T)~((SIZE_T)0))
  100. #define MAXSSIZE_T ((SSIZE_T)(MAXSIZE_T >> 1))
  101. #define MINSSIZE_T ((SSIZE_T)~MAXSSIZE_T)
  102. #define MAXUINT ((UINT)~((UINT)0))
  103. #define MAXINT ((INT)(MAXUINT >> 1))
  104. #define MININT ((INT)~MAXINT)
  105. #define MAXDWORD32 ((DWORD32)~((DWORD32)0))
  106. #define MAXDWORD64 ((DWORD64)~((DWORD64)0))
  107. #define MINBYTE 0x00
  108. #define MAXBYTE 0xFF
  109. #define MINCHAR 0x80
  110. #define MAXCHAR 0x7F
  111. #define MINSHORT 0x8000
  112. #define MAXSHORT 0x7FFF
  113. #define MINUSHORT 0x0000
  114. #define MAXUSHORT 0xFFFF
  115. #define MINWORD 0x0000
  116. #define MAXWORD 0xFFFF
  117. #define MINDWORD 0x00000000
  118. #define MAXDWORD 0xFFFFFFFF
  119. #ifdef _UNICODE
  120. #define __T(x) L ## x
  121. #else
  122. #define __T(x) x
  123. #define T2A(p) (p)
  124. #define A2T(p) (p)
  125. #define A2CT(p) (p)
  126. #define T2CA(p) (p)
  127. #define CT2A(p) (p)
  128. #define CA2T(p) (p)
  129. #define CA2CT(p) (p)
  130. #endif
  131. #define _T(x) __T(x)
  132. #define _TEXT(x) __T(x)
  133. #define _In_
  134. #define _Out_
  135. #define _Inout_
  136. #define _In_opt_
  137. #define _Out_opt_
  138. #define _Inout_opt_
  139. #define USES_CONVERSION
  140. #define INFINITE -1
  141. #define NO_ERROR 0
  142. #define HAS_ERROR -1
  143. #define TIMEOUT 0
  144. #define RS_OK NO_ERROR
  145. #define RS_FAIL HAS_ERROR
  146. #define RS_TIMEOUT TIMEOUT
  147. #define INVALID_FD -1
  148. #define INVALID_HANDLE_VALUE INVALID_FD
  149. #define INVALID_PVOID ((PVOID)-1)
  150. #define _MAX_PATH 256
  151. #define MAX_PATH _MAX_PATH
  152. #define TRUE 1
  153. #define FALSE 0
  154. #define CONST const
  155. #define MAKEWORD(a, b) ((WORD)(((BYTE)(((DWORD_PTR)(a)) & 0xff)) | ((WORD)((BYTE)(((DWORD_PTR)(b)) & 0xff))) << 8))
  156. #define MAKELONG(a, b) ((LONG)(((WORD)(((DWORD_PTR)(a)) & 0xffff)) | ((DWORD)((WORD)(((DWORD_PTR)(b)) & 0xffff))) << 16))
  157. #define LOWORD(l) ((WORD)(((DWORD_PTR)(l)) & 0xffff))
  158. #define HIWORD(l) ((WORD)((((DWORD_PTR)(l)) >> 16) & 0xffff))
  159. #define LOBYTE(w) ((BYTE)(((DWORD_PTR)(w)) & 0xff))
  160. #define HIBYTE(w) ((BYTE)((((DWORD_PTR)(w)) >> 8) & 0xff))
  161. #if !defined(MAX)
  162. #define MAX(a,b) (((a) >= (b)) ? (a) : (b))
  163. #endif
  164. #if !defined(MIN)
  165. #define MIN(a,b) (((a) <= (b)) ? (a) : (b))
  166. #endif
  167. #if !defined(_max)
  168. #define _max(a,b) MAX(a,b)
  169. #endif
  170. #if !defined(_min)
  171. #define _min(a,b) MIN(a,b)
  172. #endif
  173. #if defined(NDEBUG)
  174. #if !defined(_NDEBUG)
  175. #define _NDEBUG
  176. #endif
  177. #if defined(DEBUG)
  178. #undef DEBUG
  179. #endif
  180. #if defined(_DEBUG)
  181. #undef _DEBUG
  182. #endif
  183. #if defined(DEBUG_TRACE)
  184. #undef DEBUG_TRACE
  185. #endif
  186. #else
  187. #if defined(_NDEBUG)
  188. #undef _NDEBUG
  189. #endif
  190. #if !defined(DEBUG)
  191. #define DEBUG
  192. #endif
  193. #if !defined(_DEBUG)
  194. #define _DEBUG
  195. #endif
  196. #endif
  197. #if defined(__arm64__) && !defined(__aarch64__)
  198. #define __aarch64__ __arm64__
  199. #elif defined(__aarch64__) && !defined(__arm64__)
  200. #define __arm64__ __aarch64__
  201. #endif
  202. #ifdef __cplusplus
  203. #define EXTERN_C extern "C"
  204. #define EXTERN_C_BEGIN EXTERN_C {
  205. #define EXTERN_C_END }
  206. #else
  207. #define EXTERN_C extern
  208. #define EXTERN_C_BEGIN
  209. #define EXTERN_C_END
  210. #endif
  211. #if !defined(__stdcall)
  212. #define __stdcall __attribute__ ((__stdcall__))
  213. #endif
  214. #if !defined(__cdecl)
  215. #define __cdecl __attribute__ ((__cdecl__))
  216. #endif
  217. #if !defined(_GNU_SOURCE)
  218. #define _GNU_SOURCE
  219. #endif
  220. #if !defined(CALLBACK)
  221. #define CALLBACK
  222. #endif
  223. #if !defined(WINAPI)
  224. #define WINAPI
  225. #endif
  226. #if !defined(FORCEINLINE)
  227. #ifdef __GNUC__
  228. #define FORCEINLINE __attribute__ ((always_inline))
  229. #else
  230. #define FORCEINLINE inline
  231. #endif
  232. #endif
  233. #if !defined(STATIC_FORCEINLINE)
  234. #define STATIC_FORCEINLINE static FORCEINLINE
  235. #endif
  236. #if !defined(EXTERN_FORCEINLINE)
  237. #define EXTERN_FORCEINLINE extern FORCEINLINE
  238. #endif