LZ4IO_fwriteSparse doesn't need writable prefs

This commit is contained in:
Yann Collet 2020-11-13 16:44:39 -08:00
parent 22729ecb8b
commit f81f3a254e

View File

@ -325,6 +325,7 @@ static FILE* LZ4IO_openSrcFile(const char* srcFileName)
} }
/** FIO_openDstFile() : /** FIO_openDstFile() :
* prefs is writable, because sparseFileSupport might be updated
* condition : `dstFileName` must be non-NULL. * condition : `dstFileName` must be non-NULL.
* @result : FILE* to `dstFileName`, or NULL if it fails */ * @result : FILE* to `dstFileName`, or NULL if it fails */
static FILE* LZ4IO_openDstFile(LZ4IO_prefs_t* const prefs, const char* dstFileName) static FILE* LZ4IO_openDstFile(LZ4IO_prefs_t* const prefs, const char* dstFileName)
@ -858,7 +859,11 @@ static unsigned LZ4IO_readLE32 (const void* s)
} }
static unsigned LZ4IO_fwriteSparse(LZ4IO_prefs_t* const prefs, FILE* file, const void* buffer, size_t bufferSize, unsigned storedSkips) static unsigned
LZ4IO_fwriteSparse(FILE* file,
const void* buffer, size_t bufferSize,
int sparseFileSupport,
unsigned storedSkips)
{ {
const size_t sizeT = sizeof(size_t); const size_t sizeT = sizeof(size_t);
const size_t maskT = sizeT -1 ; const size_t maskT = sizeT -1 ;
@ -868,7 +873,7 @@ static unsigned LZ4IO_fwriteSparse(LZ4IO_prefs_t* const prefs, FILE* file, const
const size_t* const bufferTEnd = bufferT + bufferSizeT; const size_t* const bufferTEnd = bufferT + bufferSizeT;
const size_t segmentSizeT = (32 KB) / sizeT; const size_t segmentSizeT = (32 KB) / sizeT;
if (!prefs->sparseFileSupport) { /* normal write */ if (!sparseFileSupport) { /* normal write */
size_t const sizeCheck = fwrite(buffer, 1, bufferSize, file); size_t const sizeCheck = fwrite(buffer, 1, bufferSize, file);
if (sizeCheck != bufferSize) EXM_THROW(70, "Write error : cannot write decoded block"); if (sizeCheck != bufferSize) EXM_THROW(70, "Write error : cannot write decoded block");
return 0; return 0;
@ -971,7 +976,7 @@ static unsigned long long LZ4IO_decodeLegacyStream(LZ4IO_prefs_t* const prefs, F
if (decodeSize < 0) EXM_THROW(53, "Decoding Failed ! Corrupted input detected !"); if (decodeSize < 0) EXM_THROW(53, "Decoding Failed ! Corrupted input detected !");
streamSize += (unsigned long long)decodeSize; streamSize += (unsigned long long)decodeSize;
/* Write Block */ /* Write Block */
storedSkips = LZ4IO_fwriteSparse(prefs, foutput, out_buff, (size_t)decodeSize, storedSkips); /* success or die */ storedSkips = LZ4IO_fwriteSparse(foutput, out_buff, (size_t)decodeSize, prefs->sparseFileSupport, storedSkips); /* success or die */
} } } }
if (ferror(finput)) EXM_THROW(54, "Read error : ferror"); if (ferror(finput)) EXM_THROW(54, "Read error : ferror");
@ -1076,7 +1081,7 @@ static unsigned long long LZ4IO_decompressLZ4F(LZ4IO_prefs_t* const prefs, dRess
/* Write Block */ /* Write Block */
if (decodedBytes) { if (decodedBytes) {
if (!prefs->testMode) if (!prefs->testMode)
storedSkips = LZ4IO_fwriteSparse(prefs, dstFile, ress.dstBuffer, decodedBytes, storedSkips); storedSkips = LZ4IO_fwriteSparse(dstFile, ress.dstBuffer, decodedBytes, prefs->sparseFileSupport, storedSkips);
filesize += decodedBytes; filesize += decodedBytes;
DISPLAYUPDATE(2, "\rDecompressed : %u MB ", (unsigned)(filesize>>20)); DISPLAYUPDATE(2, "\rDecompressed : %u MB ", (unsigned)(filesize>>20));
} }
@ -1112,7 +1117,7 @@ LZ4IO_passThrough(LZ4IO_prefs_t* const prefs,
while (readBytes) { while (readBytes) {
readBytes = fread(buffer, 1, PTSIZE, finput); readBytes = fread(buffer, 1, PTSIZE, finput);
total += readBytes; total += readBytes;
storedSkips = LZ4IO_fwriteSparse(prefs, foutput, buffer, readBytes, storedSkips); storedSkips = LZ4IO_fwriteSparse(foutput, buffer, readBytes, prefs->sparseFileSupport, storedSkips);
} }
if (ferror(finput)) EXM_THROW(51, "Read Error"); if (ferror(finput)) EXM_THROW(51, "Read Error");