1592N/A/*
1592N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1592N/A *
1592N/A * This code is free software; you can redistribute it and/or modify it
1592N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
1592N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
1592N/A *
1592N/A * This code is distributed in the hope that it will be useful, but WITHOUT
1592N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1592N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1592N/A * version 2 for more details (a copy is included in the LICENSE file that
1592N/A * accompanied this code).
1592N/A *
1592N/A * You should have received a copy of the GNU General Public License version
1592N/A * 2 along with this work; if not, write to the Free Software Foundation,
1592N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1592N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
1592N/A */
1592N/A
1592N/A/* compress.c -- compress a memory buffer
1592N/A * Copyright (C) 1995-2003 Jean-loup Gailly.
1592N/A * For conditions of distribution and use, see copyright notice in zlib.h
1592N/A */
1592N/A
1592N/A/* @(#) $Id$ */
1592N/A
1592N/A#define ZLIB_INTERNAL
1592N/A#include "zlib.h"
1592N/A
1592N/A/* ===========================================================================
1592N/A Compresses the source buffer into the destination buffer. The level
1592N/A parameter has the same meaning as in deflateInit. sourceLen is the byte
1592N/A length of the source buffer. Upon entry, destLen is the total size of the
1592N/A destination buffer, which must be at least 0.1% larger than sourceLen plus
1592N/A 12 bytes. Upon exit, destLen is the actual size of the compressed buffer.
1592N/A
1592N/A compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
1592N/A memory, Z_BUF_ERROR if there was not enough room in the output buffer,
1592N/A Z_STREAM_ERROR if the level parameter is invalid.
1592N/A*/
1592N/Aint ZEXPORT compress2 (dest, destLen, source, sourceLen, level)
1592N/A Bytef *dest;
1592N/A uLongf *destLen;
1592N/A const Bytef *source;
1592N/A uLong sourceLen;
1592N/A int level;
1592N/A{
1592N/A z_stream stream;
1592N/A int err;
1592N/A
1592N/A stream.next_in = (Bytef*)source;
1592N/A stream.avail_in = (uInt)sourceLen;
1592N/A#ifdef MAXSEG_64K
1592N/A /* Check for source > 64K on 16-bit machine: */
1592N/A if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
1592N/A#endif
1592N/A stream.next_out = dest;
1592N/A stream.avail_out = (uInt)*destLen;
1592N/A if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
1592N/A
1592N/A stream.zalloc = (alloc_func)0;
1592N/A stream.zfree = (free_func)0;
1592N/A stream.opaque = (voidpf)0;
1592N/A
1592N/A err = deflateInit(&stream, level);
1592N/A if (err != Z_OK) return err;
1592N/A
1592N/A err = deflate(&stream, Z_FINISH);
1592N/A if (err != Z_STREAM_END) {
1592N/A deflateEnd(&stream);
1592N/A return err == Z_OK ? Z_BUF_ERROR : err;
1592N/A }
5352N/A *destLen = stream.total_out;
1592N/A
1592N/A err = deflateEnd(&stream);
1592N/A return err;
1592N/A}
1592N/A
1592N/A/* ===========================================================================
1592N/A */
1592N/Aint ZEXPORT compress (dest, destLen, source, sourceLen)
1592N/A Bytef *dest;
1592N/A uLongf *destLen;
1592N/A const Bytef *source;
1592N/A uLong sourceLen;
1592N/A{
1592N/A return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
1592N/A}
1592N/A
1592N/A/* ===========================================================================
1592N/A If the default memLevel or windowBits for deflateInit() is changed, then
1592N/A this function needs to be updated.
1592N/A */
1592N/AuLong ZEXPORT compressBound (sourceLen)
1592N/A uLong sourceLen;
1592N/A{
1592N/A return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + 11;
1592N/A}