From 3dcafd35d409380182393fdb0d5666f6a64ff841 Mon Sep 17 00:00:00 2001 From: Nick Terrell Date: Thu, 3 Nov 2016 15:41:09 -0700 Subject: [PATCH] Fix test mode and write to null Fix test mode to not always return success. Don't ask for permission to overwrite `nulmark`. Before: > echo "hello world" > file > lz4 -t file successfully decoded 12 bytes > lz4 -tf file successfully decoded 12 bytes > lz4 file null Warning : /dev/null already exists Overwrite ? (Y/n) : n Error 12 : No. Operation aborted : /dev/null already exists > lz4 file /dev/null Warning : /dev/null already exists Overwrite ? (Y/n) : n Error 12 : No. Operation aborted : /dev/null already exists After: > lz4 -t file Error 44 : Unrecognized header : file cannot be decoded > lz4 -tf file Error 44 : Unrecognized header : file cannot be decoded > lz4 file null Compressed 12 bytes into 31 bytes ==> 258.33% > lz4 file /dev/null Compressed 12 bytes into 31 bytes ==> 258.33% --- programs/lz4cli.c | 2 +- programs/lz4io.c | 12 ++++++++++-- programs/lz4io.h | 4 ++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/programs/lz4cli.c b/programs/lz4cli.c index 7cf035ee..6ed98c00 100644 --- a/programs/lz4cli.c +++ b/programs/lz4cli.c @@ -393,7 +393,7 @@ int main(int argc, const char** argv) case 'c': forceStdout=1; output_filename=stdoutmark; displayLevel=1; break; /* Test integrity */ - case 't': decode=1; LZ4IO_setOverwrite(1); output_filename=nulmark; break; + case 't': decode=1; LZ4IO_setPassThrough(0); output_filename=nulmark; break; /* Overwrite */ case 'f': LZ4IO_setOverwrite(1); break; diff --git a/programs/lz4io.c b/programs/lz4io.c index f2d7b516..3a858302 100644 --- a/programs/lz4io.c +++ b/programs/lz4io.c @@ -136,6 +136,7 @@ static clock_t g_time = 0; * Local Parameters **************************************/ static int g_overwrite = 1; +static int g_passThrough = 1; static int g_blockSizeId = LZ4IO_BLOCKSIZEID_DEFAULT; static int g_blockChecksum = 0; static int g_streamChecksum = 1; @@ -184,6 +185,13 @@ int LZ4IO_setOverwrite(int yes) return g_overwrite; } +/* Default setting : passThrough = 1; return : passThrough mode (0/1) */ +int LZ4IO_setPassThrough(int yes) +{ + g_passThrough = (yes!=0); + return g_passThrough; +} + /* blockSizeID : valid values : 4-5-6-7 */ int LZ4IO_setBlockSizeID(int bsid) { @@ -283,7 +291,7 @@ static int LZ4IO_getFiles(const char* input_filename, const char* output_filenam } else { /* Check if destination file already exists */ *pfoutput=0; - if (output_filename != nulmark) *pfoutput = fopen( output_filename, "rb" ); + if (strcmp(output_filename, nulmark)) *pfoutput = fopen( output_filename, "rb" ); if (*pfoutput!=0) { fclose(*pfoutput); if (!g_overwrite) { @@ -908,7 +916,7 @@ static unsigned long long selectDecoder(dRess_t ress, FILE* finput, FILE* foutpu EXTENDED_FORMAT; /* macro extension for custom formats */ default: if (nbCalls == 1) { /* just started */ - if (g_overwrite) + if (g_passThrough && g_overwrite) return LZ4IO_passThrough(finput, foutput, MNstore); EXM_THROW(44,"Unrecognized header : file cannot be decoded"); /* Wrong magic number at the beginning of 1st stream */ } diff --git a/programs/lz4io.h b/programs/lz4io.h index 4f0e02a4..81092983 100644 --- a/programs/lz4io.h +++ b/programs/lz4io.h @@ -63,6 +63,10 @@ int LZ4IO_decompressMultipleFilenames(const char** inFileNamesTable, int ifntSiz return : overwrite mode (0/1) */ int LZ4IO_setOverwrite(int yes); +/* Default setting : passThrough = 1; + return : passThrough mode (0/1) */ +int LZ4IO_setPassThrough(int yes); + /* blockSizeID : valid values : 4-5-6-7 return : -1 if error, blockSize if OK */ int LZ4IO_setBlockSizeID(int blockSizeID);