summaryrefslogtreecommitdiffstats
path: root/Utilities/cmzlib/uncompr.c
diff options
context:
space:
mode:
authorAndy Cedilnik <andy.cedilnik@kitware.com>2005-01-26 20:55:12 (GMT)
committerAndy Cedilnik <andy.cedilnik@kitware.com>2005-01-26 20:55:12 (GMT)
commit0e4571d25c0f5ef1407c3678521ea26a6fc71f1f (patch)
treea3eafcef58d9b123a0046bc0fbdab5bdb6555889 /Utilities/cmzlib/uncompr.c
parent483534f1a3274da6c200a9471fec116b55274900 (diff)
downloadCMake-0e4571d25c0f5ef1407c3678521ea26a6fc71f1f.zip
CMake-0e4571d25c0f5ef1407c3678521ea26a6fc71f1f.tar.gz
CMake-0e4571d25c0f5ef1407c3678521ea26a6fc71f1f.tar.bz2
ENH: Initial import from VTK
Diffstat (limited to 'Utilities/cmzlib/uncompr.c')
-rw-r--r--Utilities/cmzlib/uncompr.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/Utilities/cmzlib/uncompr.c b/Utilities/cmzlib/uncompr.c
new file mode 100644
index 0000000..08f8046
--- /dev/null
+++ b/Utilities/cmzlib/uncompr.c
@@ -0,0 +1,61 @@
+/* uncompr.c -- decompress a memory buffer
+ * Copyright (C) 1995-2002 Jean-loup Gailly.
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/* @(#) $Id$ */
+
+#if defined(_MSC_VER)
+#pragma warning ( disable : 4702 )
+#endif
+#include "zlib.h"
+
+/* ===========================================================================
+ Decompresses the source buffer into the destination buffer. sourceLen is
+ the byte length of the source buffer. Upon entry, destLen is the total
+ size of the destination buffer, which must be large enough to hold the
+ entire uncompressed data. (The size of the uncompressed data must have
+ been saved previously by the compressor and transmitted to the decompressor
+ by some mechanism outside the scope of this compression library.)
+ Upon exit, destLen is the actual size of the compressed buffer.
+ This function can be used to decompress a whole file at once if the
+ input file is mmap'ed.
+
+ uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
+ enough memory, Z_BUF_ERROR if there was not enough room in the output
+ buffer, or Z_DATA_ERROR if the input data was corrupted.
+*/
+int ZEXPORT uncompress (dest, destLen, source, sourceLen)
+ Bytef *dest;
+ uLongf *destLen;
+ const Bytef *source;
+ uLong sourceLen;
+{
+ z_stream stream;
+ int err;
+
+ stream.next_in = (Bytef*)source;
+ stream.avail_in = (uInt)sourceLen;
+ /* Check for source > 64K on 16-bit machine: */
+ if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
+
+ stream.next_out = dest;
+ stream.avail_out = (uInt)*destLen;
+ if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
+
+ stream.zalloc = (alloc_func)0;
+ stream.zfree = (free_func)0;
+
+ err = inflateInit(&stream);
+ if (err != Z_OK) return err;
+
+ err = inflate(&stream, Z_FINISH);
+ if (err != Z_STREAM_END) {
+ inflateEnd(&stream);
+ return err == Z_OK ? Z_BUF_ERROR : err;
+ }
+ *destLen = stream.total_out;
+
+ err = inflateEnd(&stream);
+ return err;
+}