1 /* 7zTypes.h -- Basic types
2 2017-07-17 : 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
52 /* typedef DWORD WRes; */
53 typedef unsigned WRes
;
54 #define MY_SRes_HRESULT_FROM_WRes(x) HRESULT_FROM_WIN32(x)
59 #define MY__FACILITY_WIN32 7
60 #define MY__FACILITY__WRes MY__FACILITY_WIN32
61 #define MY_SRes_HRESULT_FROM_WRes(x) ((HRESULT)(x) <= 0 ? ((HRESULT)(x)) : ((HRESULT) (((x) & 0x0000FFFF) | (MY__FACILITY__WRes << 16) | 0x80000000)))
67 #define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; }
70 typedef unsigned char Byte
;
72 typedef unsigned short UInt16
;
74 #ifdef _LZMA_UINT32_IS_ULONG
76 typedef unsigned long UInt32
;
79 typedef unsigned int UInt32
;
84 /* define _SZ_NO_INT_64, if your compiler doesn't support 64-bit integers.
85 NOTES: Some code will work incorrectly in that case! */
88 typedef unsigned long UInt64
;
92 #if defined(_MSC_VER) || defined(__BORLANDC__)
93 typedef __int64 Int64
;
94 typedef unsigned __int64 UInt64
;
95 #define UINT64_CONST(n) n
97 typedef long long int Int64
;
98 typedef unsigned long long int UInt64
;
99 #define UINT64_CONST(n) n ## ULL
104 #ifdef _LZMA_NO_SYSTEM_SIZE_T
105 typedef UInt32 SizeT
;
107 typedef size_t SizeT
;
116 #define MY_STD_CALL __stdcall
124 #define MY_NO_INLINE __declspec(noinline)
129 #define MY_FORCE_INLINE __forceinline
131 #define MY_CDECL __cdecl
132 #define MY_FAST_CALL __fastcall
137 #define MY_FORCE_INLINE
141 /* inline keyword : for C++ / C99 */
145 #if defined (__GNUC__) && (__GNUC__ >= 4)
146 #define MY_FORCE_INLINE __attribute__((always_inline))
147 #define MY_NO_INLINE __attribute__((noinline))
154 /* The following interfaces use first parameter as pointer to structure */
156 typedef struct IByteIn IByteIn
;
159 Byte (*Read
)(const IByteIn
*p
); /* reads one byte, returns 0 in case of EOF or error */
161 #define IByteIn_Read(p) (p)->Read(p)
164 typedef struct IByteOut IByteOut
;
167 void (*Write
)(const IByteOut
*p
, Byte b
);
169 #define IByteOut_Write(p, b) (p)->Write(p, b)
172 typedef struct ISeqInStream ISeqInStream
;
175 SRes (*Read
)(const ISeqInStream
*p
, void *buf
, size_t *size
);
176 /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
177 (output(*size) < input(*size)) is allowed */
179 #define ISeqInStream_Read(p, buf, size) (p)->Read(p, buf, size)
181 /* it can return SZ_ERROR_INPUT_EOF */
182 SRes
SeqInStream_Read(const ISeqInStream
*stream
, void *buf
, size_t size
);
183 SRes
SeqInStream_Read2(const ISeqInStream
*stream
, void *buf
, size_t size
, SRes errorType
);
184 SRes
SeqInStream_ReadByte(const ISeqInStream
*stream
, Byte
*buf
);
187 typedef struct ISeqOutStream ISeqOutStream
;
190 size_t (*Write
)(const ISeqOutStream
*p
, const void *buf
, size_t size
);
191 /* Returns: result - the number of actually written bytes.
192 (result < size) means error */
194 #define ISeqOutStream_Write(p, buf, size) (p)->Write(p, buf, size)
204 typedef struct ISeekInStream ISeekInStream
;
207 SRes (*Read
)(const ISeekInStream
*p
, void *buf
, size_t *size
); /* same as ISeqInStream::Read */
208 SRes (*Seek
)(const ISeekInStream
*p
, Int64
*pos
, ESzSeek origin
);
210 #define ISeekInStream_Read(p, buf, size) (p)->Read(p, buf, size)
211 #define ISeekInStream_Seek(p, pos, origin) (p)->Seek(p, pos, origin)
214 typedef struct ILookInStream ILookInStream
;
217 SRes (*Look
)(const ILookInStream
*p
, const void **buf
, size_t *size
);
218 /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
219 (output(*size) > input(*size)) is not allowed
220 (output(*size) < input(*size)) is allowed */
221 SRes (*Skip
)(const ILookInStream
*p
, size_t offset
);
222 /* offset must be <= output(*size) of Look */
224 SRes (*Read
)(const ILookInStream
*p
, void *buf
, size_t *size
);
225 /* reads directly (without buffer). It's same as ISeqInStream::Read */
226 SRes (*Seek
)(const ILookInStream
*p
, Int64
*pos
, ESzSeek origin
);
229 #define ILookInStream_Look(p, buf, size) (p)->Look(p, buf, size)
230 #define ILookInStream_Skip(p, offset) (p)->Skip(p, offset)
231 #define ILookInStream_Read(p, buf, size) (p)->Read(p, buf, size)
232 #define ILookInStream_Seek(p, pos, origin) (p)->Seek(p, pos, origin)
235 SRes
LookInStream_LookRead(const ILookInStream
*stream
, void *buf
, size_t *size
);
236 SRes
LookInStream_SeekTo(const ILookInStream
*stream
, UInt64 offset
);
238 /* reads via ILookInStream::Read */
239 SRes
LookInStream_Read2(const ILookInStream
*stream
, void *buf
, size_t size
, SRes errorType
);
240 SRes
LookInStream_Read(const ILookInStream
*stream
, void *buf
, size_t size
);
247 const ISeekInStream
*realStream
;
250 size_t size
; /* it's data size */
252 /* the following variables must be set outside */
257 void LookToRead2_CreateVTable(CLookToRead2
*p
, int lookahead
);
259 #define LookToRead2_Init(p) { (p)->pos = (p)->size = 0; }
265 const ILookInStream
*realStream
;
268 void SecToLook_CreateVTable(CSecToLook
*p
);
275 const ILookInStream
*realStream
;
278 void SecToRead_CreateVTable(CSecToRead
*p
);
281 typedef struct ICompressProgress ICompressProgress
;
283 struct ICompressProgress
285 SRes (*Progress
)(const ICompressProgress
*p
, UInt64 inSize
, UInt64 outSize
);
286 /* Returns: result. (result != SZ_OK) means break.
287 Value (UInt64)(Int64)-1 for size means unknown value. */
289 #define ICompressProgress_Progress(p, inSize, outSize) (p)->Progress(p, inSize, outSize)
293 typedef struct ISzAlloc ISzAlloc
;
294 typedef const ISzAlloc
* ISzAllocPtr
;
298 void *(*Alloc
)(ISzAllocPtr p
, size_t size
);
299 void (*Free
)(ISzAllocPtr p
, void *address
); /* address can be 0 */
302 #define ISzAlloc_Alloc(p, size) (p)->Alloc(p, size)
303 #define ISzAlloc_Free(p, a) (p)->Free(p, a)
306 #define IAlloc_Alloc(p, size) ISzAlloc_Alloc(p, size)
307 #define IAlloc_Free(p, a) ISzAlloc_Free(p, a)
315 #define MY_offsetof(type, m) offsetof(type, m)
317 #define MY_offsetof(type, m) FIELD_OFFSET(type, m)
320 #define MY_offsetof(type, m) ((size_t)&(((type *)0)->m))
326 #ifndef MY_container_of
329 #define MY_container_of(ptr, type, m) container_of(ptr, type, m)
330 #define MY_container_of(ptr, type, m) CONTAINING_RECORD(ptr, type, m)
331 #define MY_container_of(ptr, type, m) ((type *)((char *)(ptr) - offsetof(type, m)))
332 #define MY_container_of(ptr, type, m) (&((type *)0)->m == (ptr), ((type *)(((char *)(ptr)) - MY_offsetof(type, m))))
336 GCC shows warning: "perhaps the 'offsetof' macro was used incorrectly"
337 GCC 3.4.4 : classes with constructor
338 GCC 4.8.1 : classes with non-public variable members"
341 #define MY_container_of(ptr, type, m) ((type *)((char *)(1 ? (ptr) : &((type *)0)->m) - MY_offsetof(type, m)))
346 #define CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m) ((type *)(ptr))
349 #define CONTAINER_FROM_VTBL(ptr, type, m) CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m)
351 #define CONTAINER_FROM_VTBL(ptr, type, m) MY_container_of(ptr, type, m)
353 #define CONTAINER_FROM_VTBL_CLS(ptr, type, m) CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m)
355 #define CONTAINER_FROM_VTBL_CLS(ptr, type, m) CONTAINER_FROM_VTBL(ptr, type, m)
362 #define CHAR_PATH_SEPARATOR '\\'
363 #define WCHAR_PATH_SEPARATOR L'\\'
364 #define STRING_PATH_SEPARATOR "\\"
365 #define WSTRING_PATH_SEPARATOR L"\\"
369 #define CHAR_PATH_SEPARATOR '/'
370 #define WCHAR_PATH_SEPARATOR L'/'
371 #define STRING_PATH_SEPARATOR "/"
372 #define WSTRING_PATH_SEPARATOR L"/"