Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 | /* SPDX-License-Identifier: LZMA-SDK-9.22 */ /* 7zTypes.h -- Basic types 2024-01-24 : Igor Pavlov : Public domain */ #ifndef ZIP7_7Z_TYPES_H #define ZIP7_7Z_TYPES_H #ifdef _WIN32 /* #include <windows.h> */ #else #include <errno.h> #endif #include <stddef.h> #ifndef EXTERN_C_BEGIN #ifdef __cplusplus #define EXTERN_C_BEGIN extern "C" { #define EXTERN_C_END } #else #define EXTERN_C_BEGIN #define EXTERN_C_END #endif #endif EXTERN_C_BEGIN #define SZ_OK 0 #define SZ_ERROR_DATA 1 #define SZ_ERROR_MEM 2 #define SZ_ERROR_CRC 3 #define SZ_ERROR_UNSUPPORTED 4 #define SZ_ERROR_PARAM 5 #define SZ_ERROR_INPUT_EOF 6 #define SZ_ERROR_OUTPUT_EOF 7 #define SZ_ERROR_READ 8 #define SZ_ERROR_WRITE 9 #define SZ_ERROR_PROGRESS 10 #define SZ_ERROR_FAIL 11 #define SZ_ERROR_THREAD 12 #define SZ_ERROR_ARCHIVE 16 #define SZ_ERROR_NO_ARCHIVE 17 typedef int SRes; #ifdef _MSC_VER #if _MSC_VER > 1200 #define MY_ALIGN(n) __declspec(align(n)) #else #define MY_ALIGN(n) #endif #else /* // C11/C++11: #include <stdalign.h> #define MY_ALIGN(n) alignas(n) */ #define MY_ALIGN(n) __attribute__ ((aligned(n))) #endif #ifdef _WIN32 /* typedef DWORD WRes; */ typedef unsigned WRes; #define MY_SRes_HRESULT_FROM_WRes(x) HRESULT_FROM_WIN32(x) // #define MY_HRES_ERROR_INTERNAL_ERROR MY_SRes_HRESULT_FROM_WRes(ERROR_INTERNAL_ERROR) #else // _WIN32 // #define ENV_HAVE_LSTAT typedef int WRes; // (FACILITY_ERRNO = 0x800) is 7zip's FACILITY constant to represent (errno) errors in HRESULT #define MY_FACILITY_ERRNO 0x800 #define MY_FACILITY_WIN32 7 #define MY_FACILITY_WRes MY_FACILITY_ERRNO #define MY_HRESULT_FROM_errno_CONST_ERROR(x) ((HRESULT)( \ ( (HRESULT)(x) & 0x0000FFFF) \ | (MY_FACILITY_WRes << 16) \ | (HRESULT)0x80000000 )) #define MY_SRes_HRESULT_FROM_WRes(x) \ ((HRESULT)(x) <= 0 ? ((HRESULT)(x)) : MY_HRESULT_FROM_errno_CONST_ERROR(x)) // we call macro HRESULT_FROM_WIN32 for system errors (WRes) that are (errno) #define HRESULT_FROM_WIN32(x) MY_SRes_HRESULT_FROM_WRes(x) /* #define ERROR_FILE_NOT_FOUND 2L #define ERROR_ACCESS_DENIED 5L #define ERROR_NO_MORE_FILES 18L #define ERROR_LOCK_VIOLATION 33L #define ERROR_FILE_EXISTS 80L #define ERROR_DISK_FULL 112L #define ERROR_NEGATIVE_SEEK 131L #define ERROR_ALREADY_EXISTS 183L #define ERROR_DIRECTORY 267L #define ERROR_TOO_MANY_POSTS 298L #define ERROR_INTERNAL_ERROR 1359L #define ERROR_INVALID_REPARSE_DATA 4392L #define ERROR_REPARSE_TAG_INVALID 4393L #define ERROR_REPARSE_TAG_MISMATCH 4394L */ // we use errno equivalents for some WIN32 errors: #define ERROR_INVALID_PARAMETER EINVAL #define ERROR_INVALID_FUNCTION EINVAL #define ERROR_ALREADY_EXISTS EEXIST #define ERROR_FILE_EXISTS EEXIST #define ERROR_PATH_NOT_FOUND ENOENT #define ERROR_FILE_NOT_FOUND ENOENT #define ERROR_DISK_FULL ENOSPC // #define ERROR_INVALID_HANDLE EBADF // we use FACILITY_WIN32 for errors that has no errno equivalent // Too many posts were made to a semaphore. #define ERROR_TOO_MANY_POSTS ((HRESULT)0x8007012AL) #define ERROR_INVALID_REPARSE_DATA ((HRESULT)0x80071128L) #define ERROR_REPARSE_TAG_INVALID ((HRESULT)0x80071129L) // if (MY_FACILITY_WRes != FACILITY_WIN32), // we use FACILITY_WIN32 for COM errors: #define E_OUTOFMEMORY ((HRESULT)0x8007000EL) #define E_INVALIDARG ((HRESULT)0x80070057L) #define MY_E_ERROR_NEGATIVE_SEEK ((HRESULT)0x80070083L) /* // we can use FACILITY_ERRNO for some COM errors, that have errno equivalents: #define E_OUTOFMEMORY MY_HRESULT_FROM_errno_CONST_ERROR(ENOMEM) #define E_INVALIDARG MY_HRESULT_FROM_errno_CONST_ERROR(EINVAL) #define MY_E_ERROR_NEGATIVE_SEEK MY_HRESULT_FROM_errno_CONST_ERROR(EINVAL) */ // gcc / clang : (sizeof(long) == sizeof(void*)) in 32/64 bits typedef long INT_PTR; typedef unsigned long UINT_PTR; #ifndef __UBOOT__ #define TEXT(quote) quote #endif #define FILE_ATTRIBUTE_READONLY 0x0001 #define FILE_ATTRIBUTE_HIDDEN 0x0002 #define FILE_ATTRIBUTE_SYSTEM 0x0004 #define FILE_ATTRIBUTE_DIRECTORY 0x0010 #define FILE_ATTRIBUTE_ARCHIVE 0x0020 #define FILE_ATTRIBUTE_DEVICE 0x0040 #define FILE_ATTRIBUTE_NORMAL 0x0080 #define FILE_ATTRIBUTE_TEMPORARY 0x0100 #define FILE_ATTRIBUTE_SPARSE_FILE 0x0200 #define FILE_ATTRIBUTE_REPARSE_POINT 0x0400 #define FILE_ATTRIBUTE_COMPRESSED 0x0800 #define FILE_ATTRIBUTE_OFFLINE 0x1000 #define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x2000 #define FILE_ATTRIBUTE_ENCRYPTED 0x4000 #define FILE_ATTRIBUTE_UNIX_EXTENSION 0x8000 /* trick for Unix */ #endif #ifndef RINOK #define RINOK(x) { const int _result_ = (x); if (_result_ != 0) return _result_; } #endif #ifndef RINOK_WRes #define RINOK_WRes(x) { const WRes _result_ = (x); if (_result_ != 0) return _result_; } #endif typedef unsigned char Byte; typedef short Int16; typedef unsigned short UInt16; #ifdef Z7_DECL_Int32_AS_long typedef long Int32; typedef unsigned long UInt32; #else typedef int Int32; typedef unsigned int UInt32; #endif #ifndef _WIN32 typedef int INT; typedef Int32 INT32; typedef unsigned int UINT; typedef UInt32 UINT32; #ifndef __UBOOT__ typedef INT32 LONG; // LONG, ULONG and DWORD must be 32-bit for _WIN32 compatibility #endif typedef UINT32 ULONG; #undef DWORD typedef UINT32 DWORD; #define VOID void #define HRESULT LONG typedef void *LPVOID; // typedef void VOID; // typedef ULONG_PTR DWORD_PTR, *PDWORD_PTR; // gcc / clang on Unix : sizeof(long==sizeof(void*) in 32 or 64 bits) typedef long INT_PTR; typedef unsigned long UINT_PTR; typedef long LONG_PTR; typedef unsigned long DWORD_PTR; typedef size_t SIZE_T; #endif // _WIN32 #define MY_HRES_ERROR_INTERNAL_ERROR ((HRESULT)0x8007054FL) #ifdef Z7_DECL_Int64_AS_long typedef long Int64; typedef unsigned long UInt64; #else #if (defined(_MSC_VER) || defined(__BORLANDC__)) && !defined(__clang__) typedef __int64 Int64; typedef unsigned __int64 UInt64; #else #if defined(__clang__) || defined(__GNUC__) #include <stdint.h> typedef int64_t Int64; typedef uint64_t UInt64; #else typedef long long int Int64; typedef unsigned long long int UInt64; // #define UINT64_CONST(n) n ## ULL #endif #endif #endif #define UINT64_CONST(n) n #ifdef Z7_DECL_SizeT_AS_unsigned_int typedef unsigned int SizeT; #else typedef size_t SizeT; #endif /* #if (defined(_MSC_VER) && _MSC_VER <= 1200) typedef size_t MY_uintptr_t; #else #include <stdint.h> typedef uintptr_t MY_uintptr_t; #endif */ typedef int BoolInt; /* typedef BoolInt Bool; */ #define True 1 #define False 0 #ifdef _WIN32 #define Z7_STDCALL __stdcall #else #define Z7_STDCALL #endif #ifdef _MSC_VER #if _MSC_VER >= 1300 #define Z7_NO_INLINE __declspec(noinline) #else #define Z7_NO_INLINE #endif #define Z7_FORCE_INLINE __forceinline #define Z7_CDECL __cdecl #define Z7_FASTCALL __fastcall #else // _MSC_VER #if (defined(__GNUC__) && (__GNUC__ >= 4)) \ || (defined(__clang__) && (__clang_major__ >= 4)) \ || defined(__INTEL_COMPILER) \ || defined(__xlC__) #define Z7_NO_INLINE __attribute__((noinline)) #define Z7_FORCE_INLINE __attribute__((always_inline)) inline #else #define Z7_NO_INLINE #define Z7_FORCE_INLINE #endif #define Z7_CDECL #if defined(_M_IX86) \ || defined(__i386__) // #define Z7_FASTCALL __attribute__((fastcall)) // #define Z7_FASTCALL __attribute__((cdecl)) #define Z7_FASTCALL #elif defined(MY_CPU_AMD64) // #define Z7_FASTCALL __attribute__((ms_abi)) #define Z7_FASTCALL #else #define Z7_FASTCALL #endif #endif // _MSC_VER /* The following interfaces use first parameter as pointer to structure */ // #define Z7_C_IFACE_CONST_QUAL #define Z7_C_IFACE_CONST_QUAL const #define Z7_C_IFACE_DECL(a) \ struct a ## _; \ typedef Z7_C_IFACE_CONST_QUAL struct a ## _ * a ## Ptr; \ typedef struct a ## _ a; \ struct a ## _ Z7_C_IFACE_DECL (IByteIn) { Byte (*Read)(IByteInPtr p); /* reads one byte, returns 0 in case of EOF or error */ }; #define IByteIn_Read(p) (p)->Read(p) Z7_C_IFACE_DECL (IByteOut) { void (*Write)(IByteOutPtr p, Byte b); }; #define IByteOut_Write(p, b) (p)->Write(p, b) Z7_C_IFACE_DECL (ISeqInStream) { SRes (*Read)(ISeqInStreamPtr p, void *buf, size_t *size); /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream. (output(*size) < input(*size)) is allowed */ }; #define ISeqInStream_Read(p, buf, size) (p)->Read(p, buf, size) /* try to read as much as avail in stream and limited by (*processedSize) */ SRes SeqInStream_ReadMax(ISeqInStreamPtr stream, void *buf, size_t *processedSize); /* it can return SZ_ERROR_INPUT_EOF */ // SRes SeqInStream_Read(ISeqInStreamPtr stream, void *buf, size_t size); // SRes SeqInStream_Read2(ISeqInStreamPtr stream, void *buf, size_t size, SRes errorType); SRes SeqInStream_ReadByte(ISeqInStreamPtr stream, Byte *buf); Z7_C_IFACE_DECL (ISeqOutStream) { size_t (*Write)(ISeqOutStreamPtr p, const void *buf, size_t size); /* Returns: result - the number of actually written bytes. (result < size) means error */ }; #define ISeqOutStream_Write(p, buf, size) (p)->Write(p, buf, size) typedef enum { SZ_SEEK_SET = 0, SZ_SEEK_CUR = 1, SZ_SEEK_END = 2 } ESzSeek; Z7_C_IFACE_DECL (ISeekInStream) { SRes (*Read)(ISeekInStreamPtr p, void *buf, size_t *size); /* same as ISeqInStream::Read */ SRes (*Seek)(ISeekInStreamPtr p, Int64 *pos, ESzSeek origin); }; #define ISeekInStream_Read(p, buf, size) (p)->Read(p, buf, size) #define ISeekInStream_Seek(p, pos, origin) (p)->Seek(p, pos, origin) Z7_C_IFACE_DECL (ILookInStream) { SRes (*Look)(ILookInStreamPtr p, const void **buf, size_t *size); /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream. (output(*size) > input(*size)) is not allowed (output(*size) < input(*size)) is allowed */ SRes (*Skip)(ILookInStreamPtr p, size_t offset); /* offset must be <= output(*size) of Look */ SRes (*Read)(ILookInStreamPtr p, void *buf, size_t *size); /* reads directly (without buffer). It's same as ISeqInStream::Read */ SRes (*Seek)(ILookInStreamPtr p, Int64 *pos, ESzSeek origin); }; #define ILookInStream_Look(p, buf, size) (p)->Look(p, buf, size) #define ILookInStream_Skip(p, offset) (p)->Skip(p, offset) #define ILookInStream_Read(p, buf, size) (p)->Read(p, buf, size) #define ILookInStream_Seek(p, pos, origin) (p)->Seek(p, pos, origin) SRes LookInStream_LookRead(ILookInStreamPtr stream, void *buf, size_t *size); SRes LookInStream_SeekTo(ILookInStreamPtr stream, UInt64 offset); /* reads via ILookInStream::Read */ SRes LookInStream_Read2(ILookInStreamPtr stream, void *buf, size_t size, SRes errorType); SRes LookInStream_Read(ILookInStreamPtr stream, void *buf, size_t size); typedef struct { ILookInStream vt; ISeekInStreamPtr realStream; size_t pos; size_t size; /* it's data size */ /* the following variables must be set outside */ Byte *buf; size_t bufSize; } CLookToRead2; void LookToRead2_CreateVTable(CLookToRead2 *p, int lookahead); #define LookToRead2_INIT(p) { (p)->pos = (p)->size = 0; } typedef struct { ISeqInStream vt; ILookInStreamPtr realStream; } CSecToLook; void SecToLook_CreateVTable(CSecToLook *p); typedef struct { ISeqInStream vt; ILookInStreamPtr realStream; } CSecToRead; void SecToRead_CreateVTable(CSecToRead *p); Z7_C_IFACE_DECL (ICompressProgress) { SRes (*Progress)(ICompressProgressPtr p, UInt64 inSize, UInt64 outSize); /* Returns: result. (result != SZ_OK) means break. Value (UInt64)(Int64)-1 for size means unknown value. */ }; #define ICompressProgress_Progress(p, inSize, outSize) (p)->Progress(p, inSize, outSize) typedef struct ISzAlloc ISzAlloc; typedef const ISzAlloc * ISzAllocPtr; struct ISzAlloc { void *(*Alloc)(ISzAllocPtr p, size_t size); void (*Free)(ISzAllocPtr p, void *address); /* address can be 0 */ }; #define ISzAlloc_Alloc(p, size) (p)->Alloc(p, size) #define ISzAlloc_Free(p, a) (p)->Free(p, a) /* deprecated */ #define IAlloc_Alloc(p, size) ISzAlloc_Alloc(p, size) #define IAlloc_Free(p, a) ISzAlloc_Free(p, a) #ifndef MY_offsetof #ifdef offsetof #define MY_offsetof(type, m) offsetof(type, m) /* #define MY_offsetof(type, m) FIELD_OFFSET(type, m) */ #else #define MY_offsetof(type, m) ((size_t)&(((type *)0)->m)) #endif #endif #ifndef Z7_container_of /* #define Z7_container_of(ptr, type, m) container_of(ptr, type, m) #define Z7_container_of(ptr, type, m) CONTAINING_RECORD(ptr, type, m) #define Z7_container_of(ptr, type, m) ((type *)((char *)(ptr) - offsetof(type, m))) #define Z7_container_of(ptr, type, m) (&((type *)0)->m == (ptr), ((type *)(((char *)(ptr)) - MY_offsetof(type, m)))) */ /* GCC shows warning: "perhaps the 'offsetof' macro was used incorrectly" GCC 3.4.4 : classes with constructor GCC 4.8.1 : classes with non-public variable members" */ #define Z7_container_of(ptr, type, m) \ ((type *)(void *)((char *)(void *) \ (1 ? (ptr) : &((type *)NULL)->m) - MY_offsetof(type, m))) #define Z7_container_of_CONST(ptr, type, m) \ ((const type *)(const void *)((const char *)(const void *) \ (1 ? (ptr) : &((type *)NULL)->m) - MY_offsetof(type, m))) /* #define Z7_container_of_NON_CONST_FROM_CONST(ptr, type, m) \ ((type *)(void *)(const void *)((const char *)(const void *) \ (1 ? (ptr) : &((type *)NULL)->m) - MY_offsetof(type, m))) */ #endif #define Z7_CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m) ((type *)(void *)(ptr)) // #define Z7_CONTAINER_FROM_VTBL(ptr, type, m) Z7_CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m) #define Z7_CONTAINER_FROM_VTBL(ptr, type, m) Z7_container_of(ptr, type, m) // #define Z7_CONTAINER_FROM_VTBL(ptr, type, m) Z7_container_of_NON_CONST_FROM_CONST(ptr, type, m) #define Z7_CONTAINER_FROM_VTBL_CONST(ptr, type, m) Z7_container_of_CONST(ptr, type, m) #define Z7_CONTAINER_FROM_VTBL_CLS(ptr, type, m) Z7_CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m) /* #define Z7_CONTAINER_FROM_VTBL_CLS(ptr, type, m) Z7_CONTAINER_FROM_VTBL(ptr, type, m) */ #if defined (__clang__) || defined(__GNUC__) #define Z7_DIAGNOSTIC_IGNORE_BEGIN_CAST_QUAL \ _Pragma("GCC diagnostic push") \ _Pragma("GCC diagnostic ignored \"-Wcast-qual\"") #define Z7_DIAGNOSTIC_IGNORE_END_CAST_QUAL \ _Pragma("GCC diagnostic pop") #else #define Z7_DIAGNOSTIC_IGNORE_BEGIN_CAST_QUAL #define Z7_DIAGNOSTIC_IGNORE_END_CAST_QUAL #endif #define Z7_CONTAINER_FROM_VTBL_TO_DECL_VAR(ptr, type, m, p) \ Z7_DIAGNOSTIC_IGNORE_BEGIN_CAST_QUAL \ type *p = Z7_CONTAINER_FROM_VTBL(ptr, type, m); \ Z7_DIAGNOSTIC_IGNORE_END_CAST_QUAL #define Z7_CONTAINER_FROM_VTBL_TO_DECL_VAR_pp_vt_p(type) \ Z7_CONTAINER_FROM_VTBL_TO_DECL_VAR(pp, type, vt, p) // #define ZIP7_DECLARE_HANDLE(name) typedef void *name; #define Z7_DECLARE_HANDLE(name) struct name##_dummy{int unused;}; typedef struct name##_dummy *name; #define Z7_memset_0_ARRAY(a) memset((a), 0, sizeof(a)) #ifndef Z7_ARRAY_SIZE #define Z7_ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) #endif #ifdef _WIN32 #define CHAR_PATH_SEPARATOR '\\' #define WCHAR_PATH_SEPARATOR L'\\' #define STRING_PATH_SEPARATOR "\\" #define WSTRING_PATH_SEPARATOR L"\\" #else #define CHAR_PATH_SEPARATOR '/' #define WCHAR_PATH_SEPARATOR L'/' #define STRING_PATH_SEPARATOR "/" #define WSTRING_PATH_SEPARATOR L"/" #endif #define k_PropVar_TimePrec_0 0 #define k_PropVar_TimePrec_Unix 1 #define k_PropVar_TimePrec_DOS 2 #define k_PropVar_TimePrec_HighPrec 3 #define k_PropVar_TimePrec_Base 16 #define k_PropVar_TimePrec_100ns (k_PropVar_TimePrec_Base + 7) #define k_PropVar_TimePrec_1ns (k_PropVar_TimePrec_Base + 9) EXTERN_C_END #endif /* #ifndef Z7_ST #ifdef _7ZIP_ST #define Z7_ST #endif #endif */ |