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