Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

uncompr.c

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

Generated on Thu Dec 15 10:39:54 2005 for Shareaza 2.2.1.0 by  doxygen 1.4.2