Worst case size is : "inputsize + 0.4%", with "0.4%" being at least 8 bytes.\r
\r
LZ4_uncompress :\r
+ osize : is the output size, therefore the original size\r
return : the number of bytes read in the source buffer\r
If the source stream is malformed, the function will stop decoding and return a negative result, indicating the byte position of the faulty instruction\r
This version never writes beyond dest + osize, and is therefore protected against malicious data packets\r
- note 1 : osize is the output size, therefore the original size\r
note 2 : destination buffer must be already allocated\r
*/\r
\r
\r
/*\r
LZ4_uncompress_unknownOutputSize :\r
+ isize : is the input size, therefore the compressed size\r
+ maxOutputSize : is the size of the destination buffer (which must be already allocated)\r
return : the number of bytes decoded in the destination buffer (necessarily <= maxOutputSize)\r
If the source stream is malformed, the function will stop decoding and return a negative result, indicating the byte position of the faulty instruction\r
This version never writes beyond dest + maxOutputSize, and is therefore protected against malicious data packets\r
- note 1 : isize is the input size, therefore the compressed size\r
- note 2 : destination buffer must already be allocated, with at least maxOutputSize bytes\r
- note 3 : this version is slower by up to 10%, and is therefore not recommended for general use\r
+ note : This version is slower than LZ4_uncompress, and is therefore not recommended for general use\r
*/\r
\r
\r
*/\r
\r
\r
-//*********************************\r
-// Deprecated decoding function\r
-//*********************************\r
-\r
-/*\r
-LZ4_decode : Starting with r12, LZ4_decode() is no longer provided in LZ4 source code.\r
- If you need to provide "isize" instead of "osize" to the decoder, please use LZ4_uncompress_unknownOutputSize(), which is safer.\r
-*/\r
-\r
-\r
#if defined (__cplusplus)\r
}\r
#endif\r
//****************************\r
// Includes\r
//****************************\r
-#include <stdio.h> // fprintf, fopen, fread\r
-#include <stdlib.h> // malloc\r
-#include <string.h> // strcmp\r
+#include <stdio.h> // fprintf, fopen, fread\r
+#include <stdlib.h> // malloc\r
+#include <string.h> // strcmp\r
#ifdef _WIN32 \r
-#include <io.h> // _setmode\r
-#include <fcntl.h> // _O_BINARY\r
+#include <io.h> // _setmode\r
+#include <fcntl.h> // _O_BINARY\r
#endif\r
#include "lz4.h"\r
\r
fprintf(stderr, "Usage :\n");\r
fprintf(stderr, " %s [arg] input output\n",BINARY_NAME);\r
fprintf(stderr, "Arguments :\n");\r
- fprintf(stderr, " -c : force compression (default)\n");\r
- fprintf(stderr, " -d : force decompression \n");\r
+ fprintf(stderr, " -c : compression (default)\n");\r
+ fprintf(stderr, " -d : decompression \n");\r
+ fprintf(stderr, " -t : test compressed file \n");\r
fprintf(stderr, " -h : help (this text)\n"); \r
fprintf(stderr, "input : can be 'stdin' (pipe) or a filename\n");\r
- fprintf(stderr, "output : can be 'stdout'(pipe) or a filename or 'nul'\n");\r
+ fprintf(stderr, "output : can be 'stdout'(pipe) or a filename or 'null'\n");\r
return 0;\r
}\r
\r
FILE* foutput;\r
char stdinmark[] = "stdin";\r
char stdoutmark[] = "stdout";\r
- char nulmark[] = "nul";\r
\r
if (!strcmp (input_filename, stdinmark)) {\r
fprintf(stderr, "Using stdin for input\n");\r
#ifdef _WIN32 // Need to set stdin/stdout to binary mode specifically for windows\r
_setmode( _fileno( stdout ), _O_BINARY );\r
#endif\r
- } else if (!strcmp (input_filename, nulmark)) {\r
- fprintf(stderr, "Sending output to nul\n");\r
- foutput = NULL;\r
} else {\r
foutput = fopen( output_filename, "wb" );\r
}\r
FILE* foutput;\r
char stdinmark[] = "stdin";\r
char stdoutmark[] = "stdout";\r
- char nulmark[] = "nul";\r
\r
if (!strcmp (input_filename, stdinmark)) {\r
fprintf(stderr, "Using stdin for input\n");\r
#ifdef _WIN32 // need to set stdin/stdout to binary mode\r
_setmode( _fileno( stdout ), _O_BINARY );\r
#endif\r
- } else if (!strcmp (input_filename, nulmark)) {\r
- fprintf(stderr, "Sending output to nul\n");\r
- foutput = NULL;\r
} else {\r
foutput = fopen( output_filename, "wb" );\r
}\r
\r
// Check Archive Header\r
uselessRet = fread(out_buff, 1, ARCHIVE_MAGICNUMBER_SIZE, finput);\r
- if (*(U32*)out_buff != ARCHIVE_MAGICNUMBER) { fprintf(stderr,"Wrong file : cannot be decoded\n"); return 6; }\r
+ if (*(U32*)out_buff != ARCHIVE_MAGICNUMBER) { fprintf(stderr,"Unrecognized header : file cannot be decoded\n"); return 6; }\r
uselessRet = fread(in_buff, 1, 4, finput);\r
nextSize = *(U32*)in_buff;\r
\r
int i,\r
compression=1, // default action if no argument\r
decode=0;\r
- char *input_filename=0,\r
- *output_filename=0;\r
+ char* input_filename=0;\r
+ char* output_filename=0;\r
+#ifdef _WIN32 \r
+ char nulmark[] = "nul";\r
+#else\r
+ char nulmark[] = "/dev/null";\r
+#endif\r
+ char nullinput[] = "null";\r
\r
// Welcome message\r
fprintf(stderr, WELCOME_MESSAGE);\r
{\r
argument += command;\r
\r
- // display help on usage\r
+ // Display help on usage\r
if ( argument[0] =='h' ) { usage(); return 0; }\r
\r
- // Forced Compression (default)\r
+ // Compression (default)\r
if ( argument[0] =='c' ) { compression=1; continue; }\r
\r
- // Forced Decoding\r
+ // Decoding\r
if ( argument[0] =='d' ) { decode=1; continue; }\r
+\r
+ // Test\r
+ if ( argument[0] =='t' ) { decode=1; output_filename=nulmark; continue; }\r
}\r
\r
// first provided filename is input\r
if (!input_filename) { input_filename=argument; continue; }\r
\r
// second provided filename is output\r
- if (!output_filename) { output_filename=argument; continue; }\r
+ if (!output_filename) \r
+ { \r
+ output_filename=argument; \r
+ if (!strcmp (output_filename, nullinput)) output_filename = nulmark;\r
+ continue; \r
+ }\r
}\r
\r
// No input filename ==> Error\r