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