Lines Matching refs:zwd

534 static void ZWRAP_initDCtx(ZWRAP_DCtx* zwd)  in ZWRAP_initDCtx()  argument
536 zwd->errorCount = 0; in ZWRAP_initDCtx()
537 zwd->outBuffer.pos = 0; in ZWRAP_initDCtx()
538 zwd->outBuffer.size = 0; in ZWRAP_initDCtx()
543 ZWRAP_DCtx* zwd; in ZWRAP_createDCtx() local
552 zwd = (ZWRAP_DCtx*)ZWRAP_customCalloc(sizeof(ZWRAP_DCtx), customMem); in ZWRAP_createDCtx()
553 if (zwd == NULL) return NULL; in ZWRAP_createDCtx()
554 zwd->allocFunc = *strm; in ZWRAP_createDCtx()
555 customMem.opaque = &zwd->allocFunc; in ZWRAP_createDCtx()
556 zwd->customMem = customMem; in ZWRAP_createDCtx()
558 ZWRAP_initDCtx(zwd); in ZWRAP_createDCtx()
559 return zwd; in ZWRAP_createDCtx()
562 static size_t ZWRAP_freeDCtx(ZWRAP_DCtx* zwd) in ZWRAP_freeDCtx() argument
564 if (zwd==NULL) return 0; /* support free on null */ in ZWRAP_freeDCtx()
565 ZSTD_freeDStream(zwd->zbd); in ZWRAP_freeDCtx()
566 ZWRAP_customFree(zwd->version, zwd->customMem); in ZWRAP_freeDCtx()
567 ZWRAP_customFree(zwd, zwd->customMem); in ZWRAP_freeDCtx()
579 static int ZWRAPD_finishWithError(ZWRAP_DCtx* zwd, z_streamp strm, int error) in ZWRAPD_finishWithError() argument
582 ZWRAP_freeDCtx(zwd); in ZWRAPD_finishWithError()
589 ZWRAP_DCtx* const zwd = (ZWRAP_DCtx*) strm->state; in ZWRAPD_finishWithErrorMsg() local
591 if (zwd == NULL) return Z_STREAM_ERROR; in ZWRAPD_finishWithErrorMsg()
593 return ZWRAPD_finishWithError(zwd, strm, 0); in ZWRAPD_finishWithErrorMsg()
605 { ZWRAP_DCtx* const zwd = ZWRAP_createDCtx(strm); in z_inflateInit_() local
607 if (zwd == NULL) return ZWRAPD_finishWithError(zwd, strm, 0); in z_inflateInit_()
609 zwd->version = (char*)ZWRAP_customMalloc(strlen(version)+1, zwd->customMem); in z_inflateInit_()
610 if (zwd->version == NULL) return ZWRAPD_finishWithError(zwd, strm, 0); in z_inflateInit_()
611 strcpy(zwd->version, version); in z_inflateInit_()
613 zwd->stream_size = stream_size; in z_inflateInit_()
614 zwd->totalInBytes = 0; in z_inflateInit_()
615 strm->state = convert_into_sis(zwd); in z_inflateInit_()
636 ZWRAP_DCtx* const zwd = (ZWRAP_DCtx*)strm->state; in z_inflateInit2_() local
637 if (zwd == NULL) return Z_STREAM_ERROR; in z_inflateInit2_()
638 zwd->windowBits = windowBits; in z_inflateInit2_()
650 { ZWRAP_DCtx* const zwd = (ZWRAP_DCtx*) strm->state; in ZWRAP_inflateReset_keepDict() local
651 if (zwd == NULL) return Z_STREAM_ERROR; in ZWRAP_inflateReset_keepDict()
652 ZWRAP_initDCtx(zwd); in ZWRAP_inflateReset_keepDict()
653 zwd->decompState = ZWRAP_useReset; in ZWRAP_inflateReset_keepDict()
654 zwd->totalInBytes = 0; in ZWRAP_inflateReset_keepDict()
672 { ZWRAP_DCtx* const zwd = (ZWRAP_DCtx*) strm->state; in z_inflateReset() local
673 if (zwd == NULL) return Z_STREAM_ERROR; in z_inflateReset()
674 zwd->decompState = ZWRAP_useInit; } in z_inflateReset()
689 ZWRAP_DCtx* const zwd = (ZWRAP_DCtx*)strm->state; in z_inflateReset2() local
690 if (zwd == NULL) return Z_STREAM_ERROR; in z_inflateReset2()
691 zwd->windowBits = windowBits; in z_inflateReset2()
707 { ZWRAP_DCtx* const zwd = (ZWRAP_DCtx*) strm->state; in z_inflateSetDictionary() local
708 if (zwd == NULL || zwd->zbd == NULL) return Z_STREAM_ERROR; in z_inflateSetDictionary()
709 { size_t const initErr = ZSTD_initDStream_usingDict(zwd->zbd, dictionary, dictLength); in z_inflateSetDictionary()
710 if (ZSTD_isError(initErr)) return ZWRAPD_finishWithError(zwd, strm, 0); } in z_inflateSetDictionary()
711 zwd->decompState = ZWRAP_useReset; in z_inflateSetDictionary()
713 if (zwd->totalInBytes == ZSTD_HEADERSIZE) { in z_inflateSetDictionary()
714 zwd->inBuffer.src = zwd->headerBuf; in z_inflateSetDictionary()
715 zwd->inBuffer.size = zwd->totalInBytes; in z_inflateSetDictionary()
716 zwd->inBuffer.pos = 0; in z_inflateSetDictionary()
717 zwd->outBuffer.dst = strm->next_out; in z_inflateSetDictionary()
718 zwd->outBuffer.size = 0; in z_inflateSetDictionary()
719 zwd->outBuffer.pos = 0; in z_inflateSetDictionary()
720 … { size_t const errorCode = ZSTD_decompressStream(zwd->zbd, &zwd->outBuffer, &zwd->inBuffer); in z_inflateSetDictionary()
722 (int)errorCode, (int)zwd->inBuffer.size, (int)zwd->outBuffer.size); in z_inflateSetDictionary()
723 if (zwd->inBuffer.pos < zwd->outBuffer.size || ZSTD_isError(errorCode)) { in z_inflateSetDictionary()
726 return ZWRAPD_finishWithError(zwd, strm, 0); in z_inflateSetDictionary()
735 ZWRAP_DCtx* zwd; in z_inflate() local
746 zwd = (ZWRAP_DCtx*) strm->state; in z_inflate()
750 if (zwd == NULL) return Z_STREAM_ERROR; in z_inflate()
751 if (zwd->decompState == ZWRAP_streamEnd) return Z_STREAM_END; in z_inflate()
753 if (zwd->totalInBytes < ZLIB_HEADERSIZE) { in z_inflate()
754 if (zwd->totalInBytes == 0 && strm->avail_in >= ZLIB_HEADERSIZE) { in z_inflate()
756 { int const initErr = (zwd->windowBits) ? in z_inflate()
757 … inflateInit2_(strm, zwd->windowBits, zwd->version, zwd->stream_size) : in z_inflate()
758 inflateInit_(strm, zwd->version, zwd->stream_size); in z_inflate()
760 if (initErr != Z_OK) return ZWRAPD_finishWithError(zwd, strm, initErr); in z_inflate()
764 { size_t const freeErr = ZWRAP_freeDCtx(zwd); in z_inflate()
775 size_t const srcSize = MIN(strm->avail_in, ZLIB_HEADERSIZE - zwd->totalInBytes); in z_inflate()
776 memcpy(zwd->headerBuf+zwd->totalInBytes, strm->next_in, srcSize); in z_inflate()
778 zwd->totalInBytes += srcSize; in z_inflate()
781 if (zwd->totalInBytes < ZLIB_HEADERSIZE) return Z_OK; in z_inflate()
783 if (ZWRAP_readLE32(zwd->headerBuf) != ZSTD_MAGICNUMBER) { in z_inflate()
790 { int const initErr = (zwd->windowBits) ? in z_inflate()
791 … inflateInit2_(strm, zwd->windowBits, zwd->version, zwd->stream_size) : in z_inflate()
792 inflateInit_(strm, zwd->version, zwd->stream_size); in z_inflate()
794 if (initErr != Z_OK) return ZWRAPD_finishWithError(zwd, strm, initErr); in z_inflate()
798 strm->next_in = (unsigned char*)zwd->headerBuf; in z_inflate()
805 return ZWRAPD_finishWithError(zwd, strm, dErr); in z_inflate()
815 { size_t const freeErr = ZWRAP_freeDCtx(zwd); in z_inflate()
831 if (!zwd->zbd) { in z_inflate()
832 zwd->zbd = ZSTD_createDStream_advanced(zwd->customMem); in z_inflate()
833 if (zwd->zbd == NULL) { LOG_WRAPPERD("ERROR: ZSTD_createDStream_advanced\n"); goto error; } in z_inflate()
834 zwd->decompState = ZWRAP_useInit; in z_inflate()
837 if (zwd->totalInBytes < ZSTD_HEADERSIZE) { in z_inflate()
838 if (zwd->totalInBytes == 0 && strm->avail_in >= ZSTD_HEADERSIZE) { in z_inflate()
839 if (zwd->decompState == ZWRAP_useInit) { in z_inflate()
840 size_t const initErr = ZSTD_initDStream(zwd->zbd); in z_inflate()
847 size_t const resetErr = ZSTD_DCtx_reset(zwd->zbd, ZSTD_reset_session_only); in z_inflate()
851 size_t const srcSize = MIN(strm->avail_in, ZSTD_HEADERSIZE - zwd->totalInBytes); in z_inflate()
852 memcpy(zwd->headerBuf+zwd->totalInBytes, strm->next_in, srcSize); in z_inflate()
854 zwd->totalInBytes += srcSize; in z_inflate()
857 if (zwd->totalInBytes < ZSTD_HEADERSIZE) return Z_OK; in z_inflate()
859 if (zwd->decompState == ZWRAP_useInit) { in z_inflate()
860 size_t const initErr = ZSTD_initDStream(zwd->zbd); in z_inflate()
867 size_t const resetErr = ZSTD_DCtx_reset(zwd->zbd, ZSTD_reset_session_only); in z_inflate()
871 zwd->inBuffer.src = zwd->headerBuf; in z_inflate()
872 zwd->inBuffer.size = ZSTD_HEADERSIZE; in z_inflate()
873 zwd->inBuffer.pos = 0; in z_inflate()
874 zwd->outBuffer.dst = strm->next_out; in z_inflate()
875 zwd->outBuffer.size = 0; in z_inflate()
876 zwd->outBuffer.pos = 0; in z_inflate()
877 … { size_t const dErr = ZSTD_decompressStream(zwd->zbd, &zwd->outBuffer, &zwd->inBuffer); in z_inflate()
879 (int)dErr, (int)zwd->inBuffer.size, (int)zwd->outBuffer.size); in z_inflate()
884 if (zwd->inBuffer.pos != zwd->inBuffer.size) goto error; /* not consumed */ in z_inflate()
888 zwd->inBuffer.src = strm->next_in; in z_inflate()
889 zwd->inBuffer.size = strm->avail_in; in z_inflate()
890 zwd->inBuffer.pos = 0; in z_inflate()
891 zwd->outBuffer.dst = strm->next_out; in z_inflate()
892 zwd->outBuffer.size = strm->avail_out; in z_inflate()
893 zwd->outBuffer.pos = 0; in z_inflate()
894 { size_t const dErr = ZSTD_decompressStream(zwd->zbd, &zwd->outBuffer, &zwd->inBuffer); in z_inflate()
898 zwd->errorCount++; in z_inflate()
900 ZSTD_getErrorName(dErr), zwd->errorCount); in z_inflate()
901 if (zwd->errorCount<=1) return Z_NEED_DICT; else goto error; in z_inflate()
904 …(int)zwd->inBuffer.pos, (int)zwd->inBuffer.size, (int)zwd->outBuffer.pos, (int)zwd->outBuffer.size… in z_inflate()
905 strm->next_out += zwd->outBuffer.pos; in z_inflate()
906 strm->total_out += zwd->outBuffer.pos; in z_inflate()
907 strm->avail_out -= zwd->outBuffer.pos; in z_inflate()
908 strm->total_in += zwd->inBuffer.pos; in z_inflate()
909 zwd->totalInBytes += zwd->inBuffer.pos; in z_inflate()
910 strm->next_in += zwd->inBuffer.pos; in z_inflate()
911 strm->avail_in -= zwd->inBuffer.pos; in z_inflate()
915 zwd->decompState = ZWRAP_streamEnd; in z_inflate()
925 return ZWRAPD_finishWithError(zwd, strm, 0); in z_inflate()
936 { ZWRAP_DCtx* const zwd = (ZWRAP_DCtx*) strm->state; in z_inflateEnd() local
937 if (zwd == NULL) return Z_OK; /* structures are already freed */ in z_inflateEnd()
938 { size_t const freeErr = ZWRAP_freeDCtx(zwd); in z_inflateEnd()