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