1 /* 7zTypes.h -- Basic types
2 2018-08-04 : Igor Pavlov : Public domain */
8 /* #include <windows.h> */
17 #ifndef EXTERN_C_BEGIN
19 #define EXTERN_C_BEGIN extern "C" {
20 #define EXTERN_C_END }
22 #define EXTERN_C_BEGIN
31 #define SZ_ERROR_DATA 1
32 #define SZ_ERROR_MEM 2
33 #define SZ_ERROR_CRC 3
34 #define SZ_ERROR_UNSUPPORTED 4
35 #define SZ_ERROR_PARAM 5
36 #define SZ_ERROR_INPUT_EOF 6
37 #define SZ_ERROR_OUTPUT_EOF 7
38 #define SZ_ERROR_READ 8
39 #define SZ_ERROR_WRITE 9
40 #define SZ_ERROR_PROGRESS 10
41 #define SZ_ERROR_FAIL 11
42 #define SZ_ERROR_THREAD 12
44 #define SZ_ERROR_ARCHIVE 16
45 #define SZ_ERROR_NO_ARCHIVE 17
51 /* typedef DWORD WRes; */
52 typedef unsigned WRes
;
53 #define MY_SRes_HRESULT_FROM_WRes(x) HRESULT_FROM_WIN32(x)
58 #define MY__FACILITY_WIN32 7
59 #define MY__FACILITY__WRes MY__FACILITY_WIN32
60 #define MY_SRes_HRESULT_FROM_WRes(x) ((HRESULT)(x) <= 0 ? ((HRESULT)(x)) : ((HRESULT) (((x) & 0x0000FFFF) | (MY__FACILITY__WRes << 16) | 0x80000000)))
65 #define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; }
68 typedef unsigned char Byte
;
70 typedef unsigned short UInt16
;
72 #ifdef _LZMA_UINT32_IS_ULONG
74 typedef unsigned long UInt32
;
77 typedef unsigned int UInt32
;
82 /* define _SZ_NO_INT_64, if your compiler doesn't support 64-bit integers.
83 NOTES: Some code will work incorrectly in that case! */
86 typedef unsigned long UInt64
;
90 #if defined (_MSC_VER) || defined (__BORLANDC__)
91 typedef __int64 Int64
;
92 typedef unsigned __int64 UInt64
;
93 #define UINT64_CONST(n) n
95 typedef long long int Int64
;
96 typedef unsigned long long int UInt64
;
97 #define UINT64_CONST(n) n ## ULL
102 #ifdef _LZMA_NO_SYSTEM_SIZE_T
103 typedef UInt32 SizeT
;
105 typedef size_t SizeT
;
109 /* typedef BoolInt Bool; */
114 #define MY_STD_CALL __stdcall
119 #if defined (_MSC_VER) && !defined (__clang__)
122 #define MY_NO_INLINE __declspec(noinline)
127 #define MY_FORCE_INLINE __forceinline
129 #define MY_CDECL __cdecl
130 #define MY_FAST_CALL __fastcall
135 #define MY_FORCE_INLINE
139 /* inline keyword : for C++ / C99 */
144 #if defined (__GNUC__) && (__GNUC__ >= 4)
145 #define MY_FORCE_INLINE __attribute__((always_inline))
146 #define MY_NO_INLINE __attribute__((noinline))
152 /* The following interfaces use first parameter as pointer to structure */
154 typedef struct IByteIn IByteIn
;
158 ); /* reads one byte, returns 0 in case of EOF or error */
161 #define IByteIn_Read(p) (p)->Read(p)
163 typedef struct IByteOut IByteOut
;
171 #define IByteOut_Write(p, b) (p)->Write(p, b)
173 typedef struct ISeqInStream ISeqInStream
;
174 struct ISeqInStream
{
176 const ISeqInStream
*p
,
181 /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
182 (output(*size) < input(*size)) is allowed */
185 #define ISeqInStream_Read(p, buf, size) (p)->Read(p, buf, size)
187 /* it can return SZ_ERROR_INPUT_EOF */
190 const ISeqInStream
*stream
,
197 const ISeqInStream
*stream
,
204 SeqInStream_ReadByte (
205 const ISeqInStream
*stream
,
209 typedef struct ISeqOutStream ISeqOutStream
;
210 struct ISeqOutStream
{
212 const ISeqOutStream
*p
,
217 /* Returns: result - the number of actually written bytes.
218 (result < size) means error */
221 #define ISeqOutStream_Write(p, buf, size) (p)->Write(p, buf, size)
229 typedef struct ISeekInStream ISeekInStream
;
230 struct ISeekInStream
{
232 const ISeekInStream
*p
,
235 ); /* same as ISeqInStream::Read */
237 const ISeekInStream
*p
,
243 #define ISeekInStream_Read(p, buf, size) (p)->Read(p, buf, size)
244 #define ISeekInStream_Seek(p, pos, origin) (p)->Seek(p, pos, origin)
246 typedef struct ILookInStream ILookInStream
;
247 struct ILookInStream
{
249 const ILookInStream
*p
,
254 /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
255 (output(*size) > input(*size)) is not allowed
256 (output(*size) < input(*size)) is allowed */
258 const ILookInStream
*p
,
261 /* offset must be <= output(*size) of Look */
264 const ILookInStream
*p
,
268 /* reads directly (without buffer). It's same as ISeqInStream::Read */
270 const ILookInStream
*p
,
276 #define ILookInStream_Look(p, buf, size) (p)->Look(p, buf, size)
277 #define ILookInStream_Skip(p, offset) (p)->Skip(p, offset)
278 #define ILookInStream_Read(p, buf, size) (p)->Read(p, buf, size)
279 #define ILookInStream_Seek(p, pos, origin) (p)->Seek(p, pos, origin)
282 LookInStream_LookRead (
283 const ILookInStream
*stream
,
289 LookInStream_SeekTo (
290 const ILookInStream
*stream
,
294 /* reads via ILookInStream::Read */
297 const ILookInStream
*stream
,
305 const ILookInStream
*stream
,
312 const ISeekInStream
*realStream
;
315 size_t size
; /* it's data size */
317 /* the following variables must be set outside */
323 LookToRead2_CreateVTable (
328 #define LookToRead2_Init(p) { (p)->pos = (p)->size = 0; }
332 const ILookInStream
*realStream
;
336 SecToLook_CreateVTable (
342 const ILookInStream
*realStream
;
346 SecToRead_CreateVTable (
350 typedef struct ICompressProgress ICompressProgress
;
352 struct ICompressProgress
{
354 const ICompressProgress
*p
,
359 /* Returns: result. (result != SZ_OK) means break.
360 Value (UInt64)(Int64)-1 for size means unknown value. */
363 #define ICompressProgress_Progress(p, inSize, outSize) (p)->Progress(p, inSize, outSize)
365 typedef struct ISzAlloc ISzAlloc
;
366 typedef const ISzAlloc
*ISzAllocPtr
;
376 ); /* address can be 0 */
379 #define ISzAlloc_Alloc(p, size) (p)->Alloc(p, size)
380 #define ISzAlloc_Free(p, a) (p)->Free(p, a)
383 #define IAlloc_Alloc(p, size) ISzAlloc_Alloc(p, size)
384 #define IAlloc_Free(p, a) ISzAlloc_Free(p, a)
388 #define MY_offsetof(type, m) offsetof(type, m)
391 #define MY_offsetof(type, m) FIELD_OFFSET(type, m)
394 #define MY_offsetof(type, m) ((size_t)&(((type *)0)->m))
398 #ifndef MY_container_of
401 #define MY_container_of(ptr, type, m) container_of(ptr, type, m)
402 #define MY_container_of(ptr, type, m) CONTAINING_RECORD(ptr, type, m)
403 #define MY_container_of(ptr, type, m) ((type *)((char *)(ptr) - offsetof(type, m)))
404 #define MY_container_of(ptr, type, m) (&((type *)0)->m == (ptr), ((type *)(((char *)(ptr)) - MY_offsetof(type, m))))
408 GCC shows warning: "perhaps the 'offsetof' macro was used incorrectly"
409 GCC 3.4.4 : classes with constructor
410 GCC 4.8.1 : classes with non-public variable members"
413 #define MY_container_of(ptr, type, m) ((type *)((char *)(1 ? (ptr) : &((type *)0)->m) - MY_offsetof(type, m)))
417 #define CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m) ((type *)(ptr))
420 #define CONTAINER_FROM_VTBL(ptr, type, m) CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m)
422 #define CONTAINER_FROM_VTBL(ptr, type, m) MY_container_of(ptr, type, m)
424 #define CONTAINER_FROM_VTBL_CLS(ptr, type, m) CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m)
427 #define CONTAINER_FROM_VTBL_CLS(ptr, type, m) CONTAINER_FROM_VTBL(ptr, type, m)
432 #define CHAR_PATH_SEPARATOR '\\'
433 #define WCHAR_PATH_SEPARATOR L'\\'
434 #define STRING_PATH_SEPARATOR "\\"
435 #define WSTRING_PATH_SEPARATOR L"\\"
439 #define CHAR_PATH_SEPARATOR '/'
440 #define WCHAR_PATH_SEPARATOR L'/'
441 #define STRING_PATH_SEPARATOR "/"
442 #define WSTRING_PATH_SEPARATOR L"/"