diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2023-05-05 10:02:34 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2023-05-09 15:07:09 +0200 |
commit | 1f00afcb5a5b30593543268acbcbcb94f60d24a2 (patch) | |
tree | d78dc96223ec34a63cbfdd92e3fc6dc5037f3eac /cpukit/zlib/compress.c | |
parent | bsps/amd64: add a new EFI-based variant of AMD64 BSP (diff) | |
download | rtems-1f00afcb5a5b30593543268acbcbcb94f60d24a2.tar.bz2 |
zlib: Update from 1.2.5 to 1.2.13
The updated files were extracted from:
https://www.zlib.net/zlib-1.2.13.tar.xz
The archive had an SHA-256 hash value of:
d14c38e313afc35a9a8760dadf26042f51ea0f5d154b0630a31da0540107fb98
Close #4902.
Diffstat (limited to 'cpukit/zlib/compress.c')
-rw-r--r-- | cpukit/zlib/compress.c | 50 |
1 files changed, 29 insertions, 21 deletions
diff --git a/cpukit/zlib/compress.c b/cpukit/zlib/compress.c index 30ffc77cb9..2ad5326c14 100644 --- a/cpukit/zlib/compress.c +++ b/cpukit/zlib/compress.c @@ -1,8 +1,10 @@ /* compress.c -- compress a memory buffer - * Copyright (C) 1995-2005 Jean-loup Gailly. + * Copyright (C) 1995-2005, 2014, 2016 Jean-loup Gailly, Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ +/* @(#) $Id$ */ + #define ZLIB_INTERNAL #include "zlib.h" @@ -17,7 +19,7 @@ memory, Z_BUF_ERROR if there was not enough room in the output buffer, Z_STREAM_ERROR if the level parameter is invalid. */ -int ZEXPORT compress2 (dest, destLen, source, sourceLen, level) +int ZEXPORT compress2(dest, destLen, source, sourceLen, level) Bytef *dest; uLongf *destLen; const Bytef *source; @@ -26,16 +28,11 @@ int ZEXPORT compress2 (dest, destLen, source, sourceLen, level) { z_stream stream; int err; + const uInt max = (uInt)-1; + uLong left; - stream.next_in = (Bytef*)source; - stream.avail_in = (uInt)sourceLen; -#ifdef MAXSEG_64K - /* Check for source > 64K on 16-bit machine: */ - if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; -#endif - stream.next_out = dest; - stream.avail_out = (uInt)*destLen; - if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; + left = *destLen; + *destLen = 0; stream.zalloc = (alloc_func)0; stream.zfree = (free_func)0; @@ -44,20 +41,31 @@ int ZEXPORT compress2 (dest, destLen, source, sourceLen, level) err = deflateInit(&stream, level); if (err != Z_OK) return err; - err = deflate(&stream, Z_FINISH); - if (err != Z_STREAM_END) { - deflateEnd(&stream); - return err == Z_OK ? Z_BUF_ERROR : err; - } - *destLen = stream.total_out; + stream.next_out = dest; + stream.avail_out = 0; + stream.next_in = (z_const Bytef *)source; + stream.avail_in = 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 = sourceLen > (uLong)max ? max : (uInt)sourceLen; + sourceLen -= stream.avail_in; + } + err = deflate(&stream, sourceLen ? Z_NO_FLUSH : Z_FINISH); + } while (err == Z_OK); - err = deflateEnd(&stream); - return err; + *destLen = stream.total_out; + deflateEnd(&stream); + return err == Z_STREAM_END ? Z_OK : err; } /* =========================================================================== */ -int ZEXPORT compress (dest, destLen, source, sourceLen) +int ZEXPORT compress(dest, destLen, source, sourceLen) Bytef *dest; uLongf *destLen; const Bytef *source; @@ -70,7 +78,7 @@ int ZEXPORT compress (dest, destLen, source, sourceLen) If the default memLevel or windowBits for deflateInit() is changed, then this function needs to be updated. */ -uLong ZEXPORT compressBound (sourceLen) +uLong ZEXPORT compressBound(sourceLen) uLong sourceLen; { return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + |