From 8d37662e481e95527f9ecf97abbb160f0a674cad Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Fri, 13 Nov 2020 21:47:17 -0800 Subject: LZ4IO_passThrough() doesn't need prefs --- programs/lz4io.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/programs/lz4io.c b/programs/lz4io.c index 3753271..9395037 100644 --- a/programs/lz4io.c +++ b/programs/lz4io.c @@ -1102,25 +1102,30 @@ LZ4IO_decompressLZ4F(dRess_t ress, } +/* LZ4IO_passThrough: + * just output the same content as input, no decoding. + * This is a capability of zcat, and by extension lz4cat + * MNstore : contain the first MAGICNUMBER_SIZE bytes already read from finput + */ #define PTSIZE (64 KB) #define PTSIZET (PTSIZE / sizeof(size_t)) static unsigned long long -LZ4IO_passThrough(LZ4IO_prefs_t* const prefs, - FILE* finput, FILE* foutput, - unsigned char MNstore[MAGICNUMBER_SIZE]) +LZ4IO_passThrough(FILE* finput, FILE* foutput, + unsigned char MNstore[MAGICNUMBER_SIZE], + int sparseFileSupport) { size_t buffer[PTSIZET]; size_t readBytes = 1; unsigned long long total = MAGICNUMBER_SIZE; unsigned storedSkips = 0; - size_t const sizeCheck = fwrite(MNstore, 1, MAGICNUMBER_SIZE, foutput); - if (sizeCheck != MAGICNUMBER_SIZE) EXM_THROW(50, "Pass-through write error"); - + if (fwrite(MNstore, 1, MAGICNUMBER_SIZE, foutput) != MAGICNUMBER_SIZE) { + EXM_THROW(50, "Pass-through write error"); + } while (readBytes) { - readBytes = fread(buffer, 1, PTSIZE, finput); + readBytes = fread(buffer, 1, sizeof(buffer), finput); total += readBytes; - storedSkips = LZ4IO_fwriteSparse(foutput, buffer, readBytes, prefs->sparseFileSupport, storedSkips); + storedSkips = LZ4IO_fwriteSparse(foutput, buffer, readBytes, sparseFileSupport, storedSkips); } if (ferror(finput)) EXM_THROW(51, "Read Error"); @@ -1198,7 +1203,7 @@ selectDecoder(LZ4IO_prefs_t* const prefs, /* Wrong magic number at the beginning of 1st stream */ if (!prefs->testMode && prefs->overwrite && prefs->passThrough) { nbFrames = 0; - return LZ4IO_passThrough(prefs, finput, foutput, MNstore); + return LZ4IO_passThrough(finput, foutput, MNstore, prefs->sparseFileSupport); } EXM_THROW(44,"Unrecognized header : file cannot be decoded"); } -- cgit v0.12