types.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. #ifndef __types_h
  2. #define __types_h
  3. #ifndef CONFIG
  4. #define CONFIG "config.h"
  5. #endif // CONFIG
  6. #include CONFIG
  7. #define ANDROID_API_LEVEL ANDROID_HELPER1(__ANDROID_API__)
  8. #define ANDROID_HELPER1(s) ANDROID_HELPER2(s)
  9. #define ANDROID_HELPER2(s) #s
  10. #if !defined(_WIN32) && !__CYGWIN__
  11. #define __declspec(x) __attribute__((__visibility__("default")))
  12. #endif
  13. #if !defined(EXTERNAL)
  14. #define EXTERNAL dllimport
  15. #endif
  16. #ifdef __cplusplus
  17. #define EXTERNC extern "C"
  18. #else
  19. #define EXTERNC
  20. #endif
  21. #include <stdlib.h>
  22. #include <limits.h>
  23. #include <stdint.h>
  24. #ifdef __ANDROID__
  25. #include <android/api-level.h>
  26. #endif // __ANDROID__
  27. #ifndef _WIN32
  28. #include <netinet/in.h>
  29. #endif // _WIN32
  30. #if (IP_BINDANY || IP_FREEBIND || IPV6_BINDANY || IP_NONLOCALOK) && !defined(NO_FREEBIND) && !defined(USE_MSRPC) && !defined(SIMPLE_SOCKETS)
  31. #define HAVE_FREEBIND 1
  32. #endif
  33. #ifndef alloca
  34. #ifdef __GNUC__
  35. #define alloca(x) __builtin_alloca(x)
  36. #endif // __GNUC__
  37. #endif // alloca
  38. #ifndef alloca
  39. #if _MSC_VER
  40. #define alloca _malloca
  41. #endif // _MSC_VER
  42. #endif // alloca
  43. #ifndef alloca
  44. #ifdef __has_builtin // clang feature test
  45. #if __has_builtin(__builtin_alloca)
  46. #define alloca(x) __builtin_alloca(x)
  47. #endif // __has_builtin(__builtin_alloca)
  48. #endif // __has_builtin
  49. #endif // alloca
  50. #ifndef alloca
  51. #include <alloca.h>
  52. #endif
  53. #ifndef __packed
  54. #if _MSC_VER
  55. #define __packed
  56. #else // !_MSC_VER
  57. #define __packed __attribute__((packed))
  58. #endif // !_MSC_VER
  59. #endif
  60. #ifndef __pure
  61. #define __pure __attribute__((pure))
  62. #endif
  63. #ifndef __noreturn
  64. #define __noreturn __attribute__((noreturn))
  65. #endif
  66. #define restrict __restrict
  67. typedef struct __packed
  68. {
  69. uint16_t val[0];
  70. } PACKED16;
  71. typedef struct __packed
  72. {
  73. uint32_t val[0];
  74. } PACKED32;
  75. typedef struct __packed
  76. {
  77. uint64_t val[0];
  78. } PACKED64;
  79. // Extend this type to 16 or 32 bits if more than 254 products appear
  80. typedef uint8_t ProdListIndex_t;
  81. // Deal with Mingw32-w64 C++ header which defines a _countof that is incompatible with vlmcsd
  82. #define vlmcsd_countof(x) ( sizeof(x) / sizeof(x[0]) )
  83. // PATH_MAX is optional in Posix. We use a default of 260 here
  84. #ifndef PATH_MAX
  85. #ifdef _WIN32
  86. #define PATH_MAX MAX_PATH
  87. #else
  88. #define PATH_MAX 260
  89. #endif // _WIN32
  90. #endif // !PATH_MAX
  91. #if PATH_MAX > 260
  92. #define VLMCSD_PATH_MAX 260
  93. #else
  94. #define VLMCSD_PATH_MAX PATH_MAX
  95. #endif
  96. // Synchronization Objects
  97. // Mutexes
  98. #ifdef USE_THREADS
  99. #if !defined(_WIN32) && !defined(__CYGWIN__)
  100. #define lock_mutex(x) pthread_mutex_lock(x)
  101. #define unlock_mutex(x) pthread_mutex_unlock(x)
  102. #else
  103. #define lock_mutex(x) EnterCriticalSection(x)
  104. #define unlock_mutex(x) LeaveCriticalSection(x)
  105. #endif
  106. #else // !USE_THREADS
  107. //defines to nothing
  108. #define lock_mutex(x)
  109. #define unlock_mutex(x)
  110. #endif // !USE_THREADS
  111. // Semaphores
  112. #ifndef _WIN32
  113. #define semaphore_wait(x) sem_wait(x)
  114. #define semaphore_post(x) sem_post(x)
  115. #else // _WIN32
  116. #define semaphore_wait(x) WaitForSingleObject(x, INFINITE)
  117. #define semaphore_post(x) ReleaseSemaphore(x, 1, NULL)
  118. #endif // _WIN32
  119. // Stupid MingW just uses rand() from msvcrt.dll which uses RAND_MAX of 0x7fff
  120. #if RAND_MAX < 0x7fffffff
  121. #define rand32(x) ((uint32_t)((rand(x) << 17) | (rand(x) << 2) | (rand(x) & 3)))
  122. #elif RAND_MAX < 0xffffffff
  123. #define rand32(x) ((uint32_t)((rand(x) << 1) | (rand(x) & 1)))
  124. #else
  125. #define rand32(x) (uint32_t)rand(x)
  126. #endif
  127. #if (defined(_WIN32) || defined(__CYGWIN__)) && !defined(NO_SOCKETS)
  128. #define _NTSERVICE
  129. #endif
  130. #if (defined(__CYGWIN__) || defined(_WIN32) || defined(NO_SOCKETS)) && !defined(NO_SIGHUP)
  131. #define NO_SIGHUP
  132. #endif // (defined(__CYGWIN__) || defined(_WIN32) || defined(NO_SOCKETS)) && !defined(NO_SIGHUP)
  133. #ifdef _WIN32
  134. #ifndef USE_THREADS
  135. #define USE_THREADS
  136. #endif
  137. #endif
  138. #if defined(USE_THREADS)
  139. #define _TLS __thread
  140. #else
  141. #define _TLS
  142. #endif
  143. #define GUID_STRING_LENGTH 36
  144. #if defined(_WIN32)
  145. #ifndef USE_MSRPC
  146. #include <winsock2.h>
  147. #include <ws2tcpip.h>
  148. #endif // USE_MSRPC
  149. #include <windows.h>
  150. //#include <VersionHelpers.h>
  151. typedef char* sockopt_t;
  152. // Map VLMCSD error codes to WSAGetLastError() codes
  153. // Add more if you need them
  154. #define VLMCSD_EADDRINUSE WSAEADDRINUSE
  155. #define VLMCSD_ENODEV WSAENODEV
  156. #define VLMCSD_EADDRNOTAVAIL WSAEADDRNOTAVAIL
  157. #define VLMCSD_EACCES WSAEACCES
  158. #define VLMCSD_EINVAL WSAEINVAL
  159. #define VLMCSD_ENOTSOCK WSAENOTSOCK
  160. #define VLMCSD_EINTR WSAEINTR
  161. #define VLMCSD_EINPROGRESS WSAEINPROGRESS
  162. #define VLMCSD_ECONNABORTED WSAECONNABORTED
  163. #define socket_errno WSAGetLastError()
  164. #define socketclose(x) (closesocket(x))
  165. #define vlmcsd_strerror(x) win_strerror(x)
  166. #define VLMCSD_SHUT_RD SD_RECEIVE
  167. #define VLMCSD_SHUT_WR SD_SEND
  168. #define VLMCSD_SHUT_RDWR SD_BOTH
  169. /* Unknown Winsock error codes */
  170. #define WSAENODEV -1
  171. #elif defined(__CYGWIN__)
  172. #include <windows.h>
  173. // Resolve conflicts between OpenSSL and MS Crypto API
  174. #ifdef _CRYPTO_OPENSSL
  175. #undef OCSP_RESPONSE
  176. #undef X509_NAME
  177. #endif
  178. #else
  179. typedef uint32_t DWORD;
  180. typedef uint16_t WORD;
  181. typedef uint8_t BYTE;
  182. typedef uint16_t WCHAR;
  183. typedef int BOOL;
  184. #define FALSE 0
  185. #define TRUE !0
  186. typedef struct {
  187. DWORD Data1;
  188. WORD Data2;
  189. WORD Data3;
  190. BYTE Data4[8];
  191. } /*__packed*/ GUID;
  192. typedef struct {
  193. DWORD dwLowDateTime;
  194. DWORD dwHighDateTime;
  195. } /*__packed*/ FILETIME;
  196. #endif // defined(__CYGWIN__)
  197. #ifndef _WIN32
  198. // Map VLMCSD error codes to POSIX codes
  199. // Add more if you need them
  200. #define VLMCSD_EADDRINUSE EADDRINUSE
  201. #define VLMCSD_ENODEV ENODEV
  202. #define VLMCSD_EADDRNOTAVAIL EADDRNOTAVAIL
  203. #define VLMCSD_EACCES EACCES
  204. #define VLMCSD_EINVAL EINVAL
  205. #define VLMCSD_ENOTSOCK ENOTSOCK
  206. #define VLMCSD_EINTR EINTR
  207. #define VLMCSD_EINPROGRESS EINPROGRESS
  208. #define VLMCSD_ECONNABORTED ECONNABORTED
  209. typedef void* sockopt_t;
  210. #define _countof(x) ( sizeof(x) / sizeof(x[0]) )
  211. #define SOCKET int
  212. #define INVALID_SOCKET -1
  213. #define socket_errno errno
  214. #define socketclose(x) (close(x))
  215. #define vlmcsd_strerror strerror
  216. #define VLMCSD_SHUT_RD SHUT_RD
  217. #define VLMCSD_SHUT_WR SHUT_WR
  218. #define VLMCSD_SHUT_RDWR SHUT_RDWR
  219. #endif // __MINGW__
  220. #define INVALID_UID ((uid_t)~0)
  221. #define INVALID_GID ((gid_t)~0)
  222. #undef IsEqualGUID
  223. #define IsEqualGUID(a, b) ( !memcmp(a, b, sizeof(GUID)) )
  224. #ifndef __stdcall
  225. #define __stdcall
  226. #endif
  227. #ifndef __cdecl
  228. #define __cdecl
  229. #endif
  230. typedef const char *const * CARGV;
  231. typedef struct {
  232. SOCKET socket;
  233. DWORD RpcAssocGroup;
  234. } CLDATA, *const PCLDATA;
  235. #endif // __types_h