** $Date $Author $Comment
** 2 Nov 2006 Lin Mars init version which derived from LzmaTest.c from
** LZMA v4.43 SDK
+** 24 May 2007 Lin Mars Fix issue for multiple lzma_inflate involved
*******************************************************************************/
#define LZMA_NO_STDIO
#ifndef LZMA_NO_STDIO
#include "LzmaDecode.h"
#include "LzmaWrapper.h"
+#if defined(DEBUG_ENABLE_BOOTSTRAP_PRINTF) || !defined(CFG_BOOTSTRAP_CODE)
static const char *kCantReadMessage = "Can not read from source buffer";
static const char *kCantAllocateMessage = "Not enough buffer for decompression";
+#endif
static size_t rpos=0, dpos=0;
int res;
+ rpos=0; dpos=0;
+
if (sizeof(UInt32) < 4)
{
+#if defined(DEBUG_ENABLE_BOOTSTRAP_PRINTF) || !defined(CFG_BOOTSTRAP_CODE)
printf("LZMA decoder needs correct UInt32\n");
+#endif
return LZMA_RESULT_DATA_ERROR;
}
long length=s_len;
if ((long)(SizeT)length != length)
{
+#if defined(DEBUG_ENABLE_BOOTSTRAP_PRINTF) || !defined(CFG_BOOTSTRAP_CODE)
printf("Too big compressed stream\n");
+#endif
return LZMA_RESULT_DATA_ERROR;
}
compressedSize = (SizeT)(length - (LZMA_PROPERTIES_SIZE + 8));
if (!MyReadFileAndCheck(source, properties, sizeof(properties)))
{
+#if defined(DEBUG_ENABLE_BOOTSTRAP_PRINTF) || !defined(CFG_BOOTSTRAP_CODE)
printf("%s\n", kCantReadMessage);
+#endif
return LZMA_RESULT_DATA_ERROR;
}
unsigned char b;
if (!MyReadFileAndCheck(source, &b, 1))
{
+#if defined(DEBUG_ENABLE_BOOTSTRAP_PRINTF) || !defined(CFG_BOOTSTRAP_CODE)
printf("%s\n", kCantReadMessage);
+#endif
return LZMA_RESULT_DATA_ERROR;
}
if (b != 0xFF)
if (waitEOS)
{
+#if defined(DEBUG_ENABLE_BOOTSTRAP_PRINTF) || !defined(CFG_BOOTSTRAP_CODE)
printf("Stream with EOS marker is not supported");
+#endif
return LZMA_RESULT_DATA_ERROR;
}
outSizeFull = (SizeT)outSize;
outSizeFull |= (((SizeT)outSizeHigh << 16) << 16);
else if (outSizeHigh != 0 || (UInt32)(SizeT)outSize != outSize)
{
+#if defined(DEBUG_ENABLE_BOOTSTRAP_PRINTF) || !defined(CFG_BOOTSTRAP_CODE)
printf("Too big uncompressed stream");
+#endif
return LZMA_RESULT_DATA_ERROR;
}
}
/* Decode LZMA properties and allocate memory */
if (LzmaDecodeProperties(&state.Properties, properties, LZMA_PROPERTIES_SIZE) != LZMA_RESULT_OK)
{
+#if defined(DEBUG_ENABLE_BOOTSTRAP_PRINTF) || !defined(CFG_BOOTSTRAP_CODE)
printf("Incorrect stream properties");
+#endif
return LZMA_RESULT_DATA_ERROR;
}
state.Probs = (CProb *)malloc(LzmaGetNumProbs(&state.Properties) * sizeof(CProb));
)
{
free(state.Probs);
+#if defined(DEBUG_ENABLE_BOOTSTRAP_PRINTF) || !defined(CFG_BOOTSTRAP_CODE)
printf("%s\n", kCantAllocateMessage);
+#endif
return LZMA_RESULT_DATA_ERROR;
}
outStream, outSizeFull, &outProcessed);
if (res != 0)
{
+#if defined(DEBUG_ENABLE_BOOTSTRAP_PRINTF) || !defined(CFG_BOOTSTRAP_CODE)
printf("\nDecoding error = %d\n", res);
+#endif
res = 1;
}
else