uncompr.c

00001 /* uncompr.c -- decompress a memory buffer
00002  * Copyright (C) 1995-2002 Jean-loup Gailly.
00003  * For conditions of distribution and use, see copyright notice in zlib.h 
00004  */
00005 
00006 /* @(#) $Id: uncompr.c,v 1.1 2003/11/09 01:37:56 gabest Exp $ */
00007 
00008 #include "zlib.h"
00009 
00010 /* ===========================================================================
00011      Decompresses the source buffer into the destination buffer.  sourceLen is
00012    the byte length of the source buffer. Upon entry, destLen is the total
00013    size of the destination buffer, which must be large enough to hold the
00014    entire uncompressed data. (The size of the uncompressed data must have
00015    been saved previously by the compressor and transmitted to the decompressor
00016    by some mechanism outside the scope of this compression library.)
00017    Upon exit, destLen is the actual size of the compressed buffer.
00018      This function can be used to decompress a whole file at once if the
00019    input file is mmap'ed.
00020 
00021      uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
00022    enough memory, Z_BUF_ERROR if there was not enough room in the output
00023    buffer, or Z_DATA_ERROR if the input data was corrupted.
00024 */
00025 int ZEXPORT uncompress (dest, destLen, source, sourceLen)
00026     Bytef *dest;
00027     uLongf *destLen;
00028     const Bytef *source;
00029     uLong sourceLen;
00030 {
00031     z_stream stream;
00032     int err;
00033 
00034     stream.next_in = (Bytef*)source;
00035     stream.avail_in = (uInt)sourceLen;
00036     /* Check for source > 64K on 16-bit machine: */
00037     if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
00038 
00039     stream.next_out = dest;
00040     stream.avail_out = (uInt)*destLen;
00041     if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
00042 
00043     stream.zalloc = (alloc_func)0;
00044     stream.zfree = (free_func)0;
00045 
00046     err = inflateInit(&stream);
00047     if (err != Z_OK) return err;
00048 
00049     err = inflate(&stream, Z_FINISH);
00050     if (err != Z_STREAM_END) {
00051         inflateEnd(&stream);
00052         return err == Z_OK ? Z_BUF_ERROR : err;
00053     }
00054     *destLen = stream.total_out;
00055 
00056     err = inflateEnd(&stream);
00057     return err;
00058 }

Generated on Tue Dec 13 14:48:00 2005 for guliverkli by  doxygen 1.4.5