• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /freebsd-13-stable/sys/contrib/zstd/zlibWrapper/

Lines Matching defs:strm

108     z_streamp strm = (z_streamp) opaque;
109 void* address = strm->zalloc(strm->opaque, 1, (uInt)size);
116 z_streamp strm = (z_streamp) opaque;
117 strm->zfree(strm->opaque, address);
159 unsigned long long totalInBytes; /* we need it as strm->total_in can be reset by user */
181 static ZWRAP_CCtx* ZWRAP_createCCtx(z_streamp strm)
186 if (strm->zalloc && strm->zfree) {
190 customMem.opaque = strm;
194 zwc->allocFunc = *strm;
220 static int ZWRAPC_finishWithError(ZWRAP_CCtx* zwc, z_streamp strm, int error)
224 if (strm) strm->state = NULL;
229 static int ZWRAPC_finishWithErrorMsg(z_streamp strm, char* message)
231 ZWRAP_CCtx* zwc = (ZWRAP_CCtx*) strm->state;
232 strm->msg = message;
235 return ZWRAPC_finishWithError(zwc, strm, 0);
239 int ZWRAP_setPledgedSrcSize(z_streamp strm, unsigned long long pledgedSrcSize)
241 ZWRAP_CCtx* zwc = (ZWRAP_CCtx*) strm->state;
254 ZEXTERN int ZEXPORT z_deflateInit_ OF((z_streamp strm, int level,
261 return deflateInit_((strm), (level), version, stream_size);
264 zwc = ZWRAP_createCCtx(strm);
273 strm->state = convert_into_sis(zwc); /* use state which in not used by user */
274 strm->total_in = 0;
275 strm->total_out = 0;
276 strm->adler = 0;
281 ZEXTERN int ZEXPORT z_deflateInit2_ OF((z_streamp strm, int level, int method,
287 return deflateInit2_(strm, level, method, windowBits, memLevel, strategy, version, stream_size);
289 return z_deflateInit_ (strm, level, version, stream_size);
293 int ZWRAP_deflateReset_keepDict(z_streamp strm)
297 return deflateReset(strm);
299 { ZWRAP_CCtx* zwc = (ZWRAP_CCtx*) strm->state;
306 strm->total_in = 0;
307 strm->total_out = 0;
308 strm->adler = 0;
313 ZEXTERN int ZEXPORT z_deflateReset OF((z_streamp strm))
317 return deflateReset(strm);
319 ZWRAP_deflateReset_keepDict(strm);
321 { ZWRAP_CCtx* zwc = (ZWRAP_CCtx*) strm->state;
328 ZEXTERN int ZEXPORT z_deflateSetDictionary OF((z_streamp strm,
334 return deflateSetDictionary(strm, dictionary, dictLength);
337 { ZWRAP_CCtx* zwc = (ZWRAP_CCtx*) strm->state;
342 if (zwc->zbc == NULL) return ZWRAPC_finishWithError(zwc, strm, 0);
345 if (res != Z_OK) return ZWRAPC_finishWithError(zwc, strm, res); }
353 ZEXTERN int ZEXPORT z_deflate OF((z_streamp strm, int flush))
359 (int)flush, (int)strm->avail_in, (int)strm->avail_out, (int)strm->total_in, (int)strm->total_out);
360 return deflate(strm, flush);
363 zwc = (ZWRAP_CCtx*) strm->state;
368 if (zwc->zbc == NULL) return ZWRAPC_finishWithError(zwc, strm, 0);
369 { int const initErr = ZWRAP_initializeCStream(zwc, NULL, 0, (flush == Z_FINISH) ? strm->avail_in : ZSTD_CONTENTSIZE_UNKNOWN);
370 if (initErr != Z_OK) return ZWRAPC_finishWithError(zwc, strm, initErr); }
375 size_t const resetErr = ZSTD_resetCStream(zwc->zbc, (flush == Z_FINISH) ? strm->avail_in : zwc->pledgedSrcSize);
379 return ZWRAPC_finishWithError(zwc, strm, 0);
382 int const res = ZWRAP_initializeCStream(zwc, NULL, 0, (flush == Z_FINISH) ? strm->avail_in : ZSTD_CONTENTSIZE_UNKNOWN);
383 if (res != Z_OK) return ZWRAPC_finishWithError(zwc, strm, res);
389 LOG_WRAPPERC("- deflate2 flush=%d avail_in=%d avail_out=%d total_in=%d total_out=%d\n", (int)flush, (int)strm->avail_in, (int)strm->avail_out, (int)strm->total_in, (int)strm->total_out);
390 if (strm->avail_in > 0) {
391 zwc->inBuffer.src = strm->next_in;
392 zwc->inBuffer.size = strm->avail_in;
394 zwc->outBuffer.dst = strm->next_out;
395 zwc->outBuffer.size = strm->avail_out;
399 if (ZSTD_isError(cErr)) return ZWRAPC_finishWithError(zwc, strm, 0);
401 strm->next_out += zwc->outBuffer.pos;
402 strm->total_out += zwc->outBuffer.pos;
403 strm->avail_out -= zwc->outBuffer.pos;
404 strm->total_in += zwc->inBuffer.pos;
406 strm->next_in += zwc->inBuffer.pos;
407 strm->avail_in -= zwc->inBuffer.pos;
415 return ZWRAPC_finishWithErrorMsg(strm, "Z_FULL_FLUSH, Z_BLOCK and Z_TREES are not supported!");
420 zwc->outBuffer.dst = strm->next_out;
421 zwc->outBuffer.size = strm->avail_out;
424 LOG_WRAPPERC("deflate ZSTD_endStream dstCapacity=%d bytesLeft=%d\n", (int)strm->avail_out, (int)bytesLeft);
425 if (ZSTD_isError(bytesLeft)) return ZWRAPC_finishWithError(zwc, strm, 0);
426 strm->next_out += zwc->outBuffer.pos;
427 strm->total_out += zwc->outBuffer.pos;
428 strm->avail_out -= zwc->outBuffer.pos;
431 LOG_WRAPPERC("Z_STREAM_END2 strm->total_in=%d strm->avail_out=%d strm->total_out=%d\n",
432 (int)strm->total_in, (int)strm->avail_out, (int)strm->total_out);
438 zwc->outBuffer.dst = strm->next_out;
439 zwc->outBuffer.size = strm->avail_out;
442 LOG_WRAPPERC("deflate ZSTD_flushStream dstCapacity=%d bytesLeft=%d\n", (int)strm->avail_out, (int)bytesLeft);
443 if (ZSTD_isError(bytesLeft)) return ZWRAPC_finishWithError(zwc, strm, 0);
444 strm->next_out += zwc->outBuffer.pos;
445 strm->total_out += zwc->outBuffer.pos;
446 strm->avail_out -= zwc->outBuffer.pos;
448 LOG_WRAPPERC("- deflate3 flush=%d avail_in=%d avail_out=%d total_in=%d total_out=%d\n", (int)flush, (int)strm->avail_in, (int)strm->avail_out, (int)strm->total_in, (int)strm->total_out);
453 ZEXTERN int ZEXPORT z_deflateEnd OF((z_streamp strm))
457 return deflateEnd(strm);
459 LOG_WRAPPERC("- deflateEnd total_in=%d total_out=%d\n", (int)(strm->total_in), (int)(strm->total_out));
461 ZWRAP_CCtx* zwc = (ZWRAP_CCtx*) strm->state;
463 strm->state = NULL;
471 ZEXTERN uLong ZEXPORT z_deflateBound OF((z_streamp strm,
475 return deflateBound(strm, sourceLen);
481 ZEXTERN int ZEXPORT z_deflateParams OF((z_streamp strm,
487 return deflateParams(strm, level, strategy);
505 unsigned long long totalInBytes; /* we need it as strm->total_in can be reset by user */
526 static ZWRAP_DCtx* ZWRAP_createDCtx(z_streamp strm)
531 if (strm->zalloc && strm->zfree) {
535 customMem.opaque = strm;
539 zwd->allocFunc = *strm;
557 int ZWRAP_isUsingZSTDdecompression(z_streamp strm)
559 if (strm == NULL) return 0;
560 return (strm->reserved == ZWRAP_ZSTD_STREAM);
564 static int ZWRAPD_finishWithError(ZWRAP_DCtx* zwd, z_streamp strm, int error)
568 strm->state = NULL;
572 static int ZWRAPD_finishWithErrorMsg(z_streamp strm, char* message)
574 ZWRAP_DCtx* const zwd = (ZWRAP_DCtx*) strm->state;
575 strm->msg = message;
578 return ZWRAPD_finishWithError(zwd, strm, 0);
582 ZEXTERN int ZEXPORT z_inflateInit_ OF((z_streamp strm,
586 strm->reserved = ZWRAP_ZLIB_STREAM;
587 return inflateInit(strm);
590 { ZWRAP_DCtx* const zwd = ZWRAP_createDCtx(strm);
592 if (zwd == NULL) return ZWRAPD_finishWithError(zwd, strm, 0);
595 if (zwd->version == NULL) return ZWRAPD_finishWithError(zwd, strm, 0);
600 strm->state = convert_into_sis(zwd);
601 strm->total_in = 0;
602 strm->total_out = 0;
603 strm->reserved = ZWRAP_UNKNOWN_STREAM;
604 strm->adler = 0;
611 ZEXTERN int ZEXPORT z_inflateInit2_ OF((z_streamp strm, int windowBits,
615 return inflateInit2_(strm, windowBits, version, stream_size);
618 { int const ret = z_inflateInit_ (strm, version, stream_size);
621 ZWRAP_DCtx* const zwd = (ZWRAP_DCtx*)strm->state;
629 int ZWRAP_inflateReset_keepDict(z_streamp strm)
632 if (g_ZWRAPdecompressionType == ZWRAP_FORCE_ZLIB || !strm->reserved)
633 return inflateReset(strm);
635 { ZWRAP_DCtx* const zwd = (ZWRAP_DCtx*) strm->state;
642 strm->total_in = 0;
643 strm->total_out = 0;
648 ZEXTERN int ZEXPORT z_inflateReset OF((z_streamp strm))
651 if (g_ZWRAPdecompressionType == ZWRAP_FORCE_ZLIB || !strm->reserved)
652 return inflateReset(strm);
654 { int const ret = ZWRAP_inflateReset_keepDict(strm);
657 { ZWRAP_DCtx* const zwd = (ZWRAP_DCtx*) strm->state;
666 ZEXTERN int ZEXPORT z_inflateReset2 OF((z_streamp strm,
669 if (g_ZWRAPdecompressionType == ZWRAP_FORCE_ZLIB || !strm->reserved)
670 return inflateReset2(strm, windowBits);
672 { int const ret = z_inflateReset (strm);
674 ZWRAP_DCtx* const zwd = (ZWRAP_DCtx*)strm->state;
684 ZEXTERN int ZEXPORT z_inflateSetDictionary OF((z_streamp strm,
689 if (g_ZWRAPdecompressionType == ZWRAP_FORCE_ZLIB || !strm->reserved)
690 return inflateSetDictionary(strm, dictionary, dictLength);
692 { ZWRAP_DCtx* const zwd = (ZWRAP_DCtx*) strm->state;
695 if (ZSTD_isError(initErr)) return ZWRAPD_finishWithError(zwd, strm, 0); }
702 zwd->outBuffer.dst = strm->next_out;
711 return ZWRAPD_finishWithError(zwd, strm, 0);
718 ZEXTERN int ZEXPORT z_inflate OF((z_streamp strm, int flush))
722 if (g_ZWRAPdecompressionType == ZWRAP_FORCE_ZLIB || !strm->reserved) {
723 int const result = inflate(strm, flush);
725 (int)flush, (int)strm->avail_in, (int)strm->avail_out, (int)strm->total_in, (int)strm->total_out, result);
729 if (strm->avail_in <= 0) return Z_OK;
731 zwd = (ZWRAP_DCtx*) strm->state;
733 (int)flush, (int)strm->avail_in, (int)strm->avail_out, (int)strm->total_in, (int)strm->total_out);
739 if (zwd->totalInBytes == 0 && strm->avail_in >= ZLIB_HEADERSIZE) {
740 if (ZWRAP_readLE32(strm->next_in) != ZSTD_MAGICNUMBER) {
742 inflateInit2_(strm, zwd->windowBits, zwd->version, zwd->stream_size) :
743 inflateInit_(strm, zwd->version, zwd->stream_size);
745 if (initErr != Z_OK) return ZWRAPD_finishWithError(zwd, strm, initErr);
748 strm->reserved = ZWRAP_ZLIB_STREAM;
753 inflateSync(strm) :
754 inflate(strm, flush);
756 (int)flush, (int)strm->avail_in, (int)strm->avail_out, (int)strm->total_in, (int)strm->total_out, res);
759 } else { /* ! (zwd->totalInBytes == 0 && strm->avail_in >= ZLIB_HEADERSIZE) */
760 size_t const srcSize = MIN(strm->avail_in, ZLIB_HEADERSIZE - zwd->totalInBytes);
761 memcpy(zwd->headerBuf+zwd->totalInBytes, strm->next_in, srcSize);
762 strm->total_in += srcSize;
764 strm->next_in += srcSize;
765 strm->avail_in -= srcSize;
770 strm2.next_in = strm->next_in;
771 strm2.avail_in = strm->avail_in;
772 strm2.next_out = strm->next_out;
773 strm2.avail_out = strm->avail_out;
776 inflateInit2_(strm, zwd->windowBits, zwd->version, zwd->stream_size) :
777 inflateInit_(strm, zwd->version, zwd->stream_size);
779 if (initErr != Z_OK) return ZWRAPD_finishWithError(zwd, strm, initErr);
783 strm->next_in = (unsigned char*)zwd->headerBuf;
784 strm->avail_in = ZLIB_HEADERSIZE;
785 strm->avail_out = 0;
786 { int const dErr = inflate(strm, Z_NO_FLUSH);
787 LOG_WRAPPERD("ZLIB inflate errorCode=%d strm->avail_in=%d\n",
788 dErr, (int)strm->avail_in);
790 return ZWRAPD_finishWithError(zwd, strm, dErr);
792 if (strm->avail_in > 0) goto error;
794 strm->next_in = strm2.next_in;
795 strm->avail_in = strm2.avail_in;
796 strm->next_out = strm2.next_out;
797 strm->avail_out = strm2.avail_out;
799 strm->reserved = ZWRAP_ZLIB_STREAM; /* mark as zlib stream */
804 inflateSync(strm) :
805 inflate(strm, flush);
807 (int)flush, (int)strm->avail_in, (int)strm->avail_out, (int)strm->total_in, (int)strm->total_out, res);
809 } } } /* if ! (zwd->totalInBytes == 0 && strm->avail_in >= ZLIB_HEADERSIZE) */
812 strm->reserved = ZWRAP_ZSTD_STREAM; /* mark as zstd steam */
814 if (flush == Z_INFLATE_SYNC) { strm->msg = "inflateSync is not supported!"; goto error; }
823 if (zwd->totalInBytes == 0 && strm->avail_in >= ZSTD_HEADERSIZE) {
836 size_t const srcSize = MIN(strm->avail_in, ZSTD_HEADERSIZE - zwd->totalInBytes);
837 memcpy(zwd->headerBuf+zwd->totalInBytes, strm->next_in, srcSize);
838 strm->total_in += srcSize;
840 strm->next_in += srcSize;
841 strm->avail_in -= srcSize;
859 zwd->outBuffer.dst = strm->next_out;
873 zwd->inBuffer.src = strm->next_in;
874 zwd->inBuffer.size = strm->avail_in;
876 zwd->outBuffer.dst = strm->next_out;
877 zwd->outBuffer.size = strm->avail_out;
881 (int)dErr, (int)strm->avail_in, (int)strm->avail_out);
890 strm->next_out += zwd->outBuffer.pos;
891 strm->total_out += zwd->outBuffer.pos;
892 strm->avail_out -= zwd->outBuffer.pos;
893 strm->total_in += zwd->inBuffer.pos;
895 strm->next_in += zwd->inBuffer.pos;
896 strm->avail_in -= zwd->inBuffer.pos;
899 (int)strm->avail_in, (int)strm->avail_out, (int)strm->total_in, (int)strm->total_out);
906 (int)flush, (int)strm->avail_in, (int)strm->avail_out, (int)strm->total_in, (int)strm->total_out, Z_OK);
910 return ZWRAPD_finishWithError(zwd, strm, 0);
914 ZEXTERN int ZEXPORT z_inflateEnd OF((z_streamp strm))
916 if (g_ZWRAPdecompressionType == ZWRAP_FORCE_ZLIB || !strm->reserved)
917 return inflateEnd(strm);
920 (int)(strm->total_in), (int)(strm->total_out));
921 { ZWRAP_DCtx* const zwd = (ZWRAP_DCtx*) strm->state;
925 strm->state = NULL;
931 ZEXTERN int ZEXPORT z_inflateSync OF((z_streamp strm))
933 if (g_ZWRAPdecompressionType == ZWRAP_FORCE_ZLIB || !strm->reserved) {
934 return inflateSync(strm);
937 return z_inflate(strm, Z_INFLATE_SYNC);
952 ZEXTERN int ZEXPORT z_deflateTune OF((z_streamp strm,
959 return deflateTune(strm, good_length, max_lazy, nice_length, max_chain);
960 return ZWRAPC_finishWithErrorMsg(strm, "deflateTune is not supported!");
965 ZEXTERN int ZEXPORT z_deflatePending OF((z_streamp strm,
970 return deflatePending(strm, pending, bits);
971 return ZWRAPC_finishWithErrorMsg(strm, "deflatePending is not supported!");
976 ZEXTERN int ZEXPORT z_deflatePrime OF((z_streamp strm,
981 return deflatePrime(strm, bits, value);
982 return ZWRAPC_finishWithErrorMsg(strm, "deflatePrime is not supported!");
986 ZEXTERN int ZEXPORT z_deflateSetHeader OF((z_streamp strm,
990 return deflateSetHeader(strm, head);
991 return ZWRAPC_finishWithErrorMsg(strm, "deflateSetHeader is not supported!");
999 ZEXTERN int ZEXPORT z_inflateGetDictionary OF((z_streamp strm,
1003 if (g_ZWRAPdecompressionType == ZWRAP_FORCE_ZLIB || !strm->reserved)
1004 return inflateGetDictionary(strm, dictionary, dictLength);
1005 return ZWRAPD_finishWithErrorMsg(strm, "inflateGetDictionary is not supported!");
1020 ZEXTERN long ZEXPORT z_inflateMark OF((z_streamp strm))
1022 if (g_ZWRAPdecompressionType == ZWRAP_FORCE_ZLIB || !strm->reserved)
1023 return inflateMark(strm);
1024 return ZWRAPD_finishWithErrorMsg(strm, "inflateMark is not supported!");
1029 ZEXTERN int ZEXPORT z_inflatePrime OF((z_streamp strm,
1033 if (g_ZWRAPdecompressionType == ZWRAP_FORCE_ZLIB || !strm->reserved)
1034 return inflatePrime(strm, bits, value);
1035 return ZWRAPD_finishWithErrorMsg(strm, "inflatePrime is not supported!");
1039 ZEXTERN int ZEXPORT z_inflateGetHeader OF((z_streamp strm,
1042 if (g_ZWRAPdecompressionType == ZWRAP_FORCE_ZLIB || !strm->reserved)
1043 return inflateGetHeader(strm, head);
1044 return ZWRAPD_finishWithErrorMsg(strm, "inflateGetHeader is not supported!");
1048 ZEXTERN int ZEXPORT z_inflateBackInit_ OF((z_streamp strm, int windowBits,
1053 if (g_ZWRAPdecompressionType == ZWRAP_FORCE_ZLIB || !strm->reserved)
1054 return inflateBackInit_(strm, windowBits, window, version, stream_size);
1055 return ZWRAPD_finishWithErrorMsg(strm, "inflateBackInit is not supported!");
1059 ZEXTERN int ZEXPORT z_inflateBack OF((z_streamp strm,
1063 if (g_ZWRAPdecompressionType == ZWRAP_FORCE_ZLIB || !strm->reserved)
1064 return inflateBack(strm, in, in_desc, out, out_desc);
1065 return ZWRAPD_finishWithErrorMsg(strm, "inflateBack is not supported!");
1069 ZEXTERN int ZEXPORT z_inflateBackEnd OF((z_streamp strm))
1071 if (g_ZWRAPdecompressionType == ZWRAP_FORCE_ZLIB || !strm->reserved)
1072 return inflateBackEnd(strm);
1073 return ZWRAPD_finishWithErrorMsg(strm, "inflateBackEnd is not supported!");