From a4ca246ecae023469a6c93c0c274f2bc97d7103f Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Sat, 14 Sep 2019 20:15:35 +0300 Subject: [PATCH 1/8] build/cmake/README.md: improve --- build/cmake/README.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/build/cmake/README.md b/build/cmake/README.md index 854389ad8..73b30dc77 100644 --- a/build/cmake/README.md +++ b/build/cmake/README.md @@ -5,9 +5,9 @@ use case sensitivity that matches modern (ie. cmake version 2.6 and above) conventions of using lower-case for commands, and upper-case for variables. -# How to build +## How to build -As cmake doesn't support command like `cmake clean`, it's recommanded to perform a "out of source build". +As cmake doesn't support command like `cmake clean`, it's recommended to perform a "out of source build". To do this, you can create a new directory and build in it: ```sh cd build/cmake @@ -16,7 +16,7 @@ cd builddir cmake .. make ``` -Then you can clean all cmake caches by simpily delete the new directory: +Then you can clean all cmake caches by simply delete the new directory: ```sh rm -rf build/cmake/builddir ``` @@ -34,19 +34,19 @@ cd build/cmake/builddir cmake -LH .. ``` -Bool options can be set to ON/OFF with -D\[option\]=\[ON/OFF\]. You can configure cmake options like this: +Bool options can be set to `ON/OFF` with `-D[option]=[ON/OFF]`. You can configure cmake options like this: ```sh cd build/cmake/builddir cmake -DZSTD_BUILD_TESTS=ON -DZSTD_LEGACY_SUPPORT=ON .. make ``` -## referring +### referring [Looking for a 'cmake clean' command to clear up CMake output](https://stackoverflow.com/questions/9680420/looking-for-a-cmake-clean-command-to-clear-up-cmake-output) -# CMake Style Recommendations +## CMake Style Recommendations -## Indent all code correctly, i.e. the body of +### Indent all code correctly, i.e. the body of * if/else/endif * foreach/endforeach @@ -57,7 +57,7 @@ make Use spaces for indenting, 2, 3 or 4 spaces preferably. Use the same amount of spaces for indenting as is used in the rest of the file. Do not use tabs. -## Upper/lower casing +### Upper/lower casing Most important: use consistent upper- or lowercasing within one file ! @@ -77,7 +77,7 @@ Add_Executable(hello hello.c) aDd_ExEcUtAbLe(blub blub.c) ``` -## End commands +### End commands To make the code easier to read, use empty commands for endforeach(), endif(), endfunction(), endmacro() and endwhile(). Also, use empty else() commands. @@ -99,6 +99,6 @@ if(BARVAR) endif(BARVAR) ``` -## Other resources for best practices +### Other resources for best practices -`https://cmake.org/cmake/help/latest/manual/cmake-developer.7.html#modules` +https://cmake.org/cmake/help/latest/manual/cmake-developer.7.html#modules From b804dd3e5bd3397fa5bbb3a5313496e9156d4fb5 Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Sat, 14 Sep 2019 21:14:43 +0300 Subject: [PATCH 2/8] #754 move sufixlist upper and improve error message on missing suffix --- programs/fileio.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/programs/fileio.c b/programs/fileio.c index 8a45563d4..e5fb1aad1 100644 --- a/programs/fileio.c +++ b/programs/fileio.c @@ -2169,12 +2169,24 @@ FIO_determineDstName(const char* srcFileName) static size_t dfnbCapacity = 0; static char* dstFileNameBuffer = NULL; /* using static allocation : this function cannot be multi-threaded */ + const char* suffixlist = ZSTD_EXTENSION + #ifdef ZSTD_GZDECOMPRESS + "/" GZ_EXTENSION + #endif + #ifdef ZSTD_LZMADECOMPRESS + "/" XZ_EXTENSION "/" LZMA_EXTENSION + #endif + #ifdef ZSTD_LZ4DECOMPRESS + "/" LZ4_EXTENSION + #endif + ; + size_t const sfnSize = strlen(srcFileName); size_t suffixSize; const char* const suffixPtr = strrchr(srcFileName, '.'); if (suffixPtr == NULL) { - DISPLAYLEVEL(1, "zstd: %s: unknown suffix -- ignored \n", - srcFileName); + DISPLAYLEVEL(1, "zstd: %s: missing suffix (%s expected) -- ignored \n", + srcFileName, suffixlist); return NULL; } suffixSize = strlen(suffixPtr); @@ -2193,17 +2205,6 @@ FIO_determineDstName(const char* srcFileName) && strcmp(suffixPtr, LZ4_EXTENSION) #endif ) ) { - const char* suffixlist = ZSTD_EXTENSION - #ifdef ZSTD_GZDECOMPRESS - "/" GZ_EXTENSION - #endif - #ifdef ZSTD_LZMADECOMPRESS - "/" XZ_EXTENSION "/" LZMA_EXTENSION - #endif - #ifdef ZSTD_LZ4DECOMPRESS - "/" LZ4_EXTENSION - #endif - ; DISPLAYLEVEL(1, "zstd: %s: unknown suffix (%s expected) -- ignored \n", srcFileName, suffixlist); return NULL; From 8cc815a941d2b96a867a4c3d89af3b4cd574d0e8 Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Sat, 14 Sep 2019 21:15:24 +0300 Subject: [PATCH 3/8] #754 sufixlist->SUFFIX_LIST --- programs/fileio.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/programs/fileio.c b/programs/fileio.c index e5fb1aad1..7ad540558 100644 --- a/programs/fileio.c +++ b/programs/fileio.c @@ -2169,7 +2169,7 @@ FIO_determineDstName(const char* srcFileName) static size_t dfnbCapacity = 0; static char* dstFileNameBuffer = NULL; /* using static allocation : this function cannot be multi-threaded */ - const char* suffixlist = ZSTD_EXTENSION + const char* SUFFIX_LIST = ZSTD_EXTENSION #ifdef ZSTD_GZDECOMPRESS "/" GZ_EXTENSION #endif @@ -2186,7 +2186,7 @@ FIO_determineDstName(const char* srcFileName) const char* const suffixPtr = strrchr(srcFileName, '.'); if (suffixPtr == NULL) { DISPLAYLEVEL(1, "zstd: %s: missing suffix (%s expected) -- ignored \n", - srcFileName, suffixlist); + srcFileName, SUFFIX_LIST); return NULL; } suffixSize = strlen(suffixPtr); @@ -2206,7 +2206,7 @@ FIO_determineDstName(const char* srcFileName) #endif ) ) { DISPLAYLEVEL(1, "zstd: %s: unknown suffix (%s expected) -- ignored \n", - srcFileName, suffixlist); + srcFileName, SUFFIX_LIST); return NULL; } From 7d9cd22e2145f68cb04b87d76907366726ab0bc3 Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Sat, 14 Sep 2019 21:23:47 +0300 Subject: [PATCH 4/8] #754 Add a hint about -o option --- programs/fileio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/programs/fileio.c b/programs/fileio.c index 7ad540558..edf58fee6 100644 --- a/programs/fileio.c +++ b/programs/fileio.c @@ -2185,7 +2185,7 @@ FIO_determineDstName(const char* srcFileName) size_t suffixSize; const char* const suffixPtr = strrchr(srcFileName, '.'); if (suffixPtr == NULL) { - DISPLAYLEVEL(1, "zstd: %s: missing suffix (%s expected) -- ignored \n", + DISPLAYLEVEL(1, "zstd: %s: missing suffix (%s expected). Can't derive the output file name so specify it with -o dstFileName. -- ignored \n", srcFileName, SUFFIX_LIST); return NULL; } @@ -2205,7 +2205,7 @@ FIO_determineDstName(const char* srcFileName) && strcmp(suffixPtr, LZ4_EXTENSION) #endif ) ) { - DISPLAYLEVEL(1, "zstd: %s: unknown suffix (%s expected) -- ignored \n", + DISPLAYLEVEL(1, "zstd: %s: unknown suffix (%s expected). Can't derive the output file name so specify it with -o dstFileName. -- ignored \n", srcFileName, SUFFIX_LIST); return NULL; } From a101721f4e2f3cfa0296b5b61147f272e77c8b68 Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Sat, 14 Sep 2019 21:26:27 +0300 Subject: [PATCH 5/8] Use one strstr() call instead of chain of strcmp() --- programs/fileio.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/programs/fileio.c b/programs/fileio.c index edf58fee6..8816115b5 100644 --- a/programs/fileio.c +++ b/programs/fileio.c @@ -2193,18 +2193,7 @@ FIO_determineDstName(const char* srcFileName) /* check suffix is authorized */ if (sfnSize <= suffixSize - || ( strcmp(suffixPtr, ZSTD_EXTENSION) - #ifdef ZSTD_GZDECOMPRESS - && strcmp(suffixPtr, GZ_EXTENSION) - #endif - #ifdef ZSTD_LZMADECOMPRESS - && strcmp(suffixPtr, XZ_EXTENSION) - && strcmp(suffixPtr, LZMA_EXTENSION) - #endif - #ifdef ZSTD_LZ4DECOMPRESS - && strcmp(suffixPtr, LZ4_EXTENSION) - #endif - ) ) { + || (strstr(SUFFIX_LIST, suffixPtr) == NULL)) { DISPLAYLEVEL(1, "zstd: %s: unknown suffix (%s expected). Can't derive the output file name so specify it with -o dstFileName. -- ignored \n", srcFileName, SUFFIX_LIST); return NULL; From 59f369a6da86e83948084270a06ad72368f079cc Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Sat, 14 Sep 2019 21:30:15 +0300 Subject: [PATCH 6/8] Add short tar's extensions .tgz (.tar.gz), .txz (.tar.xz), .tzst (.tar.zst) --- programs/fileio.c | 8 ++++---- programs/fileio.h | 4 ++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/programs/fileio.c b/programs/fileio.c index 8816115b5..f7e3b2349 100644 --- a/programs/fileio.c +++ b/programs/fileio.c @@ -2169,15 +2169,15 @@ FIO_determineDstName(const char* srcFileName) static size_t dfnbCapacity = 0; static char* dstFileNameBuffer = NULL; /* using static allocation : this function cannot be multi-threaded */ - const char* SUFFIX_LIST = ZSTD_EXTENSION + const char* SUFFIX_LIST = ZSTD_EXTENSION "/" TZSTD_EXTENSION #ifdef ZSTD_GZDECOMPRESS - "/" GZ_EXTENSION + "/" GZ_EXTENSION "/" TGZ_EXTENSION #endif #ifdef ZSTD_LZMADECOMPRESS - "/" XZ_EXTENSION "/" LZMA_EXTENSION + "/" XZ_EXTENSION "/" LZMA_EXTENSION "/" TXZ_EXTENSION #endif #ifdef ZSTD_LZ4DECOMPRESS - "/" LZ4_EXTENSION + "/" LZ4_EXTENSION "/" TLZ4_EXTENSION #endif ; diff --git a/programs/fileio.h b/programs/fileio.h index 096d90b5c..ebd2ffbee 100644 --- a/programs/fileio.h +++ b/programs/fileio.h @@ -32,9 +32,13 @@ extern "C" { #endif #define LZMA_EXTENSION ".lzma" #define XZ_EXTENSION ".xz" +#define TXZ_EXTENSION ".txz" #define GZ_EXTENSION ".gz" +#define TGZ_EXTENSION ".tgz" #define ZSTD_EXTENSION ".zst" +#define TZSTD_EXTENSION ".tzst" #define LZ4_EXTENSION ".lz4" +#define TLZ4_EXTENSION ".tlz4" /*-************************************* From bfb4d830b299feb14da189b775700b5fa41950d5 Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Wed, 18 Sep 2019 09:21:00 +0300 Subject: [PATCH 7/8] FIO_determineDstName: extract dstFileNameEndPos variable --- programs/fileio.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/programs/fileio.c b/programs/fileio.c index f7e3b2349..96170b14a 100644 --- a/programs/fileio.c +++ b/programs/fileio.c @@ -2210,8 +2210,9 @@ FIO_determineDstName(const char* srcFileName) /* return dst name == src name truncated from suffix */ assert(dstFileNameBuffer != NULL); - memcpy(dstFileNameBuffer, srcFileName, sfnSize - suffixSize); - dstFileNameBuffer[sfnSize-suffixSize] = '\0'; + size_t dstFileNameEndPos = sfnSize - suffixSize; + memcpy(dstFileNameBuffer, srcFileName, dstFileNameEndPos); + dstFileNameBuffer[dstFileNameEndPos] = '\0'; return dstFileNameBuffer; /* note : dstFileNameBuffer memory is not going to be free */ From dafe796e39492a180dacec35b4a4c963dcd88a37 Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Wed, 18 Sep 2019 09:23:10 +0300 Subject: [PATCH 8/8] #1790 short tar's extensions tgz, txz, tlz4m .tzst should be decompressed with .tar suffix --- programs/fileio.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/programs/fileio.c b/programs/fileio.c index 96170b14a..5aaad0e96 100644 --- a/programs/fileio.c +++ b/programs/fileio.c @@ -2212,6 +2212,15 @@ FIO_determineDstName(const char* srcFileName) assert(dstFileNameBuffer != NULL); size_t dstFileNameEndPos = sfnSize - suffixSize; memcpy(dstFileNameBuffer, srcFileName, dstFileNameEndPos); + /* The short tar extensions tzst, tgz, txz and tlz4 files should have "tar" extension on decompression + * To check that the file is one of them we can check that it starts with "t" + */ + if (suffixPtr[1] == 't') { + dstFileNameBuffer[dstFileNameEndPos++] = '.'; + dstFileNameBuffer[dstFileNameEndPos++] = 't'; + dstFileNameBuffer[dstFileNameEndPos++] = 'a'; + dstFileNameBuffer[dstFileNameEndPos++] = 'r'; + } dstFileNameBuffer[dstFileNameEndPos] = '\0'; return dstFileNameBuffer;