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