]>
Commit | Line | Data |
---|---|---|
1e230224 | 1 | /* 7zTypes.h -- Basic types\r |
7e6776de | 2 | 2018-08-04 : Igor Pavlov : Public domain */\r |
11ff2c71 LG |
3 | \r |
4 | #ifndef __7Z_TYPES_H\r | |
5 | #define __7Z_TYPES_H\r | |
6 | \r | |
1e230224 LG |
7 | #ifdef _WIN32\r |
8 | /* #include <windows.h> */\r | |
9 | #endif\r | |
11ff2c71 | 10 | \r |
1e230224 | 11 | #ifdef EFIAPI\r |
1436aea4 | 12 | #include "UefiLzma.h"\r |
11ff2c71 | 13 | #else\r |
1436aea4 | 14 | #include <stddef.h>\r |
11ff2c71 LG |
15 | #endif\r |
16 | \r | |
1e230224 | 17 | #ifndef EXTERN_C_BEGIN\r |
1436aea4 MK |
18 | #ifdef __cplusplus\r |
19 | #define EXTERN_C_BEGIN extern "C" {\r | |
20 | #define EXTERN_C_END }\r | |
21 | #else\r | |
1e230224 LG |
22 | #define EXTERN_C_BEGIN\r |
23 | #define EXTERN_C_END\r | |
1436aea4 | 24 | #endif\r |
1e230224 LG |
25 | #endif\r |
26 | \r | |
27 | EXTERN_C_BEGIN\r | |
11ff2c71 | 28 | \r |
1436aea4 | 29 | #define SZ_OK 0\r |
11ff2c71 | 30 | \r |
1436aea4 MK |
31 | #define SZ_ERROR_DATA 1\r |
32 | #define SZ_ERROR_MEM 2\r | |
33 | #define SZ_ERROR_CRC 3\r | |
34 | #define SZ_ERROR_UNSUPPORTED 4\r | |
35 | #define SZ_ERROR_PARAM 5\r | |
36 | #define SZ_ERROR_INPUT_EOF 6\r | |
37 | #define SZ_ERROR_OUTPUT_EOF 7\r | |
38 | #define SZ_ERROR_READ 8\r | |
39 | #define SZ_ERROR_WRITE 9\r | |
40 | #define SZ_ERROR_PROGRESS 10\r | |
41 | #define SZ_ERROR_FAIL 11\r | |
42 | #define SZ_ERROR_THREAD 12\r | |
11ff2c71 | 43 | \r |
1436aea4 MK |
44 | #define SZ_ERROR_ARCHIVE 16\r |
45 | #define SZ_ERROR_NO_ARCHIVE 17\r | |
11ff2c71 LG |
46 | \r |
47 | typedef int SRes;\r | |
48 | \r | |
49 | #ifdef _WIN32\r | |
f0737de8 | 50 | \r |
1e230224 LG |
51 | /* typedef DWORD WRes; */\r |
52 | typedef unsigned WRes;\r | |
1436aea4 | 53 | #define MY_SRes_HRESULT_FROM_WRes(x) HRESULT_FROM_WIN32(x)\r |
f0737de8 | 54 | \r |
11ff2c71 | 55 | #else\r |
f0737de8 | 56 | \r |
11ff2c71 | 57 | typedef int WRes;\r |
1436aea4 MK |
58 | #define MY__FACILITY_WIN32 7\r |
59 | #define MY__FACILITY__WRes MY__FACILITY_WIN32\r | |
60 | #define MY_SRes_HRESULT_FROM_WRes(x) ((HRESULT)(x) <= 0 ? ((HRESULT)(x)) : ((HRESULT) (((x) & 0x0000FFFF) | (MY__FACILITY__WRes << 16) | 0x80000000)))\r | |
f0737de8 | 61 | \r |
11ff2c71 LG |
62 | #endif\r |
63 | \r | |
64 | #ifndef RINOK\r | |
1436aea4 | 65 | #define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; }\r |
11ff2c71 LG |
66 | #endif\r |
67 | \r | |
1436aea4 MK |
68 | typedef unsigned char Byte;\r |
69 | typedef short Int16;\r | |
11ff2c71 LG |
70 | typedef unsigned short UInt16;\r |
71 | \r | |
72 | #ifdef _LZMA_UINT32_IS_ULONG\r | |
1436aea4 | 73 | typedef long Int32;\r |
11ff2c71 LG |
74 | typedef unsigned long UInt32;\r |
75 | #else\r | |
1436aea4 | 76 | typedef int Int32;\r |
11ff2c71 LG |
77 | typedef unsigned int UInt32;\r |
78 | #endif\r | |
79 | \r | |
80 | #ifdef _SZ_NO_INT_64\r | |
81 | \r | |
82 | /* define _SZ_NO_INT_64, if your compiler doesn't support 64-bit integers.\r | |
83 | NOTES: Some code will work incorrectly in that case! */\r | |
84 | \r | |
1436aea4 | 85 | typedef long Int64;\r |
11ff2c71 LG |
86 | typedef unsigned long UInt64;\r |
87 | \r | |
88 | #else\r | |
89 | \r | |
1436aea4 MK |
90 | #if defined (_MSC_VER) || defined (__BORLANDC__)\r |
91 | typedef __int64 Int64;\r | |
11ff2c71 | 92 | typedef unsigned __int64 UInt64;\r |
1436aea4 MK |
93 | #define UINT64_CONST(n) n\r |
94 | #else\r | |
95 | typedef long long int Int64;\r | |
11ff2c71 | 96 | typedef unsigned long long int UInt64;\r |
1436aea4 MK |
97 | #define UINT64_CONST(n) n ## ULL\r |
98 | #endif\r | |
11ff2c71 LG |
99 | \r |
100 | #endif\r | |
101 | \r | |
102 | #ifdef _LZMA_NO_SYSTEM_SIZE_T\r | |
103 | typedef UInt32 SizeT;\r | |
104 | #else\r | |
105 | typedef size_t SizeT;\r | |
106 | #endif\r | |
107 | \r | |
7e6776de LW |
108 | typedef int BoolInt;\r |
109 | /* typedef BoolInt Bool; */\r | |
1436aea4 MK |
110 | #define True 1\r |
111 | #define False 0\r | |
11ff2c71 | 112 | \r |
1e230224 | 113 | #ifdef _WIN32\r |
1436aea4 | 114 | #define MY_STD_CALL __stdcall\r |
1e230224 LG |
115 | #else\r |
116 | #define MY_STD_CALL\r | |
117 | #endif\r | |
118 | \r | |
1436aea4 | 119 | #if defined (_MSC_VER) && !defined (__clang__)\r |
11ff2c71 | 120 | \r |
1436aea4 MK |
121 | #if _MSC_VER >= 1300\r |
122 | #define MY_NO_INLINE __declspec(noinline)\r | |
123 | #else\r | |
11ff2c71 | 124 | #define MY_NO_INLINE\r |
1436aea4 | 125 | #endif\r |
11ff2c71 | 126 | \r |
1436aea4 | 127 | #define MY_FORCE_INLINE __forceinline\r |
f0737de8 | 128 | \r |
1436aea4 MK |
129 | #define MY_CDECL __cdecl\r |
130 | #define MY_FAST_CALL __fastcall\r | |
11ff2c71 LG |
131 | \r |
132 | #else\r | |
133 | \r | |
1e230224 | 134 | #define MY_NO_INLINE\r |
f0737de8 | 135 | #define MY_FORCE_INLINE\r |
11ff2c71 | 136 | #define MY_CDECL\r |
11ff2c71 LG |
137 | #define MY_FAST_CALL\r |
138 | \r | |
f0737de8 LG |
139 | /* inline keyword : for C++ / C99 */\r |
140 | \r | |
141 | /* GCC, clang: */\r | |
1436aea4 | 142 | \r |
f0737de8 LG |
143 | /*\r |
144 | #if defined (__GNUC__) && (__GNUC__ >= 4)\r | |
145 | #define MY_FORCE_INLINE __attribute__((always_inline))\r | |
146 | #define MY_NO_INLINE __attribute__((noinline))\r | |
147 | #endif\r | |
148 | */\r | |
149 | \r | |
11ff2c71 LG |
150 | #endif\r |
151 | \r | |
11ff2c71 LG |
152 | /* The following interfaces use first parameter as pointer to structure */\r |
153 | \r | |
f0737de8 | 154 | typedef struct IByteIn IByteIn;\r |
1436aea4 MK |
155 | struct IByteIn {\r |
156 | Byte (*Read)(\r | |
157 | const IByteIn *p\r | |
158 | ); /* reads one byte, returns 0 in case of EOF or error */\r | |
f0737de8 | 159 | };\r |
1e230224 | 160 | \r |
1436aea4 | 161 | #define IByteIn_Read(p) (p)->Read(p)\r |
f0737de8 LG |
162 | \r |
163 | typedef struct IByteOut IByteOut;\r | |
1436aea4 MK |
164 | struct IByteOut {\r |
165 | void (*Write)(\r | |
166 | const IByteOut *p,\r | |
167 | Byte b\r | |
168 | );\r | |
f0737de8 | 169 | };\r |
1e230224 | 170 | \r |
1436aea4 | 171 | #define IByteOut_Write(p, b) (p)->Write(p, b)\r |
f0737de8 LG |
172 | \r |
173 | typedef struct ISeqInStream ISeqInStream;\r | |
1436aea4 MK |
174 | struct ISeqInStream {\r |
175 | SRes (*Read)(\r | |
176 | const ISeqInStream *p,\r | |
177 | void *buf,\r | |
178 | size_t *size\r | |
179 | );\r | |
180 | \r | |
181 | /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.\r | |
182 | (output(*size) < input(*size)) is allowed */\r | |
f0737de8 | 183 | };\r |
11ff2c71 | 184 | \r |
1436aea4 | 185 | #define ISeqInStream_Read(p, buf, size) (p)->Read(p, buf, size)\r |
11ff2c71 | 186 | \r |
1436aea4 MK |
187 | /* it can return SZ_ERROR_INPUT_EOF */\r |
188 | SRes\r | |
189 | SeqInStream_Read (\r | |
190 | const ISeqInStream *stream,\r | |
191 | void *buf,\r | |
192 | size_t size\r | |
193 | );\r | |
194 | \r | |
195 | SRes\r | |
196 | SeqInStream_Read2 (\r | |
197 | const ISeqInStream *stream,\r | |
198 | void *buf,\r | |
199 | size_t size,\r | |
200 | SRes errorType\r | |
201 | );\r | |
202 | \r | |
203 | SRes\r | |
204 | SeqInStream_ReadByte (\r | |
205 | const ISeqInStream *stream,\r | |
206 | Byte *buf\r | |
207 | );\r | |
f0737de8 LG |
208 | \r |
209 | typedef struct ISeqOutStream ISeqOutStream;\r | |
1436aea4 MK |
210 | struct ISeqOutStream {\r |
211 | size_t (*Write)(\r | |
212 | const ISeqOutStream *p,\r | |
213 | const void *buf,\r | |
214 | size_t size\r | |
215 | );\r | |
216 | \r | |
217 | /* Returns: result - the number of actually written bytes.\r | |
218 | (result < size) means error */\r | |
f0737de8 | 219 | };\r |
11ff2c71 | 220 | \r |
1436aea4 MK |
221 | #define ISeqOutStream_Write(p, buf, size) (p)->Write(p, buf, size)\r |
222 | \r | |
223 | typedef enum {\r | |
11ff2c71 LG |
224 | SZ_SEEK_SET = 0,\r |
225 | SZ_SEEK_CUR = 1,\r | |
226 | SZ_SEEK_END = 2\r | |
227 | } ESzSeek;\r | |
228 | \r | |
f0737de8 | 229 | typedef struct ISeekInStream ISeekInStream;\r |
1436aea4 MK |
230 | struct ISeekInStream {\r |
231 | SRes (*Read)(\r | |
232 | const ISeekInStream *p,\r | |
233 | void *buf,\r | |
234 | size_t *size\r | |
235 | ); /* same as ISeqInStream::Read */\r | |
236 | SRes (*Seek)(\r | |
237 | const ISeekInStream *p,\r | |
238 | Int64 *pos,\r | |
239 | ESzSeek origin\r | |
240 | );\r | |
f0737de8 | 241 | };\r |
11ff2c71 | 242 | \r |
1436aea4 MK |
243 | #define ISeekInStream_Read(p, buf, size) (p)->Read(p, buf, size)\r |
244 | #define ISeekInStream_Seek(p, pos, origin) (p)->Seek(p, pos, origin)\r | |
f0737de8 LG |
245 | \r |
246 | typedef struct ILookInStream ILookInStream;\r | |
1436aea4 MK |
247 | struct ILookInStream {\r |
248 | SRes (*Look)(\r | |
249 | const ILookInStream *p,\r | |
250 | const void **buf,\r | |
251 | size_t *size\r | |
252 | );\r | |
253 | \r | |
254 | /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.\r | |
255 | (output(*size) > input(*size)) is not allowed\r | |
256 | (output(*size) < input(*size)) is allowed */\r | |
257 | SRes (*Skip)(\r | |
258 | const ILookInStream *p,\r | |
259 | size_t offset\r | |
260 | );\r | |
261 | /* offset must be <= output(*size) of Look */\r | |
262 | \r | |
263 | SRes (*Read)(\r | |
264 | const ILookInStream *p,\r | |
265 | void *buf,\r | |
266 | size_t *size\r | |
267 | );\r | |
268 | /* reads directly (without buffer). It's same as ISeqInStream::Read */\r | |
269 | SRes (*Seek)(\r | |
270 | const ILookInStream *p,\r | |
271 | Int64 *pos,\r | |
272 | ESzSeek origin\r | |
273 | );\r | |
f0737de8 | 274 | };\r |
11ff2c71 | 275 | \r |
1436aea4 MK |
276 | #define ILookInStream_Look(p, buf, size) (p)->Look(p, buf, size)\r |
277 | #define ILookInStream_Skip(p, offset) (p)->Skip(p, offset)\r | |
278 | #define ILookInStream_Read(p, buf, size) (p)->Read(p, buf, size)\r | |
279 | #define ILookInStream_Seek(p, pos, origin) (p)->Seek(p, pos, origin)\r | |
f0737de8 | 280 | \r |
1436aea4 MK |
281 | SRes\r |
282 | LookInStream_LookRead (\r | |
283 | const ILookInStream *stream,\r | |
284 | void *buf,\r | |
285 | size_t *size\r | |
286 | );\r | |
f0737de8 | 287 | \r |
1436aea4 MK |
288 | SRes\r |
289 | LookInStream_SeekTo (\r | |
290 | const ILookInStream *stream,\r | |
291 | UInt64 offset\r | |
292 | );\r | |
11ff2c71 LG |
293 | \r |
294 | /* reads via ILookInStream::Read */\r | |
1436aea4 MK |
295 | SRes\r |
296 | LookInStream_Read2 (\r | |
297 | const ILookInStream *stream,\r | |
298 | void *buf,\r | |
299 | size_t size,\r | |
300 | SRes errorType\r | |
301 | );\r | |
302 | \r | |
303 | SRes\r | |
304 | LookInStream_Read (\r | |
305 | const ILookInStream *stream,\r | |
306 | void *buf,\r | |
307 | size_t size\r | |
308 | );\r | |
309 | \r | |
310 | typedef struct {\r | |
311 | ILookInStream vt;\r | |
312 | const ISeekInStream *realStream;\r | |
313 | \r | |
314 | size_t pos;\r | |
315 | size_t size; /* it's data size */\r | |
ba39402f | 316 | \r |
f0737de8 | 317 | /* the following variables must be set outside */\r |
1436aea4 MK |
318 | Byte *buf;\r |
319 | size_t bufSize;\r | |
f0737de8 LG |
320 | } CLookToRead2;\r |
321 | \r | |
1436aea4 MK |
322 | void\r |
323 | LookToRead2_CreateVTable (\r | |
324 | CLookToRead2 *p,\r | |
325 | int lookahead\r | |
326 | );\r | |
11ff2c71 | 327 | \r |
1436aea4 | 328 | #define LookToRead2_Init(p) { (p)->pos = (p)->size = 0; }\r |
11ff2c71 | 329 | \r |
1436aea4 MK |
330 | typedef struct {\r |
331 | ISeqInStream vt;\r | |
332 | const ILookInStream *realStream;\r | |
11ff2c71 LG |
333 | } CSecToLook;\r |
334 | \r | |
1436aea4 MK |
335 | void\r |
336 | SecToLook_CreateVTable (\r | |
337 | CSecToLook *p\r | |
338 | );\r | |
11ff2c71 | 339 | \r |
1436aea4 MK |
340 | typedef struct {\r |
341 | ISeqInStream vt;\r | |
342 | const ILookInStream *realStream;\r | |
11ff2c71 LG |
343 | } CSecToRead;\r |
344 | \r | |
1436aea4 MK |
345 | void\r |
346 | SecToRead_CreateVTable (\r | |
347 | CSecToRead *p\r | |
348 | );\r | |
f0737de8 LG |
349 | \r |
350 | typedef struct ICompressProgress ICompressProgress;\r | |
351 | \r | |
1436aea4 MK |
352 | struct ICompressProgress {\r |
353 | SRes (*Progress)(\r | |
354 | const ICompressProgress *p,\r | |
355 | UInt64 inSize,\r | |
356 | UInt64 outSize\r | |
357 | );\r | |
11ff2c71 | 358 | \r |
1436aea4 MK |
359 | /* Returns: result. (result != SZ_OK) means break.\r |
360 | Value (UInt64)(Int64)-1 for size means unknown value. */\r | |
361 | };\r | |
f0737de8 | 362 | \r |
1436aea4 | 363 | #define ICompressProgress_Progress(p, inSize, outSize) (p)->Progress(p, inSize, outSize)\r |
f0737de8 LG |
364 | \r |
365 | typedef struct ISzAlloc ISzAlloc;\r | |
1436aea4 MK |
366 | typedef const ISzAlloc *ISzAllocPtr;\r |
367 | \r | |
368 | struct ISzAlloc {\r | |
369 | void *(*Alloc)(\r | |
370 | ISzAllocPtr p,\r | |
371 | size_t size\r | |
372 | );\r | |
373 | void (*Free)(\r | |
374 | ISzAllocPtr p,\r | |
375 | void *address\r | |
376 | ); /* address can be 0 */\r | |
f0737de8 LG |
377 | };\r |
378 | \r | |
1436aea4 MK |
379 | #define ISzAlloc_Alloc(p, size) (p)->Alloc(p, size)\r |
380 | #define ISzAlloc_Free(p, a) (p)->Free(p, a)\r | |
f0737de8 LG |
381 | \r |
382 | /* deprecated */\r | |
1436aea4 MK |
383 | #define IAlloc_Alloc(p, size) ISzAlloc_Alloc(p, size)\r |
384 | #define IAlloc_Free(p, a) ISzAlloc_Free(p, a)\r | |
f0737de8 LG |
385 | \r |
386 | #ifndef MY_offsetof\r | |
387 | #ifdef offsetof\r | |
1436aea4 MK |
388 | #define MY_offsetof(type, m) offsetof(type, m)\r |
389 | \r | |
390 | /*\r | |
391 | #define MY_offsetof(type, m) FIELD_OFFSET(type, m)\r | |
392 | */\r | |
f0737de8 | 393 | #else\r |
1436aea4 | 394 | #define MY_offsetof(type, m) ((size_t)&(((type *)0)->m))\r |
f0737de8 LG |
395 | #endif\r |
396 | #endif\r | |
397 | \r | |
f0737de8 LG |
398 | #ifndef MY_container_of\r |
399 | \r | |
400 | /*\r | |
401 | #define MY_container_of(ptr, type, m) container_of(ptr, type, m)\r | |
402 | #define MY_container_of(ptr, type, m) CONTAINING_RECORD(ptr, type, m)\r | |
403 | #define MY_container_of(ptr, type, m) ((type *)((char *)(ptr) - offsetof(type, m)))\r | |
404 | #define MY_container_of(ptr, type, m) (&((type *)0)->m == (ptr), ((type *)(((char *)(ptr)) - MY_offsetof(type, m))))\r | |
405 | */\r | |
406 | \r | |
407 | /*\r | |
408 | GCC shows warning: "perhaps the 'offsetof' macro was used incorrectly"\r | |
409 | GCC 3.4.4 : classes with constructor\r | |
410 | GCC 4.8.1 : classes with non-public variable members"\r | |
411 | */\r | |
412 | \r | |
1436aea4 | 413 | #define MY_container_of(ptr, type, m) ((type *)((char *)(1 ? (ptr) : &((type *)0)->m) - MY_offsetof(type, m)))\r |
f0737de8 LG |
414 | \r |
415 | #endif\r | |
416 | \r | |
1436aea4 | 417 | #define CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m) ((type *)(ptr))\r |
f0737de8 LG |
418 | \r |
419 | /*\r | |
420 | #define CONTAINER_FROM_VTBL(ptr, type, m) CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m)\r | |
421 | */\r | |
1436aea4 MK |
422 | #define CONTAINER_FROM_VTBL(ptr, type, m) MY_container_of(ptr, type, m)\r |
423 | \r | |
424 | #define CONTAINER_FROM_VTBL_CLS(ptr, type, m) CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m)\r | |
f0737de8 | 425 | \r |
f0737de8 LG |
426 | /*\r |
427 | #define CONTAINER_FROM_VTBL_CLS(ptr, type, m) CONTAINER_FROM_VTBL(ptr, type, m)\r | |
428 | */\r | |
429 | \r | |
1e230224 LG |
430 | #ifdef _WIN32\r |
431 | \r | |
1436aea4 MK |
432 | #define CHAR_PATH_SEPARATOR '\\'\r |
433 | #define WCHAR_PATH_SEPARATOR L'\\'\r | |
434 | #define STRING_PATH_SEPARATOR "\\"\r | |
435 | #define WSTRING_PATH_SEPARATOR L"\\"\r | |
1e230224 LG |
436 | \r |
437 | #else\r | |
438 | \r | |
1436aea4 MK |
439 | #define CHAR_PATH_SEPARATOR '/'\r |
440 | #define WCHAR_PATH_SEPARATOR L'/'\r | |
441 | #define STRING_PATH_SEPARATOR "/"\r | |
442 | #define WSTRING_PATH_SEPARATOR L"/"\r | |
1e230224 LG |
443 | \r |
444 | #endif\r | |
445 | \r | |
446 | EXTERN_C_END\r | |
447 | \r | |
11ff2c71 | 448 | #endif\r |