summaryrefslogtreecommitdiff
path: root/sys/lib
diff options
context:
space:
mode:
authorTheo Buehler <tb@cvs.openbsd.org>2024-08-01 04:03:11 +0000
committerTheo Buehler <tb@cvs.openbsd.org>2024-08-01 04:03:11 +0000
commit991e865468d4ea4d076bb4456090918c3a4b3ef4 (patch)
treeb81e126faa992dd2fe75a659770d4bd322c6254b /sys/lib
parentc8856c478dfaada703776ea73ce54c17618ad1fa (diff)
sync with src
Diffstat (limited to 'sys/lib')
-rw-r--r--sys/lib/libz/deflate.c14
-rw-r--r--sys/lib/libz/deflate.h3
-rw-r--r--sys/lib/libz/trees.c2
-rw-r--r--sys/lib/libz/zconf.h1
-rw-r--r--sys/lib/libz/zlib.h12
5 files changed, 31 insertions, 1 deletions
diff --git a/sys/lib/libz/deflate.c b/sys/lib/libz/deflate.c
index e653d530c51..2a4fc280c39 100644
--- a/sys/lib/libz/deflate.c
+++ b/sys/lib/libz/deflate.c
@@ -716,6 +716,14 @@ int ZEXPORT deflatePending(z_streamp strm, unsigned *pending, int *bits) {
}
/* ========================================================================= */
+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) {
deflate_state *s;
int put;
@@ -1744,8 +1752,10 @@ local block_state deflate_stored(deflate_state *s, int flush) {
s->high_water = s->strstart;
/* If the last block was written to next_out, then done. */
- if (last)
+ if (last) {
+ s->bi_used = 8;
return finish_done;
+ }
/* If flushing and all input has been consumed, then done. */
if (flush != Z_NO_FLUSH && flush != Z_FINISH &&
@@ -1797,6 +1807,8 @@ local block_state deflate_stored(deflate_state *s, int flush) {
}
/* We've done all we can with the available input and output. */
+ if (last)
+ s->bi_used = 8;
return last ? finish_started : need_more;
}
diff --git a/sys/lib/libz/deflate.h b/sys/lib/libz/deflate.h
index 8182a260418..ad230ef7394 100644
--- a/sys/lib/libz/deflate.h
+++ b/sys/lib/libz/deflate.h
@@ -269,6 +269,9 @@ typedef struct internal_state {
/* Number of valid bits in bi_buf. All bits above the last valid bit
* are always zero.
*/
+ int bi_used;
+ /* Last number of used bits when going to a byte boundary.
+ */
ulg high_water;
/* High water mark offset in window for initialized bytes -- bytes above
diff --git a/sys/lib/libz/trees.c b/sys/lib/libz/trees.c
index cba0708b602..7ce629afb58 100644
--- a/sys/lib/libz/trees.c
+++ b/sys/lib/libz/trees.c
@@ -182,6 +182,7 @@ local void bi_windup(deflate_state *s) {
} else if (s->bi_valid > 0) {
put_byte(s, (Byte)s->bi_buf);
}
+ s->bi_used = ((s->bi_valid - 1) & 7) + 1;
s->bi_buf = 0;
s->bi_valid = 0;
#ifdef ZLIB_DEBUG
@@ -464,6 +465,7 @@ void ZLIB_INTERNAL _tr_init(deflate_state *s) {
s->bi_buf = 0;
s->bi_valid = 0;
+ s->bi_used = 0;
#ifdef ZLIB_DEBUG
s->compressed_len = 0L;
s->bits_sent = 0L;
diff --git a/sys/lib/libz/zconf.h b/sys/lib/libz/zconf.h
index 1a3d41ebbb6..7221b8923b6 100644
--- a/sys/lib/libz/zconf.h
+++ b/sys/lib/libz/zconf.h
@@ -57,6 +57,7 @@
# define deflateSetDictionary z_deflateSetDictionary
# define deflateSetHeader z_deflateSetHeader
# define deflateTune z_deflateTune
+# define deflateUsed z_deflateUsed
# define deflate_copyright z_deflate_copyright
# define get_crc_table z_get_crc_table
# ifndef Z_SOLO
diff --git a/sys/lib/libz/zlib.h b/sys/lib/libz/zlib.h
index 5322a85f58a..6c0e02d6c6e 100644
--- a/sys/lib/libz/zlib.h
+++ b/sys/lib/libz/zlib.h
@@ -791,6 +791,18 @@ ZEXTERN int ZEXPORT deflatePending(z_streamp strm,
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,
int bits,
int value);