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