Lines Matching refs:zwd

519 static void ZWRAP_initDCtx(ZWRAP_DCtx* zwd)  in ZWRAP_initDCtx()  argument
521 zwd->errorCount = 0; in ZWRAP_initDCtx()
522 zwd->outBuffer.pos = 0; in ZWRAP_initDCtx()
523 zwd->outBuffer.size = 0; in ZWRAP_initDCtx()
528 ZWRAP_DCtx* zwd; in ZWRAP_createDCtx() local
537 zwd = (ZWRAP_DCtx*)ZWRAP_customCalloc(sizeof(ZWRAP_DCtx), customMem); in ZWRAP_createDCtx()
538 if (zwd == NULL) return NULL; in ZWRAP_createDCtx()
539 zwd->allocFunc = *strm; in ZWRAP_createDCtx()
540 customMem.opaque = &zwd->allocFunc; in ZWRAP_createDCtx()
541 zwd->customMem = customMem; in ZWRAP_createDCtx()
543 ZWRAP_initDCtx(zwd); in ZWRAP_createDCtx()
544 return zwd; in ZWRAP_createDCtx()
547 static size_t ZWRAP_freeDCtx(ZWRAP_DCtx* zwd) in ZWRAP_freeDCtx() argument
549 if (zwd==NULL) return 0; /* support free on null */ in ZWRAP_freeDCtx()
550 ZSTD_freeDStream(zwd->zbd); in ZWRAP_freeDCtx()
551 ZWRAP_customFree(zwd->version, zwd->customMem); in ZWRAP_freeDCtx()
552 ZWRAP_customFree(zwd, zwd->customMem); in ZWRAP_freeDCtx()
564 static int ZWRAPD_finishWithError(ZWRAP_DCtx* zwd, z_streamp strm, int error) in ZWRAPD_finishWithError() argument
567 ZWRAP_freeDCtx(zwd); in ZWRAPD_finishWithError()
574 ZWRAP_DCtx* const zwd = (ZWRAP_DCtx*) strm->state; in ZWRAPD_finishWithErrorMsg() local
576 if (zwd == NULL) return Z_STREAM_ERROR; in ZWRAPD_finishWithErrorMsg()
578 return ZWRAPD_finishWithError(zwd, strm, 0); in ZWRAPD_finishWithErrorMsg()
590 { ZWRAP_DCtx* const zwd = ZWRAP_createDCtx(strm); in z_inflateInit_() local
592 if (zwd == NULL) return ZWRAPD_finishWithError(zwd, strm, 0); in z_inflateInit_()
594 zwd->version = (char*)ZWRAP_customMalloc(strlen(version)+1, zwd->customMem); in z_inflateInit_()
595 if (zwd->version == NULL) return ZWRAPD_finishWithError(zwd, strm, 0); in z_inflateInit_()
596 strcpy(zwd->version, version); in z_inflateInit_()
598 zwd->stream_size = stream_size; in z_inflateInit_()
599 zwd->totalInBytes = 0; in z_inflateInit_()
600 strm->state = convert_into_sis(zwd); in z_inflateInit_()
621 ZWRAP_DCtx* const zwd = (ZWRAP_DCtx*)strm->state; in z_inflateInit2_() local
622 if (zwd == NULL) return Z_STREAM_ERROR; in z_inflateInit2_()
623 zwd->windowBits = windowBits; in z_inflateInit2_()
635 { ZWRAP_DCtx* const zwd = (ZWRAP_DCtx*) strm->state; in ZWRAP_inflateReset_keepDict() local
636 if (zwd == NULL) return Z_STREAM_ERROR; in ZWRAP_inflateReset_keepDict()
637 ZWRAP_initDCtx(zwd); in ZWRAP_inflateReset_keepDict()
638 zwd->decompState = ZWRAP_useReset; in ZWRAP_inflateReset_keepDict()
639 zwd->totalInBytes = 0; in ZWRAP_inflateReset_keepDict()
657 { ZWRAP_DCtx* const zwd = (ZWRAP_DCtx*) strm->state; in z_inflateReset() local
658 if (zwd == NULL) return Z_STREAM_ERROR; in z_inflateReset()
659 zwd->decompState = ZWRAP_useInit; } in z_inflateReset()
674 ZWRAP_DCtx* const zwd = (ZWRAP_DCtx*)strm->state; in z_inflateReset2() local
675 if (zwd == NULL) return Z_STREAM_ERROR; in z_inflateReset2()
676 zwd->windowBits = windowBits; in z_inflateReset2()
692 { ZWRAP_DCtx* const zwd = (ZWRAP_DCtx*) strm->state; in z_inflateSetDictionary() local
693 if (zwd == NULL || zwd->zbd == NULL) return Z_STREAM_ERROR; in z_inflateSetDictionary()
694 { size_t const initErr = ZSTD_initDStream_usingDict(zwd->zbd, dictionary, dictLength); in z_inflateSetDictionary()
695 if (ZSTD_isError(initErr)) return ZWRAPD_finishWithError(zwd, strm, 0); } in z_inflateSetDictionary()
696 zwd->decompState = ZWRAP_useReset; in z_inflateSetDictionary()
698 if (zwd->totalInBytes == ZSTD_HEADERSIZE) { in z_inflateSetDictionary()
699 zwd->inBuffer.src = zwd->headerBuf; in z_inflateSetDictionary()
700 zwd->inBuffer.size = zwd->totalInBytes; in z_inflateSetDictionary()
701 zwd->inBuffer.pos = 0; in z_inflateSetDictionary()
702 zwd->outBuffer.dst = strm->next_out; in z_inflateSetDictionary()
703 zwd->outBuffer.size = 0; in z_inflateSetDictionary()
704 zwd->outBuffer.pos = 0; in z_inflateSetDictionary()
705 … { size_t const errorCode = ZSTD_decompressStream(zwd->zbd, &zwd->outBuffer, &zwd->inBuffer); in z_inflateSetDictionary()
707 (int)errorCode, (int)zwd->inBuffer.size, (int)zwd->outBuffer.size); in z_inflateSetDictionary()
708 if (zwd->inBuffer.pos < zwd->outBuffer.size || ZSTD_isError(errorCode)) { in z_inflateSetDictionary()
711 return ZWRAPD_finishWithError(zwd, strm, 0); in z_inflateSetDictionary()
720 ZWRAP_DCtx* zwd; in z_inflate() local
731 zwd = (ZWRAP_DCtx*) strm->state; in z_inflate()
735 if (zwd == NULL) return Z_STREAM_ERROR; in z_inflate()
736 if (zwd->decompState == ZWRAP_streamEnd) return Z_STREAM_END; in z_inflate()
738 if (zwd->totalInBytes < ZLIB_HEADERSIZE) { in z_inflate()
739 if (zwd->totalInBytes == 0 && strm->avail_in >= ZLIB_HEADERSIZE) { in z_inflate()
741 { int const initErr = (zwd->windowBits) ? in z_inflate()
742 … inflateInit2_(strm, zwd->windowBits, zwd->version, zwd->stream_size) : in z_inflate()
743 inflateInit_(strm, zwd->version, zwd->stream_size); in z_inflate()
745 if (initErr != Z_OK) return ZWRAPD_finishWithError(zwd, strm, initErr); in z_inflate()
749 { size_t const freeErr = ZWRAP_freeDCtx(zwd); in z_inflate()
760 size_t const srcSize = MIN(strm->avail_in, ZLIB_HEADERSIZE - zwd->totalInBytes); in z_inflate()
761 memcpy(zwd->headerBuf+zwd->totalInBytes, strm->next_in, srcSize); in z_inflate()
763 zwd->totalInBytes += srcSize; in z_inflate()
766 if (zwd->totalInBytes < ZLIB_HEADERSIZE) return Z_OK; in z_inflate()
768 if (ZWRAP_readLE32(zwd->headerBuf) != ZSTD_MAGICNUMBER) { in z_inflate()
775 { int const initErr = (zwd->windowBits) ? in z_inflate()
776 … inflateInit2_(strm, zwd->windowBits, zwd->version, zwd->stream_size) : in z_inflate()
777 inflateInit_(strm, zwd->version, zwd->stream_size); in z_inflate()
779 if (initErr != Z_OK) return ZWRAPD_finishWithError(zwd, strm, initErr); in z_inflate()
783 strm->next_in = (unsigned char*)zwd->headerBuf; in z_inflate()
790 return ZWRAPD_finishWithError(zwd, strm, dErr); in z_inflate()
800 { size_t const freeErr = ZWRAP_freeDCtx(zwd); in z_inflate()
816 if (!zwd->zbd) { in z_inflate()
817 zwd->zbd = ZSTD_createDStream_advanced(zwd->customMem); in z_inflate()
818 if (zwd->zbd == NULL) { LOG_WRAPPERD("ERROR: ZSTD_createDStream_advanced\n"); goto error; } in z_inflate()
819 zwd->decompState = ZWRAP_useInit; in z_inflate()
822 if (zwd->totalInBytes < ZSTD_HEADERSIZE) { in z_inflate()
823 if (zwd->totalInBytes == 0 && strm->avail_in >= ZSTD_HEADERSIZE) { in z_inflate()
824 if (zwd->decompState == ZWRAP_useInit) { in z_inflate()
825 size_t const initErr = ZSTD_initDStream(zwd->zbd); in z_inflate()
832 size_t const resetErr = ZSTD_resetDStream(zwd->zbd); in z_inflate()
836 size_t const srcSize = MIN(strm->avail_in, ZSTD_HEADERSIZE - zwd->totalInBytes); in z_inflate()
837 memcpy(zwd->headerBuf+zwd->totalInBytes, strm->next_in, srcSize); in z_inflate()
839 zwd->totalInBytes += srcSize; in z_inflate()
842 if (zwd->totalInBytes < ZSTD_HEADERSIZE) return Z_OK; in z_inflate()
844 if (zwd->decompState == ZWRAP_useInit) { in z_inflate()
845 size_t const initErr = ZSTD_initDStream(zwd->zbd); in z_inflate()
852 size_t const resetErr = ZSTD_resetDStream(zwd->zbd); in z_inflate()
856 zwd->inBuffer.src = zwd->headerBuf; in z_inflate()
857 zwd->inBuffer.size = ZSTD_HEADERSIZE; in z_inflate()
858 zwd->inBuffer.pos = 0; in z_inflate()
859 zwd->outBuffer.dst = strm->next_out; in z_inflate()
860 zwd->outBuffer.size = 0; in z_inflate()
861 zwd->outBuffer.pos = 0; in z_inflate()
862 … { size_t const dErr = ZSTD_decompressStream(zwd->zbd, &zwd->outBuffer, &zwd->inBuffer); in z_inflate()
864 (int)dErr, (int)zwd->inBuffer.size, (int)zwd->outBuffer.size); in z_inflate()
869 if (zwd->inBuffer.pos != zwd->inBuffer.size) goto error; /* not consumed */ in z_inflate()
873 zwd->inBuffer.src = strm->next_in; in z_inflate()
874 zwd->inBuffer.size = strm->avail_in; in z_inflate()
875 zwd->inBuffer.pos = 0; in z_inflate()
876 zwd->outBuffer.dst = strm->next_out; in z_inflate()
877 zwd->outBuffer.size = strm->avail_out; in z_inflate()
878 zwd->outBuffer.pos = 0; in z_inflate()
879 { size_t const dErr = ZSTD_decompressStream(zwd->zbd, &zwd->outBuffer, &zwd->inBuffer); in z_inflate()
883 zwd->errorCount++; in z_inflate()
885 ZSTD_getErrorName(dErr), zwd->errorCount); in z_inflate()
886 if (zwd->errorCount<=1) return Z_NEED_DICT; else goto error; in z_inflate()
889 …(int)zwd->inBuffer.pos, (int)zwd->inBuffer.size, (int)zwd->outBuffer.pos, (int)zwd->outBuffer.size… in z_inflate()
890 strm->next_out += zwd->outBuffer.pos; in z_inflate()
891 strm->total_out += zwd->outBuffer.pos; in z_inflate()
892 strm->avail_out -= zwd->outBuffer.pos; in z_inflate()
893 strm->total_in += zwd->inBuffer.pos; in z_inflate()
894 zwd->totalInBytes += zwd->inBuffer.pos; in z_inflate()
895 strm->next_in += zwd->inBuffer.pos; in z_inflate()
896 strm->avail_in -= zwd->inBuffer.pos; in z_inflate()
900 zwd->decompState = ZWRAP_streamEnd; in z_inflate()
910 return ZWRAPD_finishWithError(zwd, strm, 0); in z_inflate()
921 { ZWRAP_DCtx* const zwd = (ZWRAP_DCtx*) strm->state; in z_inflateEnd() local
922 if (zwd == NULL) return Z_OK; /* structures are already freed */ in z_inflateEnd()
923 { size_t const freeErr = ZWRAP_freeDCtx(zwd); in z_inflateEnd()