41 const char*
const src =
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor site amat.";
43 const int src_size = (
int)(strlen(
src) + 1);
47 char* compressed_data =
malloc((
size_t)max_dst_size);
48 if (compressed_data ==
NULL)
49 run_screaming(
"Failed to allocate memory for *compressed_data.", 1);
55 if (compressed_data_size <= 0)
56 run_screaming(
"A 0 or negative result from LZ4_compress_default() indicates a failure trying to compress the data. ", 1);
57 if (compressed_data_size > 0)
58 printf(
"We successfully compressed some data! Ratio: %.2f\n",
59 (
float) compressed_data_size/src_size);
62 compressed_data = (
char *)
realloc(compressed_data, (
size_t)compressed_data_size);
63 if (compressed_data ==
NULL)
64 run_screaming(
"Failed to re-alloc memory for compressed_data. Sad :(", 1);
76 char*
const regen_buffer =
malloc(src_size);
77 if (regen_buffer ==
NULL)
78 run_screaming(
"Failed to allocate memory for *regen_buffer.", 1);
82 const int decompressed_size =
LZ4_decompress_safe(compressed_data, regen_buffer, compressed_data_size, src_size);
83 free(compressed_data);
84 if (decompressed_size < 0)
85 run_screaming(
"A negative result from LZ4_decompress_safe indicates a failure trying to decompress the data. See exit code (echo $?) for value returned.", decompressed_size);
86 if (decompressed_size >= 0)
87 printf(
"We successfully decompressed some data!\n");
90 if (decompressed_size != src_size)
91 run_screaming(
"Decompressed data is different from original! \n", 1);
95 if (memcmp(
src, regen_buffer, src_size) != 0)
96 run_screaming(
"Validation failed. *src and *new_src are not identical.", 1);
97 printf(
"Validation done. The string we ended up with is:\n%s\n", regen_buffer);
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
RZ_API void Ht_() free(HtName_(Ht) *ht)
void * realloc(void *ptr, size_t size)
void * malloc(size_t size)
int LZ4_compressBound(int isize)
int LZ4_compress_default(const char *src, char *dst, int srcSize, int maxOutputSize)
LZ4_FORCE_O2 int LZ4_decompress_safe(const char *source, char *dest, int compressedSize, int maxDecompressedSize)
void run_screaming(const char *message, const int code)