1 /* 7zTypes.h -- Basic types
2 2018-08-04 : 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
;
107 /* typedef BoolInt Bool; */
113 #define MY_STD_CALL __stdcall
121 #define MY_NO_INLINE __declspec(noinline)
126 #define MY_FORCE_INLINE __forceinline
128 #define MY_CDECL __cdecl
129 #define MY_FAST_CALL __fastcall
134 #define MY_FORCE_INLINE
138 /* inline keyword : for C++ / C99 */
142 #if defined (__GNUC__) && (__GNUC__ >= 4)
143 #define MY_FORCE_INLINE __attribute__((always_inline))
144 #define MY_NO_INLINE __attribute__((noinline))
151 /* The following interfaces use first parameter as pointer to structure */
153 typedef struct IByteIn IByteIn
;
156 Byte (*Read
)(const IByteIn
*p
); /* reads one byte, returns 0 in case of EOF or error */
158 #define IByteIn_Read(p) (p)->Read(p)
161 typedef struct IByteOut IByteOut
;
164 void (*Write
)(const IByteOut
*p
, Byte b
);
166 #define IByteOut_Write(p, b) (p)->Write(p, b)
169 typedef struct ISeqInStream ISeqInStream
;
172 SRes (*Read
)(const ISeqInStream
*p
, void *buf
, size_t *size
);
173 /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
174 (output(*size) < input(*size)) is allowed */
176 #define ISeqInStream_Read(p, buf, size) (p)->Read(p, buf, size)
178 /* it can return SZ_ERROR_INPUT_EOF */
179 SRes
SeqInStream_Read(const ISeqInStream
*stream
, void *buf
, size_t size
);
180 SRes
SeqInStream_Read2(const ISeqInStream
*stream
, void *buf
, size_t size
, SRes errorType
);
181 SRes
SeqInStream_ReadByte(const ISeqInStream
*stream
, Byte
*buf
);
184 typedef struct ISeqOutStream ISeqOutStream
;
187 size_t (*Write
)(const ISeqOutStream
*p
, const void *buf
, size_t size
);
188 /* Returns: result - the number of actually written bytes.
189 (result < size) means error */
191 #define ISeqOutStream_Write(p, buf, size) (p)->Write(p, buf, size)
201 typedef struct ISeekInStream ISeekInStream
;
204 SRes (*Read
)(const ISeekInStream
*p
, void *buf
, size_t *size
); /* same as ISeqInStream::Read */
205 SRes (*Seek
)(const ISeekInStream
*p
, Int64
*pos
, ESzSeek origin
);
207 #define ISeekInStream_Read(p, buf, size) (p)->Read(p, buf, size)
208 #define ISeekInStream_Seek(p, pos, origin) (p)->Seek(p, pos, origin)
211 typedef struct ILookInStream ILookInStream
;
214 SRes (*Look
)(const ILookInStream
*p
, const void **buf
, size_t *size
);
215 /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
216 (output(*size) > input(*size)) is not allowed
217 (output(*size) < input(*size)) is allowed */
218 SRes (*Skip
)(const ILookInStream
*p
, size_t offset
);
219 /* offset must be <= output(*size) of Look */
221 SRes (*Read
)(const ILookInStream
*p
, void *buf
, size_t *size
);
222 /* reads directly (without buffer). It's same as ISeqInStream::Read */
223 SRes (*Seek
)(const ILookInStream
*p
, Int64
*pos
, ESzSeek origin
);
226 #define ILookInStream_Look(p, buf, size) (p)->Look(p, buf, size)
227 #define ILookInStream_Skip(p, offset) (p)->Skip(p, offset)
228 #define ILookInStream_Read(p, buf, size) (p)->Read(p, buf, size)
229 #define ILookInStream_Seek(p, pos, origin) (p)->Seek(p, pos, origin)
232 SRes
LookInStream_LookRead(const ILookInStream
*stream
, void *buf
, size_t *size
);
233 SRes
LookInStream_SeekTo(const ILookInStream
*stream
, UInt64 offset
);
235 /* reads via ILookInStream::Read */
236 SRes
LookInStream_Read2(const ILookInStream
*stream
, void *buf
, size_t size
, SRes errorType
);
237 SRes
LookInStream_Read(const ILookInStream
*stream
, void *buf
, size_t size
);
244 const ISeekInStream
*realStream
;
247 size_t size
; /* it's data size */
249 /* the following variables must be set outside */
254 void LookToRead2_CreateVTable(CLookToRead2
*p
, int lookahead
);
256 #define LookToRead2_Init(p) { (p)->pos = (p)->size = 0; }
262 const ILookInStream
*realStream
;
265 void SecToLook_CreateVTable(CSecToLook
*p
);
272 const ILookInStream
*realStream
;
275 void SecToRead_CreateVTable(CSecToRead
*p
);
278 typedef struct ICompressProgress ICompressProgress
;
280 struct ICompressProgress
282 SRes (*Progress
)(const ICompressProgress
*p
, UInt64 inSize
, UInt64 outSize
);
283 /* Returns: result. (result != SZ_OK) means break.
284 Value (UInt64)(Int64)-1 for size means unknown value. */
286 #define ICompressProgress_Progress(p, inSize, outSize) (p)->Progress(p, inSize, outSize)
290 typedef struct ISzAlloc ISzAlloc
;
291 typedef const ISzAlloc
* ISzAllocPtr
;
295 void *(*Alloc
)(ISzAllocPtr p
, size_t size
);
296 void (*Free
)(ISzAllocPtr p
, void *address
); /* address can be 0 */
299 #define ISzAlloc_Alloc(p, size) (p)->Alloc(p, size)
300 #define ISzAlloc_Free(p, a) (p)->Free(p, a)
303 #define IAlloc_Alloc(p, size) ISzAlloc_Alloc(p, size)
304 #define IAlloc_Free(p, a) ISzAlloc_Free(p, a)
312 #define MY_offsetof(type, m) offsetof(type, m)
314 #define MY_offsetof(type, m) FIELD_OFFSET(type, m)
317 #define MY_offsetof(type, m) ((size_t)&(((type *)0)->m))
323 #ifndef MY_container_of
326 #define MY_container_of(ptr, type, m) container_of(ptr, type, m)
327 #define MY_container_of(ptr, type, m) CONTAINING_RECORD(ptr, type, m)
328 #define MY_container_of(ptr, type, m) ((type *)((char *)(ptr) - offsetof(type, m)))
329 #define MY_container_of(ptr, type, m) (&((type *)0)->m == (ptr), ((type *)(((char *)(ptr)) - MY_offsetof(type, m))))
333 GCC shows warning: "perhaps the 'offsetof' macro was used incorrectly"
334 GCC 3.4.4 : classes with constructor
335 GCC 4.8.1 : classes with non-public variable members"
338 #define MY_container_of(ptr, type, m) ((type *)((char *)(1 ? (ptr) : &((type *)0)->m) - MY_offsetof(type, m)))
343 #define CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m) ((type *)(ptr))
346 #define CONTAINER_FROM_VTBL(ptr, type, m) CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m)
348 #define CONTAINER_FROM_VTBL(ptr, type, m) MY_container_of(ptr, type, m)
350 #define CONTAINER_FROM_VTBL_CLS(ptr, type, m) CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m)
352 #define CONTAINER_FROM_VTBL_CLS(ptr, type, m) CONTAINER_FROM_VTBL(ptr, type, m)
359 #define CHAR_PATH_SEPARATOR '\\'
360 #define WCHAR_PATH_SEPARATOR L'\\'
361 #define STRING_PATH_SEPARATOR "\\"
362 #define WSTRING_PATH_SEPARATOR L"\\"
366 #define CHAR_PATH_SEPARATOR '/'
367 #define WCHAR_PATH_SEPARATOR L'/'
368 #define STRING_PATH_SEPARATOR "/"
369 #define WSTRING_PATH_SEPARATOR L"/"