summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYann Collet <cyan@fb.com>2020-11-14 12:40:17 -0800
committerYann Collet <cyan@fb.com>2020-11-14 12:40:17 -0800
commit36eadb205ae1fda0d92b9e4c0c1eb1ee79e7b943 (patch)
tree4e2218cb0a198e2b9c4297375590ec1e6e647327
parent7315c6e7a00494b2b8618379209732260686524f (diff)
downloadlz4-36eadb205ae1fda0d92b9e4c0c1eb1ee79e7b943.tar.gz
lz4-36eadb205ae1fda0d92b9e4c0c1eb1ee79e7b943.tar.bz2
lz4-36eadb205ae1fda0d92b9e4c0c1eb1ee79e7b943.zip
all usages of prefs within lz4io are const
-rw-r--r--programs/lz4cli.c21
-rw-r--r--programs/lz4io.c62
-rw-r--r--programs/lz4io.h10
3 files changed, 48 insertions, 45 deletions
diff --git a/programs/lz4cli.c b/programs/lz4cli.c
index d7d4f81..523b8a8 100644
--- a/programs/lz4cli.c
+++ b/programs/lz4cli.c
@@ -93,11 +93,11 @@ static unsigned displayLevel = 2; /* 0 : no display ; 1: errors only ; 2 : dow
***************************************/
#define DEFAULT_COMPRESSOR LZ4IO_compressFilename
#define DEFAULT_DECOMPRESSOR LZ4IO_decompressFilename
-int LZ4IO_compressFilename_Legacy(LZ4IO_prefs_t* const prefs, const char* input_filename, const char* output_filename, int compressionlevel); /* hidden function */
-int LZ4IO_compressMultipleFilenames_Legacy(LZ4IO_prefs_t* const prefs,
+int LZ4IO_compressFilename_Legacy(const char* input_filename, const char* output_filename, int compressionlevel, const LZ4IO_prefs_t* prefs); /* hidden function */
+int LZ4IO_compressMultipleFilenames_Legacy(
const char** inFileNamesTable, int ifntSize,
const char* suffix,
- int compressionLevel);
+ int compressionLevel, const LZ4IO_prefs_t* prefs);
/*-***************************
* Functions
@@ -747,10 +747,11 @@ int main(int argc, const char** argv)
if (ifnIdx == 0) multiple_inputs = 0;
if (mode == om_decompress) {
if (multiple_inputs) {
+ const char* const dec_extension = !strcmp(output_filename,stdoutmark) ? stdoutmark : LZ4_EXTENSION;
assert(ifnIdx <= INT_MAX);
- operationResult = LZ4IO_decompressMultipleFilenames(prefs, inFileNames, (int)ifnIdx, !strcmp(output_filename,stdoutmark) ? stdoutmark : LZ4_EXTENSION);
+ operationResult = LZ4IO_decompressMultipleFilenames(inFileNames, (int)ifnIdx, dec_extension, prefs);
} else {
- operationResult = DEFAULT_DECOMPRESSOR(prefs, input_filename, output_filename);
+ operationResult = DEFAULT_DECOMPRESSOR(input_filename, output_filename, prefs);
}
} else if (mode == om_list){
operationResult = LZ4IO_displayCompressedFilesInfo(inFileNames, ifnIdx);
@@ -758,16 +759,18 @@ int main(int argc, const char** argv)
if (legacy_format) {
DISPLAYLEVEL(3, "! Generating LZ4 Legacy format (deprecated) ! \n");
if(multiple_inputs){
- LZ4IO_compressMultipleFilenames_Legacy(prefs, inFileNames, (int)ifnIdx, !strcmp(output_filename,stdoutmark) ? stdoutmark : LZ4_EXTENSION, cLevel);
+ const char* const leg_extension = !strcmp(output_filename,stdoutmark) ? stdoutmark : LZ4_EXTENSION;
+ LZ4IO_compressMultipleFilenames_Legacy(inFileNames, (int)ifnIdx, leg_extension, cLevel, prefs);
} else {
- LZ4IO_compressFilename_Legacy(prefs, input_filename, output_filename, cLevel);
+ LZ4IO_compressFilename_Legacy(input_filename, output_filename, cLevel, prefs);
}
} else {
if (multiple_inputs) {
+ const char* const comp_extension = !strcmp(output_filename,stdoutmark) ? stdoutmark : LZ4_EXTENSION;
assert(ifnIdx <= INT_MAX);
- operationResult = LZ4IO_compressMultipleFilenames(prefs, inFileNames, (int)ifnIdx, !strcmp(output_filename,stdoutmark) ? stdoutmark : LZ4_EXTENSION, cLevel);
+ operationResult = LZ4IO_compressMultipleFilenames(inFileNames, (int)ifnIdx, comp_extension, cLevel, prefs);
} else {
- operationResult = DEFAULT_COMPRESSOR(prefs, input_filename, output_filename, cLevel);
+ operationResult = DEFAULT_COMPRESSOR(input_filename, output_filename, cLevel, prefs);
} } }
_cleanup:
diff --git a/programs/lz4io.c b/programs/lz4io.c
index 302d747..4c4678c 100644
--- a/programs/lz4io.c
+++ b/programs/lz4io.c
@@ -178,7 +178,7 @@ LZ4IO_prefs_t* LZ4IO_defaultPreferences(void)
return ret;
}
-void LZ4IO_freePreferences(LZ4IO_prefs_t* const prefs)
+void LZ4IO_freePreferences(LZ4IO_prefs_t* prefs)
{
free(prefs);
}
@@ -396,9 +396,8 @@ static int LZ4IO_LZ4_compress(const char* src, char* dst, int srcSize, int dstSi
/* LZ4IO_compressFilename_Legacy :
* This function is intentionally "hidden" (not published in .h)
* It generates compressed streams using the old 'legacy' format */
-int LZ4IO_compressFilename_Legacy(LZ4IO_prefs_t* const prefs,
- const char* input_filename, const char* output_filename,
- int compressionlevel)
+int LZ4IO_compressFilename_Legacy(const char* input_filename, const char* output_filename,
+ int compressionlevel, const LZ4IO_prefs_t* prefs)
{
typedef int (*compress_f)(const char* src, char* dst, int srcSize, int dstSize, int cLevel);
compress_f const compressionFunction = (compressionlevel < 3) ? LZ4IO_LZ4_compress : LZ4_compress_HC;
@@ -483,10 +482,10 @@ int LZ4IO_compressFilename_Legacy(LZ4IO_prefs_t* const prefs,
/* LZ4IO_compressMultipleFilenames_Legacy :
* This function is intentionally "hidden" (not published in .h)
* It generates multiple compressed streams using the old 'legacy' format */
-int LZ4IO_compressMultipleFilenames_Legacy(LZ4IO_prefs_t* const prefs,
+int LZ4IO_compressMultipleFilenames_Legacy(
const char** inFileNamesTable, int ifntSize,
const char* suffix,
- int compressionLevel)
+ int compressionLevel, const LZ4IO_prefs_t* prefs)
{
int i;
int missed_files = 0;
@@ -500,9 +499,9 @@ int LZ4IO_compressMultipleFilenames_Legacy(LZ4IO_prefs_t* const prefs,
for (i=0; i<ifntSize; i++) {
size_t const ifnSize = strlen(inFileNamesTable[i]);
if (!strcmp(suffix, stdoutmark)) {
- missed_files += LZ4IO_compressFilename_Legacy(prefs,
+ missed_files += LZ4IO_compressFilename_Legacy(
inFileNamesTable[i], stdoutmark,
- compressionLevel);
+ compressionLevel, prefs);
continue;
}
@@ -516,9 +515,9 @@ int LZ4IO_compressMultipleFilenames_Legacy(LZ4IO_prefs_t* const prefs,
strcpy(dstFileName, inFileNamesTable[i]);
strcat(dstFileName, suffix);
- missed_files += LZ4IO_compressFilename_Legacy(prefs,
+ missed_files += LZ4IO_compressFilename_Legacy(
inFileNamesTable[i], dstFileName,
- compressionLevel);
+ compressionLevel, prefs);
}
/* Close & Free */
@@ -610,7 +609,7 @@ static LZ4F_CDict* LZ4IO_createCDict(const LZ4IO_prefs_t* const prefs)
return cdict;
}
-static cRess_t LZ4IO_createCResources(LZ4IO_prefs_t* const prefs)
+static cRess_t LZ4IO_createCResources(const LZ4IO_prefs_t* const prefs)
{
const size_t blockSize = prefs->blockSize;
cRess_t ress;
@@ -644,14 +643,13 @@ static void LZ4IO_freeCResources(cRess_t ress)
/*
* LZ4IO_compressFilename_extRess()
- * io_prefs is mutable, as it may update sparseFileSupport
* result : 0 : compression completed correctly
* 1 : missing or pb opening srcFileName
*/
static int
-LZ4IO_compressFilename_extRess(LZ4IO_prefs_t* const io_prefs, cRess_t ress,
+LZ4IO_compressFilename_extRess(cRess_t ress,
const char* srcFileName, const char* dstFileName,
- int compressionLevel)
+ int compressionLevel, const LZ4IO_prefs_t* const io_prefs)
{
unsigned long long filesize = 0;
unsigned long long compressedfilesize = 0;
@@ -773,13 +771,13 @@ LZ4IO_compressFilename_extRess(LZ4IO_prefs_t* const io_prefs, cRess_t ress,
}
-int LZ4IO_compressFilename(LZ4IO_prefs_t* const prefs, const char* srcFileName, const char* dstFileName, int compressionLevel)
+int LZ4IO_compressFilename(const char* srcFileName, const char* dstFileName, int compressionLevel, const LZ4IO_prefs_t* prefs)
{
UTIL_time_t const timeStart = UTIL_getTime();
clock_t const cpuStart = clock();
cRess_t const ress = LZ4IO_createCResources(prefs);
- int const result = LZ4IO_compressFilename_extRess(prefs, ress, srcFileName, dstFileName, compressionLevel);
+ int const result = LZ4IO_compressFilename_extRess(ress, srcFileName, dstFileName, compressionLevel, prefs);
/* Free resources */
LZ4IO_freeCResources(ress);
@@ -797,10 +795,11 @@ int LZ4IO_compressFilename(LZ4IO_prefs_t* const prefs, const char* srcFileName,
}
-int LZ4IO_compressMultipleFilenames(LZ4IO_prefs_t* const prefs,
+int LZ4IO_compressMultipleFilenames(
const char** inFileNamesTable, int ifntSize,
const char* suffix,
- int compressionLevel)
+ int compressionLevel,
+ const LZ4IO_prefs_t* prefs)
{
int i;
int missed_files = 0;
@@ -816,9 +815,9 @@ int LZ4IO_compressMultipleFilenames(LZ4IO_prefs_t* const prefs,
for (i=0; i<ifntSize; i++) {
size_t const ifnSize = strlen(inFileNamesTable[i]);
if (!strcmp(suffix, stdoutmark)) {
- missed_files += LZ4IO_compressFilename_extRess(prefs, ress,
+ missed_files += LZ4IO_compressFilename_extRess(ress,
inFileNamesTable[i], stdoutmark,
- compressionLevel);
+ compressionLevel, prefs);
continue;
}
if (ofnSize <= ifnSize+suffixSize+1) {
@@ -832,9 +831,9 @@ int LZ4IO_compressMultipleFilenames(LZ4IO_prefs_t* const prefs,
strcpy(dstFileName, inFileNamesTable[i]);
strcat(dstFileName, suffix);
- missed_files += LZ4IO_compressFilename_extRess(prefs, ress,
+ missed_files += LZ4IO_compressFilename_extRess(ress,
inFileNamesTable[i], dstFileName,
- compressionLevel);
+ compressionLevel, prefs);
}
/* Close & Free */
@@ -1260,9 +1259,9 @@ LZ4IO_decompressSrcFile(dRess_t ress,
static int
-LZ4IO_decompressDstFile(LZ4IO_prefs_t* const prefs,
- dRess_t ress,
- const char* input_filename, const char* output_filename)
+LZ4IO_decompressDstFile(dRess_t ress,
+ const char* input_filename, const char* output_filename,
+ const LZ4IO_prefs_t* const prefs)
{
stat_t statbuf;
int stat_result = 0;
@@ -1290,12 +1289,12 @@ LZ4IO_decompressDstFile(LZ4IO_prefs_t* const prefs,
}
-int LZ4IO_decompressFilename(LZ4IO_prefs_t* const prefs, const char* input_filename, const char* output_filename)
+int LZ4IO_decompressFilename(const char* input_filename, const char* output_filename, const LZ4IO_prefs_t* prefs)
{
dRess_t const ress = LZ4IO_createDResources(prefs);
clock_t const start = clock();
- int const missingFiles = LZ4IO_decompressDstFile(prefs, ress, input_filename, output_filename);
+ int const missingFiles = LZ4IO_decompressDstFile(ress, input_filename, output_filename, prefs);
clock_t const end = clock();
double const seconds = (double)(end - start) / CLOCKS_PER_SEC;
@@ -1306,9 +1305,10 @@ int LZ4IO_decompressFilename(LZ4IO_prefs_t* const prefs, const char* input_filen
}
-int LZ4IO_decompressMultipleFilenames(LZ4IO_prefs_t* const prefs,
- const char** inFileNamesTable, int ifntSize,
- const char* suffix)
+int LZ4IO_decompressMultipleFilenames(
+ const char** inFileNamesTable, int ifntSize,
+ const char* suffix,
+ const LZ4IO_prefs_t* prefs)
{
int i;
int skippedFiles = 0;
@@ -1341,7 +1341,7 @@ int LZ4IO_decompressMultipleFilenames(LZ4IO_prefs_t* const prefs,
}
memcpy(outFileName, inFileNamesTable[i], ifnSize - suffixSize);
outFileName[ifnSize-suffixSize] = '\0';
- missingFiles += LZ4IO_decompressDstFile(prefs, ress, inFileNamesTable[i], outFileName);
+ missingFiles += LZ4IO_decompressDstFile(ress, inFileNamesTable[i], outFileName, prefs);
}
LZ4IO_freeDResources(ress);
diff --git a/programs/lz4io.h b/programs/lz4io.h
index 4763180..d6d7eee 100644
--- a/programs/lz4io.h
+++ b/programs/lz4io.h
@@ -55,7 +55,7 @@
typedef struct LZ4IO_prefs_s LZ4IO_prefs_t;
LZ4IO_prefs_t* LZ4IO_defaultPreferences(void);
-void LZ4IO_freePreferences(LZ4IO_prefs_t* const prefs);
+void LZ4IO_freePreferences(LZ4IO_prefs_t* prefs);
/* Size in bytes of a legacy block header in little-endian format */
#define LZIO_LEGACY_BLOCK_HEADER_SIZE 4
@@ -65,12 +65,12 @@ void LZ4IO_freePreferences(LZ4IO_prefs_t* const prefs);
/* ************************************************** */
/* if output_filename == stdoutmark, writes to stdout */
-int LZ4IO_compressFilename(LZ4IO_prefs_t* const prefs, const char* input_filename, const char* output_filename, int compressionlevel);
-int LZ4IO_decompressFilename(LZ4IO_prefs_t* const prefs, const char* input_filename, const char* output_filename);
+int LZ4IO_compressFilename(const char* input_filename, const char* output_filename, int compressionlevel, const LZ4IO_prefs_t* prefs);
+int LZ4IO_decompressFilename(const char* input_filename, const char* output_filename, const LZ4IO_prefs_t* prefs);
/* if suffix == stdoutmark, writes to stdout */
-int LZ4IO_compressMultipleFilenames(LZ4IO_prefs_t* const prefs, const char** inFileNamesTable, int ifntSize, const char* suffix, int compressionlevel);
-int LZ4IO_decompressMultipleFilenames(LZ4IO_prefs_t* const prefs, const char** inFileNamesTable, int ifntSize, const char* suffix);
+int LZ4IO_compressMultipleFilenames(const char** inFileNamesTable, int ifntSize, const char* suffix, int compressionlevel, const LZ4IO_prefs_t* prefs);
+int LZ4IO_decompressMultipleFilenames(const char** inFileNamesTable, int ifntSize, const char* suffix, const LZ4IO_prefs_t* prefs);
/* ************************************************** */