1 /**************************************************************************
3 * Copyright 2013-2014 RAD Game Tools and Valve Software
4 * Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 **************************************************************************/
27 /* Types.h -- Basic types
28 2008-11-23 : Igor Pavlov : Public domain */
37 #define COMPRESS_MF_MT
45 #define SZ_ERROR_DATA 1
46 #define SZ_ERROR_MEM 2
47 #define SZ_ERROR_CRC 3
48 #define SZ_ERROR_UNSUPPORTED 4
49 #define SZ_ERROR_PARAM 5
50 #define SZ_ERROR_INPUT_EOF 6
51 #define SZ_ERROR_OUTPUT_EOF 7
52 #define SZ_ERROR_READ 8
53 #define SZ_ERROR_WRITE 9
54 #define SZ_ERROR_PROGRESS 10
55 #define SZ_ERROR_FAIL 11
56 #define SZ_ERROR_THREAD 12
58 #define SZ_ERROR_ARCHIVE 16
59 #define SZ_ERROR_NO_ARCHIVE 17
72 int __result__ = (x); \
73 if (__result__ != 0) \
78 typedef unsigned char Byte;
80 typedef unsigned short UInt16;
82 #ifdef _LZMA_UINT32_IS_ULONG
84 typedef unsigned long UInt32;
87 typedef unsigned int UInt32;
92 /* define _SZ_NO_INT_64, if your compiler doesn't support 64-bit integers.
93 NOTES: Some code will work incorrectly in that case! */
96 typedef unsigned long UInt64;
100 #if defined(_MSC_VER) || defined(__BORLANDC__)
101 typedef __int64 Int64;
102 typedef unsigned __int64 UInt64;
104 typedef long long int Int64;
105 typedef unsigned long long int UInt64;
110 #ifdef _LZMA_NO_SYSTEM_SIZE_T
111 typedef UInt32 SizeT;
113 typedef size_t SizeT;
123 #define MY_NO_INLINE __declspec(noinline)
128 #define MY_CDECL __cdecl
129 #define MY_STD_CALL __stdcall
130 #define MY_FAST_CALL MY_NO_INLINE __fastcall
140 /* The following interfaces use first parameter as pointer to structure */
144 SRes (*Read)(void *p, void *buf, size_t *size);
145 /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
146 (output(*size) < input(*size)) is allowed */
149 /* it can return SZ_ERROR_INPUT_EOF */
150 SRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size);
151 SRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType);
152 SRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf);
156 size_t (*Write)(void *p, const void *buf, size_t size);
157 /* Returns: result - the number of actually written bytes.
158 (result < size) means error */
170 SRes (*Read)(void *p, void *buf, size_t *size); /* same as ISeqInStream::Read */
171 SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);
176 SRes (*Look)(void *p, void **buf, size_t *size);
177 /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
178 (output(*size) > input(*size)) is not allowed
179 (output(*size) < input(*size)) is allowed */
180 SRes (*Skip)(void *p, size_t offset);
181 /* offset must be <= output(*size) of Look */
183 SRes (*Read)(void *p, void *buf, size_t *size);
184 /* reads directly (without buffer). It's same as ISeqInStream::Read */
185 SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);
188 SRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size);
189 SRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset);
191 /* reads via ILookInStream::Read */
192 SRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType);
193 SRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size);
195 #define LookToRead_BUF_SIZE (1 << 14)
200 ISeekInStream *realStream;
203 Byte buf[LookToRead_BUF_SIZE];
206 void LookToRead_CreateVTable(CLookToRead *p, int lookahead);
207 void LookToRead_Init(CLookToRead *p);
212 ILookInStream *realStream;
215 void SecToLook_CreateVTable(CSecToLook *p);
220 ILookInStream *realStream;
223 void SecToRead_CreateVTable(CSecToRead *p);
227 SRes (*Progress)(void *p, UInt64 inSize, UInt64 outSize);
228 /* Returns: result. (result != SZ_OK) means break.
229 Value (UInt64)(Int64)-1 for size means unknown value. */
234 void *(*Alloc)(void *p, size_t size);
235 void (*Free)(void *p, void *address); /* address can be 0 */
238 #define IAlloc_Alloc(p, size) (p)->Alloc((p), size)
239 #define IAlloc_Free(p, a) (p)->Free((p), a)