TianoCore EDK2 master
Loading...
Searching...
No Matches
7zTypes.h
1/* 7zTypes.h -- Basic types
22018-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
27EXTERN_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
47typedef int SRes;
48
49#ifdef _WIN32
50
51/* typedef DWORD WRes; */
52typedef unsigned WRes;
53#define MY_SRes_HRESULT_FROM_WRes(x) HRESULT_FROM_WIN32(x)
54
55#else
56
57typedef int WRes;
58#define MY__FACILITY_WIN32 7
59#define MY__FACILITY__WRes MY__FACILITY_WIN32
60#define MY_SRes_HRESULT_FROM_WRes(x) ((HRESULT)(x) <= 0 ? ((HRESULT)(x)) : ((HRESULT) (((x) & 0x0000FFFF) | (MY__FACILITY__WRes << 16) | 0x80000000)))
61
62#endif
63
64#ifndef RINOK
65#define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; }
66#endif
67
68typedef unsigned char Byte;
69typedef short Int16;
70typedef unsigned short UInt16;
71
72#ifdef _LZMA_UINT32_IS_ULONG
73typedef long Int32;
74typedef unsigned long UInt32;
75#else
76typedef int Int32;
77typedef unsigned int UInt32;
78#endif
79
80#ifdef _SZ_NO_INT_64
81
82/* define _SZ_NO_INT_64, if your compiler doesn't support 64-bit integers.
83 NOTES: Some code will work incorrectly in that case! */
84
85typedef long Int64;
86typedef unsigned long UInt64;
87
88#else
89
90 #if defined (_MSC_VER) || defined (__BORLANDC__)
91typedef __int64 Int64;
92typedef unsigned __int64 UInt64;
93#define UINT64_CONST(n) n
94 #else
95typedef long long int Int64;
96typedef unsigned long long int UInt64;
97#define UINT64_CONST(n) n ## ULL
98 #endif
99
100#endif
101
102#ifdef _LZMA_NO_SYSTEM_SIZE_T
103typedef UInt32 SizeT;
104#else
105typedef size_t SizeT;
106#endif
107
108typedef int BoolInt;
109/* typedef BoolInt Bool; */
110#define True 1
111#define False 0
112
113#ifdef _WIN32
114#define MY_STD_CALL __stdcall
115#else
116#define MY_STD_CALL
117#endif
118
119#if defined (_MSC_VER) && !defined (__clang__)
120
121 #if _MSC_VER >= 1300
122#define MY_NO_INLINE __declspec(noinline)
123 #else
124#define MY_NO_INLINE
125 #endif
126
127#define MY_FORCE_INLINE __forceinline
128
129#define MY_CDECL __cdecl
130#define MY_FAST_CALL __fastcall
131
132#else
133
134#define MY_NO_INLINE
135#define MY_FORCE_INLINE
136#define MY_CDECL
137#define MY_FAST_CALL
138
139/* inline keyword : for C++ / C99 */
140
141/* GCC, clang: */
142
143/*
144#if defined (__GNUC__) && (__GNUC__ >= 4)
145#define MY_FORCE_INLINE __attribute__((always_inline))
146#define MY_NO_INLINE __attribute__((noinline))
147#endif
148*/
149
150#endif
151
152/* The following interfaces use first parameter as pointer to structure */
153
154typedef struct IByteIn IByteIn;
155struct IByteIn {
156 Byte (*Read)(
157 const IByteIn *p
158 ); /* reads one byte, returns 0 in case of EOF or error */
159};
160
161#define IByteIn_Read(p) (p)->Read(p)
162
163typedef struct IByteOut IByteOut;
164struct IByteOut {
165 void (*Write)(
166 const IByteOut *p,
167 Byte b
168 );
169};
170
171#define IByteOut_Write(p, b) (p)->Write(p, b)
172
173typedef struct ISeqInStream ISeqInStream;
175 SRes (*Read)(
176 const ISeqInStream *p,
177 void *buf,
178 size_t *size
179 );
180
181 /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
182 (output(*size) < input(*size)) is allowed */
183};
184
185#define ISeqInStream_Read(p, buf, size) (p)->Read(p, buf, size)
186
187/* it can return SZ_ERROR_INPUT_EOF */
188SRes
189SeqInStream_Read (
190 const ISeqInStream *stream,
191 void *buf,
192 size_t size
193 );
194
195SRes
196SeqInStream_Read2 (
197 const ISeqInStream *stream,
198 void *buf,
199 size_t size,
200 SRes errorType
201 );
202
203SRes
204SeqInStream_ReadByte (
205 const ISeqInStream *stream,
206 Byte *buf
207 );
208
209typedef struct ISeqOutStream ISeqOutStream;
211 size_t (*Write)(
212 const ISeqOutStream *p,
213 const void *buf,
214 size_t size
215 );
216
217 /* Returns: result - the number of actually written bytes.
218 (result < size) means error */
219};
220
221#define ISeqOutStream_Write(p, buf, size) (p)->Write(p, buf, size)
222
223typedef enum {
224 SZ_SEEK_SET = 0,
225 SZ_SEEK_CUR = 1,
226 SZ_SEEK_END = 2
227} ESzSeek;
228
229typedef struct ISeekInStream ISeekInStream;
231 SRes (*Read)(
232 const ISeekInStream *p,
233 void *buf,
234 size_t *size
235 ); /* same as ISeqInStream::Read */
236 SRes (*Seek)(
237 const ISeekInStream *p,
238 Int64 *pos,
239 ESzSeek origin
240 );
241};
242
243#define ISeekInStream_Read(p, buf, size) (p)->Read(p, buf, size)
244#define ISeekInStream_Seek(p, pos, origin) (p)->Seek(p, pos, origin)
245
246typedef struct ILookInStream ILookInStream;
248 SRes (*Look)(
249 const ILookInStream *p,
250 const void **buf,
251 size_t *size
252 );
253
254 /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
255 (output(*size) > input(*size)) is not allowed
256 (output(*size) < input(*size)) is allowed */
257 SRes (*Skip)(
258 const ILookInStream *p,
259 size_t offset
260 );
261 /* offset must be <= output(*size) of Look */
262
263 SRes (*Read)(
264 const ILookInStream *p,
265 void *buf,
266 size_t *size
267 );
268 /* reads directly (without buffer). It's same as ISeqInStream::Read */
269 SRes (*Seek)(
270 const ILookInStream *p,
271 Int64 *pos,
272 ESzSeek origin
273 );
274};
275
276#define ILookInStream_Look(p, buf, size) (p)->Look(p, buf, size)
277#define ILookInStream_Skip(p, offset) (p)->Skip(p, offset)
278#define ILookInStream_Read(p, buf, size) (p)->Read(p, buf, size)
279#define ILookInStream_Seek(p, pos, origin) (p)->Seek(p, pos, origin)
280
281SRes
282LookInStream_LookRead (
283 const ILookInStream *stream,
284 void *buf,
285 size_t *size
286 );
287
288SRes
289LookInStream_SeekTo (
290 const ILookInStream *stream,
291 UInt64 offset
292 );
293
294/* reads via ILookInStream::Read */
295SRes
296LookInStream_Read2 (
297 const ILookInStream *stream,
298 void *buf,
299 size_t size,
300 SRes errorType
301 );
302
303SRes
304LookInStream_Read (
305 const ILookInStream *stream,
306 void *buf,
307 size_t size
308 );
309
310typedef struct {
311 ILookInStream vt;
312 const ISeekInStream *realStream;
313
314 size_t pos;
315 size_t size; /* it's data size */
316
317 /* the following variables must be set outside */
318 Byte *buf;
319 size_t bufSize;
321
322void
323LookToRead2_CreateVTable (
324 CLookToRead2 *p,
325 int lookahead
326 );
327
328#define LookToRead2_Init(p) { (p)->pos = (p)->size = 0; }
329
330typedef struct {
331 ISeqInStream vt;
332 const ILookInStream *realStream;
333} CSecToLook;
334
335void
336SecToLook_CreateVTable (
337 CSecToLook *p
338 );
339
340typedef struct {
341 ISeqInStream vt;
342 const ILookInStream *realStream;
343} CSecToRead;
344
345void
346SecToRead_CreateVTable (
347 CSecToRead *p
348 );
349
351
353 SRes (*Progress)(
354 const ICompressProgress *p,
355 UInt64 inSize,
356 UInt64 outSize
357 );
358
359 /* Returns: result. (result != SZ_OK) means break.
360 Value (UInt64)(Int64)-1 for size means unknown value. */
361};
362
363#define ICompressProgress_Progress(p, inSize, outSize) (p)->Progress(p, inSize, outSize)
364
365typedef struct ISzAlloc ISzAlloc;
366typedef const ISzAlloc *ISzAllocPtr;
367
368struct ISzAlloc {
369 void *(*Alloc)(
370 ISzAllocPtr p,
371 size_t size
372 );
373 void (*Free)(
374 ISzAllocPtr p,
375 void *address
376 ); /* address can be 0 */
377};
378
379#define ISzAlloc_Alloc(p, size) (p)->Alloc(p, size)
380#define ISzAlloc_Free(p, a) (p)->Free(p, a)
381
382/* deprecated */
383#define IAlloc_Alloc(p, size) ISzAlloc_Alloc(p, size)
384#define IAlloc_Free(p, a) ISzAlloc_Free(p, a)
385
386#ifndef MY_offsetof
387 #ifdef offsetof
388#define MY_offsetof(type, m) offsetof(type, m)
389
390/*
391#define MY_offsetof(type, m) FIELD_OFFSET(type, m)
392*/
393 #else
394#define MY_offsetof(type, m) ((size_t)&(((type *)0)->m))
395 #endif
396#endif
397
398#ifndef MY_container_of
399
400/*
401#define MY_container_of(ptr, type, m) container_of(ptr, type, m)
402#define MY_container_of(ptr, type, m) CONTAINING_RECORD(ptr, type, m)
403#define MY_container_of(ptr, type, m) ((type *)((char *)(ptr) - offsetof(type, m)))
404#define MY_container_of(ptr, type, m) (&((type *)0)->m == (ptr), ((type *)(((char *)(ptr)) - MY_offsetof(type, m))))
405*/
406
407/*
408 GCC shows warning: "perhaps the 'offsetof' macro was used incorrectly"
409 GCC 3.4.4 : classes with constructor
410 GCC 4.8.1 : classes with non-public variable members"
411*/
412
413#define MY_container_of(ptr, type, m) ((type *)((char *)(1 ? (ptr) : &((type *)0)->m) - MY_offsetof(type, m)))
414
415#endif
416
417#define CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m) ((type *)(ptr))
418
419/*
420#define CONTAINER_FROM_VTBL(ptr, type, m) CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m)
421*/
422#define CONTAINER_FROM_VTBL(ptr, type, m) MY_container_of(ptr, type, m)
423
424#define CONTAINER_FROM_VTBL_CLS(ptr, type, m) CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m)
425
426/*
427#define CONTAINER_FROM_VTBL_CLS(ptr, type, m) CONTAINER_FROM_VTBL(ptr, type, m)
428*/
429
430#ifdef _WIN32
431
432#define CHAR_PATH_SEPARATOR '\\'
433#define WCHAR_PATH_SEPARATOR L'\\'
434#define STRING_PATH_SEPARATOR "\\"
435#define WSTRING_PATH_SEPARATOR L"\\"
436
437#else
438
439#define CHAR_PATH_SEPARATOR '/'
440#define WCHAR_PATH_SEPARATOR L'/'
441#define STRING_PATH_SEPARATOR "/"
442#define WSTRING_PATH_SEPARATOR L"/"
443
444#endif
445
446EXTERN_C_END
447
448#endif