• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <stddef.h>
12 
13 #ifndef EXTERN_C_BEGIN
14 #ifdef __cplusplus
15 #define EXTERN_C_BEGIN extern "C" {
16 #define EXTERN_C_END }
17 #else
18 #define EXTERN_C_BEGIN
19 #define EXTERN_C_END
20 #endif
21 #endif
22 
23 EXTERN_C_BEGIN
24 
25 #define SZ_OK 0
26 
27 #define SZ_ERROR_DATA 1
28 #define SZ_ERROR_MEM 2
29 #define SZ_ERROR_CRC 3
30 #define SZ_ERROR_UNSUPPORTED 4
31 #define SZ_ERROR_PARAM 5
32 #define SZ_ERROR_INPUT_EOF 6
33 #define SZ_ERROR_OUTPUT_EOF 7
34 #define SZ_ERROR_READ 8
35 #define SZ_ERROR_WRITE 9
36 #define SZ_ERROR_PROGRESS 10
37 #define SZ_ERROR_FAIL 11
38 #define SZ_ERROR_THREAD 12
39 
40 #define SZ_ERROR_ARCHIVE 16
41 #define SZ_ERROR_NO_ARCHIVE 17
42 
43 typedef int SRes;
44 
45 #ifdef _WIN32
46 /* typedef DWORD WRes; */
47 typedef unsigned 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_NO_INLINE
121 #define MY_CDECL
122 #define MY_FAST_CALL
123 
124 #endif
125 
126 
127 /* The following interfaces use first parameter as pointer to structure */
128 
129 typedef struct
130 {
131   Byte (*Read)(void *p); /* reads one byte, returns 0 in case of EOF or error */
132 } IByteIn;
133 
134 typedef struct
135 {
136   void (*Write)(void *p, Byte b);
137 } IByteOut;
138 
139 typedef struct
140 {
141   SRes (*Read)(void *p, void *buf, size_t *size);
142     /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
143        (output(*size) < input(*size)) is allowed */
144 } ISeqInStream;
145 
146 /* it can return SZ_ERROR_INPUT_EOF */
147 SRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size);
148 SRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType);
149 SRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf);
150 
151 typedef struct
152 {
153   size_t (*Write)(void *p, const void *buf, size_t size);
154     /* Returns: result - the number of actually written bytes.
155        (result < size) means error */
156 } ISeqOutStream;
157 
158 typedef enum
159 {
160   SZ_SEEK_SET = 0,
161   SZ_SEEK_CUR = 1,
162   SZ_SEEK_END = 2
163 } ESzSeek;
164 
165 typedef struct
166 {
167   SRes (*Read)(void *p, void *buf, size_t *size);  /* same as ISeqInStream::Read */
168   SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);
169 } ISeekInStream;
170 
171 typedef struct
172 {
173   SRes (*Look)(void *p, const void **buf, size_t *size);
174     /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
175        (output(*size) > input(*size)) is not allowed
176        (output(*size) < input(*size)) is allowed */
177   SRes (*Skip)(void *p, size_t offset);
178     /* offset must be <= output(*size) of Look */
179 
180   SRes (*Read)(void *p, void *buf, size_t *size);
181     /* reads directly (without buffer). It's same as ISeqInStream::Read */
182   SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);
183 } ILookInStream;
184 
185 SRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size);
186 SRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset);
187 
188 /* reads via ILookInStream::Read */
189 SRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType);
190 SRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size);
191 
192 #define LookToRead_BUF_SIZE (1 << 14)
193 
194 typedef struct
195 {
196   ILookInStream s;
197   ISeekInStream *realStream;
198   size_t pos;
199   size_t size;
200   Byte buf[LookToRead_BUF_SIZE];
201 } CLookToRead;
202 
203 void LookToRead_CreateVTable(CLookToRead *p, int lookahead);
204 void LookToRead_Init(CLookToRead *p);
205 
206 typedef struct
207 {
208   ISeqInStream s;
209   ILookInStream *realStream;
210 } CSecToLook;
211 
212 void SecToLook_CreateVTable(CSecToLook *p);
213 
214 typedef struct
215 {
216   ISeqInStream s;
217   ILookInStream *realStream;
218 } CSecToRead;
219 
220 void SecToRead_CreateVTable(CSecToRead *p);
221 
222 typedef struct
223 {
224   SRes (*Progress)(void *p, UInt64 inSize, UInt64 outSize);
225     /* Returns: result. (result != SZ_OK) means break.
226        Value (UInt64)(Int64)-1 for size means unknown value. */
227 } ICompressProgress;
228 
229 typedef struct
230 {
231   void *(*Alloc)(void *p, size_t size);
232   void (*Free)(void *p, void *address); /* address can be 0 */
233 } ISzAlloc;
234 
235 #define IAlloc_Alloc(p, size) (p)->Alloc((p), size)
236 #define IAlloc_Free(p, a) (p)->Free((p), a)
237 
238 #ifdef _WIN32
239 
240 #define CHAR_PATH_SEPARATOR '\\'
241 #define WCHAR_PATH_SEPARATOR L'\\'
242 #define STRING_PATH_SEPARATOR "\\"
243 #define WSTRING_PATH_SEPARATOR L"\\"
244 
245 #else
246 
247 #define CHAR_PATH_SEPARATOR '/'
248 #define WCHAR_PATH_SEPARATOR L'/'
249 #define STRING_PATH_SEPARATOR "/"
250 #define WSTRING_PATH_SEPARATOR L"/"
251 
252 #endif
253 
254 EXTERN_C_END
255 
256 #endif
257