1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/compressionlibs/ziplib/test/oldezlib/Zlib/compress.c Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,59 @@
1.4 +/* compress.c -- compress a memory buffer
1.5 + * Copyright (C) 1995-1998 Jean-loup Gailly.
1.6 + * For conditions of distribution and use, see copyright notice in zlib.h
1.7 + */
1.8 +
1.9 +/* @(#) $Id$ */
1.10 +
1.11 +#include "zlib.h"
1.12 +
1.13 +/* ===========================================================================
1.14 + Compresses the source buffer into the destination buffer. The level
1.15 + parameter has the same meaning as in deflateInit. sourceLen is the byte
1.16 + length of the source buffer. Upon entry, destLen is the total size of the
1.17 + destination buffer, which must be at least 0.1% larger than sourceLen plus
1.18 + 12 bytes. Upon exit, destLen is the actual size of the compressed buffer.
1.19 +
1.20 + compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
1.21 + memory, Z_BUF_ERROR if there was not enough room in the output buffer,
1.22 + Z_STREAM_ERROR if the level parameter is invalid.
1.23 +*/
1.24 +int ZEXPORT compress2 (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen, int level)
1.25 +{
1.26 + z_stream stream;
1.27 + int err;
1.28 +
1.29 + stream.next_in = (Bytef*)source;
1.30 + stream.avail_in = (uInt)sourceLen;
1.31 +#ifdef MAXSEG_64K
1.32 + /* Check for source > 64K on 16-bit machine: */
1.33 + if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
1.34 +#endif
1.35 + stream.next_out = dest;
1.36 + stream.avail_out = (uInt)*destLen;
1.37 + if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
1.38 +
1.39 + stream.zalloc = (alloc_func)0;
1.40 + stream.zfree = (free_func)0;
1.41 + stream.opaque = (voidpf)0;
1.42 +
1.43 + err = deflateInit(&stream, level);
1.44 + if (err != Z_OK) return err;
1.45 +
1.46 + err = deflate(&stream, Z_FINISH);
1.47 + if (err != Z_STREAM_END) {
1.48 + deflateEnd(&stream);
1.49 + return err == Z_OK ? Z_BUF_ERROR : err;
1.50 + }
1.51 + *destLen = stream.total_out;
1.52 +
1.53 + err = deflateEnd(&stream);
1.54 + return err;
1.55 +}
1.56 +
1.57 +/* ===========================================================================
1.58 + */
1.59 +int ZEXPORT compress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)
1.60 +{
1.61 + return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
1.62 +}