#include <lzo/lzoconf.h>
#include <lzo/lzo1x.h>
static const char *progname = NULL;
#define WANT_LZO_MALLOC 1
#define WANT_XMALLOC 1
#include "examples/portab.h"
#ifndef IN_LEN
#define IN_LEN (128*1024L)
#endif
#define OUT_LEN (IN_LEN + IN_LEN / 16 + 64 + 3)
int __lzo_cdecl_main main(int argc, char *argv[])
{
int r;
lzo_bytep in;
lzo_bytep out;
lzo_voidp wrkmem;
lzo_uint in_len;
lzo_uint out_len;
lzo_uint new_len;
if (argc < 0 && argv == NULL)
return 0;
printf("\nLZO real-time data compression library (v%s, %s).\n",
lzo_version_string(), lzo_version_date());
printf("Copyright (C) 1996-2017 Markus Franz Xaver Johannes Oberhumer\nAll Rights Reserved.\n\n");
if (lzo_init() != LZO_E_OK)
{
printf("internal error - lzo_init() failed !!!\n");
printf("(this usually indicates a compiler bug - try recompiling\nwithout optimizations, and enable '-DLZO_DEBUG' for diagnostics)\n");
return 4;
}
in = (lzo_bytep) xmalloc(IN_LEN);
out = (lzo_bytep) xmalloc(OUT_LEN);
wrkmem = (lzo_voidp) xmalloc(LZO1X_1_MEM_COMPRESS);
if (in == NULL || out == NULL || wrkmem == NULL)
{
printf("out of memory\n");
return 3;
}
in_len = IN_LEN;
lzo_memset(in,0,in_len);
r = lzo1x_1_compress(in, in_len, out, &out_len, wrkmem);
if (r == LZO_E_OK)
printf("compressed %lu bytes into %lu bytes\n",
(unsigned long) in_len, (unsigned long) out_len);
else
{
printf("internal error - compression failed: %d\n", r);
return 2;
}
if (out_len >= in_len)
{
printf("This block contains incompressible data.\n");
return 0;
}
new_len = in_len;
r = lzo1x_decompress(out, out_len, in, &new_len, NULL);
if (r == LZO_E_OK && new_len == in_len)
printf("decompressed %lu bytes back into %lu bytes\n",
(unsigned long) out_len, (unsigned long) in_len);
else
{
printf("internal error - decompression failed: %d\n", r);
return 1;
}
lzo_free(wrkmem);
lzo_free(out);
lzo_free(in);
printf("Simple compression test passed.\n");
return 0;
}