aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYann Collet <yann.collet.73@gmail.com>2014-11-03 09:29:45 +0100
committerMohamad Ayyash <mkayyash@google.com>2015-02-23 17:26:18 -0800
commitd62ca5cbdfc5f54985de8da1d593a4741106eebf (patch)
treebd1f7da1480be7fdd67ddca328660219d1ef5e8b
parent20ac4d0144728f96af22bb3ca8f872306aecaabd (diff)
downloadlz4-d62ca5cbdfc5f54985de8da1d593a4741106eebf.tar.gz
Updated ring buffer examples
-rw-r--r--[-rwxr-xr-x]examples/HCStreaming_ringBuffer.c25
-rw-r--r--examples/blockStreaming_ringBuffer.c22
2 files changed, 30 insertions, 17 deletions
diff --git a/examples/HCStreaming_ringBuffer.c b/examples/HCStreaming_ringBuffer.c
index 53e14cac..afe77ae6 100755..100644
--- a/examples/HCStreaming_ringBuffer.c
+++ b/examples/HCStreaming_ringBuffer.c
@@ -3,8 +3,8 @@
/**************************************
-Compiler Options
-**************************************/
+ * Compiler Options
+ **************************************/
#ifdef _MSC_VER /* Visual Studio */
# define _CRT_SECURE_NO_WARNINGS // for MSVC
# define snprintf sprintf_s
@@ -16,10 +16,9 @@ Compiler Options
#endif
-
/**************************************
-Includes
-**************************************/
+ * Includes
+ **************************************/
#include "lz4hc.h"
#include "lz4.h"
@@ -98,7 +97,7 @@ void test_decompress(FILE* outFp, FILE* inpFp)
LZ4_streamDecode_t* lz4StreamDecode = &lz4StreamDecode_body;
unsigned done = 0;
- for(;;)
+ for(;;)
{
int cmpBytes = 0;
char cmpBuf[LZ4_COMPRESSBOUND(MESSAGE_MAX_BYTES)];
@@ -106,11 +105,11 @@ void test_decompress(FILE* outFp, FILE* inpFp)
{
const size_t r0 = read_int32(inpFp, &cmpBytes);
size_t r1;
- if(r0 != 1 || cmpBytes <= 0)
+ if(r0 != 1 || cmpBytes <= 0)
break;
r1 = read_bin(inpFp, cmpBuf, cmpBytes);
- if(r1 != (size_t) cmpBytes)
+ if(r1 != (size_t) cmpBytes)
break;
}
@@ -118,7 +117,7 @@ void test_decompress(FILE* outFp, FILE* inpFp)
char* const decPtr = &decBuf[decOffset];
const int decBytes = LZ4_decompress_safe_continue(
lz4StreamDecode, cmpBuf, decPtr, cmpBytes, MESSAGE_MAX_BYTES);
- if(decBytes <= 0)
+ if(decBytes <= 0)
break;
done += decBytes;
@@ -126,7 +125,7 @@ void test_decompress(FILE* outFp, FILE* inpFp)
write_bin(outFp, decPtr, decBytes);
// Wraparound the ringbuffer offset
- if(decOffset >= DEC_BUFFER_BYTES - MESSAGE_MAX_BYTES)
+ if(decOffset >= DEC_BUFFER_BYTES - MESSAGE_MAX_BYTES)
decOffset = 0;
}
}
@@ -192,9 +191,9 @@ int main(int argc, char** argv)
snprintf(lz4Filename, 256, "%s.lz4s-%d", argv[fileID], 9);
snprintf(decFilename, 256, "%s.lz4s-%d.dec", argv[fileID], 9);
- printf("inp = [%s]\n", inpFilename);
- printf("lz4 = [%s]\n", lz4Filename);
- printf("dec = [%s]\n", decFilename);
+ printf("input = [%s]\n", inpFilename);
+ printf("lz4 = [%s]\n", lz4Filename);
+ printf("decoded = [%s]\n", decFilename);
// compress
{
diff --git a/examples/blockStreaming_ringBuffer.c b/examples/blockStreaming_ringBuffer.c
index bfdbed1b..eda721f1 100644
--- a/examples/blockStreaming_ringBuffer.c
+++ b/examples/blockStreaming_ringBuffer.c
@@ -1,18 +1,32 @@
// LZ4 streaming API example : ring buffer
-// Copyright : Takayuki Matsuoka
+// Based on sample code from Takayuki Matsuoka
-#define _CRT_SECURE_NO_WARNINGS // for MSVC
-#include "lz4.h"
+/**************************************
+ * Compiler Options
+ **************************************/
+#ifdef _MSC_VER /* Visual Studio */
+# define _CRT_SECURE_NO_WARNINGS // for MSVC
+# define snprintf sprintf_s
+#endif
+#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) */
+#endif
+
+/**************************************
+ * Includes
+ **************************************/
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
+#include "lz4.h"
+
enum {
MESSAGE_MAX_BYTES = 1024,
- RING_BUFFER_BYTES = 1024 * 256 + MESSAGE_MAX_BYTES,
+ RING_BUFFER_BYTES = 1024 * 8 + MESSAGE_MAX_BYTES,
DICT_BYTES = 65536,
};