mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2024-12-21 04:42:53 +08:00
de1ab01e8e
Changes in 1.2.10 (2 Jan 2017) - Avoid warnings on snprintf() return value - Fix bug in deflate_stored() for zero-length input - Fix bug in gzwrite.c that produced corrupt gzip files - Remove files to be installed before copying them in Makefile.in - Add warnings when compiling with assembler code Changes in 1.2.9 (31 Dec 2016) - Fix contrib/minizip to permit unzipping with desktop API [Zouzou] - Improve contrib/blast to return unused bytes - Assure that gzoffset() is correct when appending - Improve compress() and uncompress() to support large lengths - Fix bug in test/example.c where error code not saved - Remedy Coverity warning [Randers-Pehrson] - Improve speed of gzprintf() in transparent mode - Fix inflateInit2() bug when windowBits is 16 or 32 - Change DEBUG macro to ZLIB_DEBUG - Avoid uninitialized access by gzclose_w() - Allow building zlib outside of the source directory - Fix bug that accepted invalid zlib header when windowBits is zero - Fix gzseek() problem on MinGW due to buggy _lseeki64 there - Loop on write() calls in gzwrite.c in case of non-blocking I/O - Add --warn (-w) option to ./configure for more compiler warnings - Reject a window size of 256 bytes if not using the zlib wrapper - Fix bug when level 0 used with Z_HUFFMAN or Z_RLE - Add --debug (-d) option to ./configure to define ZLIB_DEBUG - Fix bugs in creating a very large gzip header - Add uncompress2() function, which returns the input size used - Assure that deflateParams() will not switch functions mid-block - Dramatically speed up deflation for level 0 (storing) - Add gzfread(), duplicating the interface of fread() - Add gzfwrite(), duplicating the interface of fwrite() - Add deflateGetDictionary() function - Use snprintf() for later versions of Microsoft C - Fix *Init macros to use z_ prefix when requested - Replace as400 with os400 for OS/400 support [Monnerat] - Add crc32_z() and adler32_z() functions with size_t lengths - Update Visual Studio project files [AraHaan]
94 lines
2.9 KiB
C
94 lines
2.9 KiB
C
/* uncompr.c -- decompress a memory buffer
|
|
* Copyright (C) 1995-2003, 2010, 2014, 2016 Jean-loup Gailly, Mark Adler
|
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
|
*/
|
|
|
|
/* @(#) $Id: uncompr.c,v 1.1.1.2 2002/03/11 21:53:27 tromey Exp $ */
|
|
|
|
#define ZLIB_INTERNAL
|
|
#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 size of the decompressed data and *sourceLen is the number
|
|
of source bytes consumed. Upon return, source + *sourceLen points to the
|
|
first unused input byte.
|
|
|
|
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, including if the input data is
|
|
an incomplete zlib stream.
|
|
*/
|
|
int ZEXPORT uncompress2 (dest, destLen, source, sourceLen)
|
|
Bytef *dest;
|
|
uLongf *destLen;
|
|
const Bytef *source;
|
|
uLong *sourceLen;
|
|
{
|
|
z_stream stream;
|
|
int err;
|
|
const uInt max = (uInt)-1;
|
|
uLong len, left;
|
|
Byte buf[1]; /* for detection of incomplete stream when *destLen == 0 */
|
|
|
|
len = *sourceLen;
|
|
if (*destLen) {
|
|
left = *destLen;
|
|
*destLen = 0;
|
|
}
|
|
else {
|
|
left = 1;
|
|
dest = buf;
|
|
}
|
|
|
|
stream.next_in = (z_const Bytef *)source;
|
|
stream.avail_in = 0;
|
|
stream.zalloc = (alloc_func)0;
|
|
stream.zfree = (free_func)0;
|
|
stream.opaque = (voidpf)0;
|
|
|
|
err = inflateInit(&stream);
|
|
if (err != Z_OK) return err;
|
|
|
|
stream.next_out = dest;
|
|
stream.avail_out = 0;
|
|
|
|
do {
|
|
if (stream.avail_out == 0) {
|
|
stream.avail_out = left > (uLong)max ? max : (uInt)left;
|
|
left -= stream.avail_out;
|
|
}
|
|
if (stream.avail_in == 0) {
|
|
stream.avail_in = len > (uLong)max ? max : (uInt)len;
|
|
len -= stream.avail_in;
|
|
}
|
|
err = inflate(&stream, Z_NO_FLUSH);
|
|
} while (err == Z_OK);
|
|
|
|
*sourceLen -= len + stream.avail_in;
|
|
if (dest != buf)
|
|
*destLen = stream.total_out;
|
|
else if (stream.total_out && err == Z_BUF_ERROR)
|
|
left = 1;
|
|
|
|
inflateEnd(&stream);
|
|
return err == Z_STREAM_END ? Z_OK :
|
|
err == Z_NEED_DICT ? Z_DATA_ERROR :
|
|
err == Z_BUF_ERROR && left + stream.avail_out ? Z_DATA_ERROR :
|
|
err;
|
|
}
|
|
|
|
int ZEXPORT uncompress (dest, destLen, source, sourceLen)
|
|
Bytef *dest;
|
|
uLongf *destLen;
|
|
const Bytef *source;
|
|
uLong sourceLen;
|
|
{
|
|
return uncompress2(dest, destLen, source, &sourceLen);
|
|
}
|