Lines Matching +full:- +full:o
2 * LZ4 auto-framing library
3 * Copyright (C) 2011-2016, Yann Collet.
5 * BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
11 * - Redistributions of source code must retain the above copyright
13 * - Redistributions in binary form must reproduce the above
31 * - LZ4 homepage : http://www.lz4.org
32 * - LZ4 source repository : https://github.com/lz4/lz4
35 /* LZ4F is a stand-alone API to create LZ4-compressed Frames
44 /*-************************************
52 /*-************************************
65 /*-************************************
87 /*-************************************
100 /*-************************************
127 /*-************************************
194 /*-************************************
220 /*-************************************
242 /*-************************************
251 return (code > (LZ4F_errorCode_t)(-LZ4F_ERROR_maxCode)); in LZ4F_isError()
257 if (LZ4F_isError(code)) return LZ4F_errorStrings[-(int)(code)]; in LZ4F_getErrorName()
264 return (LZ4F_errorCodes)(-(ptrdiff_t)functionResult); in LZ4F_getErrorCode()
271 return (LZ4F_errorCode_t)-(ptrdiff_t)code; in err0r()
285 blockSizeID -= LZ4F_max64KB; in LZ4F_getBlockSize()
289 /*-************************************
301 /*-************************************
302 * Simple-pass compression functions
332 U32 const flush = prefsPtr->autoFlush | (srcSize==0); in LZ4F_compressBound_internal()
333 LZ4F_blockSizeID_t const blockID = prefsPtr->frameInfo.blockSizeID; in LZ4F_compressBound_internal()
335 size_t const maxBuffered = blockSize - 1; in LZ4F_compressBound_internal()
339 size_t const partialBlockSize = maxSrcSize & (blockSize-1); in LZ4F_compressBound_internal()
343 size_t const blockCRCSize = BFSize * prefsPtr->frameInfo.blockChecksumFlag; in LZ4F_compressBound_internal()
344 size_t const frameEnd = BHSize + (prefsPtr->frameInfo.contentChecksumFlag*BFSize); in LZ4F_compressBound_internal()
390 … prefs.frameInfo.contentSize = (U64)srcSize; /* auto-correct content size if selected (!=0) */ in LZ4F_compressFrame_usingCDict()
395 …frameInfo.blockMode = LZ4F_blockIndependent; /* only one block => no need for inter-block link */ in LZ4F_compressFrame_usingCDict()
408 …{ size_t const cSize = LZ4F_compressUpdate(cctx, dstPtr, (size_t)(dstEnd-dstPtr), srcBuffer, srcSi… in LZ4F_compressFrame_usingCDict()
413 …{ size_t const tailSize = LZ4F_compressEnd(cctx, dstPtr, (size_t)(dstEnd-dstPtr), &options); /* … in LZ4F_compressFrame_usingCDict()
418 return (size_t)(dstPtr - dstStart); in LZ4F_compressFrame_usingCDict()
448 preferencesPtr->compressionLevel < LZ4HC_CLEVEL_MIN) in LZ4F_compressFrame()
451 cctxPtr->lz4CtxPtr = &lz4ctx; in LZ4F_compressFrame()
452 cctxPtr->lz4CtxAlloc = 1; in LZ4F_compressFrame()
453 cctxPtr->lz4CtxState = 1; in LZ4F_compressFrame()
465 preferencesPtr->compressionLevel >= LZ4HC_CLEVEL_MIN) in LZ4F_compressFrame()
467 FREEMEM(cctxPtr->lz4CtxPtr); in LZ4F_compressFrame()
474 /*-***************************************************
487 …Dict can be created once and shared by multiple threads concurrently, since its usage is read-only.
497 dictStart += dictSize - 64 KB; in LZ4F_createCDict()
500 cdict->dictContent = ALLOC(dictSize); in LZ4F_createCDict()
501 cdict->fastCtx = LZ4_createStream(); in LZ4F_createCDict()
502 cdict->HCCtx = LZ4_createStreamHC(); in LZ4F_createCDict()
503 if (!cdict->dictContent || !cdict->fastCtx || !cdict->HCCtx) { in LZ4F_createCDict()
507 memcpy(cdict->dictContent, dictStart, dictSize); in LZ4F_createCDict()
508 LZ4_loadDict (cdict->fastCtx, (const char*)cdict->dictContent, (int)dictSize); in LZ4F_createCDict()
509 LZ4_setCompressionLevel(cdict->HCCtx, LZ4HC_CLEVEL_DEFAULT); in LZ4F_createCDict()
510 LZ4_loadDictHC(cdict->HCCtx, (const char*)cdict->dictContent, (int)dictSize); in LZ4F_createCDict()
517 FREEMEM(cdict->dictContent); in LZ4F_freeCDict()
518 LZ4_freeStream(cdict->fastCtx); in LZ4F_freeCDict()
519 LZ4_freeStreamHC(cdict->HCCtx); in LZ4F_freeCDict()
524 /*-*********************************
541 cctxPtr->version = version; in LZ4F_createCompressionContext()
542 cctxPtr->cStage = 0; /* Next stage : init stream */ in LZ4F_createCompressionContext()
553 … FREEMEM(cctxPtr->lz4CtxPtr); /* note: LZ4_streamHC_t and LZ4_stream_t are simple POD types */ in LZ4F_freeCompressionContext()
554 FREEMEM(cctxPtr->tmpBuff); in LZ4F_freeCompressionContext()
578 * one-shot API. The non-continued APIs internally perform their own in LZ4F_initStream()
584 LZ4_attach_dictionary((LZ4_stream_t *)ctx, cdict ? cdict->fastCtx : NULL); in LZ4F_initStream()
587 LZ4_attach_HC_dictionary((LZ4_streamHC_t *)ctx, cdict ? cdict->HCCtx : NULL); in LZ4F_initStream()
611 cctxPtr->prefs = *preferencesPtr; in LZ4F_compressBegin_usingCDict()
614 { U16 const ctxTypeID = (cctxPtr->prefs.compressionLevel < LZ4HC_CLEVEL_MIN) ? 1 : 2; in LZ4F_compressBegin_usingCDict()
615 if (cctxPtr->lz4CtxAlloc < ctxTypeID) { in LZ4F_compressBegin_usingCDict()
616 FREEMEM(cctxPtr->lz4CtxPtr); in LZ4F_compressBegin_usingCDict()
617 if (cctxPtr->prefs.compressionLevel < LZ4HC_CLEVEL_MIN) { in LZ4F_compressBegin_usingCDict()
618 cctxPtr->lz4CtxPtr = LZ4_createStream(); in LZ4F_compressBegin_usingCDict()
620 cctxPtr->lz4CtxPtr = LZ4_createStreamHC(); in LZ4F_compressBegin_usingCDict()
622 if (cctxPtr->lz4CtxPtr == NULL) in LZ4F_compressBegin_usingCDict()
624 cctxPtr->lz4CtxAlloc = ctxTypeID; in LZ4F_compressBegin_usingCDict()
625 cctxPtr->lz4CtxState = ctxTypeID; in LZ4F_compressBegin_usingCDict()
626 } else if (cctxPtr->lz4CtxState != ctxTypeID) { in LZ4F_compressBegin_usingCDict()
629 if (cctxPtr->prefs.compressionLevel < LZ4HC_CLEVEL_MIN) { in LZ4F_compressBegin_usingCDict()
630 LZ4_initStream((LZ4_stream_t *) cctxPtr->lz4CtxPtr, sizeof (LZ4_stream_t)); in LZ4F_compressBegin_usingCDict()
632 LZ4_initStreamHC((LZ4_streamHC_t *) cctxPtr->lz4CtxPtr, sizeof(LZ4_streamHC_t)); in LZ4F_compressBegin_usingCDict()
633 … LZ4_setCompressionLevel((LZ4_streamHC_t *) cctxPtr->lz4CtxPtr, cctxPtr->prefs.compressionLevel); in LZ4F_compressBegin_usingCDict()
635 cctxPtr->lz4CtxState = ctxTypeID; in LZ4F_compressBegin_usingCDict()
640 if (cctxPtr->prefs.frameInfo.blockSizeID == 0) in LZ4F_compressBegin_usingCDict()
641 cctxPtr->prefs.frameInfo.blockSizeID = LZ4F_BLOCKSIZEID_DEFAULT; in LZ4F_compressBegin_usingCDict()
642 cctxPtr->maxBlockSize = LZ4F_getBlockSize(cctxPtr->prefs.frameInfo.blockSizeID); in LZ4F_compressBegin_usingCDict()
644 { size_t const requiredBuffSize = preferencesPtr->autoFlush ? in LZ4F_compressBegin_usingCDict()
645 …((cctxPtr->prefs.frameInfo.blockMode == LZ4F_blockLinked) ? 64 KB : 0) : /* only needs past data … in LZ4F_compressBegin_usingCDict()
646 … cctxPtr->maxBlockSize + ((cctxPtr->prefs.frameInfo.blockMode == LZ4F_blockLinked) ? 128 KB : 0); in LZ4F_compressBegin_usingCDict()
648 if (cctxPtr->maxBufferSize < requiredBuffSize) { in LZ4F_compressBegin_usingCDict()
649 cctxPtr->maxBufferSize = 0; in LZ4F_compressBegin_usingCDict()
650 FREEMEM(cctxPtr->tmpBuff); in LZ4F_compressBegin_usingCDict()
651 cctxPtr->tmpBuff = (BYTE*)ALLOC_AND_ZERO(requiredBuffSize); in LZ4F_compressBegin_usingCDict()
652 if (cctxPtr->tmpBuff == NULL) return err0r(LZ4F_ERROR_allocation_failed); in LZ4F_compressBegin_usingCDict()
653 cctxPtr->maxBufferSize = requiredBuffSize; in LZ4F_compressBegin_usingCDict()
655 cctxPtr->tmpIn = cctxPtr->tmpBuff; in LZ4F_compressBegin_usingCDict()
656 cctxPtr->tmpInSize = 0; in LZ4F_compressBegin_usingCDict()
657 (void)XXH32_reset(&(cctxPtr->xxh), 0); in LZ4F_compressBegin_usingCDict()
660 cctxPtr->cdict = cdict; in LZ4F_compressBegin_usingCDict()
661 if (cctxPtr->prefs.frameInfo.blockMode == LZ4F_blockLinked) { in LZ4F_compressBegin_usingCDict()
663 … LZ4F_initStream(cctxPtr->lz4CtxPtr, cdict, cctxPtr->prefs.compressionLevel, LZ4F_blockLinked); in LZ4F_compressBegin_usingCDict()
665 if (preferencesPtr->compressionLevel >= LZ4HC_CLEVEL_MIN) { in LZ4F_compressBegin_usingCDict()
666 …LZ4_favorDecompressionSpeed((LZ4_streamHC_t*)cctxPtr->lz4CtxPtr, (int)preferencesPtr->favorDecSpee… in LZ4F_compressBegin_usingCDict()
676 + ((cctxPtr->prefs.frameInfo.blockMode & _1BIT ) << 5) in LZ4F_compressBegin_usingCDict()
677 + ((cctxPtr->prefs.frameInfo.blockChecksumFlag & _1BIT ) << 4) in LZ4F_compressBegin_usingCDict()
678 + ((unsigned)(cctxPtr->prefs.frameInfo.contentSize > 0) << 3) in LZ4F_compressBegin_usingCDict()
679 + ((cctxPtr->prefs.frameInfo.contentChecksumFlag & _1BIT ) << 2) in LZ4F_compressBegin_usingCDict()
680 + (cctxPtr->prefs.frameInfo.dictID > 0) ); in LZ4F_compressBegin_usingCDict()
682 *dstPtr++ = (BYTE)((cctxPtr->prefs.frameInfo.blockSizeID & _3BITS) << 4); in LZ4F_compressBegin_usingCDict()
684 if (cctxPtr->prefs.frameInfo.contentSize) { in LZ4F_compressBegin_usingCDict()
685 LZ4F_writeLE64(dstPtr, cctxPtr->prefs.frameInfo.contentSize); in LZ4F_compressBegin_usingCDict()
687 cctxPtr->totalInSize = 0; in LZ4F_compressBegin_usingCDict()
690 if (cctxPtr->prefs.frameInfo.dictID) { in LZ4F_compressBegin_usingCDict()
691 LZ4F_writeLE32(dstPtr, cctxPtr->prefs.frameInfo.dictID); in LZ4F_compressBegin_usingCDict()
695 *dstPtr = LZ4F_headerChecksum(headerStart, (size_t)(dstPtr - headerStart)); in LZ4F_compressBegin_usingCDict()
698 cctxPtr->cStage = 1; /* header written, now request input data block */ in LZ4F_compressBegin_usingCDict()
699 return (size_t)(dstPtr - dstStart); in LZ4F_compressBegin_usingCDict()
726 if (preferencesPtr && preferencesPtr->autoFlush) { in LZ4F_compressBound()
729 return LZ4F_compressBound_internal(srcSize, preferencesPtr, (size_t)-1); in LZ4F_compressBound()
748 (int)(srcSize), (int)(srcSize-1), in LZ4F_makeBlock()
768 int const acceleration = (level < 0) ? -level + 1 : 1; in LZ4F_compressBlock()
779 int const acceleration = (level < 0) ? -level + 1 : 1; in LZ4F_compressBlock_continue()
811 if (cctxPtr->prefs.compressionLevel < LZ4HC_CLEVEL_MIN) in LZ4F_localSaveDict()
812 return LZ4_saveDict ((LZ4_stream_t*)(cctxPtr->lz4CtxPtr), (char*)(cctxPtr->tmpBuff), 64 KB); in LZ4F_localSaveDict()
813 return LZ4_saveDictHC ((LZ4_streamHC_t*)(cctxPtr->lz4CtxPtr), (char*)(cctxPtr->tmpBuff), 64 KB); in LZ4F_localSaveDict()
831 size_t const blockSize = cctxPtr->maxBlockSize; in LZ4F_compressUpdate()
837 …ressFunc_t const compress = LZ4F_selectCompression(cctxPtr->prefs.frameInfo.blockMode, cctxPtr->pr… in LZ4F_compressUpdate()
841 if (cctxPtr->cStage != 1) return err0r(LZ4F_ERROR_GENERIC); in LZ4F_compressUpdate()
842 if (dstCapacity < LZ4F_compressBound_internal(srcSize, &(cctxPtr->prefs), cctxPtr->tmpInSize)) in LZ4F_compressUpdate()
848 if (cctxPtr->tmpInSize > 0) { /* some data already within tmp buffer */ in LZ4F_compressUpdate()
849 size_t const sizeToCopy = blockSize - cctxPtr->tmpInSize; in LZ4F_compressUpdate()
852 memcpy(cctxPtr->tmpIn + cctxPtr->tmpInSize, srcBuffer, srcSize); in LZ4F_compressUpdate()
854 cctxPtr->tmpInSize += srcSize; in LZ4F_compressUpdate()
859 memcpy(cctxPtr->tmpIn + cctxPtr->tmpInSize, srcBuffer, sizeToCopy); in LZ4F_compressUpdate()
863 cctxPtr->tmpIn, blockSize, in LZ4F_compressUpdate()
864 compress, cctxPtr->lz4CtxPtr, cctxPtr->prefs.compressionLevel, in LZ4F_compressUpdate()
865 cctxPtr->cdict, in LZ4F_compressUpdate()
866 cctxPtr->prefs.frameInfo.blockChecksumFlag); in LZ4F_compressUpdate()
868 if (cctxPtr->prefs.frameInfo.blockMode==LZ4F_blockLinked) cctxPtr->tmpIn += blockSize; in LZ4F_compressUpdate()
869 cctxPtr->tmpInSize = 0; in LZ4F_compressUpdate()
873 while ((size_t)(srcEnd - srcPtr) >= blockSize) { in LZ4F_compressUpdate()
878 compress, cctxPtr->lz4CtxPtr, cctxPtr->prefs.compressionLevel, in LZ4F_compressUpdate()
879 cctxPtr->cdict, in LZ4F_compressUpdate()
880 cctxPtr->prefs.frameInfo.blockChecksumFlag); in LZ4F_compressUpdate()
884 if ((cctxPtr->prefs.autoFlush) && (srcPtr < srcEnd)) { in LZ4F_compressUpdate()
888 srcPtr, (size_t)(srcEnd - srcPtr), in LZ4F_compressUpdate()
889 compress, cctxPtr->lz4CtxPtr, cctxPtr->prefs.compressionLevel, in LZ4F_compressUpdate()
890 cctxPtr->cdict, in LZ4F_compressUpdate()
891 cctxPtr->prefs.frameInfo.blockChecksumFlag); in LZ4F_compressUpdate()
896 …if ((cctxPtr->prefs.frameInfo.blockMode==LZ4F_blockLinked) && (lastBlockCompressed==fromSrcBuffer)… in LZ4F_compressUpdate()
897 if (compressOptionsPtr->stableSrc) { in LZ4F_compressUpdate()
898 cctxPtr->tmpIn = cctxPtr->tmpBuff; in LZ4F_compressUpdate()
902 cctxPtr->tmpIn = cctxPtr->tmpBuff + realDictSize; in LZ4F_compressUpdate()
907 …if ((cctxPtr->tmpIn + blockSize) > (cctxPtr->tmpBuff + cctxPtr->maxBufferSize) /* necessarily LZ… in LZ4F_compressUpdate()
908 && !(cctxPtr->prefs.autoFlush)) in LZ4F_compressUpdate()
911 cctxPtr->tmpIn = cctxPtr->tmpBuff + realDictSize; in LZ4F_compressUpdate()
917 size_t const sizeToCopy = (size_t)(srcEnd - srcPtr); in LZ4F_compressUpdate()
918 memcpy(cctxPtr->tmpIn, srcPtr, sizeToCopy); in LZ4F_compressUpdate()
919 cctxPtr->tmpInSize = sizeToCopy; in LZ4F_compressUpdate()
922 if (cctxPtr->prefs.frameInfo.contentChecksumFlag == LZ4F_contentChecksumEnabled) in LZ4F_compressUpdate()
923 (void)XXH32_update(&(cctxPtr->xxh), srcBuffer, srcSize); in LZ4F_compressUpdate()
925 cctxPtr->totalInSize += srcSize; in LZ4F_compressUpdate()
926 return (size_t)(dstPtr - dstStart); in LZ4F_compressUpdate()
946 if (cctxPtr->tmpInSize == 0) return 0; /* nothing to flush */ in LZ4F_flush()
947 if (cctxPtr->cStage != 1) return err0r(LZ4F_ERROR_GENERIC); in LZ4F_flush()
948 if (dstCapacity < (cctxPtr->tmpInSize + BHSize + BFSize)) in LZ4F_flush()
953 …compress = LZ4F_selectCompression(cctxPtr->prefs.frameInfo.blockMode, cctxPtr->prefs.compressionLe… in LZ4F_flush()
957 cctxPtr->tmpIn, cctxPtr->tmpInSize, in LZ4F_flush()
958 compress, cctxPtr->lz4CtxPtr, cctxPtr->prefs.compressionLevel, in LZ4F_flush()
959 cctxPtr->cdict, in LZ4F_flush()
960 cctxPtr->prefs.frameInfo.blockChecksumFlag); in LZ4F_flush()
961 assert(((void)"flush overflows dstBuffer!", (size_t)(dstPtr - dstStart) <= dstCapacity)); in LZ4F_flush()
963 if (cctxPtr->prefs.frameInfo.blockMode == LZ4F_blockLinked) in LZ4F_flush()
964 cctxPtr->tmpIn += cctxPtr->tmpInSize; in LZ4F_flush()
965 cctxPtr->tmpInSize = 0; in LZ4F_flush()
968 …if ((cctxPtr->tmpIn + cctxPtr->maxBlockSize) > (cctxPtr->tmpBuff + cctxPtr->maxBufferSize)) { /* … in LZ4F_flush()
970 cctxPtr->tmpIn = cctxPtr->tmpBuff + realDictSize; in LZ4F_flush()
973 return (size_t)(dstPtr - dstStart); in LZ4F_flush()
999 dstCapacity -= flushSize; in LZ4F_compressEnd()
1005 if (cctxPtr->prefs.frameInfo.contentChecksumFlag == LZ4F_contentChecksumEnabled) { in LZ4F_compressEnd()
1006 U32 const xxh = XXH32_digest(&(cctxPtr->xxh)); in LZ4F_compressEnd()
1008 DEBUGLOG(5,"Writing 32-bit content checksum"); in LZ4F_compressEnd()
1013 cctxPtr->cStage = 0; /* state is now re-usable (with identical preferences) */ in LZ4F_compressEnd()
1014 cctxPtr->maxBufferSize = 0; /* reuse HC context */ in LZ4F_compressEnd()
1016 if (cctxPtr->prefs.frameInfo.contentSize) { in LZ4F_compressEnd()
1017 if (cctxPtr->prefs.frameInfo.contentSize != cctxPtr->totalInSize) in LZ4F_compressEnd()
1021 return (size_t)(dstPtr - dstStart); in LZ4F_compressEnd()
1025 /*-***************************************************
1077 dctx->version = versionNumber; in LZ4F_createDecompressionContext()
1086 result = (LZ4F_errorCode_t)dctx->dStage; in LZ4F_freeDecompressionContext()
1087 FREEMEM(dctx->tmpIn); in LZ4F_freeDecompressionContext()
1088 FREEMEM(dctx->tmpOutBuffer); in LZ4F_freeDecompressionContext()
1095 /*==--- Streaming Decompression operations ---==*/
1099 dctx->dStage = dstage_getFrameHeader; in LZ4F_resetDecompressionContext()
1100 dctx->dict = NULL; in LZ4F_resetDecompressionContext()
1101 dctx->dictSize = 0; in LZ4F_resetDecompressionContext()
1108 * dctx->frameInfo and dctx->dStage.
1122 MEM_INIT(&(dctx->frameInfo), 0, sizeof(dctx->frameInfo)); in LZ4F_decodeHeader()
1126 dctx->frameInfo.frameType = LZ4F_skippableFrame; in LZ4F_decodeHeader()
1127 if (src == (void*)(dctx->header)) { in LZ4F_decodeHeader()
1128 dctx->tmpInSize = srcSize; in LZ4F_decodeHeader()
1129 dctx->tmpInTarget = 8; in LZ4F_decodeHeader()
1130 dctx->dStage = dstage_storeSFrameSize; in LZ4F_decodeHeader()
1133 dctx->dStage = dstage_getSFrameSize; in LZ4F_decodeHeader()
1145 dctx->frameInfo.frameType = LZ4F_frame; in LZ4F_decodeHeader()
1165 if (srcPtr != dctx->header) in LZ4F_decodeHeader()
1166 memcpy(dctx->header, srcPtr, srcSize); in LZ4F_decodeHeader()
1167 dctx->tmpInSize = srcSize; in LZ4F_decodeHeader()
1168 dctx->tmpInTarget = frameHeaderSize; in LZ4F_decodeHeader()
1169 dctx->dStage = dstage_storeFrameHeader; in LZ4F_decodeHeader()
1177 …if (blockSizeID < 4) return err0r(LZ4F_ERROR_maxBlockSize_invalid); /* 4-7 only supported value… in LZ4F_decodeHeader()
1184 { BYTE const HC = LZ4F_headerChecksum(srcPtr+4, frameHeaderSize-5); in LZ4F_decodeHeader()
1185 if (HC != srcPtr[frameHeaderSize-1]) in LZ4F_decodeHeader()
1191 dctx->frameInfo.blockMode = (LZ4F_blockMode_t)blockMode; in LZ4F_decodeHeader()
1192 dctx->frameInfo.blockChecksumFlag = (LZ4F_blockChecksum_t)blockChecksumFlag; in LZ4F_decodeHeader()
1193 dctx->frameInfo.contentChecksumFlag = (LZ4F_contentChecksum_t)contentChecksumFlag; in LZ4F_decodeHeader()
1194 dctx->frameInfo.blockSizeID = (LZ4F_blockSizeID_t)blockSizeID; in LZ4F_decodeHeader()
1195 dctx->maxBlockSize = LZ4F_getBlockSize(blockSizeID); in LZ4F_decodeHeader()
1197 dctx->frameRemainingSize = in LZ4F_decodeHeader()
1198 dctx->frameInfo.contentSize = LZ4F_readLE64(srcPtr+6); in LZ4F_decodeHeader()
1200 dctx->frameInfo.dictID = LZ4F_readLE32(srcPtr + frameHeaderSize - 5); in LZ4F_decodeHeader()
1202 dctx->dStage = dstage_init; in LZ4F_decodeHeader()
1242 …* - At the beginning of a new frame, in which case it will decode this information from `srcBuff…
1245 …* - After decoding has been started. In which case, no input is read, frame parameters are extra…
1258 if (dctx->dStage > dstage_storeFrameHeader) { in LZ4F_getFrameInfo()
1260 size_t o=0, i=0; in LZ4F_getFrameInfo() local
1262 *frameInfoPtr = dctx->frameInfo; in LZ4F_getFrameInfo()
1264 return LZ4F_decompress(dctx, NULL, &o, NULL, &i, NULL); in LZ4F_getFrameInfo()
1266 if (dctx->dStage == dstage_storeFrameHeader) { in LZ4F_getFrameInfo()
1285 *frameInfoPtr = dctx->frameInfo; in LZ4F_getFrameInfo()
1300 if (dctx->dictSize==0) { in LZ4F_updateDict()
1301 dctx->dict = (const BYTE*)dstPtr; /* priority to prefix mode */ in LZ4F_updateDict()
1303 assert(dctx->dict != NULL); in LZ4F_updateDict()
1305 if (dctx->dict + dctx->dictSize == dstPtr) { /* prefix mode, everything within dstBuffer */ in LZ4F_updateDict()
1306 dctx->dictSize += dstSize; in LZ4F_updateDict()
1311 …if ((size_t)(dstPtr - dstBufferStart) + dstSize >= 64 KB) { /* history in dstBuffer becomes large… in LZ4F_updateDict()
1312 dctx->dict = (const BYTE*)dstBufferStart; in LZ4F_updateDict()
1313 dctx->dictSize = (size_t)(dstPtr - dstBufferStart) + dstSize; in LZ4F_updateDict()
1320 assert(dctx->tmpOutBuffer != NULL); in LZ4F_updateDict()
1322 …if (withinTmp && (dctx->dict == dctx->tmpOutBuffer)) { /* continue history within tmpOutBuffer */ in LZ4F_updateDict()
1324 assert(dctx->dict + dctx->dictSize == dctx->tmpOut + dctx->tmpOutStart); in LZ4F_updateDict()
1325 dctx->dictSize += dstSize; in LZ4F_updateDict()
1330 size_t const preserveSize = (size_t)(dctx->tmpOut - dctx->tmpOutBuffer); in LZ4F_updateDict()
1331 size_t copySize = 64 KB - dctx->tmpOutSize; in LZ4F_updateDict()
1332 const BYTE* const oldDictEnd = dctx->dict + dctx->dictSize - dctx->tmpOutStart; in LZ4F_updateDict()
1333 if (dctx->tmpOutSize > 64 KB) copySize = 0; in LZ4F_updateDict()
1336 memcpy(dctx->tmpOutBuffer + preserveSize - copySize, oldDictEnd - copySize, copySize); in LZ4F_updateDict()
1338 dctx->dict = dctx->tmpOutBuffer; in LZ4F_updateDict()
1339 dctx->dictSize = preserveSize + dctx->tmpOutStart + dstSize; in LZ4F_updateDict()
1343 if (dctx->dict == dctx->tmpOutBuffer) { /* copy dst into tmp to complete dict */ in LZ4F_updateDict()
1344 if (dctx->dictSize + dstSize > dctx->maxBufferSize) { /* tmp buffer not large enough */ in LZ4F_updateDict()
1345 size_t const preserveSize = 64 KB - dstSize; in LZ4F_updateDict()
1346 memcpy(dctx->tmpOutBuffer, dctx->dict + dctx->dictSize - preserveSize, preserveSize); in LZ4F_updateDict()
1347 dctx->dictSize = preserveSize; in LZ4F_updateDict()
1349 memcpy(dctx->tmpOutBuffer + dctx->dictSize, dstPtr, dstSize); in LZ4F_updateDict()
1350 dctx->dictSize += dstSize; in LZ4F_updateDict()
1355 { size_t preserveSize = 64 KB - dstSize; in LZ4F_updateDict()
1356 if (preserveSize > dctx->dictSize) preserveSize = dctx->dictSize; in LZ4F_updateDict()
1357 memcpy(dctx->tmpOutBuffer, dctx->dict + dctx->dictSize - preserveSize, preserveSize); in LZ4F_updateDict()
1358 memcpy(dctx->tmpOutBuffer + preserveSize, dstPtr, dstSize); in LZ4F_updateDict()
1359 dctx->dict = dctx->tmpOutBuffer; in LZ4F_updateDict()
1360 dctx->dictSize = preserveSize + dstSize; in LZ4F_updateDict()
1414 switch(dctx->dStage) in LZ4F_decompress()
1419 if ((size_t)(srcEnd-srcPtr) >= maxFHSize) { /* enough to decode - shortcut */ in LZ4F_decompress()
1420 …size_t const hSize = LZ4F_decodeHeader(dctx, srcPtr, (size_t)(srcEnd-srcPtr)); /* will update dSt… in LZ4F_decompress()
1425 dctx->tmpInSize = 0; in LZ4F_decompress()
1426 if (srcEnd-srcPtr == 0) return minFHSize; /* 0-size input */ in LZ4F_decompress()
1427 dctx->tmpInTarget = minFHSize; /* minimum size to decode header */ in LZ4F_decompress()
1428 dctx->dStage = dstage_storeFrameHeader; in LZ4F_decompress()
1429 /* fall-through */ in LZ4F_decompress()
1433 … { size_t const sizeToCopy = MIN(dctx->tmpInTarget - dctx->tmpInSize, (size_t)(srcEnd - srcPtr)); in LZ4F_decompress()
1434 memcpy(dctx->header + dctx->tmpInSize, srcPtr, sizeToCopy); in LZ4F_decompress()
1435 dctx->tmpInSize += sizeToCopy; in LZ4F_decompress()
1438 if (dctx->tmpInSize < dctx->tmpInTarget) { in LZ4F_decompress()
1439 …nextSrcSizeHint = (dctx->tmpInTarget - dctx->tmpInSize) + BHSize; /* rest of header + nextBlockH… in LZ4F_decompress()
1443 …{ size_t const hSize = LZ4F_decodeHeader(dctx, dctx->header, dctx->tmpInTarget); /* will update… in LZ4F_decompress()
1450 if (dctx->frameInfo.contentChecksumFlag) (void)XXH32_reset(&(dctx->xxh), 0); in LZ4F_decompress()
1452 { size_t const bufferNeeded = dctx->maxBlockSize in LZ4F_decompress()
1453 + ((dctx->frameInfo.blockMode==LZ4F_blockLinked) ? 128 KB : 0); in LZ4F_decompress()
1454 if (bufferNeeded > dctx->maxBufferSize) { /* tmp buffers too small */ in LZ4F_decompress()
1455 … dctx->maxBufferSize = 0; /* ensure allocation will be re-attempted on next entry*/ in LZ4F_decompress()
1456 FREEMEM(dctx->tmpIn); in LZ4F_decompress()
1457 dctx->tmpIn = (BYTE*)ALLOC(dctx->maxBlockSize + BFSize /* block checksum */); in LZ4F_decompress()
1458 if (dctx->tmpIn == NULL) in LZ4F_decompress()
1460 FREEMEM(dctx->tmpOutBuffer); in LZ4F_decompress()
1461 dctx->tmpOutBuffer= (BYTE*)ALLOC(bufferNeeded); in LZ4F_decompress()
1462 if (dctx->tmpOutBuffer== NULL) in LZ4F_decompress()
1464 dctx->maxBufferSize = bufferNeeded; in LZ4F_decompress()
1466 dctx->tmpInSize = 0; in LZ4F_decompress()
1467 dctx->tmpInTarget = 0; in LZ4F_decompress()
1468 dctx->tmpOut = dctx->tmpOutBuffer; in LZ4F_decompress()
1469 dctx->tmpOutStart = 0; in LZ4F_decompress()
1470 dctx->tmpOutSize = 0; in LZ4F_decompress()
1472 dctx->dStage = dstage_getBlockHeader; in LZ4F_decompress()
1473 /* fall-through */ in LZ4F_decompress()
1476 if ((size_t)(srcEnd - srcPtr) >= BHSize) { in LZ4F_decompress()
1481 dctx->tmpInSize = 0; in LZ4F_decompress()
1482 dctx->dStage = dstage_storeBlockHeader; in LZ4F_decompress()
1485 if (dctx->dStage == dstage_storeBlockHeader) /* can be skipped */ in LZ4F_decompress()
1487 { size_t const remainingInput = (size_t)(srcEnd - srcPtr); in LZ4F_decompress()
1488 size_t const wantedData = BHSize - dctx->tmpInSize; in LZ4F_decompress()
1490 memcpy(dctx->tmpIn + dctx->tmpInSize, srcPtr, sizeToCopy); in LZ4F_decompress()
1492 dctx->tmpInSize += sizeToCopy; in LZ4F_decompress()
1494 if (dctx->tmpInSize < BHSize) { /* not enough input for cBlockSize */ in LZ4F_decompress()
1495 nextSrcSizeHint = BHSize - dctx->tmpInSize; in LZ4F_decompress()
1499 selectedIn = dctx->tmpIn; in LZ4F_decompress()
1500 } /* if (dctx->dStage == dstage_storeBlockHeader) */ in LZ4F_decompress()
1505 size_t const crcSize = dctx->frameInfo.blockChecksumFlag * BFSize; in LZ4F_decompress()
1508 dctx->dStage = dstage_getSuffix; in LZ4F_decompress()
1511 if (nextCBlockSize > dctx->maxBlockSize) { in LZ4F_decompress()
1516 dctx->tmpInTarget = nextCBlockSize; in LZ4F_decompress()
1518 if (dctx->frameInfo.blockChecksumFlag) { in LZ4F_decompress()
1519 (void)XXH32_reset(&dctx->blockChecksum, 0); in LZ4F_decompress()
1521 dctx->dStage = dstage_copyDirect; in LZ4F_decompress()
1525 dctx->tmpInTarget = nextCBlockSize + crcSize; in LZ4F_decompress()
1526 dctx->dStage = dstage_getCBlock; in LZ4F_decompress()
1540 … size_t const minBuffSize = MIN((size_t)(srcEnd-srcPtr), (size_t)(dstEnd-dstPtr)); in LZ4F_decompress()
1541 sizeToCopy = MIN(dctx->tmpInTarget, minBuffSize); in LZ4F_decompress()
1543 if (dctx->frameInfo.blockChecksumFlag) { in LZ4F_decompress()
1544 (void)XXH32_update(&dctx->blockChecksum, srcPtr, sizeToCopy); in LZ4F_decompress()
1546 if (dctx->frameInfo.contentChecksumFlag) in LZ4F_decompress()
1547 (void)XXH32_update(&dctx->xxh, srcPtr, sizeToCopy); in LZ4F_decompress()
1548 if (dctx->frameInfo.contentSize) in LZ4F_decompress()
1549 dctx->frameRemainingSize -= sizeToCopy; in LZ4F_decompress()
1552 if (dctx->frameInfo.blockMode == LZ4F_blockLinked) { in LZ4F_decompress()
1558 if (sizeToCopy == dctx->tmpInTarget) { /* all done */ in LZ4F_decompress()
1559 if (dctx->frameInfo.blockChecksumFlag) { in LZ4F_decompress()
1560 dctx->tmpInSize = 0; in LZ4F_decompress()
1561 dctx->dStage = dstage_getBlockChecksum; in LZ4F_decompress()
1563 dctx->dStage = dstage_getBlockHeader; /* new block */ in LZ4F_decompress()
1566 dctx->tmpInTarget -= sizeToCopy; /* need to copy more */ in LZ4F_decompress()
1568 nextSrcSizeHint = dctx->tmpInTarget + in LZ4F_decompress()
1569 +(dctx->frameInfo.blockChecksumFlag ? BFSize : 0) in LZ4F_decompress()
1578 if ((srcEnd-srcPtr >= 4) && (dctx->tmpInSize==0)) { in LZ4F_decompress()
1582 size_t const stillToCopy = 4 - dctx->tmpInSize; in LZ4F_decompress()
1583 size_t const sizeToCopy = MIN(stillToCopy, (size_t)(srcEnd-srcPtr)); in LZ4F_decompress()
1584 memcpy(dctx->header + dctx->tmpInSize, srcPtr, sizeToCopy); in LZ4F_decompress()
1585 dctx->tmpInSize += sizeToCopy; in LZ4F_decompress()
1587 if (dctx->tmpInSize < 4) { /* all input consumed */ in LZ4F_decompress()
1591 crcSrc = dctx->header; in LZ4F_decompress()
1594 U32 const calcCRC = XXH32_digest(&dctx->blockChecksum); in LZ4F_decompress()
1607 dctx->dStage = dstage_getBlockHeader; /* new block */ in LZ4F_decompress()
1612 if ((size_t)(srcEnd-srcPtr) < dctx->tmpInTarget) { in LZ4F_decompress()
1613 dctx->tmpInSize = 0; in LZ4F_decompress()
1614 dctx->dStage = dstage_storeCBlock; in LZ4F_decompress()
1619 srcPtr += dctx->tmpInTarget; in LZ4F_decompress()
1623 { size_t const wantedData = dctx->tmpInTarget - dctx->tmpInSize; in LZ4F_decompress()
1624 size_t const inputLeft = (size_t)(srcEnd-srcPtr); in LZ4F_decompress()
1626 memcpy(dctx->tmpIn + dctx->tmpInSize, srcPtr, sizeToCopy); in LZ4F_decompress()
1627 dctx->tmpInSize += sizeToCopy; in LZ4F_decompress()
1629 if (dctx->tmpInSize < dctx->tmpInTarget) { /* need more input */ in LZ4F_decompress()
1630 nextSrcSizeHint = (dctx->tmpInTarget - dctx->tmpInSize) in LZ4F_decompress()
1631 + (dctx->frameInfo.blockChecksumFlag ? BFSize : 0) in LZ4F_decompress()
1636 selectedIn = dctx->tmpIn; in LZ4F_decompress()
1640 if (dctx->frameInfo.blockChecksumFlag) { in LZ4F_decompress()
1641 dctx->tmpInTarget -= 4; in LZ4F_decompress()
1642 …ert(selectedIn != NULL); /* selectedIn is defined at this stage (either srcPtr, or dctx->tmpIn) */ in LZ4F_decompress()
1643 { U32 const readBlockCrc = LZ4F_readLE32(selectedIn + dctx->tmpInTarget); in LZ4F_decompress()
1644 U32 const calcBlockCrc = XXH32(selectedIn, dctx->tmpInTarget, 0); in LZ4F_decompress()
1654 if ((size_t)(dstEnd-dstPtr) >= dctx->maxBlockSize) { in LZ4F_decompress()
1655 const char* dict = (const char*)dctx->dict; in LZ4F_decompress()
1656 size_t dictSize = dctx->dictSize; in LZ4F_decompress()
1661 dict += dictSize - 64 KB; in LZ4F_decompress()
1667 (int)dctx->tmpInTarget, (int)dctx->maxBlockSize, in LZ4F_decompress()
1670 if (dctx->frameInfo.contentChecksumFlag) in LZ4F_decompress()
1671 XXH32_update(&(dctx->xxh), dstPtr, (size_t)decodedSize); in LZ4F_decompress()
1672 if (dctx->frameInfo.contentSize) in LZ4F_decompress()
1673 dctx->frameRemainingSize -= (size_t)decodedSize; in LZ4F_decompress()
1676 if (dctx->frameInfo.blockMode==LZ4F_blockLinked) { in LZ4F_decompress()
1681 dctx->dStage = dstage_getBlockHeader; in LZ4F_decompress()
1687 if (dctx->frameInfo.blockMode == LZ4F_blockLinked) { in LZ4F_decompress()
1688 if (dctx->dict == dctx->tmpOutBuffer) { in LZ4F_decompress()
1689 if (dctx->dictSize > 128 KB) { in LZ4F_decompress()
1690 memcpy(dctx->tmpOutBuffer, dctx->dict + dctx->dictSize - 64 KB, 64 KB); in LZ4F_decompress()
1691 dctx->dictSize = 64 KB; in LZ4F_decompress()
1693 dctx->tmpOut = dctx->tmpOutBuffer + dctx->dictSize; in LZ4F_decompress()
1695 size_t const reservedDictSpace = MIN(dctx->dictSize, 64 KB); in LZ4F_decompress()
1696 dctx->tmpOut = dctx->tmpOutBuffer + reservedDictSpace; in LZ4F_decompress()
1700 { const char* dict = (const char*)dctx->dict; in LZ4F_decompress()
1701 size_t dictSize = dctx->dictSize; in LZ4F_decompress()
1705 dict += dictSize - 64 KB; in LZ4F_decompress()
1709 (const char*)selectedIn, (char*)dctx->tmpOut, in LZ4F_decompress()
1710 (int)dctx->tmpInTarget, (int)dctx->maxBlockSize, in LZ4F_decompress()
1714 if (dctx->frameInfo.contentChecksumFlag) in LZ4F_decompress()
1715 XXH32_update(&(dctx->xxh), dctx->tmpOut, (size_t)decodedSize); in LZ4F_decompress()
1716 if (dctx->frameInfo.contentSize) in LZ4F_decompress()
1717 dctx->frameRemainingSize -= (size_t)decodedSize; in LZ4F_decompress()
1718 dctx->tmpOutSize = (size_t)decodedSize; in LZ4F_decompress()
1719 dctx->tmpOutStart = 0; in LZ4F_decompress()
1720 dctx->dStage = dstage_flushOut; in LZ4F_decompress()
1722 /* fall-through */ in LZ4F_decompress()
1727 … size_t const sizeToCopy = MIN(dctx->tmpOutSize - dctx->tmpOutStart, (size_t)(dstEnd-dstPtr)); in LZ4F_decompress()
1728 memcpy(dstPtr, dctx->tmpOut + dctx->tmpOutStart, sizeToCopy); in LZ4F_decompress()
1731 if (dctx->frameInfo.blockMode == LZ4F_blockLinked) in LZ4F_decompress()
1734 dctx->tmpOutStart += sizeToCopy; in LZ4F_decompress()
1737 if (dctx->tmpOutStart == dctx->tmpOutSize) { /* all flushed */ in LZ4F_decompress()
1738 dctx->dStage = dstage_getBlockHeader; /* get next block */ in LZ4F_decompress()
1747 if (dctx->frameRemainingSize) in LZ4F_decompress()
1749 if (!dctx->frameInfo.contentChecksumFlag) { /* no checksum, frame is completed */ in LZ4F_decompress()
1755 if ((srcEnd - srcPtr) < 4) { /* not enough size for entire CRC */ in LZ4F_decompress()
1756 dctx->tmpInSize = 0; in LZ4F_decompress()
1757 dctx->dStage = dstage_storeSuffix; in LZ4F_decompress()
1763 if (dctx->dStage == dstage_storeSuffix) /* can be skipped */ in LZ4F_decompress()
1765 { size_t const remainingInput = (size_t)(srcEnd - srcPtr); in LZ4F_decompress()
1766 size_t const wantedData = 4 - dctx->tmpInSize; in LZ4F_decompress()
1768 memcpy(dctx->tmpIn + dctx->tmpInSize, srcPtr, sizeToCopy); in LZ4F_decompress()
1770 dctx->tmpInSize += sizeToCopy; in LZ4F_decompress()
1771 if (dctx->tmpInSize < 4) { /* not enough input to read complete suffix */ in LZ4F_decompress()
1772 nextSrcSizeHint = 4 - dctx->tmpInSize; in LZ4F_decompress()
1776 selectedIn = dctx->tmpIn; in LZ4F_decompress()
1777 } /* if (dctx->dStage == dstage_storeSuffix) */ in LZ4F_decompress()
1781 U32 const resultCRC = XXH32_digest(&(dctx->xxh)); in LZ4F_decompress()
1796 if ((srcEnd - srcPtr) >= 4) { in LZ4F_decompress()
1801 dctx->tmpInSize = 4; in LZ4F_decompress()
1802 dctx->tmpInTarget = 8; in LZ4F_decompress()
1803 dctx->dStage = dstage_storeSFrameSize; in LZ4F_decompress()
1806 if (dctx->dStage == dstage_storeSFrameSize) in LZ4F_decompress()
1808 { size_t const sizeToCopy = MIN(dctx->tmpInTarget - dctx->tmpInSize, in LZ4F_decompress()
1809 (size_t)(srcEnd - srcPtr) ); in LZ4F_decompress()
1810 memcpy(dctx->header + dctx->tmpInSize, srcPtr, sizeToCopy); in LZ4F_decompress()
1812 dctx->tmpInSize += sizeToCopy; in LZ4F_decompress()
1813 if (dctx->tmpInSize < dctx->tmpInTarget) { in LZ4F_decompress()
1815 nextSrcSizeHint = dctx->tmpInTarget - dctx->tmpInSize; in LZ4F_decompress()
1819 selectedIn = dctx->header + 4; in LZ4F_decompress()
1820 } /* if (dctx->dStage == dstage_storeSFrameSize) */ in LZ4F_decompress()
1824 dctx->frameInfo.contentSize = SFrameSize; in LZ4F_decompress()
1825 dctx->tmpInTarget = SFrameSize; in LZ4F_decompress()
1826 dctx->dStage = dstage_skipSkippable; in LZ4F_decompress()
1831 { size_t const skipSize = MIN(dctx->tmpInTarget, (size_t)(srcEnd-srcPtr)); in LZ4F_decompress()
1833 dctx->tmpInTarget -= skipSize; in LZ4F_decompress()
1835 nextSrcSizeHint = dctx->tmpInTarget; in LZ4F_decompress()
1841 } /* switch (dctx->dStage) */ in LZ4F_decompress()
1846 …if ( (dctx->frameInfo.blockMode==LZ4F_blockLinked) /* next block will use up to 64KB from previou… in LZ4F_decompress()
1847 && (dctx->dict != dctx->tmpOutBuffer) /* dictionary is not already within tmp */ in LZ4F_decompress()
1848 && (dctx->dict != NULL) /* dictionary exists */ in LZ4F_decompress()
1849 …&& (!decompressOptionsPtr->stableDst) /* cannot rely on dst data to remain there for n… in LZ4F_decompress()
1850 …&& ((unsigned)(dctx->dStage)-2 < (unsigned)(dstage_getSuffix)-2) ) /* valid stages : [init ... ge… in LZ4F_decompress()
1852 if (dctx->dStage == dstage_flushOut) { in LZ4F_decompress()
1853 size_t const preserveSize = (size_t)(dctx->tmpOut - dctx->tmpOutBuffer); in LZ4F_decompress()
1854 size_t copySize = 64 KB - dctx->tmpOutSize; in LZ4F_decompress()
1855 const BYTE* oldDictEnd = dctx->dict + dctx->dictSize - dctx->tmpOutStart; in LZ4F_decompress()
1856 if (dctx->tmpOutSize > 64 KB) copySize = 0; in LZ4F_decompress()
1858 assert(dctx->tmpOutBuffer != NULL); in LZ4F_decompress()
1860 memcpy(dctx->tmpOutBuffer + preserveSize - copySize, oldDictEnd - copySize, copySize); in LZ4F_decompress()
1862 dctx->dict = dctx->tmpOutBuffer; in LZ4F_decompress()
1863 dctx->dictSize = preserveSize + dctx->tmpOutStart; in LZ4F_decompress()
1865 const BYTE* const oldDictEnd = dctx->dict + dctx->dictSize; in LZ4F_decompress()
1866 size_t const newDictSize = MIN(dctx->dictSize, 64 KB); in LZ4F_decompress()
1868 memcpy(dctx->tmpOutBuffer, oldDictEnd - newDictSize, newDictSize); in LZ4F_decompress()
1870 dctx->dict = dctx->tmpOutBuffer; in LZ4F_decompress()
1871 dctx->dictSize = newDictSize; in LZ4F_decompress()
1872 dctx->tmpOut = dctx->tmpOutBuffer + newDictSize; in LZ4F_decompress()
1876 *srcSizePtr = (size_t)(srcPtr - srcStart); in LZ4F_decompress()
1877 *dstSizePtr = (size_t)(dstPtr - dstStart); in LZ4F_decompress()
1892 if (dctx->dStage <= dstage_init) { in LZ4F_decompress_usingDict()
1893 dctx->dict = (const BYTE*)dict; in LZ4F_decompress_usingDict()
1894 dctx->dictSize = dictSize; in LZ4F_decompress_usingDict()