10c16b537SWarner Losh /*
2*5ff13fbcSAllan Jude * Copyright (c) Yann Collet, Facebook, Inc.
30c16b537SWarner Losh * All rights reserved.
40c16b537SWarner Losh *
50c16b537SWarner Losh * This source code is licensed under both the BSD-style license (found in the
60c16b537SWarner Losh * LICENSE file in the root directory of this source tree) and the GPLv2 (found
70c16b537SWarner Losh * in the COPYING file in the root directory of this source tree).
80c16b537SWarner Losh * You may select, at your option, one of the above-listed licenses.
90c16b537SWarner Losh */
100c16b537SWarner Losh
110c16b537SWarner Losh #ifndef ZSTD_LEGACY_H
120c16b537SWarner Losh #define ZSTD_LEGACY_H
130c16b537SWarner Losh
140c16b537SWarner Losh #if defined (__cplusplus)
150c16b537SWarner Losh extern "C" {
160c16b537SWarner Losh #endif
170c16b537SWarner Losh
180c16b537SWarner Losh /* *************************************
190c16b537SWarner Losh * Includes
200c16b537SWarner Losh ***************************************/
2137f1f268SConrad Meyer #include "../common/mem.h" /* MEM_STATIC */
2237f1f268SConrad Meyer #include "../common/error_private.h" /* ERROR */
2337f1f268SConrad Meyer #include "../common/zstd_internal.h" /* ZSTD_inBuffer, ZSTD_outBuffer, ZSTD_frameSizeInfo */
240c16b537SWarner Losh
250c16b537SWarner Losh #if !defined (ZSTD_LEGACY_SUPPORT) || (ZSTD_LEGACY_SUPPORT == 0)
260c16b537SWarner Losh # undef ZSTD_LEGACY_SUPPORT
270c16b537SWarner Losh # define ZSTD_LEGACY_SUPPORT 8
280c16b537SWarner Losh #endif
290c16b537SWarner Losh
300c16b537SWarner Losh #if (ZSTD_LEGACY_SUPPORT <= 1)
310c16b537SWarner Losh # include "zstd_v01.h"
320c16b537SWarner Losh #endif
330c16b537SWarner Losh #if (ZSTD_LEGACY_SUPPORT <= 2)
340c16b537SWarner Losh # include "zstd_v02.h"
350c16b537SWarner Losh #endif
360c16b537SWarner Losh #if (ZSTD_LEGACY_SUPPORT <= 3)
370c16b537SWarner Losh # include "zstd_v03.h"
380c16b537SWarner Losh #endif
390c16b537SWarner Losh #if (ZSTD_LEGACY_SUPPORT <= 4)
400c16b537SWarner Losh # include "zstd_v04.h"
410c16b537SWarner Losh #endif
420c16b537SWarner Losh #if (ZSTD_LEGACY_SUPPORT <= 5)
430c16b537SWarner Losh # include "zstd_v05.h"
440c16b537SWarner Losh #endif
450c16b537SWarner Losh #if (ZSTD_LEGACY_SUPPORT <= 6)
460c16b537SWarner Losh # include "zstd_v06.h"
470c16b537SWarner Losh #endif
480c16b537SWarner Losh #if (ZSTD_LEGACY_SUPPORT <= 7)
490c16b537SWarner Losh # include "zstd_v07.h"
500c16b537SWarner Losh #endif
510c16b537SWarner Losh
520c16b537SWarner Losh /** ZSTD_isLegacy() :
530c16b537SWarner Losh @return : > 0 if supported by legacy decoder. 0 otherwise.
540c16b537SWarner Losh return value is the version.
550c16b537SWarner Losh */
ZSTD_isLegacy(const void * src,size_t srcSize)560c16b537SWarner Losh MEM_STATIC unsigned ZSTD_isLegacy(const void* src, size_t srcSize)
570c16b537SWarner Losh {
580c16b537SWarner Losh U32 magicNumberLE;
590c16b537SWarner Losh if (srcSize<4) return 0;
600c16b537SWarner Losh magicNumberLE = MEM_readLE32(src);
610c16b537SWarner Losh switch(magicNumberLE)
620c16b537SWarner Losh {
630c16b537SWarner Losh #if (ZSTD_LEGACY_SUPPORT <= 1)
640c16b537SWarner Losh case ZSTDv01_magicNumberLE:return 1;
650c16b537SWarner Losh #endif
660c16b537SWarner Losh #if (ZSTD_LEGACY_SUPPORT <= 2)
670c16b537SWarner Losh case ZSTDv02_magicNumber : return 2;
680c16b537SWarner Losh #endif
690c16b537SWarner Losh #if (ZSTD_LEGACY_SUPPORT <= 3)
700c16b537SWarner Losh case ZSTDv03_magicNumber : return 3;
710c16b537SWarner Losh #endif
720c16b537SWarner Losh #if (ZSTD_LEGACY_SUPPORT <= 4)
730c16b537SWarner Losh case ZSTDv04_magicNumber : return 4;
740c16b537SWarner Losh #endif
750c16b537SWarner Losh #if (ZSTD_LEGACY_SUPPORT <= 5)
760c16b537SWarner Losh case ZSTDv05_MAGICNUMBER : return 5;
770c16b537SWarner Losh #endif
780c16b537SWarner Losh #if (ZSTD_LEGACY_SUPPORT <= 6)
790c16b537SWarner Losh case ZSTDv06_MAGICNUMBER : return 6;
800c16b537SWarner Losh #endif
810c16b537SWarner Losh #if (ZSTD_LEGACY_SUPPORT <= 7)
820c16b537SWarner Losh case ZSTDv07_MAGICNUMBER : return 7;
830c16b537SWarner Losh #endif
840c16b537SWarner Losh default : return 0;
850c16b537SWarner Losh }
860c16b537SWarner Losh }
870c16b537SWarner Losh
880c16b537SWarner Losh
ZSTD_getDecompressedSize_legacy(const void * src,size_t srcSize)890c16b537SWarner Losh MEM_STATIC unsigned long long ZSTD_getDecompressedSize_legacy(const void* src, size_t srcSize)
900c16b537SWarner Losh {
910c16b537SWarner Losh U32 const version = ZSTD_isLegacy(src, srcSize);
920c16b537SWarner Losh if (version < 5) return 0; /* no decompressed size in frame header, or not a legacy format */
930c16b537SWarner Losh #if (ZSTD_LEGACY_SUPPORT <= 5)
940c16b537SWarner Losh if (version==5) {
950c16b537SWarner Losh ZSTDv05_parameters fParams;
960c16b537SWarner Losh size_t const frResult = ZSTDv05_getFrameParams(&fParams, src, srcSize);
970c16b537SWarner Losh if (frResult != 0) return 0;
980c16b537SWarner Losh return fParams.srcSize;
990c16b537SWarner Losh }
1000c16b537SWarner Losh #endif
1010c16b537SWarner Losh #if (ZSTD_LEGACY_SUPPORT <= 6)
1020c16b537SWarner Losh if (version==6) {
1030c16b537SWarner Losh ZSTDv06_frameParams fParams;
1040c16b537SWarner Losh size_t const frResult = ZSTDv06_getFrameParams(&fParams, src, srcSize);
1050c16b537SWarner Losh if (frResult != 0) return 0;
1060c16b537SWarner Losh return fParams.frameContentSize;
1070c16b537SWarner Losh }
1080c16b537SWarner Losh #endif
1090c16b537SWarner Losh #if (ZSTD_LEGACY_SUPPORT <= 7)
1100c16b537SWarner Losh if (version==7) {
1110c16b537SWarner Losh ZSTDv07_frameParams fParams;
1120c16b537SWarner Losh size_t const frResult = ZSTDv07_getFrameParams(&fParams, src, srcSize);
1130c16b537SWarner Losh if (frResult != 0) return 0;
1140c16b537SWarner Losh return fParams.frameContentSize;
1150c16b537SWarner Losh }
1160c16b537SWarner Losh #endif
1170c16b537SWarner Losh return 0; /* should not be possible */
1180c16b537SWarner Losh }
1190c16b537SWarner Losh
1200c16b537SWarner Losh
ZSTD_decompressLegacy(void * dst,size_t dstCapacity,const void * src,size_t compressedSize,const void * dict,size_t dictSize)1210c16b537SWarner Losh MEM_STATIC size_t ZSTD_decompressLegacy(
1220c16b537SWarner Losh void* dst, size_t dstCapacity,
1230c16b537SWarner Losh const void* src, size_t compressedSize,
1240c16b537SWarner Losh const void* dict,size_t dictSize)
1250c16b537SWarner Losh {
1260c16b537SWarner Losh U32 const version = ZSTD_isLegacy(src, compressedSize);
1270c16b537SWarner Losh (void)dst; (void)dstCapacity; (void)dict; (void)dictSize; /* unused when ZSTD_LEGACY_SUPPORT >= 8 */
1280c16b537SWarner Losh switch(version)
1290c16b537SWarner Losh {
1300c16b537SWarner Losh #if (ZSTD_LEGACY_SUPPORT <= 1)
1310c16b537SWarner Losh case 1 :
1320c16b537SWarner Losh return ZSTDv01_decompress(dst, dstCapacity, src, compressedSize);
1330c16b537SWarner Losh #endif
1340c16b537SWarner Losh #if (ZSTD_LEGACY_SUPPORT <= 2)
1350c16b537SWarner Losh case 2 :
1360c16b537SWarner Losh return ZSTDv02_decompress(dst, dstCapacity, src, compressedSize);
1370c16b537SWarner Losh #endif
1380c16b537SWarner Losh #if (ZSTD_LEGACY_SUPPORT <= 3)
1390c16b537SWarner Losh case 3 :
1400c16b537SWarner Losh return ZSTDv03_decompress(dst, dstCapacity, src, compressedSize);
1410c16b537SWarner Losh #endif
1420c16b537SWarner Losh #if (ZSTD_LEGACY_SUPPORT <= 4)
1430c16b537SWarner Losh case 4 :
1440c16b537SWarner Losh return ZSTDv04_decompress(dst, dstCapacity, src, compressedSize);
1450c16b537SWarner Losh #endif
1460c16b537SWarner Losh #if (ZSTD_LEGACY_SUPPORT <= 5)
1470c16b537SWarner Losh case 5 :
1480c16b537SWarner Losh { size_t result;
1490c16b537SWarner Losh ZSTDv05_DCtx* const zd = ZSTDv05_createDCtx();
1500c16b537SWarner Losh if (zd==NULL) return ERROR(memory_allocation);
1510c16b537SWarner Losh result = ZSTDv05_decompress_usingDict(zd, dst, dstCapacity, src, compressedSize, dict, dictSize);
1520c16b537SWarner Losh ZSTDv05_freeDCtx(zd);
1530c16b537SWarner Losh return result;
1540c16b537SWarner Losh }
1550c16b537SWarner Losh #endif
1560c16b537SWarner Losh #if (ZSTD_LEGACY_SUPPORT <= 6)
1570c16b537SWarner Losh case 6 :
1580c16b537SWarner Losh { size_t result;
1590c16b537SWarner Losh ZSTDv06_DCtx* const zd = ZSTDv06_createDCtx();
1600c16b537SWarner Losh if (zd==NULL) return ERROR(memory_allocation);
1610c16b537SWarner Losh result = ZSTDv06_decompress_usingDict(zd, dst, dstCapacity, src, compressedSize, dict, dictSize);
1620c16b537SWarner Losh ZSTDv06_freeDCtx(zd);
1630c16b537SWarner Losh return result;
1640c16b537SWarner Losh }
1650c16b537SWarner Losh #endif
1660c16b537SWarner Losh #if (ZSTD_LEGACY_SUPPORT <= 7)
1670c16b537SWarner Losh case 7 :
1680c16b537SWarner Losh { size_t result;
1690c16b537SWarner Losh ZSTDv07_DCtx* const zd = ZSTDv07_createDCtx();
1700c16b537SWarner Losh if (zd==NULL) return ERROR(memory_allocation);
1710c16b537SWarner Losh result = ZSTDv07_decompress_usingDict(zd, dst, dstCapacity, src, compressedSize, dict, dictSize);
1720c16b537SWarner Losh ZSTDv07_freeDCtx(zd);
1730c16b537SWarner Losh return result;
1740c16b537SWarner Losh }
1750c16b537SWarner Losh #endif
1760c16b537SWarner Losh default :
1770c16b537SWarner Losh return ERROR(prefix_unknown);
1780c16b537SWarner Losh }
1790c16b537SWarner Losh }
1800c16b537SWarner Losh
ZSTD_findFrameSizeInfoLegacy(const void * src,size_t srcSize)1812b9c00cbSConrad Meyer MEM_STATIC ZSTD_frameSizeInfo ZSTD_findFrameSizeInfoLegacy(const void *src, size_t srcSize)
1820c16b537SWarner Losh {
1832b9c00cbSConrad Meyer ZSTD_frameSizeInfo frameSizeInfo;
1842b9c00cbSConrad Meyer U32 const version = ZSTD_isLegacy(src, srcSize);
1850c16b537SWarner Losh switch(version)
1860c16b537SWarner Losh {
1870c16b537SWarner Losh #if (ZSTD_LEGACY_SUPPORT <= 1)
1880c16b537SWarner Losh case 1 :
1892b9c00cbSConrad Meyer ZSTDv01_findFrameSizeInfoLegacy(src, srcSize,
1902b9c00cbSConrad Meyer &frameSizeInfo.compressedSize,
1912b9c00cbSConrad Meyer &frameSizeInfo.decompressedBound);
1922b9c00cbSConrad Meyer break;
1930c16b537SWarner Losh #endif
1940c16b537SWarner Losh #if (ZSTD_LEGACY_SUPPORT <= 2)
1950c16b537SWarner Losh case 2 :
1962b9c00cbSConrad Meyer ZSTDv02_findFrameSizeInfoLegacy(src, srcSize,
1972b9c00cbSConrad Meyer &frameSizeInfo.compressedSize,
1982b9c00cbSConrad Meyer &frameSizeInfo.decompressedBound);
1992b9c00cbSConrad Meyer break;
2000c16b537SWarner Losh #endif
2010c16b537SWarner Losh #if (ZSTD_LEGACY_SUPPORT <= 3)
2020c16b537SWarner Losh case 3 :
2032b9c00cbSConrad Meyer ZSTDv03_findFrameSizeInfoLegacy(src, srcSize,
2042b9c00cbSConrad Meyer &frameSizeInfo.compressedSize,
2052b9c00cbSConrad Meyer &frameSizeInfo.decompressedBound);
2062b9c00cbSConrad Meyer break;
2070c16b537SWarner Losh #endif
2080c16b537SWarner Losh #if (ZSTD_LEGACY_SUPPORT <= 4)
2090c16b537SWarner Losh case 4 :
2102b9c00cbSConrad Meyer ZSTDv04_findFrameSizeInfoLegacy(src, srcSize,
2112b9c00cbSConrad Meyer &frameSizeInfo.compressedSize,
2122b9c00cbSConrad Meyer &frameSizeInfo.decompressedBound);
2132b9c00cbSConrad Meyer break;
2140c16b537SWarner Losh #endif
2150c16b537SWarner Losh #if (ZSTD_LEGACY_SUPPORT <= 5)
2160c16b537SWarner Losh case 5 :
2172b9c00cbSConrad Meyer ZSTDv05_findFrameSizeInfoLegacy(src, srcSize,
2182b9c00cbSConrad Meyer &frameSizeInfo.compressedSize,
2192b9c00cbSConrad Meyer &frameSizeInfo.decompressedBound);
2202b9c00cbSConrad Meyer break;
2210c16b537SWarner Losh #endif
2220c16b537SWarner Losh #if (ZSTD_LEGACY_SUPPORT <= 6)
2230c16b537SWarner Losh case 6 :
2242b9c00cbSConrad Meyer ZSTDv06_findFrameSizeInfoLegacy(src, srcSize,
2252b9c00cbSConrad Meyer &frameSizeInfo.compressedSize,
2262b9c00cbSConrad Meyer &frameSizeInfo.decompressedBound);
2272b9c00cbSConrad Meyer break;
2280c16b537SWarner Losh #endif
2290c16b537SWarner Losh #if (ZSTD_LEGACY_SUPPORT <= 7)
2300c16b537SWarner Losh case 7 :
2312b9c00cbSConrad Meyer ZSTDv07_findFrameSizeInfoLegacy(src, srcSize,
2322b9c00cbSConrad Meyer &frameSizeInfo.compressedSize,
2332b9c00cbSConrad Meyer &frameSizeInfo.decompressedBound);
2342b9c00cbSConrad Meyer break;
2350c16b537SWarner Losh #endif
2360c16b537SWarner Losh default :
2372b9c00cbSConrad Meyer frameSizeInfo.compressedSize = ERROR(prefix_unknown);
2382b9c00cbSConrad Meyer frameSizeInfo.decompressedBound = ZSTD_CONTENTSIZE_ERROR;
2392b9c00cbSConrad Meyer break;
2400c16b537SWarner Losh }
2414d3f1eafSConrad Meyer if (!ZSTD_isError(frameSizeInfo.compressedSize) && frameSizeInfo.compressedSize > srcSize) {
2424d3f1eafSConrad Meyer frameSizeInfo.compressedSize = ERROR(srcSize_wrong);
2434d3f1eafSConrad Meyer frameSizeInfo.decompressedBound = ZSTD_CONTENTSIZE_ERROR;
2444d3f1eafSConrad Meyer }
2452b9c00cbSConrad Meyer return frameSizeInfo;
2462b9c00cbSConrad Meyer }
2472b9c00cbSConrad Meyer
ZSTD_findFrameCompressedSizeLegacy(const void * src,size_t srcSize)2482b9c00cbSConrad Meyer MEM_STATIC size_t ZSTD_findFrameCompressedSizeLegacy(const void *src, size_t srcSize)
2492b9c00cbSConrad Meyer {
2502b9c00cbSConrad Meyer ZSTD_frameSizeInfo frameSizeInfo = ZSTD_findFrameSizeInfoLegacy(src, srcSize);
2512b9c00cbSConrad Meyer return frameSizeInfo.compressedSize;
2520c16b537SWarner Losh }
2530c16b537SWarner Losh
ZSTD_freeLegacyStreamContext(void * legacyContext,U32 version)2540c16b537SWarner Losh MEM_STATIC size_t ZSTD_freeLegacyStreamContext(void* legacyContext, U32 version)
2550c16b537SWarner Losh {
2560c16b537SWarner Losh switch(version)
2570c16b537SWarner Losh {
2580c16b537SWarner Losh default :
2590c16b537SWarner Losh case 1 :
2600c16b537SWarner Losh case 2 :
2610c16b537SWarner Losh case 3 :
2620c16b537SWarner Losh (void)legacyContext;
2630c16b537SWarner Losh return ERROR(version_unsupported);
2640c16b537SWarner Losh #if (ZSTD_LEGACY_SUPPORT <= 4)
2650c16b537SWarner Losh case 4 : return ZBUFFv04_freeDCtx((ZBUFFv04_DCtx*)legacyContext);
2660c16b537SWarner Losh #endif
2670c16b537SWarner Losh #if (ZSTD_LEGACY_SUPPORT <= 5)
2680c16b537SWarner Losh case 5 : return ZBUFFv05_freeDCtx((ZBUFFv05_DCtx*)legacyContext);
2690c16b537SWarner Losh #endif
2700c16b537SWarner Losh #if (ZSTD_LEGACY_SUPPORT <= 6)
2710c16b537SWarner Losh case 6 : return ZBUFFv06_freeDCtx((ZBUFFv06_DCtx*)legacyContext);
2720c16b537SWarner Losh #endif
2730c16b537SWarner Losh #if (ZSTD_LEGACY_SUPPORT <= 7)
2740c16b537SWarner Losh case 7 : return ZBUFFv07_freeDCtx((ZBUFFv07_DCtx*)legacyContext);
2750c16b537SWarner Losh #endif
2760c16b537SWarner Losh }
2770c16b537SWarner Losh }
2780c16b537SWarner Losh
2790c16b537SWarner Losh
ZSTD_initLegacyStream(void ** legacyContext,U32 prevVersion,U32 newVersion,const void * dict,size_t dictSize)2800c16b537SWarner Losh MEM_STATIC size_t ZSTD_initLegacyStream(void** legacyContext, U32 prevVersion, U32 newVersion,
2810c16b537SWarner Losh const void* dict, size_t dictSize)
2820c16b537SWarner Losh {
28319fcbaf1SConrad Meyer DEBUGLOG(5, "ZSTD_initLegacyStream for v0.%u", newVersion);
2840c16b537SWarner Losh if (prevVersion != newVersion) ZSTD_freeLegacyStreamContext(*legacyContext, prevVersion);
2850c16b537SWarner Losh switch(newVersion)
2860c16b537SWarner Losh {
2870c16b537SWarner Losh default :
2880c16b537SWarner Losh case 1 :
2890c16b537SWarner Losh case 2 :
2900c16b537SWarner Losh case 3 :
2910c16b537SWarner Losh (void)dict; (void)dictSize;
2920c16b537SWarner Losh return 0;
2930c16b537SWarner Losh #if (ZSTD_LEGACY_SUPPORT <= 4)
2940c16b537SWarner Losh case 4 :
2950c16b537SWarner Losh {
2960c16b537SWarner Losh ZBUFFv04_DCtx* dctx = (prevVersion != newVersion) ? ZBUFFv04_createDCtx() : (ZBUFFv04_DCtx*)*legacyContext;
2970c16b537SWarner Losh if (dctx==NULL) return ERROR(memory_allocation);
2980c16b537SWarner Losh ZBUFFv04_decompressInit(dctx);
2990c16b537SWarner Losh ZBUFFv04_decompressWithDictionary(dctx, dict, dictSize);
3000c16b537SWarner Losh *legacyContext = dctx;
3010c16b537SWarner Losh return 0;
3020c16b537SWarner Losh }
3030c16b537SWarner Losh #endif
3040c16b537SWarner Losh #if (ZSTD_LEGACY_SUPPORT <= 5)
3050c16b537SWarner Losh case 5 :
3060c16b537SWarner Losh {
3070c16b537SWarner Losh ZBUFFv05_DCtx* dctx = (prevVersion != newVersion) ? ZBUFFv05_createDCtx() : (ZBUFFv05_DCtx*)*legacyContext;
3080c16b537SWarner Losh if (dctx==NULL) return ERROR(memory_allocation);
3090c16b537SWarner Losh ZBUFFv05_decompressInitDictionary(dctx, dict, dictSize);
3100c16b537SWarner Losh *legacyContext = dctx;
3110c16b537SWarner Losh return 0;
3120c16b537SWarner Losh }
3130c16b537SWarner Losh #endif
3140c16b537SWarner Losh #if (ZSTD_LEGACY_SUPPORT <= 6)
3150c16b537SWarner Losh case 6 :
3160c16b537SWarner Losh {
3170c16b537SWarner Losh ZBUFFv06_DCtx* dctx = (prevVersion != newVersion) ? ZBUFFv06_createDCtx() : (ZBUFFv06_DCtx*)*legacyContext;
3180c16b537SWarner Losh if (dctx==NULL) return ERROR(memory_allocation);
3190c16b537SWarner Losh ZBUFFv06_decompressInitDictionary(dctx, dict, dictSize);
3200c16b537SWarner Losh *legacyContext = dctx;
3210c16b537SWarner Losh return 0;
3220c16b537SWarner Losh }
3230c16b537SWarner Losh #endif
3240c16b537SWarner Losh #if (ZSTD_LEGACY_SUPPORT <= 7)
3250c16b537SWarner Losh case 7 :
3260c16b537SWarner Losh {
3270c16b537SWarner Losh ZBUFFv07_DCtx* dctx = (prevVersion != newVersion) ? ZBUFFv07_createDCtx() : (ZBUFFv07_DCtx*)*legacyContext;
3280c16b537SWarner Losh if (dctx==NULL) return ERROR(memory_allocation);
3290c16b537SWarner Losh ZBUFFv07_decompressInitDictionary(dctx, dict, dictSize);
3300c16b537SWarner Losh *legacyContext = dctx;
3310c16b537SWarner Losh return 0;
3320c16b537SWarner Losh }
3330c16b537SWarner Losh #endif
3340c16b537SWarner Losh }
3350c16b537SWarner Losh }
3360c16b537SWarner Losh
3370c16b537SWarner Losh
3380c16b537SWarner Losh
ZSTD_decompressLegacyStream(void * legacyContext,U32 version,ZSTD_outBuffer * output,ZSTD_inBuffer * input)3390c16b537SWarner Losh MEM_STATIC size_t ZSTD_decompressLegacyStream(void* legacyContext, U32 version,
3400c16b537SWarner Losh ZSTD_outBuffer* output, ZSTD_inBuffer* input)
3410c16b537SWarner Losh {
34219fcbaf1SConrad Meyer DEBUGLOG(5, "ZSTD_decompressLegacyStream for v0.%u", version);
3430c16b537SWarner Losh switch(version)
3440c16b537SWarner Losh {
3450c16b537SWarner Losh default :
3460c16b537SWarner Losh case 1 :
3470c16b537SWarner Losh case 2 :
3480c16b537SWarner Losh case 3 :
3490c16b537SWarner Losh (void)legacyContext; (void)output; (void)input;
3500c16b537SWarner Losh return ERROR(version_unsupported);
3510c16b537SWarner Losh #if (ZSTD_LEGACY_SUPPORT <= 4)
3520c16b537SWarner Losh case 4 :
3530c16b537SWarner Losh {
3540c16b537SWarner Losh ZBUFFv04_DCtx* dctx = (ZBUFFv04_DCtx*) legacyContext;
3550c16b537SWarner Losh const void* src = (const char*)input->src + input->pos;
3560c16b537SWarner Losh size_t readSize = input->size - input->pos;
3570c16b537SWarner Losh void* dst = (char*)output->dst + output->pos;
3580c16b537SWarner Losh size_t decodedSize = output->size - output->pos;
3590c16b537SWarner Losh size_t const hintSize = ZBUFFv04_decompressContinue(dctx, dst, &decodedSize, src, &readSize);
3600c16b537SWarner Losh output->pos += decodedSize;
3610c16b537SWarner Losh input->pos += readSize;
3620c16b537SWarner Losh return hintSize;
3630c16b537SWarner Losh }
3640c16b537SWarner Losh #endif
3650c16b537SWarner Losh #if (ZSTD_LEGACY_SUPPORT <= 5)
3660c16b537SWarner Losh case 5 :
3670c16b537SWarner Losh {
3680c16b537SWarner Losh ZBUFFv05_DCtx* dctx = (ZBUFFv05_DCtx*) legacyContext;
3690c16b537SWarner Losh const void* src = (const char*)input->src + input->pos;
3700c16b537SWarner Losh size_t readSize = input->size - input->pos;
3710c16b537SWarner Losh void* dst = (char*)output->dst + output->pos;
3720c16b537SWarner Losh size_t decodedSize = output->size - output->pos;
3730c16b537SWarner Losh size_t const hintSize = ZBUFFv05_decompressContinue(dctx, dst, &decodedSize, src, &readSize);
3740c16b537SWarner Losh output->pos += decodedSize;
3750c16b537SWarner Losh input->pos += readSize;
3760c16b537SWarner Losh return hintSize;
3770c16b537SWarner Losh }
3780c16b537SWarner Losh #endif
3790c16b537SWarner Losh #if (ZSTD_LEGACY_SUPPORT <= 6)
3800c16b537SWarner Losh case 6 :
3810c16b537SWarner Losh {
3820c16b537SWarner Losh ZBUFFv06_DCtx* dctx = (ZBUFFv06_DCtx*) legacyContext;
3830c16b537SWarner Losh const void* src = (const char*)input->src + input->pos;
3840c16b537SWarner Losh size_t readSize = input->size - input->pos;
3850c16b537SWarner Losh void* dst = (char*)output->dst + output->pos;
3860c16b537SWarner Losh size_t decodedSize = output->size - output->pos;
3870c16b537SWarner Losh size_t const hintSize = ZBUFFv06_decompressContinue(dctx, dst, &decodedSize, src, &readSize);
3880c16b537SWarner Losh output->pos += decodedSize;
3890c16b537SWarner Losh input->pos += readSize;
3900c16b537SWarner Losh return hintSize;
3910c16b537SWarner Losh }
3920c16b537SWarner Losh #endif
3930c16b537SWarner Losh #if (ZSTD_LEGACY_SUPPORT <= 7)
3940c16b537SWarner Losh case 7 :
3950c16b537SWarner Losh {
3960c16b537SWarner Losh ZBUFFv07_DCtx* dctx = (ZBUFFv07_DCtx*) legacyContext;
3970c16b537SWarner Losh const void* src = (const char*)input->src + input->pos;
3980c16b537SWarner Losh size_t readSize = input->size - input->pos;
3990c16b537SWarner Losh void* dst = (char*)output->dst + output->pos;
4000c16b537SWarner Losh size_t decodedSize = output->size - output->pos;
4010c16b537SWarner Losh size_t const hintSize = ZBUFFv07_decompressContinue(dctx, dst, &decodedSize, src, &readSize);
4020c16b537SWarner Losh output->pos += decodedSize;
4030c16b537SWarner Losh input->pos += readSize;
4040c16b537SWarner Losh return hintSize;
4050c16b537SWarner Losh }
4060c16b537SWarner Losh #endif
4070c16b537SWarner Losh }
4080c16b537SWarner Losh }
4090c16b537SWarner Losh
4100c16b537SWarner Losh
4110c16b537SWarner Losh #if defined (__cplusplus)
4120c16b537SWarner Losh }
4130c16b537SWarner Losh #endif
4140c16b537SWarner Losh
4150c16b537SWarner Losh #endif /* ZSTD_LEGACY_H */
416