]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/7zTypes.h
MdeModulePkg Lzma: Update LZMA SDK version to 19.00
[mirror_edk2.git] / MdeModulePkg / Library / LzmaCustomDecompressLib / Sdk / C / 7zTypes.h
1 /* 7zTypes.h -- Basic types
2 2018-08-04 : Igor Pavlov : Public domain */
3
4 #ifndef __7Z_TYPES_H
5 #define __7Z_TYPES_H
6
7 #ifdef _WIN32
8 /* #include <windows.h> */
9 #endif
10
11 #ifdef EFIAPI
12 #include "UefiLzma.h"
13 #else
14 #include <stddef.h>
15 #endif
16
17 #ifndef EXTERN_C_BEGIN
18 #ifdef __cplusplus
19 #define EXTERN_C_BEGIN extern "C" {
20 #define EXTERN_C_END }
21 #else
22 #define EXTERN_C_BEGIN
23 #define EXTERN_C_END
24 #endif
25 #endif
26
27 EXTERN_C_BEGIN
28
29 #define SZ_OK 0
30
31 #define SZ_ERROR_DATA 1
32 #define SZ_ERROR_MEM 2
33 #define SZ_ERROR_CRC 3
34 #define SZ_ERROR_UNSUPPORTED 4
35 #define SZ_ERROR_PARAM 5
36 #define SZ_ERROR_INPUT_EOF 6
37 #define SZ_ERROR_OUTPUT_EOF 7
38 #define SZ_ERROR_READ 8
39 #define SZ_ERROR_WRITE 9
40 #define SZ_ERROR_PROGRESS 10
41 #define SZ_ERROR_FAIL 11
42 #define SZ_ERROR_THREAD 12
43
44 #define SZ_ERROR_ARCHIVE 16
45 #define SZ_ERROR_NO_ARCHIVE 17
46
47 typedef int SRes;
48
49
50 #ifdef _WIN32
51
52 /* typedef DWORD WRes; */
53 typedef unsigned WRes;
54 #define MY_SRes_HRESULT_FROM_WRes(x) HRESULT_FROM_WIN32(x)
55
56 #else
57
58 typedef int WRes;
59 #define MY__FACILITY_WIN32 7
60 #define MY__FACILITY__WRes MY__FACILITY_WIN32
61 #define MY_SRes_HRESULT_FROM_WRes(x) ((HRESULT)(x) <= 0 ? ((HRESULT)(x)) : ((HRESULT) (((x) & 0x0000FFFF) | (MY__FACILITY__WRes << 16) | 0x80000000)))
62
63 #endif
64
65
66 #ifndef RINOK
67 #define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; }
68 #endif
69
70 typedef unsigned char Byte;
71 typedef short Int16;
72 typedef unsigned short UInt16;
73
74 #ifdef _LZMA_UINT32_IS_ULONG
75 typedef long Int32;
76 typedef unsigned long UInt32;
77 #else
78 typedef int Int32;
79 typedef unsigned int UInt32;
80 #endif
81
82 #ifdef _SZ_NO_INT_64
83
84 /* define _SZ_NO_INT_64, if your compiler doesn't support 64-bit integers.
85 NOTES: Some code will work incorrectly in that case! */
86
87 typedef long Int64;
88 typedef unsigned long UInt64;
89
90 #else
91
92 #if defined(_MSC_VER) || defined(__BORLANDC__)
93 typedef __int64 Int64;
94 typedef unsigned __int64 UInt64;
95 #define UINT64_CONST(n) n
96 #else
97 typedef long long int Int64;
98 typedef unsigned long long int UInt64;
99 #define UINT64_CONST(n) n ## ULL
100 #endif
101
102 #endif
103
104 #ifdef _LZMA_NO_SYSTEM_SIZE_T
105 typedef UInt32 SizeT;
106 #else
107 typedef size_t SizeT;
108 #endif
109
110 typedef int BoolInt;
111 /* typedef BoolInt Bool; */
112 #define True 1
113 #define False 0
114
115
116 #ifdef _WIN32
117 #define MY_STD_CALL __stdcall
118 #else
119 #define MY_STD_CALL
120 #endif
121
122 #if defined(_MSC_VER) && !defined(__clang__)
123
124 #if _MSC_VER >= 1300
125 #define MY_NO_INLINE __declspec(noinline)
126 #else
127 #define MY_NO_INLINE
128 #endif
129
130 #define MY_FORCE_INLINE __forceinline
131
132 #define MY_CDECL __cdecl
133 #define MY_FAST_CALL __fastcall
134
135 #else
136
137 #define MY_NO_INLINE
138 #define MY_FORCE_INLINE
139 #define MY_CDECL
140 #define MY_FAST_CALL
141
142 /* inline keyword : for C++ / C99 */
143
144 /* GCC, clang: */
145 /*
146 #if defined (__GNUC__) && (__GNUC__ >= 4)
147 #define MY_FORCE_INLINE __attribute__((always_inline))
148 #define MY_NO_INLINE __attribute__((noinline))
149 #endif
150 */
151
152 #endif
153
154
155 /* The following interfaces use first parameter as pointer to structure */
156
157 typedef struct IByteIn IByteIn;
158 struct IByteIn
159 {
160 Byte (*Read)(const IByteIn *p); /* reads one byte, returns 0 in case of EOF or error */
161 };
162 #define IByteIn_Read(p) (p)->Read(p)
163
164
165 typedef struct IByteOut IByteOut;
166 struct IByteOut
167 {
168 void (*Write)(const IByteOut *p, Byte b);
169 };
170 #define IByteOut_Write(p, b) (p)->Write(p, b)
171
172
173 typedef struct ISeqInStream ISeqInStream;
174 struct ISeqInStream
175 {
176 SRes (*Read)(const ISeqInStream *p, void *buf, size_t *size);
177 /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
178 (output(*size) < input(*size)) is allowed */
179 };
180 #define ISeqInStream_Read(p, buf, size) (p)->Read(p, buf, size)
181
182 /* it can return SZ_ERROR_INPUT_EOF */
183 SRes SeqInStream_Read(const ISeqInStream *stream, void *buf, size_t size);
184 SRes SeqInStream_Read2(const ISeqInStream *stream, void *buf, size_t size, SRes errorType);
185 SRes SeqInStream_ReadByte(const ISeqInStream *stream, Byte *buf);
186
187
188 typedef struct ISeqOutStream ISeqOutStream;
189 struct ISeqOutStream
190 {
191 size_t (*Write)(const ISeqOutStream *p, const void *buf, size_t size);
192 /* Returns: result - the number of actually written bytes.
193 (result < size) means error */
194 };
195 #define ISeqOutStream_Write(p, buf, size) (p)->Write(p, buf, size)
196
197 typedef enum
198 {
199 SZ_SEEK_SET = 0,
200 SZ_SEEK_CUR = 1,
201 SZ_SEEK_END = 2
202 } ESzSeek;
203
204
205 typedef struct ISeekInStream ISeekInStream;
206 struct ISeekInStream
207 {
208 SRes (*Read)(const ISeekInStream *p, void *buf, size_t *size); /* same as ISeqInStream::Read */
209 SRes (*Seek)(const ISeekInStream *p, Int64 *pos, ESzSeek origin);
210 };
211 #define ISeekInStream_Read(p, buf, size) (p)->Read(p, buf, size)
212 #define ISeekInStream_Seek(p, pos, origin) (p)->Seek(p, pos, origin)
213
214
215 typedef struct ILookInStream ILookInStream;
216 struct ILookInStream
217 {
218 SRes (*Look)(const ILookInStream *p, const void **buf, size_t *size);
219 /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
220 (output(*size) > input(*size)) is not allowed
221 (output(*size) < input(*size)) is allowed */
222 SRes (*Skip)(const ILookInStream *p, size_t offset);
223 /* offset must be <= output(*size) of Look */
224
225 SRes (*Read)(const ILookInStream *p, void *buf, size_t *size);
226 /* reads directly (without buffer). It's same as ISeqInStream::Read */
227 SRes (*Seek)(const ILookInStream *p, Int64 *pos, ESzSeek origin);
228 };
229
230 #define ILookInStream_Look(p, buf, size) (p)->Look(p, buf, size)
231 #define ILookInStream_Skip(p, offset) (p)->Skip(p, offset)
232 #define ILookInStream_Read(p, buf, size) (p)->Read(p, buf, size)
233 #define ILookInStream_Seek(p, pos, origin) (p)->Seek(p, pos, origin)
234
235
236 SRes LookInStream_LookRead(const ILookInStream *stream, void *buf, size_t *size);
237 SRes LookInStream_SeekTo(const ILookInStream *stream, UInt64 offset);
238
239 /* reads via ILookInStream::Read */
240 SRes LookInStream_Read2(const ILookInStream *stream, void *buf, size_t size, SRes errorType);
241 SRes LookInStream_Read(const ILookInStream *stream, void *buf, size_t size);
242
243
244
245 typedef struct
246 {
247 ILookInStream vt;
248 const ISeekInStream *realStream;
249
250 size_t pos;
251 size_t size; /* it's data size */
252
253 /* the following variables must be set outside */
254 Byte *buf;
255 size_t bufSize;
256 } CLookToRead2;
257
258 void LookToRead2_CreateVTable(CLookToRead2 *p, int lookahead);
259
260 #define LookToRead2_Init(p) { (p)->pos = (p)->size = 0; }
261
262
263 typedef struct
264 {
265 ISeqInStream vt;
266 const ILookInStream *realStream;
267 } CSecToLook;
268
269 void SecToLook_CreateVTable(CSecToLook *p);
270
271
272
273 typedef struct
274 {
275 ISeqInStream vt;
276 const ILookInStream *realStream;
277 } CSecToRead;
278
279 void SecToRead_CreateVTable(CSecToRead *p);
280
281
282 typedef struct ICompressProgress ICompressProgress;
283
284 struct ICompressProgress
285 {
286 SRes (*Progress)(const ICompressProgress *p, UInt64 inSize, UInt64 outSize);
287 /* Returns: result. (result != SZ_OK) means break.
288 Value (UInt64)(Int64)-1 for size means unknown value. */
289 };
290 #define ICompressProgress_Progress(p, inSize, outSize) (p)->Progress(p, inSize, outSize)
291
292
293
294 typedef struct ISzAlloc ISzAlloc;
295 typedef const ISzAlloc * ISzAllocPtr;
296
297 struct ISzAlloc
298 {
299 void *(*Alloc)(ISzAllocPtr p, size_t size);
300 void (*Free)(ISzAllocPtr p, void *address); /* address can be 0 */
301 };
302
303 #define ISzAlloc_Alloc(p, size) (p)->Alloc(p, size)
304 #define ISzAlloc_Free(p, a) (p)->Free(p, a)
305
306 /* deprecated */
307 #define IAlloc_Alloc(p, size) ISzAlloc_Alloc(p, size)
308 #define IAlloc_Free(p, a) ISzAlloc_Free(p, a)
309
310
311
312
313
314 #ifndef MY_offsetof
315 #ifdef offsetof
316 #define MY_offsetof(type, m) offsetof(type, m)
317 /*
318 #define MY_offsetof(type, m) FIELD_OFFSET(type, m)
319 */
320 #else
321 #define MY_offsetof(type, m) ((size_t)&(((type *)0)->m))
322 #endif
323 #endif
324
325
326
327 #ifndef MY_container_of
328
329 /*
330 #define MY_container_of(ptr, type, m) container_of(ptr, type, m)
331 #define MY_container_of(ptr, type, m) CONTAINING_RECORD(ptr, type, m)
332 #define MY_container_of(ptr, type, m) ((type *)((char *)(ptr) - offsetof(type, m)))
333 #define MY_container_of(ptr, type, m) (&((type *)0)->m == (ptr), ((type *)(((char *)(ptr)) - MY_offsetof(type, m))))
334 */
335
336 /*
337 GCC shows warning: "perhaps the 'offsetof' macro was used incorrectly"
338 GCC 3.4.4 : classes with constructor
339 GCC 4.8.1 : classes with non-public variable members"
340 */
341
342 #define MY_container_of(ptr, type, m) ((type *)((char *)(1 ? (ptr) : &((type *)0)->m) - MY_offsetof(type, m)))
343
344
345 #endif
346
347 #define CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m) ((type *)(ptr))
348
349 /*
350 #define CONTAINER_FROM_VTBL(ptr, type, m) CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m)
351 */
352 #define CONTAINER_FROM_VTBL(ptr, type, m) MY_container_of(ptr, type, m)
353
354 #define CONTAINER_FROM_VTBL_CLS(ptr, type, m) CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m)
355 /*
356 #define CONTAINER_FROM_VTBL_CLS(ptr, type, m) CONTAINER_FROM_VTBL(ptr, type, m)
357 */
358
359
360
361 #ifdef _WIN32
362
363 #define CHAR_PATH_SEPARATOR '\\'
364 #define WCHAR_PATH_SEPARATOR L'\\'
365 #define STRING_PATH_SEPARATOR "\\"
366 #define WSTRING_PATH_SEPARATOR L"\\"
367
368 #else
369
370 #define CHAR_PATH_SEPARATOR '/'
371 #define WCHAR_PATH_SEPARATOR L'/'
372 #define STRING_PATH_SEPARATOR "/"
373 #define WSTRING_PATH_SEPARATOR L"/"
374
375 #endif
376
377 EXTERN_C_END
378
379 #endif