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/* uncompr.c -- decompress 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 Decompresses the source buffer into the destination buffer. sourceLen is
1592N/A the byte length of the source buffer. Upon entry, destLen is the total
1592N/A size of the destination buffer, which must be large enough to hold the
1592N/A entire uncompressed data. (The size of the uncompressed data must have
1592N/A been saved previously by the compressor and transmitted to the decompressor
1592N/A by some mechanism outside the scope of this compression library.)
1592N/A Upon exit, destLen is the actual size of the compressed buffer.
1592N/A This function can be used to decompress a whole file at once if the
1592N/A input file is mmap'ed.
1592N/A
1592N/A uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
1592N/A enough memory, Z_BUF_ERROR if there was not enough room in the output
1592N/A buffer, or Z_DATA_ERROR if the input data was corrupted.
1592N/A*/
1592N/Aint ZEXPORT uncompress (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 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 /* Check for source > 64K on 16-bit machine: */
1592N/A if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
1592N/A
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
1592N/A err = inflateInit(&stream);
1592N/A if (err != Z_OK) return err;
1592N/A
1592N/A err = inflate(&stream, Z_FINISH);
1592N/A if (err != Z_STREAM_END) {
1592N/A inflateEnd(&stream);
1592N/A if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0))
1592N/A return Z_DATA_ERROR;
1592N/A return err;
1592N/A }
3115N/A *destLen = (uLong)stream.total_out;
1592N/A
1592N/A err = inflateEnd(&stream);
1592N/A return err;
1592N/A}