summaryrefslogtreecommitdiff
path: root/lzo/examples/precomp2.c
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2012-07-02 17:28:05 +0200
committerArne Schwabe <arne@rfc2549.org>2012-07-02 17:28:05 +0200
commitace5e90b3dbc33f0fc34ac2f3dc40d3c990a6a11 (patch)
tree0b5cda436e04ee29efb5220da5634d04455c65c0 /lzo/examples/precomp2.c
parent78172a10165a969b8c002b6bdcf9dc47fa6cd5f3 (diff)
Update lzo version
Diffstat (limited to 'lzo/examples/precomp2.c')
-rw-r--r--lzo/examples/precomp2.c48
1 files changed, 26 insertions, 22 deletions
diff --git a/lzo/examples/precomp2.c b/lzo/examples/precomp2.c
index 44b066a5..d9e1b47b 100644
--- a/lzo/examples/precomp2.c
+++ b/lzo/examples/precomp2.c
@@ -2,6 +2,9 @@
This file is part of the LZO real-time data compression library.
+ Copyright (C) 2011 Markus Franz Xaver Johannes Oberhumer
+ Copyright (C) 2010 Markus Franz Xaver Johannes Oberhumer
+ Copyright (C) 2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer
@@ -87,9 +90,11 @@ lzo1y_999_compress_internal ( const lzo_bytep in , lzo_uint in_len,
/* portability layer */
+static const char *progname = NULL;
#define WANT_LZO_MALLOC 1
#define WANT_LZO_FREAD 1
#define WANT_LZO_WILDARGV 1
+#define WANT_XMALLOC 1
#include "examples/portab.h"
@@ -112,7 +117,7 @@ int __lzo_cdecl_main main(int argc, char *argv[])
lzo_uint out_bufsize;
lzo_uint out_len = 0;
- lzo_bytep wrkmem;
+ lzo_voidp wrkmem;
lzo_uint wrk_len;
lzo_uint best_len;
@@ -123,8 +128,7 @@ int __lzo_cdecl_main main(int argc, char *argv[])
lzo_uint32 uncompressed_checksum;
lzo_uint32 compressed_checksum;
- FILE *f;
- const char *progname = NULL;
+ FILE *fp;
const char *in_name = NULL;
const char *out_name = NULL;
long l;
@@ -134,7 +138,7 @@ int __lzo_cdecl_main main(int argc, char *argv[])
printf("\nLZO real-time data compression library (v%s, %s).\n",
lzo_version_string(), lzo_version_date());
- printf("Copyright (C) 1996-2008 Markus Franz Xaver Johannes Oberhumer\nAll Rights Reserved.\n\n");
+ printf("Copyright (C) 1996-2011 Markus Franz Xaver Johannes Oberhumer\nAll Rights Reserved.\n\n");
progname = argv[0];
if (argc < 2 || argc > 3)
@@ -151,7 +155,7 @@ int __lzo_cdecl_main main(int argc, char *argv[])
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");
+ printf("(this usually indicates a compiler bug - try recompiling\nwithout optimizations, and enable '-DLZO_DEBUG' for diagnostics)\n");
exit(1);
}
@@ -167,7 +171,7 @@ int __lzo_cdecl_main main(int argc, char *argv[])
if (wrk_len < LZO1Y_999_MEM_COMPRESS)
wrk_len = LZO1Y_999_MEM_COMPRESS;
#endif
- wrkmem = (lzo_bytep) lzo_malloc(wrk_len);
+ wrkmem = (lzo_voidp) xmalloc(wrk_len);
if (wrkmem == NULL)
{
printf("%s: out of memory\n", progname);
@@ -177,19 +181,19 @@ int __lzo_cdecl_main main(int argc, char *argv[])
/*
* Step 3: open the input file
*/
- f = fopen(in_name,"rb");
- if (f == NULL)
+ fp = fopen(in_name,"rb");
+ if (fp == NULL)
{
printf("%s: cannot open file %s\n", progname, in_name);
exit(1);
}
- fseek(f,0,SEEK_END);
- l = ftell(f);
- fseek(f,0,SEEK_SET);
+ fseek(fp, 0, SEEK_END);
+ l = ftell(fp);
+ fseek(fp, 0, SEEK_SET);
if (l <= 0)
{
printf("%s: %s: empty file\n", progname, in_name);
- fclose(f);
+ fclose(fp); fp = NULL;
exit(1);
}
in_len = (lzo_uint) l;
@@ -199,16 +203,16 @@ int __lzo_cdecl_main main(int argc, char *argv[])
/*
* Step 4: allocate compression buffers and read the file
*/
- in = (lzo_bytep) lzo_malloc(in_len);
- out = (lzo_bytep) lzo_malloc(out_bufsize);
+ in = (lzo_bytep) xmalloc(in_len);
+ out = (lzo_bytep) xmalloc(out_bufsize);
if (in == NULL || out == NULL)
{
printf("%s: out of memory\n", progname);
exit(1);
}
- in_len = (lzo_uint) lzo_fread(f,in,in_len);
+ in_len = (lzo_uint) lzo_fread(fp, in, in_len);
printf("%s: loaded file %s: %ld bytes\n", progname, in_name, (long) in_len);
- fclose(f);
+ fclose(fp); fp = NULL;
/*
* Step 5: compute a checksum of the uncompressed data
@@ -217,7 +221,7 @@ int __lzo_cdecl_main main(int argc, char *argv[])
uncompressed_checksum = lzo_adler32(uncompressed_checksum,in,in_len);
/*
- * Step 6a: compress from `in' to `out' with LZO1X-999
+ * Step 6a: compress from 'in' to 'out' with LZO1X-999
*/
#ifdef USE_LZO1X
for (lazy = 0; lazy <= max_try_lazy; lazy++)
@@ -244,7 +248,7 @@ int __lzo_cdecl_main main(int argc, char *argv[])
#endif /* USE_LZO1X */
/*
- * Step 6b: compress from `in' to `out' with LZO1Y-999
+ * Step 6b: compress from 'in' to 'out' with LZO1Y-999
*/
#ifdef USE_LZO1Y
for (lazy = 0; lazy <= max_try_lazy; lazy++)
@@ -297,7 +301,7 @@ int __lzo_cdecl_main main(int argc, char *argv[])
assert(out_len == best_len);
/*
- * Step 9: optimize compressed data (compressed data is in `out' buffer)
+ * Step 9: optimize compressed data (compressed data is in 'out' buffer)
*/
#if 1
/* Optimization does not require any data in the buffer that will
@@ -339,13 +343,13 @@ int __lzo_cdecl_main main(int argc, char *argv[])
if (out_name && out_name[0])
{
printf("%s: writing to file %s\n", progname, out_name);
- f = fopen(out_name,"wb");
- if (f == NULL)
+ fp = fopen(out_name,"wb");
+ if (fp == NULL)
{
printf("%s: cannot open output file %s\n", progname, out_name);
exit(1);
}
- if (lzo_fwrite(f,out,out_len) != out_len || fclose(f) != 0)
+ if (lzo_fwrite(fp, out, out_len) != out_len || fclose(fp) != 0)
{
printf("%s: write error !!\n", progname);
exit(1);