summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYann Collet <Cyan4973@users.noreply.github.com>2019-01-09 17:21:54 (GMT)
committerGitHub <noreply@github.com>2019-01-09 17:21:54 (GMT)
commitd6eac9c5cf376570595e07115304fbbbdeb32a06 (patch)
tree2e89bc99b0a8faeabff1c803dc740e5ccd48a836
parentec735ac53e6b216efcbcd411d496dc90b058c570 (diff)
parent4c953b46ef0526b4342a9a0890508e0c84208e8d (diff)
downloadlz4-d6eac9c5cf376570595e07115304fbbbdeb32a06.zip
lz4-d6eac9c5cf376570595e07115304fbbbdeb32a06.tar.gz
lz4-d6eac9c5cf376570595e07115304fbbbdeb32a06.tar.bz2
Merge pull request #632 from rubenochiavone/fix-lz4-extesion-not-decompressing
Fix lz4 extension in input filename not causing decompression
-rw-r--r--programs/lz4cli.c24
-rw-r--r--tests/Makefile5
2 files changed, 24 insertions, 5 deletions
diff --git a/programs/lz4cli.c b/programs/lz4cli.c
index 3709f50..84499d0 100644
--- a/programs/lz4cli.c
+++ b/programs/lz4cli.c
@@ -287,6 +287,19 @@ static unsigned longCommandWArg(const char** stringPtr, const char* longCommand)
typedef enum { om_auto, om_compress, om_decompress, om_test, om_bench } operationMode_e;
+/** determineOpMode() :
+ * auto-determine operation mode, based on input filename extension
+ * @return `om_decompress` if input filename has .lz4 extension and `om_compress` otherwise.
+ */
+static operationMode_e determineOpMode(const char* inputFilename)
+{
+ size_t const inSize = strlen(inputFilename);
+ size_t const extSize = strlen(LZ4_EXTENSION);
+ size_t const extStart= (inSize > extSize) ? inSize-extSize : 0;
+ if (!strcmp(inputFilename+extStart, LZ4_EXTENSION)) return om_decompress;
+ else return om_compress;
+}
+
int main(int argc, const char** argv)
{
int i,
@@ -633,11 +646,7 @@ int main(int argc, const char** argv)
while ((!output_filename) && (multiple_inputs==0)) {
if (!IS_CONSOLE(stdout)) { output_filename=stdoutmark; break; } /* Default to stdout whenever possible (i.e. not a console) */
if (mode == om_auto) { /* auto-determine compression or decompression, based on file extension */
- size_t const inSize = strlen(input_filename);
- size_t const extSize = strlen(LZ4_EXTENSION);
- size_t const extStart= (inSize > extSize) ? inSize-extSize : 0;
- if (!strcmp(input_filename+extStart, LZ4_EXTENSION)) mode = om_decompress;
- else mode = om_compress;
+ mode = determineOpMode(input_filename);
}
if (mode == om_compress) { /* compression to file */
size_t const l = strlen(input_filename);
@@ -675,6 +684,11 @@ int main(int argc, const char** argv)
if (!strcmp(output_filename,stdoutmark) && (displayLevel==2)) displayLevel=1;
if ((multiple_inputs) && (displayLevel==2)) displayLevel=1;
+ /* Auto-determine compression or decompression, based on file extension */
+ if (mode == om_auto) {
+ mode = determineOpMode(input_filename);
+ }
+
/* IO Stream/File */
LZ4IO_setNotificationLevel(displayLevel);
if (ifnIdx == 0) multiple_inputs = 0;
diff --git a/tests/Makefile b/tests/Makefile
index 8dcef6d..760fc32 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -284,6 +284,11 @@ test-lz4-basic: lz4 datagen unlz4 lz4cat
test "$(shell ./datagen -g20KB | $(LZ4) -c --fast=1 | wc -c)" -eq "$(shell ./datagen -g20KB| $(LZ4) -c --fast| wc -c)" # checks default fast compression is -1
! $(LZ4) -c --fast=0 tmp-tlb-dg20K # lz4 should fail when fast=0
! $(LZ4) -c --fast=-1 tmp-tlb-dg20K # lz4 should fail when fast=-1
+ # Test for #596
+ @echo "TEST" > tmp-tlb-test
+ $(LZ4) tmp-tlb-test
+ $(LZ4) tmp-tlb-test.lz4 tmp-tlb-test2
+ $(DIFF) -q tmp-tlb-test tmp-tlb-test2
@$(RM) tmp-tlb*