summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryann.collet.73@gmail.com <yann.collet.73@gmail.com@650e7d94-2a16-8b24-b05c-7c0b3f6821cd>2011-09-25 20:11:05 (GMT)
committeryann.collet.73@gmail.com <yann.collet.73@gmail.com@650e7d94-2a16-8b24-b05c-7c0b3f6821cd>2011-09-25 20:11:05 (GMT)
commitdab6b9d3dc9c1f6b6f30e23f44d5fc8fa445fd65 (patch)
tree3fbf50d03e8bdefe8e264dc4674d6e28263b45f5
parente1ae3a0b958c03ac5162f4852f183bdd0e6580f4 (diff)
downloadlz4-dab6b9d3dc9c1f6b6f30e23f44d5fc8fa445fd65.zip
lz4-dab6b9d3dc9c1f6b6f30e23f44d5fc8fa445fd65.tar.gz
lz4-dab6b9d3dc9c1f6b6f30e23f44d5fc8fa445fd65.tar.bz2
CLI : Added : capability to compress/decompress to NULL (useful for testings)
Corrected small bug into LZ4_uncompress(). Update is recommended. git-svn-id: https://lz4.googlecode.com/svn/trunk@28 650e7d94-2a16-8b24-b05c-7c0b3f6821cd
-rw-r--r--lz4.c5
-rw-r--r--main.c16
2 files changed, 15 insertions, 6 deletions
diff --git a/lz4.c b/lz4.c
index 8e9738c..fec366a 100644
--- a/lz4.c
+++ b/lz4.c
@@ -72,8 +72,8 @@
#define COPYTOKEN 4
#define COPYLENGTH 8
#define LASTLITERALS 5
-#define MFLIMIT 12
-#define MINLENGTH 13
+#define MFLIMIT (COPYLENGTH+MINMATCH)
+#define MINLENGTH (MFLIMIT+1)
#define MAXD_LOG 16
#define MAX_DISTANCE ((1 << MAXD_LOG) - 1)
@@ -302,6 +302,7 @@ int LZ4_uncompress(char* source,
{
if (ref > oend) goto _output_error;
memcpy(op, ip, length);
+ ip+=length;
break; // Necessarily EOF
}
LZ4_WILDCOPY(ip, op, ref);
diff --git a/main.c b/main.c
index f41330c..b6abfca 100644
--- a/main.c
+++ b/main.c
@@ -89,8 +89,8 @@ int usage()
fprintf(stderr, " -c : force compression (default)\n");
fprintf(stderr, " -d : force decompression \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\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");
return 0;
}
@@ -113,11 +113,12 @@ 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");
finput = stdin;
-#ifdef _WIN32 /* We need to set stdin/stdout to binary mode. Damn windows. */
+#ifdef _WIN32 // Need to set stdin/stdout to binary mode specifically for windows
_setmode( _fileno( stdin ), _O_BINARY );
#endif
} else {
@@ -127,9 +128,12 @@ int compress_file(char* input_filename, char* output_filename)
if (!strcmp (output_filename, stdoutmark)) {
fprintf(stderr, "Using stdout for output\n");
foutput = stdout;
-#ifdef _WIN32 /* We need to set stdin/stdout to binary mode. Damn windows. */
+#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" );
}
@@ -186,6 +190,7 @@ 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");
@@ -203,6 +208,9 @@ 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" );
}