lemon-project-template-glpk
diff deps/glpk/src/zlib/uncompr.c @ 9:33de93886c88
Import GLPK 4.47
author | Alpar Juttner <alpar@cs.elte.hu> |
---|---|
date | Sun, 06 Nov 2011 20:59:10 +0100 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/deps/glpk/src/zlib/uncompr.c Sun Nov 06 20:59:10 2011 +0100 1.3 @@ -0,0 +1,59 @@ 1.4 +/* uncompr.c -- decompress a memory buffer 1.5 + * Copyright (C) 1995-2003, 2010 Jean-loup Gailly. 1.6 + * For conditions of distribution and use, see copyright notice in zlib.h 1.7 + */ 1.8 + 1.9 +/* @(#) $Id$ */ 1.10 + 1.11 +#define ZLIB_INTERNAL 1.12 +#include "zlib.h" 1.13 + 1.14 +/* =========================================================================== 1.15 + Decompresses the source buffer into the destination buffer. sourceLen is 1.16 + the byte length of the source buffer. Upon entry, destLen is the total 1.17 + size of the destination buffer, which must be large enough to hold the 1.18 + entire uncompressed data. (The size of the uncompressed data must have 1.19 + been saved previously by the compressor and transmitted to the decompressor 1.20 + by some mechanism outside the scope of this compression library.) 1.21 + Upon exit, destLen is the actual size of the compressed buffer. 1.22 + 1.23 + uncompress returns Z_OK if success, Z_MEM_ERROR if there was not 1.24 + enough memory, Z_BUF_ERROR if there was not enough room in the output 1.25 + buffer, or Z_DATA_ERROR if the input data was corrupted. 1.26 +*/ 1.27 +int ZEXPORT uncompress (dest, destLen, source, sourceLen) 1.28 + Bytef *dest; 1.29 + uLongf *destLen; 1.30 + const Bytef *source; 1.31 + uLong sourceLen; 1.32 +{ 1.33 + z_stream stream; 1.34 + int err; 1.35 + 1.36 + stream.next_in = (Bytef*)source; 1.37 + stream.avail_in = (uInt)sourceLen; 1.38 + /* Check for source > 64K on 16-bit machine: */ 1.39 + if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; 1.40 + 1.41 + stream.next_out = dest; 1.42 + stream.avail_out = (uInt)*destLen; 1.43 + if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; 1.44 + 1.45 + stream.zalloc = (alloc_func)0; 1.46 + stream.zfree = (free_func)0; 1.47 + 1.48 + err = inflateInit(&stream); 1.49 + if (err != Z_OK) return err; 1.50 + 1.51 + err = inflate(&stream, Z_FINISH); 1.52 + if (err != Z_STREAM_END) { 1.53 + inflateEnd(&stream); 1.54 + if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0)) 1.55 + return Z_DATA_ERROR; 1.56 + return err; 1.57 + } 1.58 + *destLen = stream.total_out; 1.59 + 1.60 + err = inflateEnd(&stream); 1.61 + return err; 1.62 +}