1 /* 7zTypes.h -- Basic types
2 2017-07-17 : Igor Pavlov : Public domain */
8 /* #include <windows.h> */
13 #ifndef EXTERN_C_BEGIN
15 #define EXTERN_C_BEGIN extern "C" {
16 #define EXTERN_C_END }
18 #define EXTERN_C_BEGIN
27 #define SZ_ERROR_DATA 1
28 #define SZ_ERROR_MEM 2
29 #define SZ_ERROR_CRC 3
30 #define SZ_ERROR_UNSUPPORTED 4
31 #define SZ_ERROR_PARAM 5
32 #define SZ_ERROR_INPUT_EOF 6
33 #define SZ_ERROR_OUTPUT_EOF 7
34 #define SZ_ERROR_READ 8
35 #define SZ_ERROR_WRITE 9
36 #define SZ_ERROR_PROGRESS 10
37 #define SZ_ERROR_FAIL 11
38 #define SZ_ERROR_THREAD 12
40 #define SZ_ERROR_ARCHIVE 16
41 #define SZ_ERROR_NO_ARCHIVE 17
48 /* typedef DWORD WRes; */
49 typedef unsigned WRes
;
50 #define MY_SRes_HRESULT_FROM_WRes(x) HRESULT_FROM_WIN32(x)
55 #define MY__FACILITY_WIN32 7
56 #define MY__FACILITY__WRes MY__FACILITY_WIN32
57 #define MY_SRes_HRESULT_FROM_WRes(x) ((HRESULT)(x) <= 0 ? ((HRESULT)(x)) : ((HRESULT) (((x) & 0x0000FFFF) | (MY__FACILITY__WRes << 16) | 0x80000000)))
63 #define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; }
66 typedef unsigned char Byte
;
68 typedef unsigned short UInt16
;
70 #ifdef _LZMA_UINT32_IS_ULONG
72 typedef unsigned long UInt32
;
75 typedef unsigned int UInt32
;
80 /* define _SZ_NO_INT_64, if your compiler doesn't support 64-bit integers.
81 NOTES: Some code will work incorrectly in that case! */
84 typedef unsigned long UInt64
;
88 #if defined(_MSC_VER) || defined(__BORLANDC__)
89 typedef __int64 Int64
;
90 typedef unsigned __int64 UInt64
;
91 #define UINT64_CONST(n) n
93 typedef long long int Int64
;
94 typedef unsigned long long int UInt64
;
95 #define UINT64_CONST(n) n ## ULL
100 #ifdef _LZMA_NO_SYSTEM_SIZE_T
101 typedef UInt32 SizeT
;
103 typedef size_t SizeT
;
112 #define MY_STD_CALL __stdcall
120 #define MY_NO_INLINE __declspec(noinline)
125 #define MY_FORCE_INLINE __forceinline
127 #define MY_CDECL __cdecl
128 #define MY_FAST_CALL __fastcall
133 #define MY_FORCE_INLINE
137 /* inline keyword : for C++ / C99 */
141 #if defined (__GNUC__) && (__GNUC__ >= 4)
142 #define MY_FORCE_INLINE __attribute__((always_inline))
143 #define MY_NO_INLINE __attribute__((noinline))
150 /* The following interfaces use first parameter as pointer to structure */
152 typedef struct IByteIn IByteIn
;
155 Byte (*Read
)(const IByteIn
*p
); /* reads one byte, returns 0 in case of EOF or error */
157 #define IByteIn_Read(p) (p)->Read(p)
160 typedef struct IByteOut IByteOut
;
163 void (*Write
)(const IByteOut
*p
, Byte b
);
165 #define IByteOut_Write(p, b) (p)->Write(p, b)
168 typedef struct ISeqInStream ISeqInStream
;
171 SRes (*Read
)(const ISeqInStream
*p
, void *buf
, size_t *size
);
172 /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
173 (output(*size) < input(*size)) is allowed */
175 #define ISeqInStream_Read(p, buf, size) (p)->Read(p, buf, size)
177 /* it can return SZ_ERROR_INPUT_EOF */
178 SRes
SeqInStream_Read(const ISeqInStream
*stream
, void *buf
, size_t size
);
179 SRes
SeqInStream_Read2(const ISeqInStream
*stream
, void *buf
, size_t size
, SRes errorType
);
180 SRes
SeqInStream_ReadByte(const ISeqInStream
*stream
, Byte
*buf
);
183 typedef struct ISeqOutStream ISeqOutStream
;
186 size_t (*Write
)(const ISeqOutStream
*p
, const void *buf
, size_t size
);
187 /* Returns: result - the number of actually written bytes.
188 (result < size) means error */
190 #define ISeqOutStream_Write(p, buf, size) (p)->Write(p, buf, size)
200 typedef struct ISeekInStream ISeekInStream
;
203 SRes (*Read
)(const ISeekInStream
*p
, void *buf
, size_t *size
); /* same as ISeqInStream::Read */
204 SRes (*Seek
)(const ISeekInStream
*p
, Int64
*pos
, ESzSeek origin
);
206 #define ISeekInStream_Read(p, buf, size) (p)->Read(p, buf, size)
207 #define ISeekInStream_Seek(p, pos, origin) (p)->Seek(p, pos, origin)
210 typedef struct ILookInStream ILookInStream
;
213 SRes (*Look
)(const ILookInStream
*p
, const void **buf
, size_t *size
);
214 /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
215 (output(*size) > input(*size)) is not allowed
216 (output(*size) < input(*size)) is allowed */
217 SRes (*Skip
)(const ILookInStream
*p
, size_t offset
);
218 /* offset must be <= output(*size) of Look */
220 SRes (*Read
)(const ILookInStream
*p
, void *buf
, size_t *size
);
221 /* reads directly (without buffer). It's same as ISeqInStream::Read */
222 SRes (*Seek
)(const ILookInStream
*p
, Int64
*pos
, ESzSeek origin
);
225 #define ILookInStream_Look(p, buf, size) (p)->Look(p, buf, size)
226 #define ILookInStream_Skip(p, offset) (p)->Skip(p, offset)
227 #define ILookInStream_Read(p, buf, size) (p)->Read(p, buf, size)
228 #define ILookInStream_Seek(p, pos, origin) (p)->Seek(p, pos, origin)
231 SRes
LookInStream_LookRead(const ILookInStream
*stream
, void *buf
, size_t *size
);
232 SRes
LookInStream_SeekTo(const ILookInStream
*stream
, UInt64 offset
);
234 /* reads via ILookInStream::Read */
235 SRes
LookInStream_Read2(const ILookInStream
*stream
, void *buf
, size_t size
, SRes errorType
);
236 SRes
LookInStream_Read(const ILookInStream
*stream
, void *buf
, size_t size
);
243 const ISeekInStream
*realStream
;
246 size_t size
; /* it's data size */
248 /* the following variables must be set outside */
253 void LookToRead2_CreateVTable(CLookToRead2
*p
, int lookahead
);
255 #define LookToRead2_Init(p) { (p)->pos = (p)->size = 0; }
261 const ILookInStream
*realStream
;
264 void SecToLook_CreateVTable(CSecToLook
*p
);
271 const ILookInStream
*realStream
;
274 void SecToRead_CreateVTable(CSecToRead
*p
);
277 typedef struct ICompressProgress ICompressProgress
;
279 struct ICompressProgress
281 SRes (*Progress
)(const ICompressProgress
*p
, UInt64 inSize
, UInt64 outSize
);
282 /* Returns: result. (result != SZ_OK) means break.
283 Value (UInt64)(Int64)-1 for size means unknown value. */
285 #define ICompressProgress_Progress(p, inSize, outSize) (p)->Progress(p, inSize, outSize)
289 typedef struct ISzAlloc ISzAlloc
;
290 typedef const ISzAlloc
* ISzAllocPtr
;
294 void *(*Alloc
)(ISzAllocPtr p
, size_t size
);
295 void (*Free
)(ISzAllocPtr p
, void *address
); /* address can be 0 */
298 #define ISzAlloc_Alloc(p, size) (p)->Alloc(p, size)
299 #define ISzAlloc_Free(p, a) (p)->Free(p, a)
302 #define IAlloc_Alloc(p, size) ISzAlloc_Alloc(p, size)
303 #define IAlloc_Free(p, a) ISzAlloc_Free(p, a)
311 #define MY_offsetof(type, m) offsetof(type, m)
313 #define MY_offsetof(type, m) FIELD_OFFSET(type, m)
316 #define MY_offsetof(type, m) ((size_t)&(((type *)0)->m))
322 #ifndef MY_container_of
325 #define MY_container_of(ptr, type, m) container_of(ptr, type, m)
326 #define MY_container_of(ptr, type, m) CONTAINING_RECORD(ptr, type, m)
327 #define MY_container_of(ptr, type, m) ((type *)((char *)(ptr) - offsetof(type, m)))
328 #define MY_container_of(ptr, type, m) (&((type *)0)->m == (ptr), ((type *)(((char *)(ptr)) - MY_offsetof(type, m))))
332 GCC shows warning: "perhaps the 'offsetof' macro was used incorrectly"
333 GCC 3.4.4 : classes with constructor
334 GCC 4.8.1 : classes with non-public variable members"
337 #define MY_container_of(ptr, type, m) ((type *)((char *)(1 ? (ptr) : &((type *)0)->m) - MY_offsetof(type, m)))
342 #define CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m) ((type *)(ptr))
345 #define CONTAINER_FROM_VTBL(ptr, type, m) CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m)
347 #define CONTAINER_FROM_VTBL(ptr, type, m) MY_container_of(ptr, type, m)
349 #define CONTAINER_FROM_VTBL_CLS(ptr, type, m) CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m)
351 #define CONTAINER_FROM_VTBL_CLS(ptr, type, m) CONTAINER_FROM_VTBL(ptr, type, m)
358 #define CHAR_PATH_SEPARATOR '\\'
359 #define WCHAR_PATH_SEPARATOR L'\\'
360 #define STRING_PATH_SEPARATOR "\\"
361 #define WSTRING_PATH_SEPARATOR L"\\"
365 #define CHAR_PATH_SEPARATOR '/'
366 #define WCHAR_PATH_SEPARATOR L'/'
367 #define STRING_PATH_SEPARATOR "/"
368 #define WSTRING_PATH_SEPARATOR L"/"