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