summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryann.collet.73@gmail.com <yann.collet.73@gmail.com@650e7d94-2a16-8b24-b05c-7c0b3f6821cd>2011-09-25 21:34:35 (GMT)
committeryann.collet.73@gmail.com <yann.collet.73@gmail.com@650e7d94-2a16-8b24-b05c-7c0b3f6821cd>2011-09-25 21:34:35 (GMT)
commit420248cff40ee04fef085c2029498a2423fce5cc (patch)
treefed1c510402e6bfaea361353e83baf5ee19b6a6c
parentdab6b9d3dc9c1f6b6f30e23f44d5fc8fa445fd65 (diff)
downloadlz4-420248cff40ee04fef085c2029498a2423fce5cc.zip
lz4-420248cff40ee04fef085c2029498a2423fce5cc.tar.gz
lz4-420248cff40ee04fef085c2029498a2423fce5cc.tar.bz2
CLI : added test mode
CLI : corrected writing to NULL within Linux Minor : several comments were updated git-svn-id: https://lz4.googlecode.com/svn/trunk@29 650e7d94-2a16-8b24-b05c-7c0b3f6821cd
-rw-r--r--lz4.c6
-rw-r--r--lz4.h18
-rw-r--r--main.c53
3 files changed, 37 insertions, 40 deletions
diff --git a/lz4.c b/lz4.c
index fec366a..340adf6 100644
--- a/lz4.c
+++ b/lz4.c
@@ -38,9 +38,9 @@
//**************************************
// Performance parameter
//**************************************
-// Lowering this value reduce memory usage
-// It may also improve speed, especially if you reach L1 cache size (32KB for Intel, 64KB for AMD)
-// Expanding memory usage typically improves compression ratio
+// Increasing this value improves compression ratio
+// Lowering this value reduces memory usage
+// Lowering may also improve speed, typically on reaching cache size limits (L1 32KB for Intel, 64KB for AMD)
// Memory usage formula for 32 bits systems : N->2^(N+2) Bytes (examples : 17 -> 512KB ; 12 -> 16KB)
#define HASH_LOG 12
diff --git a/lz4.h b/lz4.h
index 6fcc039..70a6ec2 100644
--- a/lz4.h
+++ b/lz4.h
@@ -48,10 +48,10 @@ LZ4_compress :
Worst case size is : "inputsize + 0.4%", with "0.4%" being at least 8 bytes.
LZ4_uncompress :
+ osize : is the output size, therefore the original size
return : the number of bytes read in the source buffer
If the source stream is malformed, the function will stop decoding and return a negative result, indicating the byte position of the faulty instruction
This version never writes beyond dest + osize, and is therefore protected against malicious data packets
- note 1 : osize is the output size, therefore the original size
note 2 : destination buffer must be already allocated
*/
@@ -64,12 +64,12 @@ int LZ4_uncompress_unknownOutputSize (char* source, char* dest, int isize, int m
/*
LZ4_uncompress_unknownOutputSize :
+ isize : is the input size, therefore the compressed size
+ maxOutputSize : is the size of the destination buffer (which must be already allocated)
return : the number of bytes decoded in the destination buffer (necessarily <= maxOutputSize)
If the source stream is malformed, the function will stop decoding and return a negative result, indicating the byte position of the faulty instruction
This version never writes beyond dest + maxOutputSize, and is therefore protected against malicious data packets
- note 1 : isize is the input size, therefore the compressed size
- note 2 : destination buffer must already be allocated, with at least maxOutputSize bytes
- note 3 : this version is slower by up to 10%, and is therefore not recommended for general use
+ note : This version is slower than LZ4_uncompress, and is therefore not recommended for general use
*/
@@ -88,16 +88,6 @@ LZ4_compressCtx :
*/
-//*********************************
-// Deprecated decoding function
-//*********************************
-
-/*
-LZ4_decode : Starting with r12, LZ4_decode() is no longer provided in LZ4 source code.
- If you need to provide "isize" instead of "osize" to the decoder, please use LZ4_uncompress_unknownOutputSize(), which is safer.
-*/
-
-
#if defined (__cplusplus)
}
#endif
diff --git a/main.c b/main.c
index b6abfca..2652e4e 100644
--- a/main.c
+++ b/main.c
@@ -30,12 +30,12 @@
//****************************
// Includes
//****************************
-#include <stdio.h> // fprintf, fopen, fread
-#include <stdlib.h> // malloc
-#include <string.h> // strcmp
+#include <stdio.h> // fprintf, fopen, fread
+#include <stdlib.h> // malloc
+#include <string.h> // strcmp
#ifdef _WIN32
-#include <io.h> // _setmode
-#include <fcntl.h> // _O_BINARY
+#include <io.h> // _setmode
+#include <fcntl.h> // _O_BINARY
#endif
#include "lz4.h"
@@ -86,11 +86,12 @@ int usage()
fprintf(stderr, "Usage :\n");
fprintf(stderr, " %s [arg] input output\n",BINARY_NAME);
fprintf(stderr, "Arguments :\n");
- fprintf(stderr, " -c : force compression (default)\n");
- fprintf(stderr, " -d : force decompression \n");
+ fprintf(stderr, " -c : compression (default)\n");
+ fprintf(stderr, " -d : decompression \n");
+ fprintf(stderr, " -t : test compressed file \n");
fprintf(stderr, " -h : help (this text)\n");
fprintf(stderr, "input : can be 'stdin' (pipe) or a filename\n");
- fprintf(stderr, "output : can be 'stdout'(pipe) or a filename or 'nul'\n");
+ fprintf(stderr, "output : can be 'stdout'(pipe) or a filename or 'null'\n");
return 0;
}
@@ -113,7 +114,6 @@ int compress_file(char* input_filename, char* output_filename)
FILE* foutput;
char stdinmark[] = "stdin";
char stdoutmark[] = "stdout";
- char nulmark[] = "nul";
if (!strcmp (input_filename, stdinmark)) {
fprintf(stderr, "Using stdin for input\n");
@@ -131,9 +131,6 @@ int compress_file(char* input_filename, char* output_filename)
#ifdef _WIN32 // Need to set stdin/stdout to binary mode specifically for windows
_setmode( _fileno( stdout ), _O_BINARY );
#endif
- } else if (!strcmp (input_filename, nulmark)) {
- fprintf(stderr, "Sending output to nul\n");
- foutput = NULL;
} else {
foutput = fopen( output_filename, "wb" );
}
@@ -190,7 +187,6 @@ int decode_file(char* input_filename, char* output_filename)
FILE* foutput;
char stdinmark[] = "stdin";
char stdoutmark[] = "stdout";
- char nulmark[] = "nul";
if (!strcmp (input_filename, stdinmark)) {
fprintf(stderr, "Using stdin for input\n");
@@ -208,9 +204,6 @@ int decode_file(char* input_filename, char* output_filename)
#ifdef _WIN32 // need to set stdin/stdout to binary mode
_setmode( _fileno( stdout ), _O_BINARY );
#endif
- } else if (!strcmp (input_filename, nulmark)) {
- fprintf(stderr, "Sending output to nul\n");
- foutput = NULL;
} else {
foutput = fopen( output_filename, "wb" );
}
@@ -221,7 +214,7 @@ int decode_file(char* input_filename, char* output_filename)
// Check Archive Header
uselessRet = fread(out_buff, 1, ARCHIVE_MAGICNUMBER_SIZE, finput);
- if (*(U32*)out_buff != ARCHIVE_MAGICNUMBER) { fprintf(stderr,"Wrong file : cannot be decoded\n"); return 6; }
+ if (*(U32*)out_buff != ARCHIVE_MAGICNUMBER) { fprintf(stderr,"Unrecognized header : file cannot be decoded\n"); return 6; }
uselessRet = fread(in_buff, 1, 4, finput);
nextSize = *(U32*)in_buff;
@@ -264,8 +257,14 @@ int main(int argc, char** argv)
int i,
compression=1, // default action if no argument
decode=0;
- char *input_filename=0,
- *output_filename=0;
+ char* input_filename=0;
+ char* output_filename=0;
+#ifdef _WIN32
+ char nulmark[] = "nul";
+#else
+ char nulmark[] = "/dev/null";
+#endif
+ char nullinput[] = "null";
// Welcome message
fprintf(stderr, WELCOME_MESSAGE);
@@ -286,21 +285,29 @@ int main(int argc, char** argv)
{
argument += command;
- // display help on usage
+ // Display help on usage
if ( argument[0] =='h' ) { usage(); return 0; }
- // Forced Compression (default)
+ // Compression (default)
if ( argument[0] =='c' ) { compression=1; continue; }
- // Forced Decoding
+ // Decoding
if ( argument[0] =='d' ) { decode=1; continue; }
+
+ // Test
+ if ( argument[0] =='t' ) { decode=1; output_filename=nulmark; continue; }
}
// first provided filename is input
if (!input_filename) { input_filename=argument; continue; }
// second provided filename is output
- if (!output_filename) { output_filename=argument; continue; }
+ if (!output_filename)
+ {
+ output_filename=argument;
+ if (!strcmp (output_filename, nullinput)) output_filename = nulmark;
+ continue;
+ }
}
// No input filename ==> Error