]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/7zTypes.h
IntelFrameworkModulePkg LzmaDecompressLib: Update LZMA to new 16.04 version
[mirror_edk2.git] / IntelFrameworkModulePkg / Library / LzmaCustomDecompressLib / Sdk / C / 7zTypes.h
1 /* 7zTypes.h -- Basic types
2 2013-11-12 : 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 #ifdef _WIN32
50 /* typedef DWORD WRes; */
51 typedef unsigned WRes;
52 #else
53 typedef int WRes;
54 #endif
55
56 #ifndef RINOK
57 #define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; }
58 #endif
59
60 typedef unsigned char Byte;
61 typedef short Int16;
62 typedef unsigned short UInt16;
63
64 #ifdef _LZMA_UINT32_IS_ULONG
65 typedef long Int32;
66 typedef unsigned long UInt32;
67 #else
68 typedef int Int32;
69 typedef unsigned int UInt32;
70 #endif
71
72 #ifdef _SZ_NO_INT_64
73
74 /* define _SZ_NO_INT_64, if your compiler doesn't support 64-bit integers.
75 NOTES: Some code will work incorrectly in that case! */
76
77 typedef long Int64;
78 typedef unsigned long UInt64;
79
80 #else
81
82 #if defined(_MSC_VER) || defined(__BORLANDC__)
83 typedef __int64 Int64;
84 typedef unsigned __int64 UInt64;
85 #define UINT64_CONST(n) n
86 #else
87 typedef long long int Int64;
88 typedef unsigned long long int UInt64;
89 #define UINT64_CONST(n) n ## ULL
90 #endif
91
92 #endif
93
94 #ifdef _LZMA_NO_SYSTEM_SIZE_T
95 typedef UInt32 SizeT;
96 #else
97 typedef size_t SizeT;
98 #endif
99
100 typedef int Bool;
101 #define True 1
102 #define False 0
103
104
105 #ifdef _WIN32
106 #define MY_STD_CALL __stdcall
107 #else
108 #define MY_STD_CALL
109 #endif
110
111 #ifdef _MSC_VER
112
113 #if _MSC_VER >= 1300
114 #define MY_NO_INLINE __declspec(noinline)
115 #else
116 #define MY_NO_INLINE
117 #endif
118
119 #define MY_CDECL __cdecl
120 #define MY_FAST_CALL __fastcall
121
122 #else
123
124 #define MY_NO_INLINE
125 #define MY_CDECL
126 #define MY_FAST_CALL
127
128 #endif
129
130
131 /* The following interfaces use first parameter as pointer to structure */
132
133 typedef struct
134 {
135 Byte (*Read)(void *p); /* reads one byte, returns 0 in case of EOF or error */
136 } IByteIn;
137
138 typedef struct
139 {
140 void (*Write)(void *p, Byte b);
141 } IByteOut;
142
143 typedef struct
144 {
145 SRes (*Read)(void *p, void *buf, size_t *size);
146 /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
147 (output(*size) < input(*size)) is allowed */
148 } ISeqInStream;
149
150 /* it can return SZ_ERROR_INPUT_EOF */
151 SRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size);
152 SRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType);
153 SRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf);
154
155 typedef struct
156 {
157 size_t (*Write)(void *p, const void *buf, size_t size);
158 /* Returns: result - the number of actually written bytes.
159 (result < size) means error */
160 } ISeqOutStream;
161
162 typedef enum
163 {
164 SZ_SEEK_SET = 0,
165 SZ_SEEK_CUR = 1,
166 SZ_SEEK_END = 2
167 } ESzSeek;
168
169 typedef struct
170 {
171 SRes (*Read)(void *p, void *buf, size_t *size); /* same as ISeqInStream::Read */
172 SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);
173 } ISeekInStream;
174
175 typedef struct
176 {
177 SRes (*Look)(void *p, const void **buf, size_t *size);
178 /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
179 (output(*size) > input(*size)) is not allowed
180 (output(*size) < input(*size)) is allowed */
181 SRes (*Skip)(void *p, size_t offset);
182 /* offset must be <= output(*size) of Look */
183
184 SRes (*Read)(void *p, void *buf, size_t *size);
185 /* reads directly (without buffer). It's same as ISeqInStream::Read */
186 SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);
187 } ILookInStream;
188
189 SRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size);
190 SRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset);
191
192 /* reads via ILookInStream::Read */
193 SRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType);
194 SRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size);
195
196 #define LookToRead_BUF_SIZE (1 << 14)
197
198 typedef struct
199 {
200 ILookInStream s;
201 ISeekInStream *realStream;
202 size_t pos;
203 size_t size;
204 Byte buf[LookToRead_BUF_SIZE];
205 } CLookToRead;
206
207 void LookToRead_CreateVTable(CLookToRead *p, int lookahead);
208 void LookToRead_Init(CLookToRead *p);
209
210 typedef struct
211 {
212 ISeqInStream s;
213 ILookInStream *realStream;
214 } CSecToLook;
215
216 void SecToLook_CreateVTable(CSecToLook *p);
217
218 typedef struct
219 {
220 ISeqInStream s;
221 ILookInStream *realStream;
222 } CSecToRead;
223
224 void SecToRead_CreateVTable(CSecToRead *p);
225
226 typedef struct
227 {
228 SRes (*Progress)(void *p, UInt64 inSize, UInt64 outSize);
229 /* Returns: result. (result != SZ_OK) means break.
230 Value (UInt64)(Int64)-1 for size means unknown value. */
231 } ICompressProgress;
232
233 typedef struct
234 {
235 void *(*Alloc)(void *p, size_t size);
236 void (*Free)(void *p, void *address); /* address can be 0 */
237 } ISzAlloc;
238
239 #define IAlloc_Alloc(p, size) (p)->Alloc((p), size)
240 #define IAlloc_Free(p, a) (p)->Free((p), a)
241
242 #ifdef _WIN32
243
244 #define CHAR_PATH_SEPARATOR '\\'
245 #define WCHAR_PATH_SEPARATOR L'\\'
246 #define STRING_PATH_SEPARATOR "\\"
247 #define WSTRING_PATH_SEPARATOR L"\\"
248
249 #else
250
251 #define CHAR_PATH_SEPARATOR '/'
252 #define WCHAR_PATH_SEPARATOR L'/'
253 #define STRING_PATH_SEPARATOR "/"
254 #define WSTRING_PATH_SEPARATOR L"/"
255
256 #endif
257
258 EXTERN_C_END
259
260 #endif