Lines Matching refs:zwd
448 static void ZWRAP_initDCtx(ZWRAP_DCtx* zwd) in ZWRAP_initDCtx() argument
450 zwd->errorCount = 0; in ZWRAP_initDCtx()
451 zwd->outBuffer.pos = 0; in ZWRAP_initDCtx()
452 zwd->outBuffer.size = 0; in ZWRAP_initDCtx()
457 ZWRAP_DCtx* zwd; in ZWRAP_createDCtx() local
458 …MEM_STATIC_ASSERT(sizeof(zwd->headerBuf) >= ZSTD_FRAMEHEADERSIZE_MIN); /* check static buffer si… in ZWRAP_createDCtx()
461 zwd = (ZWRAP_DCtx*)strm->zalloc(strm->opaque, 1, sizeof(ZWRAP_DCtx)); in ZWRAP_createDCtx()
462 if (zwd==NULL) return NULL; in ZWRAP_createDCtx()
463 memset(zwd, 0, sizeof(ZWRAP_DCtx)); in ZWRAP_createDCtx()
464 zwd->allocFunc = *strm; /* just to copy zalloc, zfree & opaque */ in ZWRAP_createDCtx()
465 …{ ZSTD_customMem const ZWRAP_customMem = { ZWRAP_allocFunction, ZWRAP_freeFunction, &zwd->allocFun… in ZWRAP_createDCtx()
466 zwd->customMem = ZWRAP_customMem; } in ZWRAP_createDCtx()
468 zwd = (ZWRAP_DCtx*)calloc(1, sizeof(*zwd)); in ZWRAP_createDCtx()
469 if (zwd==NULL) return NULL; in ZWRAP_createDCtx()
472 ZWRAP_initDCtx(zwd); in ZWRAP_createDCtx()
473 return zwd; in ZWRAP_createDCtx()
476 static size_t ZWRAP_freeDCtx(ZWRAP_DCtx* zwd) in ZWRAP_freeDCtx() argument
478 if (zwd==NULL) return 0; /* support free on null */ in ZWRAP_freeDCtx()
479 ZSTD_freeDStream(zwd->zbd); in ZWRAP_freeDCtx()
480 ZSTD_free(zwd->version, zwd->customMem); in ZWRAP_freeDCtx()
481 ZSTD_free(zwd, zwd->customMem); in ZWRAP_freeDCtx()
493 static int ZWRAPD_finishWithError(ZWRAP_DCtx* zwd, z_streamp strm, int error) in ZWRAPD_finishWithError() argument
496 ZWRAP_freeDCtx(zwd); in ZWRAPD_finishWithError()
503 ZWRAP_DCtx* const zwd = (ZWRAP_DCtx*) strm->state; in ZWRAPD_finishWithErrorMsg() local
505 if (zwd == NULL) return Z_STREAM_ERROR; in ZWRAPD_finishWithErrorMsg()
507 return ZWRAPD_finishWithError(zwd, strm, 0); in ZWRAPD_finishWithErrorMsg()
519 { ZWRAP_DCtx* const zwd = ZWRAP_createDCtx(strm); in z_inflateInit_() local
521 if (zwd == NULL) return ZWRAPD_finishWithError(zwd, strm, 0); in z_inflateInit_()
523 zwd->version = ZSTD_malloc(strlen(version)+1, zwd->customMem); in z_inflateInit_()
524 if (zwd->version == NULL) return ZWRAPD_finishWithError(zwd, strm, 0); in z_inflateInit_()
525 strcpy(zwd->version, version); in z_inflateInit_()
527 zwd->stream_size = stream_size; in z_inflateInit_()
528 zwd->totalInBytes = 0; in z_inflateInit_()
529 strm->state = (struct internal_state*) zwd; in z_inflateInit_()
550 ZWRAP_DCtx* const zwd = (ZWRAP_DCtx*)strm->state; in z_inflateInit2_() local
551 if (zwd == NULL) return Z_STREAM_ERROR; in z_inflateInit2_()
552 zwd->windowBits = windowBits; in z_inflateInit2_()
564 { ZWRAP_DCtx* const zwd = (ZWRAP_DCtx*) strm->state; in ZWRAP_inflateReset_keepDict() local
565 if (zwd == NULL) return Z_STREAM_ERROR; in ZWRAP_inflateReset_keepDict()
566 ZWRAP_initDCtx(zwd); in ZWRAP_inflateReset_keepDict()
567 zwd->decompState = ZWRAP_useReset; in ZWRAP_inflateReset_keepDict()
568 zwd->totalInBytes = 0; in ZWRAP_inflateReset_keepDict()
586 { ZWRAP_DCtx* const zwd = (ZWRAP_DCtx*) strm->state; in z_inflateReset() local
587 if (zwd == NULL) return Z_STREAM_ERROR; in z_inflateReset()
588 zwd->decompState = ZWRAP_useInit; } in z_inflateReset()
603 ZWRAP_DCtx* const zwd = (ZWRAP_DCtx*)strm->state; in z_inflateReset2() local
604 if (zwd == NULL) return Z_STREAM_ERROR; in z_inflateReset2()
605 zwd->windowBits = windowBits; in z_inflateReset2()
621 { ZWRAP_DCtx* const zwd = (ZWRAP_DCtx*) strm->state; in z_inflateSetDictionary() local
622 if (zwd == NULL || zwd->zbd == NULL) return Z_STREAM_ERROR; in z_inflateSetDictionary()
623 { size_t const initErr = ZSTD_initDStream_usingDict(zwd->zbd, dictionary, dictLength); in z_inflateSetDictionary()
624 if (ZSTD_isError(initErr)) return ZWRAPD_finishWithError(zwd, strm, 0); } in z_inflateSetDictionary()
625 zwd->decompState = ZWRAP_useReset; in z_inflateSetDictionary()
627 if (zwd->totalInBytes == ZSTD_HEADERSIZE) { in z_inflateSetDictionary()
628 zwd->inBuffer.src = zwd->headerBuf; in z_inflateSetDictionary()
629 zwd->inBuffer.size = zwd->totalInBytes; in z_inflateSetDictionary()
630 zwd->inBuffer.pos = 0; in z_inflateSetDictionary()
631 zwd->outBuffer.dst = strm->next_out; in z_inflateSetDictionary()
632 zwd->outBuffer.size = 0; in z_inflateSetDictionary()
633 zwd->outBuffer.pos = 0; in z_inflateSetDictionary()
634 … { size_t const errorCode = ZSTD_decompressStream(zwd->zbd, &zwd->outBuffer, &zwd->inBuffer); in z_inflateSetDictionary()
636 (int)errorCode, (int)zwd->inBuffer.size, (int)zwd->outBuffer.size); in z_inflateSetDictionary()
637 if (zwd->inBuffer.pos < zwd->outBuffer.size || ZSTD_isError(errorCode)) { in z_inflateSetDictionary()
640 return ZWRAPD_finishWithError(zwd, strm, 0); in z_inflateSetDictionary()
649 ZWRAP_DCtx* zwd; in z_inflate() local
660 zwd = (ZWRAP_DCtx*) strm->state; in z_inflate()
664 if (zwd == NULL) return Z_STREAM_ERROR; in z_inflate()
665 if (zwd->decompState == ZWRAP_streamEnd) return Z_STREAM_END; in z_inflate()
667 if (zwd->totalInBytes < ZLIB_HEADERSIZE) { in z_inflate()
668 if (zwd->totalInBytes == 0 && strm->avail_in >= ZLIB_HEADERSIZE) { in z_inflate()
670 { int const initErr = (zwd->windowBits) ? in z_inflate()
671 … inflateInit2_(strm, zwd->windowBits, zwd->version, zwd->stream_size) : in z_inflate()
672 inflateInit_(strm, zwd->version, zwd->stream_size); in z_inflate()
674 if (initErr != Z_OK) return ZWRAPD_finishWithError(zwd, strm, initErr); in z_inflate()
678 { size_t const freeErr = ZWRAP_freeDCtx(zwd); in z_inflate()
689 size_t const srcSize = MIN(strm->avail_in, ZLIB_HEADERSIZE - zwd->totalInBytes); in z_inflate()
690 memcpy(zwd->headerBuf+zwd->totalInBytes, strm->next_in, srcSize); in z_inflate()
692 zwd->totalInBytes += srcSize; in z_inflate()
695 if (zwd->totalInBytes < ZLIB_HEADERSIZE) return Z_OK; in z_inflate()
697 if (MEM_readLE32(zwd->headerBuf) != ZSTD_MAGICNUMBER) { in z_inflate()
704 { int const initErr = (zwd->windowBits) ? in z_inflate()
705 … inflateInit2_(strm, zwd->windowBits, zwd->version, zwd->stream_size) : in z_inflate()
706 inflateInit_(strm, zwd->version, zwd->stream_size); in z_inflate()
708 if (initErr != Z_OK) return ZWRAPD_finishWithError(zwd, strm, initErr); in z_inflate()
712 strm->next_in = (unsigned char*)zwd->headerBuf; in z_inflate()
719 return ZWRAPD_finishWithError(zwd, strm, dErr); in z_inflate()
729 { size_t const freeErr = ZWRAP_freeDCtx(zwd); in z_inflate()
745 if (!zwd->zbd) { in z_inflate()
746 zwd->zbd = ZSTD_createDStream_advanced(zwd->customMem); in z_inflate()
747 if (zwd->zbd == NULL) { LOG_WRAPPERD("ERROR: ZSTD_createDStream_advanced\n"); goto error; } in z_inflate()
748 zwd->decompState = ZWRAP_useInit; in z_inflate()
751 if (zwd->totalInBytes < ZSTD_HEADERSIZE) { in z_inflate()
752 if (zwd->totalInBytes == 0 && strm->avail_in >= ZSTD_HEADERSIZE) { in z_inflate()
753 if (zwd->decompState == ZWRAP_useInit) { in z_inflate()
754 size_t const initErr = ZSTD_initDStream(zwd->zbd); in z_inflate()
761 size_t const resetErr = ZSTD_resetDStream(zwd->zbd); in z_inflate()
765 size_t const srcSize = MIN(strm->avail_in, ZSTD_HEADERSIZE - zwd->totalInBytes); in z_inflate()
766 memcpy(zwd->headerBuf+zwd->totalInBytes, strm->next_in, srcSize); in z_inflate()
768 zwd->totalInBytes += srcSize; in z_inflate()
771 if (zwd->totalInBytes < ZSTD_HEADERSIZE) return Z_OK; in z_inflate()
773 if (zwd->decompState == ZWRAP_useInit) { in z_inflate()
774 size_t const initErr = ZSTD_initDStream(zwd->zbd); in z_inflate()
781 size_t const resetErr = ZSTD_resetDStream(zwd->zbd); in z_inflate()
785 zwd->inBuffer.src = zwd->headerBuf; in z_inflate()
786 zwd->inBuffer.size = ZSTD_HEADERSIZE; in z_inflate()
787 zwd->inBuffer.pos = 0; in z_inflate()
788 zwd->outBuffer.dst = strm->next_out; in z_inflate()
789 zwd->outBuffer.size = 0; in z_inflate()
790 zwd->outBuffer.pos = 0; in z_inflate()
791 … { size_t const dErr = ZSTD_decompressStream(zwd->zbd, &zwd->outBuffer, &zwd->inBuffer); in z_inflate()
793 (int)dErr, (int)zwd->inBuffer.size, (int)zwd->outBuffer.size); in z_inflate()
798 if (zwd->inBuffer.pos != zwd->inBuffer.size) goto error; /* not consumed */ in z_inflate()
802 zwd->inBuffer.src = strm->next_in; in z_inflate()
803 zwd->inBuffer.size = strm->avail_in; in z_inflate()
804 zwd->inBuffer.pos = 0; in z_inflate()
805 zwd->outBuffer.dst = strm->next_out; in z_inflate()
806 zwd->outBuffer.size = strm->avail_out; in z_inflate()
807 zwd->outBuffer.pos = 0; in z_inflate()
808 { size_t const dErr = ZSTD_decompressStream(zwd->zbd, &zwd->outBuffer, &zwd->inBuffer); in z_inflate()
812 zwd->errorCount++; in z_inflate()
814 ZSTD_getErrorName(dErr), zwd->errorCount); in z_inflate()
815 if (zwd->errorCount<=1) return Z_NEED_DICT; else goto error; in z_inflate()
818 …(int)zwd->inBuffer.pos, (int)zwd->inBuffer.size, (int)zwd->outBuffer.pos, (int)zwd->outBuffer.size… in z_inflate()
819 strm->next_out += zwd->outBuffer.pos; in z_inflate()
820 strm->total_out += zwd->outBuffer.pos; in z_inflate()
821 strm->avail_out -= zwd->outBuffer.pos; in z_inflate()
822 strm->total_in += zwd->inBuffer.pos; in z_inflate()
823 zwd->totalInBytes += zwd->inBuffer.pos; in z_inflate()
824 strm->next_in += zwd->inBuffer.pos; in z_inflate()
825 strm->avail_in -= zwd->inBuffer.pos; in z_inflate()
829 zwd->decompState = ZWRAP_streamEnd; in z_inflate()
839 return ZWRAPD_finishWithError(zwd, strm, 0); in z_inflate()
850 { ZWRAP_DCtx* const zwd = (ZWRAP_DCtx*) strm->state; in z_inflateEnd() local
851 if (zwd == NULL) return Z_OK; /* structures are already freed */ in z_inflateEnd()
852 { size_t const freeErr = ZWRAP_freeDCtx(zwd); in z_inflateEnd()