5 #if defined(_MSC_VER) && (_MSC_VER <= 1800)
6 # define _CRT_SECURE_NO_WARNINGS
7 # define snprintf sprintf_s
18 return fwrite(&
i,
sizeof(
i), 1, fp);
23 return fwrite(array, 1, arrayBytes, fp);
28 return fread(
i,
sizeof(*
i), 1, fp);
33 return fread(array, 1, arrayBytes, fp);
40 size_t messageMaxBytes,
41 size_t ringBufferBytes)
45 char*
const cmpBuf = (
char*)
malloc(cmpBufBytes);
46 char*
const inpBuf = (
char*)
malloc(ringBufferBytes);
51 char*
const inpPtr = &inpBuf[inpOffset];
55 const int randomLength = (rand() % messageMaxBytes) + 1;
56 const int inpBytes = (
int)
read_bin(inpFp, inpPtr, randomLength);
57 if (0 == inpBytes)
break;
61 if (!fgets(inpPtr, (
int) messageMaxBytes, inpFp))
63 inpBytes = (
int) strlen(inpPtr);
68 lz4Stream, inpPtr, cmpBuf, inpBytes, cmpBufBytes, 1);
69 if (cmpBytes <= 0)
break;
74 inpOffset += inpBytes;
75 if ((
size_t)inpOffset >= ringBufferBytes - messageMaxBytes) inpOffset = 0;
89 size_t messageMaxBytes,
90 size_t ringBufferBytes)
94 char*
const decBuf = (
char*)
malloc(ringBufferBytes);
102 if (cmpBytes == 0)
break;
103 if (
read_bin(inpFp, cmpBuf, cmpBytes) != cmpBytes)
break;
106 char*
const decPtr = &decBuf[decOffset];
108 lz4StreamDecode, cmpBuf, decPtr, cmpBytes, (
int) messageMaxBytes);
109 if (decBytes <= 0)
break;
113 decOffset += decBytes;
114 if ((
size_t)decOffset >= ringBufferBytes - messageMaxBytes) decOffset = 0;
127 const size_t tempBufferBytes = 65536;
128 char*
const b0 = (
char*)
malloc(tempBufferBytes);
129 char*
const b1 = (
char*)
malloc(tempBufferBytes);
133 const size_t r0 = fread(b0, 1, tempBufferBytes,
f0);
134 const size_t r1 = fread(
b1, 1, tempBufferBytes,
f1);
138 if (0 ==
r0 || 0 ==
r1)
break;
139 if (0 == result) result = memcmp(b0,
b1,
r0);
155 char inpFilename[256] = { 0 };
156 char lz4Filename[256] = { 0 };
157 char decFilename[256] = { 0 };
161 printf(
"Please specify input filename\n");
169 printf(
"inp = [%s]\n", inpFilename);
170 printf(
"lz4 = [%s]\n", lz4Filename);
171 printf(
"dec = [%s]\n", decFilename);
175 FILE* inpFp = fopen(inpFilename,
"rb");
176 FILE* outFp = fopen(lz4Filename,
"wb");
186 FILE* inpFp = fopen(lz4Filename,
"rb");
187 FILE* outFp = fopen(decFilename,
"wb");
197 FILE* inpFp = fopen(inpFilename,
"rb");
198 FILE* decFp = fopen(decFilename,
"rb");
static RzILOpEffect * cmp(cs_insn *insn, bool is_thumb)
int main(int argc, char *argv[])
static void test_compress(FILE *outFp, FILE *inpFp, size_t messageMaxBytes, size_t ringBufferBytes)
static size_t write_bin(FILE *fp, const void *array, int arrayBytes)
static size_t write_uint16(FILE *fp, uint16_t i)
static void test_decompress(FILE *outFp, FILE *inpFp, size_t messageMaxBytes, size_t ringBufferBytes)
static int compare(FILE *f0, FILE *f1)
static size_t read_uint16(FILE *fp, uint16_t *i)
static size_t read_bin(FILE *fp, void *array, int arrayBytes)
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
RZ_API void Ht_() free(HtName_(Ht) *ht)
void * malloc(size_t size)
static static fork const void static count static fd const char const char static newpath char char argv
LZ4_stream_t * LZ4_createStream(void)
LZ4_streamDecode_t * LZ4_createStreamDecode(void)
int LZ4_freeStream(LZ4_stream_t *LZ4_stream)
LZ4_FORCE_O2 int LZ4_decompress_safe_continue(LZ4_streamDecode_t *LZ4_streamDecode, const char *source, char *dest, int compressedSize, int maxOutputSize)
int LZ4_compress_fast_continue(LZ4_stream_t *LZ4_stream, const char *source, char *dest, int inputSize, int maxOutputSize, int acceleration)
int LZ4_freeStreamDecode(LZ4_streamDecode_t *LZ4_stream)
#define LZ4_COMPRESSBOUND(isize)