summaryrefslogtreecommitdiff
path: root/examples/precomp.c
diff options
context:
space:
mode:
authorKévin THIERRY <kevin.thierry@open.eurogiciel.org>2014-12-23 14:06:25 +0100
committerKévin THIERRY <kevin.thierry@open.eurogiciel.org>2014-12-23 14:06:25 +0100
commit79a9578a33ecd3093970bd18df677edc9214fafb (patch)
tree8ae5c6780a1fcd2124e71f27ad9b4256acd24268 /examples/precomp.c
parent1bb1ce141783168d44a38cd1bb6b822eb13114fc (diff)
downloadlzo-79a9578a33ecd3093970bd18df677edc9214fafb.tar.gz
lzo-79a9578a33ecd3093970bd18df677edc9214fafb.tar.bz2
lzo-79a9578a33ecd3093970bd18df677edc9214fafb.zip
Imported Upstream version 2.08upstream/2.08sandbox/kevinthierry/upstream
Diffstat (limited to 'examples/precomp.c')
-rw-r--r--examples/precomp.c77
1 files changed, 31 insertions, 46 deletions
diff --git a/examples/precomp.c b/examples/precomp.c
index 10f4e7f..01b1e77 100644
--- a/examples/precomp.c
+++ b/examples/precomp.c
@@ -2,19 +2,7 @@
This file is part of the LZO real-time data compression library.
- Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer
- Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer
- Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer
- Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer
- Copyright (C) 2004 Markus Franz Xaver Johannes Oberhumer
- Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer
- Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer
- Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer
- Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer
- Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer
- Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer
- Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer
- Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer
+ Copyright (C) 1996-2014 Markus Franz Xaver Johannes Oberhumer
All Rights Reserved.
The LZO library is free software; you can redistribute it and/or
@@ -58,9 +46,11 @@
/* 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"
@@ -79,18 +69,17 @@ int __lzo_cdecl_main main(int argc, char *argv[])
lzo_uint out_bufsize;
lzo_uint out_len = 0;
- lzo_bytep wrkmem;
- lzo_uint wrk_len;
+ lzo_voidp wrkmem;
+ lzo_uint wrkmem_size;
lzo_uint best_len;
int best_compress = -1;
lzo_uint orig_len;
- lzo_uint32 uncompressed_checksum;
- lzo_uint32 compressed_checksum;
+ lzo_uint32_t uncompressed_checksum;
+ lzo_uint32_t compressed_checksum;
- FILE *f;
- const char *progname = NULL;
+ FILE *fp;
const char *in_name = NULL;
const char *out_name = NULL;
long l;
@@ -100,7 +89,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-2014 Markus Franz Xaver Johannes Oberhumer\nAll Rights Reserved.\n\n");
progname = argv[0];
if (argc < 2 || argc > 3)
@@ -117,23 +106,21 @@ 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);
}
/*
* Step 2: allocate the work-memory
*/
- wrk_len = 1;
+ wrkmem_size = 1;
#ifdef USE_LZO1X
- if (wrk_len < LZO1X_999_MEM_COMPRESS)
- wrk_len = LZO1X_999_MEM_COMPRESS;
+ wrkmem_size = (LZO1X_999_MEM_COMPRESS > wrkmem_size) ? LZO1X_999_MEM_COMPRESS : wrkmem_size;
#endif
#ifdef USE_LZO1Y
- if (wrk_len < LZO1Y_999_MEM_COMPRESS)
- wrk_len = LZO1Y_999_MEM_COMPRESS;
+ wrkmem_size = (LZO1Y_999_MEM_COMPRESS > wrkmem_size) ? LZO1Y_999_MEM_COMPRESS : wrkmem_size;
#endif
- wrkmem = (lzo_bytep) lzo_malloc(wrk_len);
+ wrkmem = (lzo_voidp) xmalloc(wrkmem_size);
if (wrkmem == NULL)
{
printf("%s: out of memory\n", progname);
@@ -143,19 +130,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;
@@ -165,16 +152,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
@@ -183,7 +170,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
out_len = out_bufsize;
@@ -203,7 +190,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
out_len = out_bufsize;
@@ -245,7 +232,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
@@ -287,13 +274,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);
@@ -339,7 +326,5 @@ int __lzo_cdecl_main main(int argc, char *argv[])
return 0;
}
-/*
-vi:ts=4:et
-*/
+/* vim:set ts=4 sw=4 et: */