1 /* Types.h -- Basic types 2 2010-10-09 : 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 #define SZ_OK 0 14 15 #define SZ_ERROR_DATA 1 16 #define SZ_ERROR_MEM 2 17 #define SZ_ERROR_CRC 3 18 #define SZ_ERROR_UNSUPPORTED 4 19 #define SZ_ERROR_PARAM 5 20 #define SZ_ERROR_INPUT_EOF 6 21 #define SZ_ERROR_OUTPUT_EOF 7 22 #define SZ_ERROR_READ 8 23 #define SZ_ERROR_WRITE 9 24 #define SZ_ERROR_PROGRESS 10 25 #define SZ_ERROR_FAIL 11 26 #define SZ_ERROR_THREAD 12 27 28 #define SZ_ERROR_ARCHIVE 16 29 #define SZ_ERROR_NO_ARCHIVE 17 30 31 typedef int SRes; 32 33 #ifdef _WIN32 34 typedef DWORD WRes; 35 #else 36 typedef int WRes; 37 #endif 38 39 #ifndef RINOK 40 #define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; } 41 #endif 42 43 typedef unsigned char Byte; 44 typedef short Int16; 45 typedef unsigned short UInt16; 46 47 #ifdef _LZMA_UINT32_IS_ULONG 48 typedef long Int32; 49 typedef unsigned long UInt32; 50 #else 51 typedef int Int32; 52 typedef unsigned int UInt32; 53 #endif 54 55 #ifdef _SZ_NO_INT_64 56 57 /* define _SZ_NO_INT_64, if your compiler doesn't support 64-bit integers. 58 NOTES: Some code will work incorrectly in that case! */ 59 60 typedef long Int64; 61 typedef unsigned long UInt64; 62 63 #else 64 65 #if defined(_MSC_VER) || defined(__BORLANDC__) 66 typedef __int64 Int64; 67 typedef unsigned __int64 UInt64; 68 #define UINT64_CONST(n) n 69 #else 70 typedef long long int Int64; 71 typedef unsigned long long int UInt64; 72 #define UINT64_CONST(n) n ## ULL 73 #endif 74 75 #endif 76 77 #ifdef _LZMA_NO_SYSTEM_SIZE_T 78 typedef UInt32 SizeT; 79 #else 80 typedef size_t SizeT; 81 #endif 82 83 typedef int Bool; 84 #define True 1 85 #define False 0 86 87 #ifdef _MSC_VER 88 89 #if _MSC_VER >= 1300 90 #define MY_NO_INLINE __declspec(noinline) 91 #else 92 #define MY_NO_INLINE 93 #endif 94 95 #define MY_CDECL __cdecl 96 #define MY_FAST_CALL __fastcall 97 98 #else 99 100 #define MY_CDECL 101 #define MY_FAST_CALL 102 103 #endif 104 105 /* The following interfaces use first parameter as pointer to structure */ 106 107 typedef struct 108 { 109 Byte (*Read)(void *p); /* reads one byte, returns 0 in case of EOF or error */ 110 } IByteIn; 111 112 typedef struct 113 { 114 void (*Write)(void *p, Byte b); 115 } IByteOut; 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, const 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); /* 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 #ifdef _WIN32 217 218 #define CHAR_PATH_SEPARATOR '\\' 219 #define WCHAR_PATH_SEPARATOR L'\\' 220 #define STRING_PATH_SEPARATOR "\\" 221 #define WSTRING_PATH_SEPARATOR L"\\" 222 223 #else 224 225 #define CHAR_PATH_SEPARATOR '/' 226 #define WCHAR_PATH_SEPARATOR u'/' 227 #define STRING_PATH_SEPARATOR "/" 228 #define WSTRING_PATH_SEPARATOR u"/" 229 230 #endif 231 232 #endif 233