1 /* 7zTypes.h -- Basic types 2 2017-07-17 : Igor Pavlov : Public domain */ 3 4 #ifndef __7Z_TYPES_H 5 #define __7Z_TYPES_H 6 7 #ifdef _WIN32 8 /* #include <windows.h> */ 9 #endif 10 11 #ifdef EFIAPI 12 #include "UefiLzma.h" 13 #else 14 #include <stddef.h> 15 #endif 16 17 #ifndef EXTERN_C_BEGIN 18 #ifdef __cplusplus 19 #define EXTERN_C_BEGIN extern "C" { 20 #define EXTERN_C_END } 21 #else 22 #define EXTERN_C_BEGIN 23 #define EXTERN_C_END 24 #endif 25 #endif 26 27 EXTERN_C_BEGIN 28 29 #define SZ_OK 0 30 31 #define SZ_ERROR_DATA 1 32 #define SZ_ERROR_MEM 2 33 #define SZ_ERROR_CRC 3 34 #define SZ_ERROR_UNSUPPORTED 4 35 #define SZ_ERROR_PARAM 5 36 #define SZ_ERROR_INPUT_EOF 6 37 #define SZ_ERROR_OUTPUT_EOF 7 38 #define SZ_ERROR_READ 8 39 #define SZ_ERROR_WRITE 9 40 #define SZ_ERROR_PROGRESS 10 41 #define SZ_ERROR_FAIL 11 42 #define SZ_ERROR_THREAD 12 43 44 #define SZ_ERROR_ARCHIVE 16 45 #define SZ_ERROR_NO_ARCHIVE 17 46 47 typedef int SRes; 48 49 50 #ifdef _WIN32 51 52 /* typedef DWORD WRes; */ 53 typedef unsigned WRes; 54 #define MY_SRes_HRESULT_FROM_WRes(x) HRESULT_FROM_WIN32(x) 55 56 #else 57 58 typedef int WRes; 59 #define MY__FACILITY_WIN32 7 60 #define MY__FACILITY__WRes MY__FACILITY_WIN32 61 #define MY_SRes_HRESULT_FROM_WRes(x) ((HRESULT)(x) <= 0 ? ((HRESULT)(x)) : ((HRESULT) (((x) & 0x0000FFFF) | (MY__FACILITY__WRes << 16) | 0x80000000))) 62 63 #endif 64 65 66 #ifndef RINOK 67 #define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; } 68 #endif 69 70 typedef unsigned char Byte; 71 typedef short Int16; 72 typedef unsigned short UInt16; 73 74 #ifdef _LZMA_UINT32_IS_ULONG 75 typedef long Int32; 76 typedef unsigned long UInt32; 77 #else 78 typedef int Int32; 79 typedef unsigned int UInt32; 80 #endif 81 82 #ifdef _SZ_NO_INT_64 83 84 /* define _SZ_NO_INT_64, if your compiler doesn't support 64-bit integers. 85 NOTES: Some code will work incorrectly in that case! */ 86 87 typedef long Int64; 88 typedef unsigned long UInt64; 89 90 #else 91 92 #if defined(_MSC_VER) || defined(__BORLANDC__) 93 typedef __int64 Int64; 94 typedef unsigned __int64 UInt64; 95 #define UINT64_CONST(n) n 96 #else 97 typedef long long int Int64; 98 typedef unsigned long long int UInt64; 99 #define UINT64_CONST(n) n ## ULL 100 #endif 101 102 #endif 103 104 #ifdef _LZMA_NO_SYSTEM_SIZE_T 105 typedef UInt32 SizeT; 106 #else 107 typedef size_t SizeT; 108 #endif 109 110 typedef int Bool; 111 #define True 1 112 #define False 0 113 114 115 #ifdef _WIN32 116 #define MY_STD_CALL __stdcall 117 #else 118 #define MY_STD_CALL 119 #endif 120 121 #ifdef _MSC_VER 122 123 #if _MSC_VER >= 1300 124 #define MY_NO_INLINE __declspec(noinline) 125 #else 126 #define MY_NO_INLINE 127 #endif 128 129 #define MY_FORCE_INLINE __forceinline 130 131 #define MY_CDECL __cdecl 132 #define MY_FAST_CALL __fastcall 133 134 #else 135 136 #define MY_NO_INLINE 137 #define MY_FORCE_INLINE 138 #define MY_CDECL 139 #define MY_FAST_CALL 140 141 /* inline keyword : for C++ / C99 */ 142 143 /* GCC, clang: */ 144 /* 145 #if defined (__GNUC__) && (__GNUC__ >= 4) 146 #define MY_FORCE_INLINE __attribute__((always_inline)) 147 #define MY_NO_INLINE __attribute__((noinline)) 148 #endif 149 */ 150 151 #endif 152 153 154 /* The following interfaces use first parameter as pointer to structure */ 155 156 typedef struct IByteIn IByteIn; 157 struct IByteIn 158 { 159 Byte (*Read)(const IByteIn *p); /* reads one byte, returns 0 in case of EOF or error */ 160 }; 161 #define IByteIn_Read(p) (p)->Read(p) 162 163 164 typedef struct IByteOut IByteOut; 165 struct IByteOut 166 { 167 void (*Write)(const IByteOut *p, Byte b); 168 }; 169 #define IByteOut_Write(p, b) (p)->Write(p, b) 170 171 172 typedef struct ISeqInStream ISeqInStream; 173 struct ISeqInStream 174 { 175 SRes (*Read)(const ISeqInStream *p, void *buf, size_t *size); 176 /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream. 177 (output(*size) < input(*size)) is allowed */ 178 }; 179 #define ISeqInStream_Read(p, buf, size) (p)->Read(p, buf, size) 180 181 /* it can return SZ_ERROR_INPUT_EOF */ 182 SRes SeqInStream_Read(const ISeqInStream *stream, void *buf, size_t size); 183 SRes SeqInStream_Read2(const ISeqInStream *stream, void *buf, size_t size, SRes errorType); 184 SRes SeqInStream_ReadByte(const ISeqInStream *stream, Byte *buf); 185 186 187 typedef struct ISeqOutStream ISeqOutStream; 188 struct ISeqOutStream 189 { 190 size_t (*Write)(const ISeqOutStream *p, const void *buf, size_t size); 191 /* Returns: result - the number of actually written bytes. 192 (result < size) means error */ 193 }; 194 #define ISeqOutStream_Write(p, buf, size) (p)->Write(p, buf, size) 195 196 typedef enum 197 { 198 SZ_SEEK_SET = 0, 199 SZ_SEEK_CUR = 1, 200 SZ_SEEK_END = 2 201 } ESzSeek; 202 203 204 typedef struct ISeekInStream ISeekInStream; 205 struct ISeekInStream 206 { 207 SRes (*Read)(const ISeekInStream *p, void *buf, size_t *size); /* same as ISeqInStream::Read */ 208 SRes (*Seek)(const ISeekInStream *p, Int64 *pos, ESzSeek origin); 209 }; 210 #define ISeekInStream_Read(p, buf, size) (p)->Read(p, buf, size) 211 #define ISeekInStream_Seek(p, pos, origin) (p)->Seek(p, pos, origin) 212 213 214 typedef struct ILookInStream ILookInStream; 215 struct ILookInStream 216 { 217 SRes (*Look)(const ILookInStream *p, const void **buf, size_t *size); 218 /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream. 219 (output(*size) > input(*size)) is not allowed 220 (output(*size) < input(*size)) is allowed */ 221 SRes (*Skip)(const ILookInStream *p, size_t offset); 222 /* offset must be <= output(*size) of Look */ 223 224 SRes (*Read)(const ILookInStream *p, void *buf, size_t *size); 225 /* reads directly (without buffer). It's same as ISeqInStream::Read */ 226 SRes (*Seek)(const ILookInStream *p, Int64 *pos, ESzSeek origin); 227 }; 228 229 #define ILookInStream_Look(p, buf, size) (p)->Look(p, buf, size) 230 #define ILookInStream_Skip(p, offset) (p)->Skip(p, offset) 231 #define ILookInStream_Read(p, buf, size) (p)->Read(p, buf, size) 232 #define ILookInStream_Seek(p, pos, origin) (p)->Seek(p, pos, origin) 233 234 235 SRes LookInStream_LookRead(const ILookInStream *stream, void *buf, size_t *size); 236 SRes LookInStream_SeekTo(const ILookInStream *stream, UInt64 offset); 237 238 /* reads via ILookInStream::Read */ 239 SRes LookInStream_Read2(const ILookInStream *stream, void *buf, size_t size, SRes errorType); 240 SRes LookInStream_Read(const ILookInStream *stream, void *buf, size_t size); 241 242 243 244 typedef struct 245 { 246 ILookInStream vt; 247 const ISeekInStream *realStream; 248 249 size_t pos; 250 size_t size; /* it's data size */ 251 252 /* the following variables must be set outside */ 253 Byte *buf; 254 size_t bufSize; 255 } CLookToRead2; 256 257 void LookToRead2_CreateVTable(CLookToRead2 *p, int lookahead); 258 259 #define LookToRead2_Init(p) { (p)->pos = (p)->size = 0; } 260 261 262 typedef struct 263 { 264 ISeqInStream vt; 265 const ILookInStream *realStream; 266 } CSecToLook; 267 268 void SecToLook_CreateVTable(CSecToLook *p); 269 270 271 272 typedef struct 273 { 274 ISeqInStream vt; 275 const ILookInStream *realStream; 276 } CSecToRead; 277 278 void SecToRead_CreateVTable(CSecToRead *p); 279 280 281 typedef struct ICompressProgress ICompressProgress; 282 283 struct ICompressProgress 284 { 285 SRes (*Progress)(const ICompressProgress *p, UInt64 inSize, UInt64 outSize); 286 /* Returns: result. (result != SZ_OK) means break. 287 Value (UInt64)(Int64)-1 for size means unknown value. */ 288 }; 289 #define ICompressProgress_Progress(p, inSize, outSize) (p)->Progress(p, inSize, outSize) 290 291 292 293 typedef struct ISzAlloc ISzAlloc; 294 typedef const ISzAlloc * ISzAllocPtr; 295 296 struct ISzAlloc 297 { 298 void *(*Alloc)(ISzAllocPtr p, size_t size); 299 void (*Free)(ISzAllocPtr p, void *address); /* address can be 0 */ 300 }; 301 302 #define ISzAlloc_Alloc(p, size) (p)->Alloc(p, size) 303 #define ISzAlloc_Free(p, a) (p)->Free(p, a) 304 305 /* deprecated */ 306 #define IAlloc_Alloc(p, size) ISzAlloc_Alloc(p, size) 307 #define IAlloc_Free(p, a) ISzAlloc_Free(p, a) 308 309 310 311 312 313 #ifndef MY_offsetof 314 #ifdef offsetof 315 #define MY_offsetof(type, m) offsetof(type, m) 316 /* 317 #define MY_offsetof(type, m) FIELD_OFFSET(type, m) 318 */ 319 #else 320 #define MY_offsetof(type, m) ((size_t)&(((type *)0)->m)) 321 #endif 322 #endif 323 324 325 326 #ifndef MY_container_of 327 328 /* 329 #define MY_container_of(ptr, type, m) container_of(ptr, type, m) 330 #define MY_container_of(ptr, type, m) CONTAINING_RECORD(ptr, type, m) 331 #define MY_container_of(ptr, type, m) ((type *)((char *)(ptr) - offsetof(type, m))) 332 #define MY_container_of(ptr, type, m) (&((type *)0)->m == (ptr), ((type *)(((char *)(ptr)) - MY_offsetof(type, m)))) 333 */ 334 335 /* 336 GCC shows warning: "perhaps the 'offsetof' macro was used incorrectly" 337 GCC 3.4.4 : classes with constructor 338 GCC 4.8.1 : classes with non-public variable members" 339 */ 340 341 #define MY_container_of(ptr, type, m) ((type *)((char *)(1 ? (ptr) : &((type *)0)->m) - MY_offsetof(type, m))) 342 343 344 #endif 345 346 #define CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m) ((type *)(ptr)) 347 348 /* 349 #define CONTAINER_FROM_VTBL(ptr, type, m) CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m) 350 */ 351 #define CONTAINER_FROM_VTBL(ptr, type, m) MY_container_of(ptr, type, m) 352 353 #define CONTAINER_FROM_VTBL_CLS(ptr, type, m) CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m) 354 /* 355 #define CONTAINER_FROM_VTBL_CLS(ptr, type, m) CONTAINER_FROM_VTBL(ptr, type, m) 356 */ 357 358 359 360 #ifdef _WIN32 361 362 #define CHAR_PATH_SEPARATOR '\\' 363 #define WCHAR_PATH_SEPARATOR L'\\' 364 #define STRING_PATH_SEPARATOR "\\" 365 #define WSTRING_PATH_SEPARATOR L"\\" 366 367 #else 368 369 #define CHAR_PATH_SEPARATOR '/' 370 #define WCHAR_PATH_SEPARATOR L'/' 371 #define STRING_PATH_SEPARATOR "/" 372 #define WSTRING_PATH_SEPARATOR L"/" 373 374 #endif 375 376 EXTERN_C_END 377 378 #endif 379