1
0
mirror of https://github.com/openbsd/src.git synced 2025-01-03 06:45:37 -08:00

sync with upstream

This adds a new public API, deflateUsed(), so is technically a minor bump.
Nothing will be using this anytime soon, so no shared library bump.

discussed with deraadt during c2k24
This commit is contained in:
tb 2024-08-01 04:02:26 +00:00
parent ed4f4290d7
commit a225ed8233
5 changed files with 31 additions and 1 deletions

View File

@ -715,6 +715,14 @@ int ZEXPORT deflatePending(z_streamp strm, unsigned *pending, int *bits) {
return Z_OK; return Z_OK;
} }
/* ========================================================================= */
int ZEXPORT deflateUsed(z_streamp strm, int *bits) {
if (deflateStateCheck(strm)) return Z_STREAM_ERROR;
if (bits != Z_NULL)
*bits = strm->state->bi_used;
return Z_OK;
}
/* ========================================================================= */ /* ========================================================================= */
int ZEXPORT deflatePrime(z_streamp strm, int bits, int value) { int ZEXPORT deflatePrime(z_streamp strm, int bits, int value) {
deflate_state *s; deflate_state *s;
@ -1742,8 +1750,10 @@ local block_state deflate_stored(deflate_state *s, int flush) {
s->high_water = s->strstart; s->high_water = s->strstart;
/* If the last block was written to next_out, then done. */ /* If the last block was written to next_out, then done. */
if (last) if (last) {
s->bi_used = 8;
return finish_done; return finish_done;
}
/* If flushing and all input has been consumed, then done. */ /* If flushing and all input has been consumed, then done. */
if (flush != Z_NO_FLUSH && flush != Z_FINISH && if (flush != Z_NO_FLUSH && flush != Z_FINISH &&
@ -1795,6 +1805,8 @@ local block_state deflate_stored(deflate_state *s, int flush) {
} }
/* We've done all we can with the available input and output. */ /* We've done all we can with the available input and output. */
if (last)
s->bi_used = 8;
return last ? finish_started : need_more; return last ? finish_started : need_more;
} }

View File

@ -269,6 +269,9 @@ typedef struct internal_state {
/* Number of valid bits in bi_buf. All bits above the last valid bit /* Number of valid bits in bi_buf. All bits above the last valid bit
* are always zero. * are always zero.
*/ */
int bi_used;
/* Last number of used bits when going to a byte boundary.
*/
ulg high_water; ulg high_water;
/* High water mark offset in window for initialized bytes -- bytes above /* High water mark offset in window for initialized bytes -- bytes above

View File

@ -182,6 +182,7 @@ local void bi_windup(deflate_state *s) {
} else if (s->bi_valid > 0) { } else if (s->bi_valid > 0) {
put_byte(s, (Byte)s->bi_buf); put_byte(s, (Byte)s->bi_buf);
} }
s->bi_used = ((s->bi_valid - 1) & 7) + 1;
s->bi_buf = 0; s->bi_buf = 0;
s->bi_valid = 0; s->bi_valid = 0;
#ifdef ZLIB_DEBUG #ifdef ZLIB_DEBUG
@ -464,6 +465,7 @@ void ZLIB_INTERNAL _tr_init(deflate_state *s) {
s->bi_buf = 0; s->bi_buf = 0;
s->bi_valid = 0; s->bi_valid = 0;
s->bi_used = 0;
#ifdef ZLIB_DEBUG #ifdef ZLIB_DEBUG
s->compressed_len = 0L; s->compressed_len = 0L;
s->bits_sent = 0L; s->bits_sent = 0L;

View File

@ -57,6 +57,7 @@
# define deflateSetDictionary z_deflateSetDictionary # define deflateSetDictionary z_deflateSetDictionary
# define deflateSetHeader z_deflateSetHeader # define deflateSetHeader z_deflateSetHeader
# define deflateTune z_deflateTune # define deflateTune z_deflateTune
# define deflateUsed z_deflateUsed
# define deflate_copyright z_deflate_copyright # define deflate_copyright z_deflate_copyright
# define get_crc_table z_get_crc_table # define get_crc_table z_get_crc_table
# ifndef Z_SOLO # ifndef Z_SOLO

View File

@ -791,6 +791,18 @@ ZEXTERN int ZEXPORT deflatePending(z_streamp strm,
stream state was inconsistent. stream state was inconsistent.
*/ */
ZEXTERN int ZEXPORT deflateUsed(z_streamp strm,
int *bits);
/*
deflateUsed() returns in *bits the most recent number of deflate bits used
in the last byte when flushing to a byte boundary. The result is in 1..8, or
0 if there has not yet been a flush. This helps determine the location of
the last bit of a deflate stream.
deflateUsed returns Z_OK if success, or Z_STREAM_ERROR if the source
stream state was inconsistent.
*/
ZEXTERN int ZEXPORT deflatePrime(z_streamp strm, ZEXTERN int ZEXPORT deflatePrime(z_streamp strm,
int bits, int bits,
int value); int value);