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