summaryrefslogtreecommitdiffstats
path: root/programs/lz4io.c
diff options
context:
space:
mode:
authorYann Collet <yann.collet.73@gmail.com>2015-03-10 15:57:42 (GMT)
committerYann Collet <yann.collet.73@gmail.com>2015-03-10 15:57:42 (GMT)
commitceec6fa8492a5ff0ed163c96516716a3c2b09461 (patch)
tree2e478ef1c6960cb419760761e432471f115522c5 /programs/lz4io.c
parent6b0c39b839b8343da195252a8c46e6d93138f3b8 (diff)
downloadlz4-ceec6fa8492a5ff0ed163c96516716a3c2b09461.zip
lz4-ceec6fa8492a5ff0ed163c96516716a3c2b09461.tar.gz
lz4-ceec6fa8492a5ff0ed163c96516716a3c2b09461.tar.bz2
g++ compatibility
Diffstat (limited to 'programs/lz4io.c')
-rw-r--r--programs/lz4io.c178
1 files changed, 11 insertions, 167 deletions
diff --git a/programs/lz4io.c b/programs/lz4io.c
index 9d5bee5..fd98247 100644
--- a/programs/lz4io.c
+++ b/programs/lz4io.c
@@ -39,20 +39,15 @@
#endif
#define GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
-#ifdef __GNUC__
-# pragma GCC diagnostic ignored "-Wmissing-braces" /* GCC bug 53119 : doesn't accept { 0 } as initializer (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53119) */
-# pragma GCC diagnostic ignored "-Wmissing-field-initializers" /* GCC bug 53119 : doesn't accept { 0 } as initializer (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53119) */
-#endif
#define _LARGE_FILES /* Large file support on 32-bits AIX */
#define _FILE_OFFSET_BITS 64 /* Large file support on 32-bits unix */
-#define _POSIX_SOURCE 1 /* for fileno() within <stdio.h> on unix */
/****************************
* Includes
*****************************/
-#include <stdio.h> /* fprintf, fopen, fread, _fileno, stdin, stdout */
+#include <stdio.h> /* fprintf, fopen, fread, stdin, stdout */
#include <stdlib.h> /* malloc, free */
#include <string.h> /* strcmp, strlen */
#include <time.h> /* clock */
@@ -62,55 +57,18 @@
#include "lz4frame.h"
-/**************************************
- Basic Types
-**************************************/
-#if defined(LZ4IO_ENABLE_SPARSE_FILE)
-#if defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */
-# include <stdint.h>
- typedef uint8_t BYTE;
- typedef uint16_t U16;
- typedef uint32_t U32;
- typedef int32_t S32;
- typedef uint64_t U64;
-#else
- typedef unsigned char BYTE;
- typedef unsigned short U16;
- typedef unsigned int U32;
- typedef signed int S32;
- typedef unsigned long long U64;
-#endif
-#endif /* LZ4IO_ENABLE_SPARSE_FILE */
-
-
/****************************
* OS-specific Includes
*****************************/
#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__)
# include <fcntl.h> /* _O_BINARY */
-# include <io.h> /* _setmode, _isatty */
-# ifdef __MINGW32__
- int _fileno(FILE *stream); /* MINGW somehow forgets to include this windows declaration into <stdio.h> */
-# endif
+# include <io.h> /* _setmode, _fileno */
+# define SET_BINARY_MODE(file) _setmode(_fileno(file), _O_BINARY)
# if defined(_MSC_VER) && (_MSC_VER >= 1400) /* Avoid MSVC fseek()'s 2GiB barrier */
# define fseek _fseeki64
# endif
-# define SET_BINARY_MODE(file) _setmode(_fileno(file), _O_BINARY)
-# define IS_CONSOLE(stdStream) _isatty(_fileno(stdStream))
-# if defined(LZ4IO_ENABLE_SPARSE_FILE)
-# include <windows.h>
-# define SET_SPARSE_FILE_MODE(file) do { DWORD dw; DeviceIoControl((HANDLE) _get_osfhandle(_fileno(file)), FSCTL_SET_SPARSE, 0, 0, 0, 0, &dw, 0); } while(0)
-# if defined(_MSC_VER) && (_MSC_VER >= 1400)
-# define fseek _fseeki64
-# endif
-# endif /* LZ4IO_ENABLE_SPARSE_FILE */
#else
-# include <unistd.h> /* isatty */
# define SET_BINARY_MODE(file)
-# define IS_CONSOLE(stdStream) isatty(fileno(stdStream))
-# if defined(LZ4IO_ENABLE_SPARSE_FILE)
-# define SET_SPARSE_FILE_MODE(file)
-# endif /* LZ4IO_ENABLE_SPARSE_FILE */
#endif
@@ -164,9 +122,6 @@ static int globalBlockSizeId = LZ4S_BLOCKSIZEID_DEFAULT;
static int blockChecksum = 0;
static int streamChecksum = 1;
static int blockIndependence = 1;
-#if defined(LZ4IO_ENABLE_SPARSE_FILE)
-static int sparseFile = 0;
-#endif /* LZ4IO_ENABLE_SPARSE_FILE */
static const int minBlockSizeID = 4;
static const int maxBlockSizeID = 7;
@@ -193,7 +148,6 @@ static const int maxBlockSizeID = 7;
#define EXTENDED_ARGUMENTS
#define EXTENDED_HELP
#define EXTENDED_FORMAT
-#define DEFAULT_COMPRESSOR compress_file
#define DEFAULT_DECOMPRESSOR decodeLZ4S
@@ -208,75 +162,6 @@ int LZ4IO_setOverwrite(int yes)
return overwrite;
}
-#if defined(LZ4IO_ENABLE_SPARSE_FILE)
-/* Default setting : sparseFile = 0; (Disable)
- return : sparse file mode (0:Disable / 1:Enable) */
-int LZ4IO_setSparseFile(int yes)
-{
- sparseFile = yes;
- return sparseFile;
-}
-
-static int isSparse(const void* p, size_t size)
-{
-#if 0
- /* naive */
- const char* p8 = p;
- for(; size; --size)
- {
- if(*p8 != 0)
- {
- return 0;
- }
- ++p8;
- }
- return 1;
-#elif 0
- /* xz method */
- const U64* p64 = (const U64*) p;
- const char* p8 = (const char*) p;
- const size_t n = size / sizeof(*p64);
- size_t i;
-
- for (i = 0; i < n; ++i)
- {
- if (p64[i] != 0)
- {
- return 0;
- }
- }
-
- for(i = n * sizeof(*p64); i < size; ++i)
- {
- if (p8[i] != 0)
- {
- return 0;
- }
- }
-
- return 1;
-#elif 0
- /* Neil's */
- const char* buf = (const char*) p;
- return buf[0] == 0 && !memcmp(buf, buf + 1, size - 1);
-#else
- /* GNU Core Utilities : coreutils/src/system.h / is_nul() */
- const U64* wp = (const U64*) p;
- const char* cbuf = (const char*) p;
- const char* cp;
-
- // Find first nonzero *word*, or the word with the sentinel.
- while(*wp++ == 0) ;
-
- // Find the first nonzero *byte*, or the sentinel.
- cp = (const char*) (wp - 1);
- while(*cp++ == 0) ;
-
- return cbuf + size < cp;
-#endif
-}
-#endif /* LZ4IO_ENABLE_SPARSE_FILE */
-
/* blockSizeID : valid values : 4-5-6-7 */
int LZ4IO_setBlockSizeID(int bsid)
{
@@ -386,7 +271,7 @@ static int get_fileHandle(const char* input_filename, const char* output_filenam
/* unoptimized version; solves endianess & alignment issues */
static void LZ4IO_writeLE32 (void* p, unsigned value32)
{
- unsigned char* dstPtr = p;
+ unsigned char* dstPtr = (unsigned char*)p;
dstPtr[0] = (unsigned char)value32;
dstPtr[1] = (unsigned char)(value32 >> 8);
dstPtr[2] = (unsigned char)(value32 >> 16);
@@ -483,11 +368,12 @@ int LZ4IO_compressFilename(const char* input_filename, const char* output_filena
size_t sizeCheck, headerSize, readSize, outBuffSize;
LZ4F_compressionContext_t ctx;
LZ4F_errorCode_t errorCode;
- LZ4F_preferences_t prefs = {0};
+ LZ4F_preferences_t prefs;
/* Init */
start = clock();
+ memset(&prefs, 0, sizeof(prefs));
if ((displayLevel==2) && (compressionLevel>=3)) displayLevel=3;
errorCode = LZ4F_createCompressionContext(&ctx, LZ4F_VERSION);
if (LZ4F_isError(errorCode)) EXM_THROW(30, "Allocation error : can't create LZ4F context : %s", LZ4F_getErrorName(errorCode));
@@ -497,9 +383,9 @@ int LZ4IO_compressFilename(const char* input_filename, const char* output_filena
/* Set compression parameters */
prefs.autoFlush = 1;
prefs.compressionLevel = compressionLevel;
- prefs.frameInfo.blockMode = blockIndependence;
- prefs.frameInfo.blockSizeID = globalBlockSizeId;
- prefs.frameInfo.contentChecksumFlag = streamChecksum;
+ prefs.frameInfo.blockMode = (blockMode_t)blockIndependence;
+ prefs.frameInfo.blockSizeID = (blockSizeID_t)globalBlockSizeId;
+ prefs.frameInfo.contentChecksumFlag = (contentChecksum_t)streamChecksum;
/* Allocate Memory */
in_buff = (char*)malloc(blockSize);
@@ -578,7 +464,7 @@ int LZ4IO_compressMultipleFilenames(const char** inFileNamesTable, int ifntSize,
for (i=0; i<ifntSize; i++)
{
size_t ifnSize = strlen(inFileNamesTable[i]);
- if (ofnSize <= ifnSize+suffixSize+1) { free(outFileName); ofnSize = ifnSize + 20; outFileName = malloc(ofnSize); }
+ if (ofnSize <= ifnSize+suffixSize+1) { free(outFileName); ofnSize = ifnSize + 20; outFileName = (char*)malloc(ofnSize); }
strcpy(outFileName, inFileNamesTable[i]);
strcat(outFileName, suffix);
LZ4IO_compressFilename(inFileNamesTable[i], outFileName, compressionlevel);
@@ -595,7 +481,7 @@ int LZ4IO_compressMultipleFilenames(const char** inFileNamesTable, int ifntSize,
static unsigned LZ4IO_readLE32 (const void* s)
{
- const unsigned char* srcPtr = s;
+ const unsigned char* srcPtr = (const unsigned char*)s;
unsigned value32 = srcPtr[0];
value32 += (srcPtr[1]<<8);
value32 += (srcPtr[2]<<16);
@@ -663,9 +549,6 @@ static unsigned long long decodeLZ4S(FILE* finput, FILE* foutput)
LZ4F_decompressionContext_t ctx;
LZ4F_errorCode_t errorCode;
LZ4F_frameInfo_t frameInfo;
-#if defined(LZ4IO_ENABLE_SPARSE_FILE)
- size_t sparsePending = 0;
-#endif /* LZ4IO_ENABLE_SPARSE_FILE */
/* init */
errorCode = LZ4F_createDecompressionContext(&ctx, LZ4F_VERSION);
@@ -687,12 +570,7 @@ static unsigned long long decodeLZ4S(FILE* finput, FILE* foutput)
outBuffSize = LZ4IO_setBlockSizeID(frameInfo.blockSizeID);
inBuffSize = outBuffSize + 4;
inBuff = (char*)malloc(inBuffSize);
-#if defined(LZ4IO_ENABLE_SPARSE_FILE)
- outBuff = (char*)malloc(outBuffSize+sizeof(U64));
- *(U64*) &outBuff[outBuffSize] = (U64) -1; /* sentinel */
-#else /* LZ4IO_ENABLE_SPARSE_FILE */
outBuff = (char*)malloc(outBuffSize);
-#endif /* LZ4IO_ENABLE_SPARSE_FILE */
if (!inBuff || !outBuff) EXM_THROW(65, "Allocation error : not enough memory");
/* Main Loop */
@@ -712,35 +590,9 @@ static unsigned long long decodeLZ4S(FILE* finput, FILE* foutput)
filesize += decodedBytes;
/* Write Block */
-#if defined(LZ4IO_ENABLE_SPARSE_FILE)
- if(sparseFile)
- {
- if(isSparse(outBuff, decodedBytes))
- {
- sparsePending += decodedBytes;
- continue;
- }
- if(sparsePending > 0)
- {
- fseek(foutput, sparsePending, SEEK_CUR);
- sparsePending = 0;
- }
- }
-#endif /* LZ4IO_ENABLE_SPARSE_FILE */
sizeCheck = fwrite(outBuff, 1, decodedBytes, foutput);
if (sizeCheck != decodedBytes) EXM_THROW(68, "Write error : cannot write decoded block\n");
}
-#if defined(LZ4IO_ENABLE_SPARSE_FILE)
- if(sparseFile)
- {
- if(sparsePending > 0)
- {
- fseek(foutput, sparsePending-1, SEEK_CUR);
- fputc(0, foutput);
- sparsePending = 0;
- }
- }
-#endif /* LZ4IO_ENABLE_SPARSE_FILE */
/* Free */
free(inBuff);
@@ -803,14 +655,6 @@ int LZ4IO_decompressFilename(const char* input_filename, const char* output_file
start = clock();
get_fileHandle(input_filename, output_filename, &finput, &foutput);
-#if defined(LZ4IO_ENABLE_SPARSE_FILE)
- if (sparseFile!=0 && foutput!=0)
- {
- DISPLAY("Experimental : Using sparse file\n");
- SET_SPARSE_FILE_MODE(foutput);
- }
-#endif /* LZ4IO_ENABLE_SPARSE_FILE */
-
/* Loop over multiple streams */
do
{