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