1/* Types.h -- Basic types
22010-10-09 : Igor Pavlov : Public domain
3in 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
24EXTERN_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
44typedef int SRes;
45
46#ifdef _WIN32
47typedef DWORD WRes;
48#else
49typedef int WRes;
50#endif
51
52#ifndef RINOK
53#define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; }
54#endif
55
56typedef unsigned char Byte;
57typedef short Int16;
58typedef unsigned short UInt16;
59
60#ifdef _LZMA_UINT32_IS_ULONG
61typedef long Int32;
62typedef unsigned long UInt32;
63#else
64typedef int Int32;
65typedef 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
73typedef long Int64;
74typedef unsigned long UInt64;
75
76#else
77
78#if defined(_MSC_VER) || defined(__BORLANDC__)
79typedef __int64 Int64;
80typedef unsigned __int64 UInt64;
81#define UINT64_CONST(n) n
82#else
83typedef long long int Int64;
84typedef 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
91typedef UInt32 SizeT;
92#else
93typedef size_t SizeT;
94#endif
95
96typedef 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
128typedef struct
129{
130  Byte (*Read)(void *p); /* reads one byte, returns 0 in case of EOF or error */
131} IByteIn;
132
133typedef struct
134{
135  void (*Write)(void *p, Byte b);
136} IByteOut;
137
138typedef 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 */
146SRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size);
147SRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType);
148SRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf);
149
150typedef 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
157typedef enum
158{
159  SZ_SEEK_SET = 0,
160  SZ_SEEK_CUR = 1,
161  SZ_SEEK_END = 2
162} ESzSeek;
163
164typedef 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
170typedef 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
184SRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size);
185SRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset);
186
187/* reads via ILookInStream::Read */
188SRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType);
189SRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size);
190
191#define LookToRead_BUF_SIZE (1 << 14)
192
193typedef 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
202void LookToRead_CreateVTable(CLookToRead *p, int lookahead);
203void LookToRead_Init(CLookToRead *p);
204
205typedef struct
206{
207  ISeqInStream s;
208  ILookInStream *realStream;
209} CSecToLook;
210
211void SecToLook_CreateVTable(CSecToLook *p);
212
213typedef struct
214{
215  ISeqInStream s;
216  ILookInStream *realStream;
217} CSecToRead;
218
219void SecToRead_CreateVTable(CSecToRead *p);
220
221typedef 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
228typedef 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
253EXTERN_C_END
254
255#endif
256