summaryrefslogtreecommitdiff
path: root/zlib/trees.c
diff options
context:
space:
mode:
authorMartin Pool <mbp@samba.org>2002-03-11 03:35:35 +0000
committerMartin Pool <mbp@samba.org>2002-03-11 03:35:35 +0000
commit06b91d8eb97dd7ba1fa8af3f58e5aee28d831b3f (patch)
tree2699056d9b1c1f6a4adaa395bd4297b67d3aa0c9 /zlib/trees.c
parent9ec5422c37fb38725523c8617df403954beb61dc (diff)
downloadrsync-06b91d8eb97dd7ba1fa8af3f58e5aee28d831b3f.tar.gz
Try to merge across changes in zlib from 1.1.2 to 1.1.3.
Diffstat (limited to 'zlib/trees.c')
-rw-r--r--zlib/trees.c52
1 files changed, 25 insertions, 27 deletions
diff --git a/zlib/trees.c b/zlib/trees.c
index 41b7fe8f..7df48033 100644
--- a/zlib/trees.c
+++ b/zlib/trees.c
@@ -252,6 +252,13 @@ local void tr_static_init()
if (static_init_done) return;
+ /* For some embedded targets, global variables are not initialized: */
+ static_l_desc.static_tree = static_ltree;
+ static_l_desc.extra_bits = extra_lbits;
+ static_d_desc.static_tree = static_dtree;
+ static_d_desc.extra_bits = extra_dbits;
+ static_bl_desc.extra_bits = extra_blbits;
+
/* Initialize the mapping length (0..255) -> length code (0..28) */
length = 0;
for (code = 0; code < LENGTH_CODES-1; code++) {
@@ -380,8 +387,6 @@ void _tr_init(s)
{
tr_static_init();
- s->compressed_len = 0L;
-
s->l_desc.dyn_tree = s->dyn_ltree;
s->l_desc.stat_desc = &static_l_desc;
@@ -395,6 +400,7 @@ void _tr_init(s)
s->bi_valid = 0;
s->last_eob_len = 8; /* enough lookahead for inflate */
#ifdef DEBUG
+ s->compressed_len = 0L;
s->bits_sent = 0L;
#endif
@@ -867,9 +873,10 @@ void _tr_stored_block(s, buf, stored_len, eof)
int eof; /* true if this is the last block for a file */
{
send_bits(s, (STORED_BLOCK<<1)+eof, 3); /* send block type */
+#ifdef DEBUG
s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L;
s->compressed_len += (stored_len + 4) << 3;
-
+#endif
copy_block(s, buf, (unsigned)stored_len, 1); /* with header */
}
@@ -889,7 +896,9 @@ void _tr_align(s)
{
send_bits(s, STATIC_TREES<<1, 3);
send_code(s, END_BLOCK, static_ltree);
+#ifdef DEBUG
s->compressed_len += 10L; /* 3 for block type, 7 for EOB */
+#endif
bi_flush(s);
/* Of the 10 bits for the empty block, we have already sent
* (10 - bi_valid) bits. The lookahead for the last real code (before
@@ -899,7 +908,9 @@ void _tr_align(s)
if (1 + s->last_eob_len + 10 - s->bi_valid < 9) {
send_bits(s, STATIC_TREES<<1, 3);
send_code(s, END_BLOCK, static_ltree);
+#ifdef DEBUG
s->compressed_len += 10L;
+#endif
bi_flush(s);
}
s->last_eob_len = 7;
@@ -907,10 +918,9 @@ void _tr_align(s)
/* ===========================================================================
* Determine the best encoding for the current block: dynamic trees, static
- * trees or store, and output the encoded block to the zip file. This function
- * returns the total compressed length for the file so far.
+ * trees or store, and output the encoded block to the zip file.
*/
-ulg _tr_flush_block(s, buf, stored_len, eof)
+void _tr_flush_block(s, buf, stored_len, eof)
deflate_state *s;
charf *buf; /* input block, or NULL if too old */
ulg stored_len; /* length of input block */
@@ -957,25 +967,6 @@ ulg _tr_flush_block(s, buf, stored_len, eof)
opt_lenb = static_lenb = stored_len + 5; /* force a stored block */
}
- /* If compression failed and this is the first and last block,
- * and if the .zip file can be seeked (to rewrite the local header),
- * the whole file is transformed into a stored file:
- */
-#ifdef STORED_FILE_OK
-# ifdef FORCE_STORED_FILE
- if (eof && s->compressed_len == 0L) { /* force stored file */
-# else
- if (stored_len <= opt_lenb && eof && s->compressed_len==0L && seekable()) {
-# endif
- /* Since LIT_BUFSIZE <= 2*WSIZE, the input data must be there: */
- if (buf == (charf*)0) error ("block vanished");
-
- copy_block(buf, (unsigned)stored_len, 0); /* without header */
- s->compressed_len = stored_len << 3;
- s->method = STORED;
- } else
-#endif /* STORED_FILE_OK */
-
#ifdef FORCE_STORED
if (buf != (char*)0) { /* force stored block */
#else
@@ -997,25 +988,32 @@ ulg _tr_flush_block(s, buf, stored_len, eof)
#endif
send_bits(s, (STATIC_TREES<<1)+eof, 3);
compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree);
+#ifdef DEBUG
s->compressed_len += 3 + s->static_len;
+#endif
} else {
send_bits(s, (DYN_TREES<<1)+eof, 3);
send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1,
max_blindex+1);
compress_block(s, (ct_data *)s->dyn_ltree, (ct_data *)s->dyn_dtree);
+#ifdef DEBUG
s->compressed_len += 3 + s->opt_len;
+#endif
}
Assert (s->compressed_len == s->bits_sent, "bad compressed size");
+ /* The above check is made mod 2^32, for files larger than 512 MB
+ * and uLong implemented on 32 bits.
+ */
init_block(s);
if (eof) {
bi_windup(s);
+#ifdef DEBUG
s->compressed_len += 7; /* align on byte boundary */
+#endif
}
Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,
s->compressed_len-7*eof));
-
- return s->compressed_len >> 3;
}
/* ===========================================================================