types.h 6.4 KB

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