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