--- /dev/null
+/* uncompr.c -- decompress a memory buffer\r
+ * Copyright (C) 1995-2003, 2010 Jean-loup Gailly.\r
+ * For conditions of distribution and use, see copyright notice in zlib.h\r
+ */\r
+\r
+/* @(#) $Id$ */\r
+\r
+#define ZLIB_INTERNAL\r
+#include "zlib.h"\r
+\r
+/* ===========================================================================\r
+ Decompresses the source buffer into the destination buffer. sourceLen is\r
+ the byte length of the source buffer. Upon entry, destLen is the total\r
+ size of the destination buffer, which must be large enough to hold the\r
+ entire uncompressed data. (The size of the uncompressed data must have\r
+ been saved previously by the compressor and transmitted to the decompressor\r
+ by some mechanism outside the scope of this compression library.)\r
+ Upon exit, destLen is the actual size of the compressed buffer.\r
+\r
+ uncompress returns Z_OK if success, Z_MEM_ERROR if there was not\r
+ enough memory, Z_BUF_ERROR if there was not enough room in the output\r
+ buffer, or Z_DATA_ERROR if the input data was corrupted.\r
+*/\r
+int ZEXPORT uncompress (dest, destLen, source, sourceLen)\r
+ Bytef *dest;\r
+ uLongf *destLen;\r
+ const Bytef *source;\r
+ uLong sourceLen;\r
+{\r
+ z_stream stream;\r
+ int err;\r
+\r
+ stream.next_in = (z_const Bytef *)source;\r
+ stream.avail_in = (uInt)sourceLen;\r
+ /* Check for source > 64K on 16-bit machine: */\r
+ if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;\r
+\r
+ stream.next_out = dest;\r
+ stream.avail_out = (uInt)*destLen;\r
+ if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;\r
+\r
+ stream.zalloc = (alloc_func)0;\r
+ stream.zfree = (free_func)0;\r
+\r
+ err = inflateInit(&stream);\r
+ if (err != Z_OK) return err;\r
+\r
+ err = inflate(&stream, Z_FINISH);\r
+ if (err != Z_STREAM_END) {\r
+ inflateEnd(&stream);\r
+ if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0))\r
+ return Z_DATA_ERROR;\r
+ return err;\r
+ }\r
+ *destLen = stream.total_out;\r
+\r
+ err = inflateEnd(&stream);\r
+ return err;\r
+}\r