Annotation of elwix/tools/oldlzma/SRC/7zip/Compress/LZMA_Alone/LzmaRamDecode.c, revision 1.1.1.1

1.1       misho       1: /* LzmaRamDecode.c */
                      2: 
                      3: #include "LzmaRamDecode.h"
                      4: #ifdef _SZ_ONE_DIRECTORY
                      5: #include "LzmaDecode.h"
                      6: #include "BranchX86.h"
                      7: #else
                      8: #include "../LZMA_C/LzmaDecode.h"
                      9: #include "../Branch/BranchX86.h"
                     10: #endif
                     11: 
                     12: #define LZMA_PROPS_SIZE 14
                     13: #define LZMA_SIZE_OFFSET 6
                     14: 
                     15: int LzmaRamGetUncompressedSize(
                     16:     unsigned char *inBuffer, 
                     17:     size_t inSize,
                     18:     size_t *outSize)
                     19: {
                     20:   unsigned int i;
                     21:   if (inSize < LZMA_PROPS_SIZE)
                     22:     return 1;
                     23:   *outSize = 0;
                     24:   for(i = 0; i < sizeof(size_t); i++)
                     25:     *outSize += ((size_t)inBuffer[LZMA_SIZE_OFFSET + i]) << (8 * i);
                     26:   for(; i < 8; i++)
                     27:     if (inBuffer[LZMA_SIZE_OFFSET + i] != 0)
                     28:       return 1;
                     29:   return 0;
                     30: }
                     31: 
                     32: #define SZE_DATA_ERROR (1)
                     33: #define SZE_OUTOFMEMORY (2)
                     34: 
                     35: int LzmaRamDecompress(
                     36:     unsigned char *inBuffer, 
                     37:     size_t inSize,
                     38:     unsigned char *outBuffer,
                     39:     size_t outSize,
                     40:     size_t *outSizeProcessed,
                     41:     void * (*allocFunc)(size_t size), 
                     42:     void (*freeFunc)(void *))
                     43: {
                     44:   int lc, lp, pb;
                     45:   size_t lzmaInternalSize;
                     46:   void *lzmaInternalData;
                     47:   int result;
                     48:   UInt32 outSizeProcessedLoc;
                     49:   
                     50:   int useFilter = inBuffer[0];
                     51: 
                     52:   *outSizeProcessed = 0;
                     53:   if (useFilter > 1)
                     54:     return 1;
                     55: 
                     56:   if (inSize < LZMA_PROPS_SIZE)
                     57:     return 1;
                     58:   lc = inBuffer[1];
                     59:   if (lc >= (9 * 5 * 5))
                     60:     return 1;
                     61:   for (pb = 0; lc >= (9 * 5); pb++, lc -= (9 * 5));
                     62:   for (lp = 0; lc >= 9; lp++, lc -= 9);
                     63:   
                     64:   lzmaInternalSize = (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp))) * sizeof(CProb);
                     65:   lzmaInternalData = allocFunc(lzmaInternalSize);
                     66:   if (lzmaInternalData == 0)
                     67:     return SZE_OUTOFMEMORY;
                     68:   
                     69:   result = LzmaDecode((unsigned char *)lzmaInternalData, (UInt32)lzmaInternalSize,
                     70:     lc, lp, pb,
                     71:     inBuffer + LZMA_PROPS_SIZE, (UInt32)inSize - LZMA_PROPS_SIZE,
                     72:     outBuffer, (UInt32)outSize, 
                     73:     &outSizeProcessedLoc);
                     74:   freeFunc(lzmaInternalData);
                     75:   if (result != LZMA_RESULT_OK)
                     76:     return 1;
                     77:   *outSizeProcessed = (size_t)outSizeProcessedLoc;
                     78:   if (useFilter == 1)
                     79:   {
                     80:     UInt32 _prevMask;
                     81:     UInt32 _prevPos;
                     82:     x86_Convert_Init(_prevMask, _prevPos);
                     83:     x86_Convert(outBuffer, (UInt32)outSizeProcessedLoc, 0, &_prevMask, &_prevPos, 0);
                     84:   }
                     85:   return 0;
                     86: }
                     87: 
                     88: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>