1
0

types.h 5.5 KB

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