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
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
;
111 /* typedef BoolInt Bool; */
117 #define MY_STD_CALL __stdcall
122 #if defined(_MSC_VER) && !defined(__clang__)
125 #define MY_NO_INLINE __declspec(noinline)
130 #define MY_FORCE_INLINE __forceinline
132 #define MY_CDECL __cdecl
133 #define MY_FAST_CALL __fastcall
138 #define MY_FORCE_INLINE
142 /* inline keyword : for C++ / C99 */
146 #if defined (__GNUC__) && (__GNUC__ >= 4)
147 #define MY_FORCE_INLINE __attribute__((always_inline))
148 #define MY_NO_INLINE __attribute__((noinline))
155 /* The following interfaces use first parameter as pointer to structure */
157 typedef struct IByteIn IByteIn
;
160 Byte (*Read
)(const IByteIn
*p
); /* reads one byte, returns 0 in case of EOF or error */
162 #define IByteIn_Read(p) (p)->Read(p)
165 typedef struct IByteOut IByteOut
;
168 void (*Write
)(const IByteOut
*p
, Byte b
);
170 #define IByteOut_Write(p, b) (p)->Write(p, b)
173 typedef struct ISeqInStream ISeqInStream
;
176 SRes (*Read
)(const ISeqInStream
*p
, void *buf
, size_t *size
);
177 /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
178 (output(*size) < input(*size)) is allowed */
180 #define ISeqInStream_Read(p, buf, size) (p)->Read(p, buf, size)
182 /* it can return SZ_ERROR_INPUT_EOF */
183 SRes
SeqInStream_Read(const ISeqInStream
*stream
, void *buf
, size_t size
);
184 SRes
SeqInStream_Read2(const ISeqInStream
*stream
, void *buf
, size_t size
, SRes errorType
);
185 SRes
SeqInStream_ReadByte(const ISeqInStream
*stream
, Byte
*buf
);
188 typedef struct ISeqOutStream ISeqOutStream
;
191 size_t (*Write
)(const ISeqOutStream
*p
, const void *buf
, size_t size
);
192 /* Returns: result - the number of actually written bytes.
193 (result < size) means error */
195 #define ISeqOutStream_Write(p, buf, size) (p)->Write(p, buf, size)
205 typedef struct ISeekInStream ISeekInStream
;
208 SRes (*Read
)(const ISeekInStream
*p
, void *buf
, size_t *size
); /* same as ISeqInStream::Read */
209 SRes (*Seek
)(const ISeekInStream
*p
, Int64
*pos
, ESzSeek origin
);
211 #define ISeekInStream_Read(p, buf, size) (p)->Read(p, buf, size)
212 #define ISeekInStream_Seek(p, pos, origin) (p)->Seek(p, pos, origin)
215 typedef struct ILookInStream ILookInStream
;
218 SRes (*Look
)(const ILookInStream
*p
, const void **buf
, size_t *size
);
219 /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
220 (output(*size) > input(*size)) is not allowed
221 (output(*size) < input(*size)) is allowed */
222 SRes (*Skip
)(const ILookInStream
*p
, size_t offset
);
223 /* offset must be <= output(*size) of Look */
225 SRes (*Read
)(const ILookInStream
*p
, void *buf
, size_t *size
);
226 /* reads directly (without buffer). It's same as ISeqInStream::Read */
227 SRes (*Seek
)(const ILookInStream
*p
, Int64
*pos
, ESzSeek origin
);
230 #define ILookInStream_Look(p, buf, size) (p)->Look(p, buf, size)
231 #define ILookInStream_Skip(p, offset) (p)->Skip(p, offset)
232 #define ILookInStream_Read(p, buf, size) (p)->Read(p, buf, size)
233 #define ILookInStream_Seek(p, pos, origin) (p)->Seek(p, pos, origin)
236 SRes
LookInStream_LookRead(const ILookInStream
*stream
, void *buf
, size_t *size
);
237 SRes
LookInStream_SeekTo(const ILookInStream
*stream
, UInt64 offset
);
239 /* reads via ILookInStream::Read */
240 SRes
LookInStream_Read2(const ILookInStream
*stream
, void *buf
, size_t size
, SRes errorType
);
241 SRes
LookInStream_Read(const ILookInStream
*stream
, void *buf
, size_t size
);
248 const ISeekInStream
*realStream
;
251 size_t size
; /* it's data size */
253 /* the following variables must be set outside */
258 void LookToRead2_CreateVTable(CLookToRead2
*p
, int lookahead
);
260 #define LookToRead2_Init(p) { (p)->pos = (p)->size = 0; }
266 const ILookInStream
*realStream
;
269 void SecToLook_CreateVTable(CSecToLook
*p
);
276 const ILookInStream
*realStream
;
279 void SecToRead_CreateVTable(CSecToRead
*p
);
282 typedef struct ICompressProgress ICompressProgress
;
284 struct ICompressProgress
286 SRes (*Progress
)(const ICompressProgress
*p
, UInt64 inSize
, UInt64 outSize
);
287 /* Returns: result. (result != SZ_OK) means break.
288 Value (UInt64)(Int64)-1 for size means unknown value. */
290 #define ICompressProgress_Progress(p, inSize, outSize) (p)->Progress(p, inSize, outSize)
294 typedef struct ISzAlloc ISzAlloc
;
295 typedef const ISzAlloc
* ISzAllocPtr
;
299 void *(*Alloc
)(ISzAllocPtr p
, size_t size
);
300 void (*Free
)(ISzAllocPtr p
, void *address
); /* address can be 0 */
303 #define ISzAlloc_Alloc(p, size) (p)->Alloc(p, size)
304 #define ISzAlloc_Free(p, a) (p)->Free(p, a)
307 #define IAlloc_Alloc(p, size) ISzAlloc_Alloc(p, size)
308 #define IAlloc_Free(p, a) ISzAlloc_Free(p, a)
316 #define MY_offsetof(type, m) offsetof(type, m)
318 #define MY_offsetof(type, m) FIELD_OFFSET(type, m)
321 #define MY_offsetof(type, m) ((size_t)&(((type *)0)->m))
327 #ifndef MY_container_of
330 #define MY_container_of(ptr, type, m) container_of(ptr, type, m)
331 #define MY_container_of(ptr, type, m) CONTAINING_RECORD(ptr, type, m)
332 #define MY_container_of(ptr, type, m) ((type *)((char *)(ptr) - offsetof(type, m)))
333 #define MY_container_of(ptr, type, m) (&((type *)0)->m == (ptr), ((type *)(((char *)(ptr)) - MY_offsetof(type, m))))
337 GCC shows warning: "perhaps the 'offsetof' macro was used incorrectly"
338 GCC 3.4.4 : classes with constructor
339 GCC 4.8.1 : classes with non-public variable members"
342 #define MY_container_of(ptr, type, m) ((type *)((char *)(1 ? (ptr) : &((type *)0)->m) - MY_offsetof(type, m)))
347 #define CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m) ((type *)(ptr))
350 #define CONTAINER_FROM_VTBL(ptr, type, m) CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m)
352 #define CONTAINER_FROM_VTBL(ptr, type, m) MY_container_of(ptr, type, m)
354 #define CONTAINER_FROM_VTBL_CLS(ptr, type, m) CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m)
356 #define CONTAINER_FROM_VTBL_CLS(ptr, type, m) CONTAINER_FROM_VTBL(ptr, type, m)
363 #define CHAR_PATH_SEPARATOR '\\'
364 #define WCHAR_PATH_SEPARATOR L'\\'
365 #define STRING_PATH_SEPARATOR "\\"
366 #define WSTRING_PATH_SEPARATOR L"\\"
370 #define CHAR_PATH_SEPARATOR '/'
371 #define WCHAR_PATH_SEPARATOR L'/'
372 #define STRING_PATH_SEPARATOR "/"
373 #define WSTRING_PATH_SEPARATOR L"/"