diff options
author | Yann Collet <Cyan4973@users.noreply.github.com> | 2016-11-07 18:28:55 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-07 18:28:55 (GMT) |
commit | 839085f0507dd11f5535da01846aee32cd08611b (patch) | |
tree | 126130d7baab1481a6c228746a35c664244fbfff | |
parent | 58d7a619a599e2a4ee94ab4406f9bb490d0ee84d (diff) | |
parent | ef54f9f9dd5d69ab69a085f25adaf4ce4533fe5c (diff) | |
download | lz4-839085f0507dd11f5535da01846aee32cd08611b.zip lz4-839085f0507dd11f5535da01846aee32cd08611b.tar.gz lz4-839085f0507dd11f5535da01846aee32cd08611b.tar.bz2 |
Merge pull request #257 from inikep/dev
added --rm option
-rw-r--r-- | appveyor.yml | 15 | ||||
-rw-r--r-- | lib/lz4frame.h | 4 | ||||
-rw-r--r-- | programs/lz4cli.c | 8 | ||||
-rw-r--r-- | programs/lz4io.c | 55 | ||||
-rw-r--r-- | programs/lz4io.h | 2 | ||||
-rw-r--r-- | visual/VS2010/datagen/datagen.vcxproj | 4 | ||||
-rw-r--r-- | visual/VS2010/frametest/frametest.vcxproj | 4 | ||||
-rw-r--r-- | visual/VS2010/fullbench/fullbench.vcxproj | 4 | ||||
-rw-r--r-- | visual/VS2010/fuzzer/fuzzer.vcxproj | 4 | ||||
-rw-r--r-- | visual/VS2010/liblz4/liblz4.vcxproj | 4 | ||||
-rw-r--r-- | visual/VS2010/lz4/lz4.vcxproj | 18 |
11 files changed, 63 insertions, 59 deletions
diff --git a/appveyor.yml b/appveyor.yml index e941a7e..85d8ea2 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -14,13 +14,10 @@ environment: CONFIGURATION: "Release" PLATFORM: "Win32" - COMPILER: "gcc" - MAKE_PARAMS: "-C programs lz4 fullbench" PLATFORM: "mingw64" - COMPILER: "gcc" - MAKE_PARAMS: "-C programs lz4 fullbench" PLATFORM: "mingw32" - COMPILER: "gcc" - MAKE_PARAMS: '-C programs lz4 fullbench CC=clang MOREFLAGS="--target=x86_64-w64-mingw32 -Werror -Wconversion -Wno-sign-conversion"' PLATFORM: "clang" install: @@ -48,9 +45,15 @@ build_script: echo ----- && make -v && echo ----- && - ECHO make -%MAKE_PARAMS%- && - make %MAKE_PARAMS% - ) ELSE ( + if not [%PLATFORM%]==[clang] ( + make -C programs lz4 && make -C tests fullbench + ) ELSE ( + make -C programs lz4 CC=clang MOREFLAGS="--target=x86_64-w64-mingw32 -Werror -Wconversion -Wno-sign-conversion" && + make -C tests fullbench CC=clang MOREFLAGS="--target=x86_64-w64-mingw32 -Werror -Wconversion -Wno-sign-conversion" + ) + ) + - if [%COMPILER%]==[gcc] (COPY tests\fullbench.exe programs\) + - if [%COMPILER%]==[visual] ( ECHO *** && ECHO *** Building Visual Studio 2010 %PLATFORM%\%CONFIGURATION% && ECHO *** && diff --git a/lib/lz4frame.h b/lib/lz4frame.h index 63d61ad..43bc23c 100644 --- a/lib/lz4frame.h +++ b/lib/lz4frame.h @@ -66,7 +66,7 @@ extern "C" { #endif #if defined(_MSC_VER) -# define LZ4F_DEPRECATE(x) __declspec(deprecated) x +# define LZ4F_DEPRECATE(x) x /* __declspec(deprecated) x - only works with C++ */ #elif defined(__clang__) || (defined(__GNUC__) && (__GNUC__ >= 6)) # define LZ4F_DEPRECATE(x) x __attribute__((deprecated)) #else @@ -274,7 +274,7 @@ typedef struct { * That is, it should be == 0 if decompression has been completed fully and correctly. */ LZ4FLIB_API LZ4F_errorCode_t LZ4F_createDecompressionContext(LZ4F_dctx** dctxPtr, unsigned version); -LZ4FLIB_API LZ4F_errorCode_t LZ4F_freeDecompressionContext(LZ4F_dctx* dctx); +LZ4FLIB_API LZ4F_errorCode_t LZ4F_freeDecompressionContext(LZ4F_dctx* const dctx); /*====== Decompression ======*/ diff --git a/programs/lz4cli.c b/programs/lz4cli.c index e49bbcb..f091d3a 100644 --- a/programs/lz4cli.c +++ b/programs/lz4cli.c @@ -149,6 +149,7 @@ static int usage(void) DISPLAY( " -d : decompression (default for %s extension)\n", LZ4_EXTENSION); DISPLAY( " -z : force compression\n"); DISPLAY( " -f : overwrite output without prompting \n"); + DISPLAY( "--rm : remove source file(s) after successful de/compression \n"); DISPLAY( " -h/-H : display help/long help and exit\n"); return 0; } @@ -326,7 +327,7 @@ int main(int argc, const char** argv) if ((!strcmp(argument, "--decompress")) || (!strcmp(argument, "--uncompress"))) { decode = 1; continue; } if (!strcmp(argument, "--multiple")) { multiple_inputs = 1; if (inFileNames==NULL) inFileNames = (const char**)malloc(argc * sizeof(char*)); continue; } - if (!strcmp(argument, "--test")) { decode = 1; LZ4IO_setOverwrite(1); output_filename=nulmark; continue; } + if (!strcmp(argument, "--test")) { decode = 1; LZ4IO_setTestMode(1); output_filename=nulmark; continue; } if (!strcmp(argument, "--force")) { LZ4IO_setOverwrite(1); continue; } if (!strcmp(argument, "--no-force")) { LZ4IO_setOverwrite(0); continue; } if ((!strcmp(argument, "--stdout")) @@ -340,7 +341,8 @@ int main(int argc, const char** argv) if (!strcmp(argument, "--verbose")) { displayLevel=4; continue; } if (!strcmp(argument, "--quiet")) { if (displayLevel) displayLevel--; continue; } if (!strcmp(argument, "--version")) { DISPLAY(WELCOME_MESSAGE); return 0; } - if (!strcmp(argument, "--keep")) { continue; } /* keep source file (default anyway; just for xz/lzma compatibility) */ + if (!strcmp(argument, "--keep")) { LZ4IO_setRemoveSrcFile(0); continue; } /* keep source file (default anyway; just for xz/lzma compatibility) */ + if (!strcmp(argument, "--rm")) { LZ4IO_setRemoveSrcFile(1); continue; } /* Short commands (note : aggregated short commands are allowed) */ if (argument[0]=='-') { @@ -406,7 +408,7 @@ int main(int argc, const char** argv) case 'q': if (displayLevel) displayLevel--; break; /* keep source file (default anyway, so useless) (for xz/lzma compatibility) */ - case 'k': break; + case 'k': LZ4IO_setRemoveSrcFile(0); break; /* Modify Block Properties */ case 'B': diff --git a/programs/lz4io.c b/programs/lz4io.c index 2f64561..02f4c2b 100644 --- a/programs/lz4io.c +++ b/programs/lz4io.c @@ -33,14 +33,7 @@ /************************************** * Compiler Options **************************************/ -#ifdef _MSC_VER /* Visual Studio */ -# define _CRT_SECURE_NO_WARNINGS -# define _CRT_SECURE_NO_DEPRECATE /* VS2005 */ -# pragma warning(disable : 4127) /* disable: C4127: conditional expression is constant */ -#endif - #define _LARGE_FILES /* Large file support on 32-bits AIX */ -#define _FILE_OFFSET_BITS 64 /* Large file support on 32-bits unix */ #if defined(__MINGW32__) && !defined(_POSIX_SOURCE) # define _POSIX_SOURCE 1 /* disable %llu warnings with MinGW on Windows */ @@ -49,6 +42,7 @@ /***************************** * Includes *****************************/ +#include "util.h" /* Compiler options, UTIL_getFileStat */ #include <stdio.h> /* fprintf, fopen, fread, stdin, stdout, fflush, getchar */ #include <stdlib.h> /* malloc, free */ #include <string.h> /* strcmp, strlen */ @@ -84,10 +78,6 @@ # define SET_SPARSE_FILE_MODE(file) #endif -#if !defined(S_ISREG) -# define S_ISREG(x) (((x) & S_IFMT) == S_IFREG) -#endif - /***************************** * Constants @@ -242,19 +232,9 @@ int LZ4IO_setContentSize(int enable) return g_contentSizeFlag; } -static unsigned long long LZ4IO_GetFileSize(const char* infilename) -{ - int r; -#if defined(_MSC_VER) - struct _stat64 statbuf; - r = _stat64(infilename, &statbuf); -#else - struct stat statbuf; - r = stat(infilename, &statbuf); -#endif - if (r || !S_ISREG(statbuf.st_mode)) return 0; /* failure, or is not a regular file */ - return (unsigned long long)statbuf.st_size; -} +static U32 g_removeSrcFile = 0; +void LZ4IO_setRemoveSrcFile(unsigned flag) { g_removeSrcFile = (flag>0); } + /* ************************************************************************ ** @@ -465,7 +445,6 @@ static int LZ4IO_compressFilename_extRess(cRess_t ress, const char* srcFileName, LZ4F_compressionContext_t ctx = ress.ctx; /* just a pointer */ LZ4F_preferences_t prefs; - /* Init */ memset(&prefs, 0, sizeof(prefs)); @@ -479,7 +458,7 @@ static int LZ4IO_compressFilename_extRess(cRess_t ress, const char* srcFileName, prefs.frameInfo.blockSizeID = (LZ4F_blockSizeID_t)g_blockSizeId; prefs.frameInfo.contentChecksumFlag = (LZ4F_contentChecksum_t)g_streamChecksum; if (g_contentSizeFlag) { - unsigned long long const fileSize = LZ4IO_GetFileSize(srcFileName); + U64 const fileSize = UTIL_getFileSize(srcFileName); prefs.frameInfo.contentSize = fileSize; /* == 0 if input == stdin */ if (fileSize==0) DISPLAYLEVEL(3, "Warning : cannot determine input content size \n"); @@ -547,6 +526,14 @@ static int LZ4IO_compressFilename_extRess(cRess_t ress, const char* srcFileName, fclose (srcFile); fclose (dstFile); + /* Copy owner, file permissions and modification time */ + { stat_t statbuf; + if (strcmp (srcFileName, stdinmark) && strcmp (dstFileName, stdoutmark) && UTIL_getFileStat(srcFileName, &statbuf)) + UTIL_setFileStat(dstFileName, &statbuf); + } + + if (g_removeSrcFile) { if (remove(srcFileName)) EXM_THROW(39, "Remove error : %s: %s", srcFileName, strerror(errno)); } /* remove source file : --rm */ + /* Final Status */ DISPLAYLEVEL(2, "\r%79s\r", ""); DISPLAYLEVEL(2, "Compressed %llu bytes into %llu bytes ==> %.2f%%\n", @@ -946,14 +933,22 @@ static int LZ4IO_decompressFile_extRess(dRess_t ress, const char* input_filename filesize += decodedSize; } while (decodedSize != ENDOFSTREAM); - /* Final Status */ - DISPLAYLEVEL(2, "\r%79s\r", ""); - DISPLAYLEVEL(2, "Successfully decoded %llu bytes \n", filesize); - /* Close */ fclose(finput); fclose(foutput); + /* Copy owner, file permissions and modification time */ + { stat_t statbuf; + if (strcmp (input_filename, stdinmark) && strcmp (output_filename, stdoutmark) && UTIL_getFileStat(input_filename, &statbuf)) + UTIL_setFileStat(output_filename, &statbuf); + } + + if (g_removeSrcFile) { if (remove(input_filename)) EXM_THROW(45, "Remove error : %s: %s", input_filename, strerror(errno)); } /* remove source file : --rm */ + + /* Final Status */ + DISPLAYLEVEL(2, "\r%79s\r", ""); + DISPLAYLEVEL(2, "Successfully decoded %llu bytes \n", filesize); + return 0; } diff --git a/programs/lz4io.h b/programs/lz4io.h index bf076ee..45ae78d 100644 --- a/programs/lz4io.h +++ b/programs/lz4io.h @@ -89,3 +89,5 @@ int LZ4IO_setSparseFile(int enable); /* Default setting : 0 (disabled) */ int LZ4IO_setContentSize(int enable); + +void LZ4IO_setRemoveSrcFile(unsigned flag); diff --git a/visual/VS2010/datagen/datagen.vcxproj b/visual/VS2010/datagen/datagen.vcxproj index 4d7516e..587e457 100644 --- a/visual/VS2010/datagen/datagen.vcxproj +++ b/visual/VS2010/datagen/datagen.vcxproj @@ -121,7 +121,7 @@ <FunctionLevelLinking>true</FunctionLevelLinking> <IntrinsicFunctions>true</IntrinsicFunctions> <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;LZ4_DLL_EXPORT=1;%(PreprocessorDefinitions)</PreprocessorDefinitions> - <TreatWarningAsError>true</TreatWarningAsError> + <TreatWarningAsError>false</TreatWarningAsError> <EnablePREfast>false</EnablePREfast> </ClCompile> <Link> @@ -140,7 +140,7 @@ <FunctionLevelLinking>true</FunctionLevelLinking> <IntrinsicFunctions>true</IntrinsicFunctions> <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;LZ4_DLL_EXPORT=1;%(PreprocessorDefinitions)</PreprocessorDefinitions> - <TreatWarningAsError>true</TreatWarningAsError> + <TreatWarningAsError>false</TreatWarningAsError> <EnablePREfast>true</EnablePREfast> <AdditionalOptions>/analyze:stacksize295252 %(AdditionalOptions)</AdditionalOptions> </ClCompile> diff --git a/visual/VS2010/frametest/frametest.vcxproj b/visual/VS2010/frametest/frametest.vcxproj index 5def90e..7ac7e33 100644 --- a/visual/VS2010/frametest/frametest.vcxproj +++ b/visual/VS2010/frametest/frametest.vcxproj @@ -121,7 +121,7 @@ <FunctionLevelLinking>true</FunctionLevelLinking> <IntrinsicFunctions>true</IntrinsicFunctions> <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;LZ4_DLL_EXPORT=1;%(PreprocessorDefinitions)</PreprocessorDefinitions> - <TreatWarningAsError>true</TreatWarningAsError> + <TreatWarningAsError>false</TreatWarningAsError> <EnablePREfast>false</EnablePREfast> </ClCompile> <Link> @@ -140,7 +140,7 @@ <FunctionLevelLinking>true</FunctionLevelLinking> <IntrinsicFunctions>true</IntrinsicFunctions> <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;LZ4_DLL_EXPORT=1;%(PreprocessorDefinitions)</PreprocessorDefinitions> - <TreatWarningAsError>true</TreatWarningAsError> + <TreatWarningAsError>false</TreatWarningAsError> <EnablePREfast>true</EnablePREfast> <AdditionalOptions>/analyze:stacksize295252 %(AdditionalOptions)</AdditionalOptions> </ClCompile> diff --git a/visual/VS2010/fullbench/fullbench.vcxproj b/visual/VS2010/fullbench/fullbench.vcxproj index 3d858a3..6e2488c 100644 --- a/visual/VS2010/fullbench/fullbench.vcxproj +++ b/visual/VS2010/fullbench/fullbench.vcxproj @@ -121,7 +121,7 @@ <FunctionLevelLinking>true</FunctionLevelLinking> <IntrinsicFunctions>true</IntrinsicFunctions> <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;LZ4_DLL_EXPORT=1;%(PreprocessorDefinitions)</PreprocessorDefinitions> - <TreatWarningAsError>true</TreatWarningAsError> + <TreatWarningAsError>false</TreatWarningAsError> <EnablePREfast>false</EnablePREfast> </ClCompile> <Link> @@ -140,7 +140,7 @@ <FunctionLevelLinking>true</FunctionLevelLinking> <IntrinsicFunctions>true</IntrinsicFunctions> <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;LZ4_DLL_EXPORT=1;%(PreprocessorDefinitions)</PreprocessorDefinitions> - <TreatWarningAsError>true</TreatWarningAsError> + <TreatWarningAsError>false</TreatWarningAsError> <EnablePREfast>true</EnablePREfast> <AdditionalOptions>/analyze:stacksize295252 %(AdditionalOptions)</AdditionalOptions> </ClCompile> diff --git a/visual/VS2010/fuzzer/fuzzer.vcxproj b/visual/VS2010/fuzzer/fuzzer.vcxproj index 2b2d58d..8469c7b 100644 --- a/visual/VS2010/fuzzer/fuzzer.vcxproj +++ b/visual/VS2010/fuzzer/fuzzer.vcxproj @@ -121,7 +121,7 @@ <FunctionLevelLinking>true</FunctionLevelLinking> <IntrinsicFunctions>true</IntrinsicFunctions> <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;LZ4_DLL_EXPORT=1;%(PreprocessorDefinitions)</PreprocessorDefinitions> - <TreatWarningAsError>true</TreatWarningAsError> + <TreatWarningAsError>false</TreatWarningAsError> <EnablePREfast>false</EnablePREfast> </ClCompile> <Link> @@ -140,7 +140,7 @@ <FunctionLevelLinking>true</FunctionLevelLinking> <IntrinsicFunctions>true</IntrinsicFunctions> <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;LZ4_DLL_EXPORT=1;%(PreprocessorDefinitions)</PreprocessorDefinitions> - <TreatWarningAsError>true</TreatWarningAsError> + <TreatWarningAsError>false</TreatWarningAsError> <EnablePREfast>true</EnablePREfast> <AdditionalOptions>/analyze:stacksize295252 %(AdditionalOptions)</AdditionalOptions> </ClCompile> diff --git a/visual/VS2010/liblz4/liblz4.vcxproj b/visual/VS2010/liblz4/liblz4.vcxproj index cbc2173..cbe93bb 100644 --- a/visual/VS2010/liblz4/liblz4.vcxproj +++ b/visual/VS2010/liblz4/liblz4.vcxproj @@ -119,7 +119,7 @@ <FunctionLevelLinking>true</FunctionLevelLinking> <IntrinsicFunctions>true</IntrinsicFunctions> <PreprocessorDefinitions>WIN32;NDEBUG;LZ4_DLL_EXPORT=1;%(PreprocessorDefinitions)</PreprocessorDefinitions> - <TreatWarningAsError>true</TreatWarningAsError> + <TreatWarningAsError>false</TreatWarningAsError> <EnablePREfast>false</EnablePREfast> </ClCompile> <Link> @@ -137,7 +137,7 @@ <FunctionLevelLinking>true</FunctionLevelLinking> <IntrinsicFunctions>true</IntrinsicFunctions> <PreprocessorDefinitions>WIN32;NDEBUG;LZ4_DLL_EXPORT=1;%(PreprocessorDefinitions)</PreprocessorDefinitions> - <TreatWarningAsError>true</TreatWarningAsError> + <TreatWarningAsError>false</TreatWarningAsError> <EnablePREfast>true</EnablePREfast> <AdditionalOptions>/analyze:stacksize295252 %(AdditionalOptions)</AdditionalOptions> </ClCompile> diff --git a/visual/VS2010/lz4/lz4.vcxproj b/visual/VS2010/lz4/lz4.vcxproj index 7513d8c..d12ae65 100644 --- a/visual/VS2010/lz4/lz4.vcxproj +++ b/visual/VS2010/lz4/lz4.vcxproj @@ -1,4 +1,4 @@ -<?xml version="1.0" encoding="utf-8"?> +<?xml version="1.0" encoding="utf-8"?> <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <ItemGroup Label="ProjectConfigurations"> <ProjectConfiguration Include="Debug|Win32"> @@ -28,24 +28,24 @@ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> <ConfigurationType>Application</ConfigurationType> <UseDebugLibraries>true</UseDebugLibraries> - <CharacterSet>Unicode</CharacterSet> + <CharacterSet>MultiByte</CharacterSet> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> <ConfigurationType>Application</ConfigurationType> <UseDebugLibraries>true</UseDebugLibraries> - <CharacterSet>Unicode</CharacterSet> + <CharacterSet>MultiByte</CharacterSet> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> <ConfigurationType>Application</ConfigurationType> <UseDebugLibraries>false</UseDebugLibraries> <WholeProgramOptimization>true</WholeProgramOptimization> - <CharacterSet>Unicode</CharacterSet> + <CharacterSet>MultiByte</CharacterSet> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> <ConfigurationType>Application</ConfigurationType> <UseDebugLibraries>false</UseDebugLibraries> <WholeProgramOptimization>true</WholeProgramOptimization> - <CharacterSet>Unicode</CharacterSet> + <CharacterSet>MultiByte</CharacterSet> </PropertyGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <ImportGroup Label="ExtensionSettings"> @@ -121,7 +121,7 @@ <FunctionLevelLinking>true</FunctionLevelLinking> <IntrinsicFunctions>true</IntrinsicFunctions> <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;LZ4_DLL_EXPORT=1;%(PreprocessorDefinitions)</PreprocessorDefinitions> - <TreatWarningAsError>true</TreatWarningAsError> + <TreatWarningAsError>false</TreatWarningAsError> <EnablePREfast>false</EnablePREfast> </ClCompile> <Link> @@ -140,7 +140,7 @@ <FunctionLevelLinking>true</FunctionLevelLinking> <IntrinsicFunctions>true</IntrinsicFunctions> <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;LZ4_DLL_EXPORT=1;%(PreprocessorDefinitions)</PreprocessorDefinitions> - <TreatWarningAsError>true</TreatWarningAsError> + <TreatWarningAsError>false</TreatWarningAsError> <EnablePREfast>true</EnablePREfast> <AdditionalOptions>/analyze:stacksize295252 %(AdditionalOptions)</AdditionalOptions> </ClCompile> @@ -157,6 +157,7 @@ <ClInclude Include="..\..\..\lib\lz4frame_static.h" /> <ClInclude Include="..\..\..\lib\lz4hc.h" /> <ClInclude Include="..\..\..\lib\xxhash.h" /> + <ClInclude Include="..\..\..\programs\datagen.h" /> <ClInclude Include="..\..\..\programs\bench.h" /> <ClInclude Include="..\..\..\programs\lz4io.h" /> </ItemGroup> @@ -165,6 +166,7 @@ <ClCompile Include="..\..\..\lib\lz4frame.c" /> <ClCompile Include="..\..\..\lib\lz4hc.c" /> <ClCompile Include="..\..\..\lib\xxhash.c" /> + <ClCompile Include="..\..\..\programs\datagen.c" /> <ClCompile Include="..\..\..\programs\bench.c" /> <ClCompile Include="..\..\..\programs\lz4cli.c" /> <ClCompile Include="..\..\..\programs\lz4io.c" /> @@ -172,4 +174,4 @@ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <ImportGroup Label="ExtensionTargets"> </ImportGroup> -</Project> +</Project>
\ No newline at end of file |