1 /* 7zTypes.h -- Basic types
\r
2 2022-04-01 : Igor Pavlov : Public domain */
\r
8 /* #include <windows.h> */
\r
15 #ifndef EXTERN_C_BEGIN
\r
17 #define EXTERN_C_BEGIN extern "C" {
\r
18 #define EXTERN_C_END }
\r
20 #define EXTERN_C_BEGIN
\r
21 #define EXTERN_C_END
\r
29 #define SZ_ERROR_DATA 1
\r
30 #define SZ_ERROR_MEM 2
\r
31 #define SZ_ERROR_CRC 3
\r
32 #define SZ_ERROR_UNSUPPORTED 4
\r
33 #define SZ_ERROR_PARAM 5
\r
34 #define SZ_ERROR_INPUT_EOF 6
\r
35 #define SZ_ERROR_OUTPUT_EOF 7
\r
36 #define SZ_ERROR_READ 8
\r
37 #define SZ_ERROR_WRITE 9
\r
38 #define SZ_ERROR_PROGRESS 10
\r
39 #define SZ_ERROR_FAIL 11
\r
40 #define SZ_ERROR_THREAD 12
\r
42 #define SZ_ERROR_ARCHIVE 16
\r
43 #define SZ_ERROR_NO_ARCHIVE 17
\r
50 #define MY_ALIGN(n) __declspec(align(n))
\r
55 #define MY_ALIGN(n) __attribute__ ((aligned(n)))
\r
61 /* typedef DWORD WRes; */
\r
62 typedef unsigned WRes;
\r
63 #define MY_SRes_HRESULT_FROM_WRes(x) HRESULT_FROM_WIN32(x)
\r
65 // #define MY_HRES_ERROR__INTERNAL_ERROR MY_SRes_HRESULT_FROM_WRes(ERROR_INTERNAL_ERROR)
\r
69 // #define ENV_HAVE_LSTAT
\r
72 // (FACILITY_ERRNO = 0x800) is 7zip's FACILITY constant to represent (errno) errors in HRESULT
\r
73 #define MY__FACILITY_ERRNO 0x800
\r
74 #define MY__FACILITY_WIN32 7
\r
75 #define MY__FACILITY__WRes MY__FACILITY_ERRNO
\r
77 #define MY_HRESULT_FROM_errno_CONST_ERROR(x) ((HRESULT)( \
\r
78 ( (HRESULT)(x) & 0x0000FFFF) \
\r
79 | (MY__FACILITY__WRes << 16) \
\r
80 | (HRESULT)0x80000000 ))
\r
82 #define MY_SRes_HRESULT_FROM_WRes(x) \
\r
83 ((HRESULT)(x) <= 0 ? ((HRESULT)(x)) : MY_HRESULT_FROM_errno_CONST_ERROR(x))
\r
85 // we call macro HRESULT_FROM_WIN32 for system errors (WRes) that are (errno)
\r
86 #define HRESULT_FROM_WIN32(x) MY_SRes_HRESULT_FROM_WRes(x)
\r
89 #define ERROR_FILE_NOT_FOUND 2L
\r
90 #define ERROR_ACCESS_DENIED 5L
\r
91 #define ERROR_NO_MORE_FILES 18L
\r
92 #define ERROR_LOCK_VIOLATION 33L
\r
93 #define ERROR_FILE_EXISTS 80L
\r
94 #define ERROR_DISK_FULL 112L
\r
95 #define ERROR_NEGATIVE_SEEK 131L
\r
96 #define ERROR_ALREADY_EXISTS 183L
\r
97 #define ERROR_DIRECTORY 267L
\r
98 #define ERROR_TOO_MANY_POSTS 298L
\r
100 #define ERROR_INTERNAL_ERROR 1359L
\r
101 #define ERROR_INVALID_REPARSE_DATA 4392L
\r
102 #define ERROR_REPARSE_TAG_INVALID 4393L
\r
103 #define ERROR_REPARSE_TAG_MISMATCH 4394L
\r
106 // we use errno equivalents for some WIN32 errors:
\r
108 #define ERROR_INVALID_PARAMETER EINVAL
\r
109 #define ERROR_INVALID_FUNCTION EINVAL
\r
110 #define ERROR_ALREADY_EXISTS EEXIST
\r
111 #define ERROR_FILE_EXISTS EEXIST
\r
112 #define ERROR_PATH_NOT_FOUND ENOENT
\r
113 #define ERROR_FILE_NOT_FOUND ENOENT
\r
114 #define ERROR_DISK_FULL ENOSPC
\r
115 // #define ERROR_INVALID_HANDLE EBADF
\r
117 // we use FACILITY_WIN32 for errors that has no errno equivalent
\r
118 // Too many posts were made to a semaphore.
\r
119 #define ERROR_TOO_MANY_POSTS ((HRESULT)0x8007012AL)
\r
120 #define ERROR_INVALID_REPARSE_DATA ((HRESULT)0x80071128L)
\r
121 #define ERROR_REPARSE_TAG_INVALID ((HRESULT)0x80071129L)
\r
123 // if (MY__FACILITY__WRes != FACILITY_WIN32),
\r
124 // we use FACILITY_WIN32 for COM errors:
\r
125 #define E_OUTOFMEMORY ((HRESULT)0x8007000EL)
\r
126 #define E_INVALIDARG ((HRESULT)0x80070057L)
\r
127 #define MY__E_ERROR_NEGATIVE_SEEK ((HRESULT)0x80070083L)
\r
130 // we can use FACILITY_ERRNO for some COM errors, that have errno equivalents:
\r
131 #define E_OUTOFMEMORY MY_HRESULT_FROM_errno_CONST_ERROR(ENOMEM)
\r
132 #define E_INVALIDARG MY_HRESULT_FROM_errno_CONST_ERROR(EINVAL)
\r
133 #define MY__E_ERROR_NEGATIVE_SEEK MY_HRESULT_FROM_errno_CONST_ERROR(EINVAL)
\r
136 #define TEXT(quote) quote
\r
138 #define FILE_ATTRIBUTE_READONLY 0x0001
\r
139 #define FILE_ATTRIBUTE_HIDDEN 0x0002
\r
140 #define FILE_ATTRIBUTE_SYSTEM 0x0004
\r
141 #define FILE_ATTRIBUTE_DIRECTORY 0x0010
\r
142 #define FILE_ATTRIBUTE_ARCHIVE 0x0020
\r
143 #define FILE_ATTRIBUTE_DEVICE 0x0040
\r
144 #define FILE_ATTRIBUTE_NORMAL 0x0080
\r
145 #define FILE_ATTRIBUTE_TEMPORARY 0x0100
\r
146 #define FILE_ATTRIBUTE_SPARSE_FILE 0x0200
\r
147 #define FILE_ATTRIBUTE_REPARSE_POINT 0x0400
\r
148 #define FILE_ATTRIBUTE_COMPRESSED 0x0800
\r
149 #define FILE_ATTRIBUTE_OFFLINE 0x1000
\r
150 #define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x2000
\r
151 #define FILE_ATTRIBUTE_ENCRYPTED 0x4000
\r
153 #define FILE_ATTRIBUTE_UNIX_EXTENSION 0x8000 /* trick for Unix */
\r
159 #define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; }
\r
163 #define RINOK_WRes(x) { WRes __result__ = (x); if (__result__ != 0) return __result__; }
\r
166 typedef unsigned char Byte;
\r
167 typedef short Int16;
\r
168 typedef unsigned short UInt16;
\r
170 #ifdef _LZMA_UINT32_IS_ULONG
\r
171 typedef long Int32;
\r
172 typedef unsigned long UInt32;
\r
175 typedef unsigned int UInt32;
\r
182 typedef Int32 INT32;
\r
183 typedef unsigned int UINT;
\r
184 typedef UInt32 UINT32;
\r
185 typedef INT32 LONG; // LONG, ULONG and DWORD must be 32-bit for _WIN32 compatibility
\r
186 typedef UINT32 ULONG;
\r
189 typedef UINT32 DWORD;
\r
193 #define HRESULT LONG
\r
195 typedef void *LPVOID;
\r
196 // typedef void VOID;
\r
197 // typedef ULONG_PTR DWORD_PTR, *PDWORD_PTR;
\r
198 // gcc / clang on Unix : sizeof(long==sizeof(void*) in 32 or 64 bits)
\r
199 typedef long INT_PTR;
\r
200 typedef unsigned long UINT_PTR;
\r
201 typedef long LONG_PTR;
\r
202 typedef unsigned long DWORD_PTR;
\r
204 typedef size_t SIZE_T;
\r
209 #define MY_HRES_ERROR__INTERNAL_ERROR ((HRESULT)0x8007054FL)
\r
212 #ifdef _SZ_NO_INT_64
\r
214 /* define _SZ_NO_INT_64, if your compiler doesn't support 64-bit integers.
\r
215 NOTES: Some code will work incorrectly in that case! */
\r
217 typedef long Int64;
\r
218 typedef unsigned long UInt64;
\r
222 #if defined(_MSC_VER) || defined(__BORLANDC__)
\r
223 typedef __int64 Int64;
\r
224 typedef unsigned __int64 UInt64;
\r
225 #define UINT64_CONST(n) n
\r
227 typedef long long int Int64;
\r
228 typedef unsigned long long int UInt64;
\r
229 #define UINT64_CONST(n) n ## ULL
\r
234 #ifdef _LZMA_NO_SYSTEM_SIZE_T
\r
235 typedef UInt32 SizeT;
\r
237 typedef size_t SizeT;
\r
240 typedef int BoolInt;
\r
241 /* typedef BoolInt Bool; */
\r
247 #define MY_STD_CALL __stdcall
\r
249 #define MY_STD_CALL
\r
254 #if _MSC_VER >= 1300
\r
255 #define MY_NO_INLINE __declspec(noinline)
\r
257 #define MY_NO_INLINE
\r
260 #define MY_FORCE_INLINE __forceinline
\r
262 #define MY_CDECL __cdecl
\r
263 #define MY_FAST_CALL __fastcall
\r
267 #if (defined(__GNUC__) && (__GNUC__ >= 4)) \
\r
268 || (defined(__clang__) && (__clang_major__ >= 4)) \
\r
269 || defined(__INTEL_COMPILER) \
\r
270 || defined(__xlC__)
\r
271 #define MY_NO_INLINE __attribute__((noinline))
\r
272 // #define MY_FORCE_INLINE __attribute__((always_inline)) inline
\r
274 #define MY_NO_INLINE
\r
277 #define MY_FORCE_INLINE
\r
282 #if defined(_M_IX86) \
\r
283 || defined(__i386__)
\r
284 // #define MY_FAST_CALL __attribute__((fastcall))
\r
285 // #define MY_FAST_CALL __attribute__((cdecl))
\r
286 #define MY_FAST_CALL
\r
287 #elif defined(MY_CPU_AMD64)
\r
288 // #define MY_FAST_CALL __attribute__((ms_abi))
\r
289 #define MY_FAST_CALL
\r
291 #define MY_FAST_CALL
\r
297 /* The following interfaces use first parameter as pointer to structure */
\r
299 typedef struct IByteIn IByteIn;
\r
302 Byte (*Read)(const IByteIn *p); /* reads one byte, returns 0 in case of EOF or error */
\r
304 #define IByteIn_Read(p) (p)->Read(p)
\r
307 typedef struct IByteOut IByteOut;
\r
310 void (*Write)(const IByteOut *p, Byte b);
\r
312 #define IByteOut_Write(p, b) (p)->Write(p, b)
\r
315 typedef struct ISeqInStream ISeqInStream;
\r
316 struct ISeqInStream
\r
318 SRes (*Read)(const ISeqInStream *p, void *buf, size_t *size);
\r
319 /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
\r
320 (output(*size) < input(*size)) is allowed */
\r
322 #define ISeqInStream_Read(p, buf, size) (p)->Read(p, buf, size)
\r
324 /* it can return SZ_ERROR_INPUT_EOF */
\r
325 SRes SeqInStream_Read(const ISeqInStream *stream, void *buf, size_t size);
\r
326 SRes SeqInStream_Read2(const ISeqInStream *stream, void *buf, size_t size, SRes errorType);
\r
327 SRes SeqInStream_ReadByte(const ISeqInStream *stream, Byte *buf);
\r
330 typedef struct ISeqOutStream ISeqOutStream;
\r
331 struct ISeqOutStream
\r
333 size_t (*Write)(const ISeqOutStream *p, const void *buf, size_t size);
\r
334 /* Returns: result - the number of actually written bytes.
\r
335 (result < size) means error */
\r
337 #define ISeqOutStream_Write(p, buf, size) (p)->Write(p, buf, size)
\r
347 typedef struct ISeekInStream ISeekInStream;
\r
348 struct ISeekInStream
\r
350 SRes (*Read)(const ISeekInStream *p, void *buf, size_t *size); /* same as ISeqInStream::Read */
\r
351 SRes (*Seek)(const ISeekInStream *p, Int64 *pos, ESzSeek origin);
\r
353 #define ISeekInStream_Read(p, buf, size) (p)->Read(p, buf, size)
\r
354 #define ISeekInStream_Seek(p, pos, origin) (p)->Seek(p, pos, origin)
\r
357 typedef struct ILookInStream ILookInStream;
\r
358 struct ILookInStream
\r
360 SRes (*Look)(const ILookInStream *p, const void **buf, size_t *size);
\r
361 /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
\r
362 (output(*size) > input(*size)) is not allowed
\r
363 (output(*size) < input(*size)) is allowed */
\r
364 SRes (*Skip)(const ILookInStream *p, size_t offset);
\r
365 /* offset must be <= output(*size) of Look */
\r
367 SRes (*Read)(const ILookInStream *p, void *buf, size_t *size);
\r
368 /* reads directly (without buffer). It's same as ISeqInStream::Read */
\r
369 SRes (*Seek)(const ILookInStream *p, Int64 *pos, ESzSeek origin);
\r
372 #define ILookInStream_Look(p, buf, size) (p)->Look(p, buf, size)
\r
373 #define ILookInStream_Skip(p, offset) (p)->Skip(p, offset)
\r
374 #define ILookInStream_Read(p, buf, size) (p)->Read(p, buf, size)
\r
375 #define ILookInStream_Seek(p, pos, origin) (p)->Seek(p, pos, origin)
\r
378 SRes LookInStream_LookRead(const ILookInStream *stream, void *buf, size_t *size);
\r
379 SRes LookInStream_SeekTo(const ILookInStream *stream, UInt64 offset);
\r
381 /* reads via ILookInStream::Read */
\r
382 SRes LookInStream_Read2(const ILookInStream *stream, void *buf, size_t size, SRes errorType);
\r
383 SRes LookInStream_Read(const ILookInStream *stream, void *buf, size_t size);
\r
390 const ISeekInStream *realStream;
\r
393 size_t size; /* it's data size */
\r
395 /* the following variables must be set outside */
\r
400 void LookToRead2_CreateVTable(CLookToRead2 *p, int lookahead);
\r
402 #define LookToRead2_Init(p) { (p)->pos = (p)->size = 0; }
\r
408 const ILookInStream *realStream;
\r
411 void SecToLook_CreateVTable(CSecToLook *p);
\r
418 const ILookInStream *realStream;
\r
421 void SecToRead_CreateVTable(CSecToRead *p);
\r
424 typedef struct ICompressProgress ICompressProgress;
\r
426 struct ICompressProgress
\r
428 SRes (*Progress)(const ICompressProgress *p, UInt64 inSize, UInt64 outSize);
\r
429 /* Returns: result. (result != SZ_OK) means break.
\r
430 Value (UInt64)(Int64)-1 for size means unknown value. */
\r
432 #define ICompressProgress_Progress(p, inSize, outSize) (p)->Progress(p, inSize, outSize)
\r
436 typedef struct ISzAlloc ISzAlloc;
\r
437 typedef const ISzAlloc * ISzAllocPtr;
\r
441 void *(*Alloc)(ISzAllocPtr p, size_t size);
\r
442 void (*Free)(ISzAllocPtr p, void *address); /* address can be 0 */
\r
445 #define ISzAlloc_Alloc(p, size) (p)->Alloc(p, size)
\r
446 #define ISzAlloc_Free(p, a) (p)->Free(p, a)
\r
449 #define IAlloc_Alloc(p, size) ISzAlloc_Alloc(p, size)
\r
450 #define IAlloc_Free(p, a) ISzAlloc_Free(p, a)
\r
456 #ifndef MY_offsetof
\r
458 #define MY_offsetof(type, m) offsetof(type, m)
\r
460 #define MY_offsetof(type, m) FIELD_OFFSET(type, m)
\r
463 #define MY_offsetof(type, m) ((size_t)&(((type *)0)->m))
\r
469 #ifndef MY_container_of
\r
472 #define MY_container_of(ptr, type, m) container_of(ptr, type, m)
\r
473 #define MY_container_of(ptr, type, m) CONTAINING_RECORD(ptr, type, m)
\r
474 #define MY_container_of(ptr, type, m) ((type *)((char *)(ptr) - offsetof(type, m)))
\r
475 #define MY_container_of(ptr, type, m) (&((type *)0)->m == (ptr), ((type *)(((char *)(ptr)) - MY_offsetof(type, m))))
\r
479 GCC shows warning: "perhaps the 'offsetof' macro was used incorrectly"
\r
480 GCC 3.4.4 : classes with constructor
\r
481 GCC 4.8.1 : classes with non-public variable members"
\r
484 #define MY_container_of(ptr, type, m) ((type *)(void *)((char *)(void *)(1 ? (ptr) : &((type *)0)->m) - MY_offsetof(type, m)))
\r
488 #define CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m) ((type *)(void *)(ptr))
\r
491 #define CONTAINER_FROM_VTBL(ptr, type, m) CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m)
\r
493 #define CONTAINER_FROM_VTBL(ptr, type, m) MY_container_of(ptr, type, m)
\r
495 #define CONTAINER_FROM_VTBL_CLS(ptr, type, m) CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m)
\r
497 #define CONTAINER_FROM_VTBL_CLS(ptr, type, m) CONTAINER_FROM_VTBL(ptr, type, m)
\r
501 #define MY_memset_0_ARRAY(a) memset((a), 0, sizeof(a))
\r
505 #define CHAR_PATH_SEPARATOR '\\'
\r
506 #define WCHAR_PATH_SEPARATOR L'\\'
\r
507 #define STRING_PATH_SEPARATOR "\\"
\r
508 #define WSTRING_PATH_SEPARATOR L"\\"
\r
512 #define CHAR_PATH_SEPARATOR '/'
\r
513 #define WCHAR_PATH_SEPARATOR L'/'
\r
514 #define STRING_PATH_SEPARATOR "/"
\r
515 #define WSTRING_PATH_SEPARATOR L"/"
\r
519 #define k_PropVar_TimePrec_0 0
\r
520 #define k_PropVar_TimePrec_Unix 1
\r
521 #define k_PropVar_TimePrec_DOS 2
\r
522 #define k_PropVar_TimePrec_HighPrec 3
\r
523 #define k_PropVar_TimePrec_Base 16
\r
524 #define k_PropVar_TimePrec_100ns (k_PropVar_TimePrec_Base + 7)
\r
525 #define k_PropVar_TimePrec_1ns (k_PropVar_TimePrec_Base + 9)
\r