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