51 #include <linux/module.h>
75 static void flush_pending (
z_streamp strm);
96 #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
114 static const config configuration_table[10] = {
116 {0, 0, 0, 0, deflate_stored},
117 {4, 4, 8, 4, deflate_fast},
118 {4, 5, 16, 8, deflate_fast},
119 {4, 6, 32, 32, deflate_fast},
121 {4, 4, 16, 16, deflate_slow},
122 {8, 16, 32, 32, deflate_slow},
123 {8, 16, 128, 128, deflate_slow},
124 {8, 32, 128, 256, deflate_slow},
125 {32, 128, 258, 1024, deflate_slow},
126 {32, 258, 258, 4096, deflate_slow}};
142 #define UPDATE_HASH(s,h,c) (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask)
153 #define INSERT_STRING(s, str, match_head) \
154 (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
155 s->prev[(str) & s->w_mask] = match_head = s->head[s->ins_h], \
156 s->head[s->ins_h] = (Pos)(str))
162 #define CLEAR_HASH(s) \
163 s->head[s->hash_size-1] = NIL; \
164 memset((char *)s->head, 0, (unsigned)(s->hash_size-1)*sizeof(*s->head));
194 if (windowBits < 0) {
196 windowBits = -windowBits;
199 windowBits < 9 || windowBits > 15 || level < 0 || level > 9 ||
209 next +=
sizeof(*mem);
254 int zlib_deflateSetDictionary(
271 strm->
adler = zlib_adler32(strm->
adler, dictionary, dictLength);
276 #ifndef USE_DICT_HEAD
277 dictionary += dictLength -
length;
290 for (n = 0; n <= length -
MIN_MATCH; n++) {
293 if (hash_head) hash_head = 0;
331 int zlib_deflateParams(
347 if (level < 0 || level > 9 || strategy < 0 || strategy >
Z_HUFFMAN_ONLY) {
350 func = configuration_table[s->
level].func;
352 if (func != configuration_table[level].func && strm->
total_in != 0) {
356 if (s->
level != level) {
373 static void putShortMSB(
388 static void flush_pending(
396 if (len == 0)
return;
442 if (level_flags > 3) level_flags = 3;
443 header |= (level_flags << 6);
445 header += 31 - (header % 31);
448 putShortMSB(s, header);
452 putShortMSB(s, (
uInt)(strm->
adler >> 16));
453 putShortMSB(s, (
uInt)(strm->
adler & 0xffff));
476 }
else if (strm->
avail_in == 0 && flush <= old_flush &&
492 bstate = (*(configuration_table[s->
level].func))(
s, flush);
539 putShortMSB(s, (
uInt)(strm->
adler >> 16));
540 putShortMSB(s, (
uInt)(strm->
adler & 0xffff));
575 int zlib_deflateCopy (
644 if (len > size) len =
size;
645 if (len == 0)
return 0;
697 static uInt longest_match(
721 register ush scan_start = *(
ush*)scan;
722 register ush scan_end = *(
ush*)(scan+best_len-1);
725 register Byte scan_end1 = scan[best_len-1];
726 register Byte scan_end = scan[best_len];
746 Assert(cur_match < s->strstart,
"no future");
747 match = s->
window + cur_match;
752 #if (defined(UNALIGNED_OK) && MAX_MATCH == 258)
756 if (*(
ush*)(match+best_len-1) != scan_end ||
757 *(
ush*)match != scan_start)
continue;
768 Assert(scan[2] == match[2],
"scan[2]?");
771 }
while (*(
ush*)(scan+=2) == *(
ush*)(match+=2) &&
772 *(
ush*)(scan+=2) == *(
ush*)(match+=2) &&
773 *(
ush*)(scan+=2) == *(
ush*)(match+=2) &&
774 *(
ush*)(scan+=2) == *(
ush*)(match+=2) &&
780 if (*scan == *match) scan++;
787 if (match[best_len] != scan_end ||
788 match[best_len-1] != scan_end1 ||
790 *++match != scan[1])
continue;
799 Assert(*scan == *match,
"match[2]?");
805 }
while (*++scan == *++match && *++scan == *++match &&
806 *++scan == *++match && *++scan == *++match &&
807 *++scan == *++match && *++scan == *++match &&
808 *++scan == *++match && *++scan == *++match &&
818 if (len > best_len) {
821 if (len >= nice_match)
break;
823 scan_end = *(
ush*)(scan+best_len-1);
825 scan_end1 = scan[best_len-1];
826 scan_end = scan[best_len];
829 }
while ((cur_match = prev[cur_match & wmask]) > limit
830 && --chain_length != 0);
850 fprintf(stderr,
" start %u, match %u, length %d\n",
851 start, match, length);
854 }
while (--length != 0);
855 z_error(
"invalid match");
858 fprintf(stderr,
"\\[%d,%d]", start-match, length);
859 do {
putc(s->
window[start++], stderr); }
while (--length != 0);
863 # define check_match(s, start, match, length)
876 static void fill_window(
880 register unsigned n,
m;
892 }
else if (more == (
unsigned)(-1)) {
919 *p = (
Pos)(m >= wsize ? m-wsize :
NIL);
926 *p = (
Pos)(m >= wsize ? m-wsize :
NIL);
946 Assert(more >= 2,
"more < 2");
970 #define FLUSH_BLOCK_ONLY(s, eof) { \
971 zlib_tr_flush_block(s, (s->block_start >= 0L ? \
972 (char *)&s->window[(unsigned)s->block_start] : \
974 (ulg)((long)s->strstart - s->block_start), \
976 s->block_start = s->strstart; \
977 flush_pending(s->strm); \
978 Tracev((stderr,"[FLUSH]")); \
982 #define FLUSH_BLOCK(s, eof) { \
983 FLUSH_BLOCK_ONLY(s, eof); \
984 if (s->strm->avail_out == 0) return (eof) ? finish_started : need_more; \
1004 ulg max_block_size = 0xffff;
1092 if (s->
strategy != Z_HUFFMAN_ONLY) {
1190 if (s->
strategy != Z_HUFFMAN_ONLY) {
1269 windowBits = -windowBits;