diff --git a/ChangeLog b/ChangeLog index d60b6d37..84f9306f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,26 @@ ChangeLog file for zlib +Changes in 1.2.2.1 (31 October 2004) +- Allow inflateSetDictionary() call for raw inflate +- Fix inflate header crc check bug for file names and comments +- Add deflateSetHeader() and gz_header structure for custom gzip headers +- Add inflateGetheader() to retrieve gzip headers +- Add crc32_combine() and adler32_combine() functions +- Add alloc_func, free_func, in_func, out_func to Z_PREFIX list +- Use zstreamp consistently in zlib.h (inflate_back functions) +- Remove GUNZIP condition from definition of inflate_mode in inflate.h + and in contrib/inflate86/inffast.S [Truta, Anderson] +- Add support for AMD64 in contrib/inflate86/inffas86.c [Anderson] +- Update projects/README.projects and projects/visualc6 [Truta] +- Update win32/DLL_FAQ.txt [Truta] +- Avoid warning under NO_GZCOMPRESS in gzio.c; fix typo [Truta] +- Deprecate Z_ASCII; use Z_TEXT instead [Truta] +- Use a new algorithm for setting strm->data_type in trees.c [Truta] +- Do not define an exit() prototype in zutil.c unless DEBUG defined +- Remove prototype of exit() from zutil.c, example.c, minigzip.c [Truta] +- Add comment in zlib.h for Z_NO_FLUSH parameter to deflate() + Changes in 1.2.2 (3 October 2004) - Update zlib.h comments on gzip in-memory processing - Set adler to 1 in inflateReset() to support Java test suite [Walles] diff --git a/Makefile b/Makefile index a29e9bc6..7a6bd9a5 100644 --- a/Makefile +++ b/Makefile @@ -30,7 +30,7 @@ CPP=$(CC) -E LIBS=libz.a SHAREDLIB=libz.so -SHAREDLIBV=libz.so.1.2.2 +SHAREDLIBV=libz.so.1.2.2.1 SHAREDLIBM=libz.so.1 AR=ar rc diff --git a/Makefile.in b/Makefile.in index a29e9bc6..7a6bd9a5 100644 --- a/Makefile.in +++ b/Makefile.in @@ -30,7 +30,7 @@ CPP=$(CC) -E LIBS=libz.a SHAREDLIB=libz.so -SHAREDLIBV=libz.so.1.2.2 +SHAREDLIBV=libz.so.1.2.2.1 SHAREDLIBM=libz.so.1 AR=ar rc diff --git a/README b/README index df95ae13..f1488646 100644 --- a/README +++ b/README @@ -1,6 +1,6 @@ ZLIB DATA COMPRESSION LIBRARY -zlib 1.2.2 is a general purpose data compression library. All the code is +zlib 1.2.2.1 is a general purpose data compression library. All the code is thread safe. The data format used by the zlib library is described by RFCs (Request for Comments) 1950 to 1952 in the files http://www.ietf.org/rfc/rfc1950.txt (zlib format), rfc1951.txt (deflate format) @@ -34,7 +34,7 @@ Mark Nelson wrote an article about zlib for the Jan. 1997 issue of Dr. Dobb's Journal; a copy of the article is available in http://dogma.net/markn/articles/zlibtool/zlibtool.htm -The changes made in version 1.2.2 are documented in the file ChangeLog. +The changes made in version 1.2.2.1 are documented in the file ChangeLog. Unsupported third party contributions are provided in directory "contrib". diff --git a/adler32.c b/adler32.c index 624a1696..94f1021b 100644 --- a/adler32.c +++ b/adler32.c @@ -1,5 +1,5 @@ /* adler32.c -- compute the Adler-32 checksum of a data stream - * Copyright (C) 1995-2003 Mark Adler + * Copyright (C) 1995-2004 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -72,3 +72,25 @@ uLong ZEXPORT adler32(adler, buf, len) } return (s2 << 16) | s1; } + +/* ========================================================================= */ +uLong ZEXPORT adler32_combine(adler1, adler2, len2) + uLong adler1; + uLong adler2; + uLong len2; +{ + unsigned long s1; + unsigned long s2; + + len2 %= BASE; + s1 = adler1 & 0xffff; + s2 = len2 * s1; + MOD(s2); + s1 += (adler2 & 0xffff) + BASE - 1; + s2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - len2; + if (s1 > BASE) s1 -= BASE; + if (s1 > BASE) s1 -= BASE; + if (s2 > (BASE << 1)) s2 -= (BASE << 1); + if (s2 > BASE) s2 -= BASE; + return (s2 << 16) | s1; +} diff --git a/as400/zlib.inc b/as400/zlib.inc index e31e1a72..f85473e8 100644 --- a/as400/zlib.inc +++ b/as400/zlib.inc @@ -1,7 +1,7 @@ * ZLIB.INC - Interface to the general purpose compression library * * ILE RPG400 version by Patrick Monnerat, DATASPHERE. - * Version 1.2.2 + * Version 1.2.2.1 * * * WARNING: @@ -20,8 +20,8 @@ * Constants ************************************************************************** * - D ZLIB_VERSION C '1.2.2' Header's version - D ZLIB_VERNUM C X'1220' + D ZLIB_VERSION C '1.2.2.1' Header's version + D ZLIB_VERNUM C X'1221' * D Z_NO_FLUSH C 0 D Z_SYNC_FLUSH C 2 diff --git a/compress.c b/compress.c index 24ef0291..df04f014 100644 --- a/compress.c +++ b/compress.c @@ -1,5 +1,5 @@ /* compress.c -- compress a memory buffer - * Copyright (C) 1995-2002 Jean-loup Gailly. + * Copyright (C) 1995-2003 Jean-loup Gailly. * For conditions of distribution and use, see copyright notice in zlib.h */ diff --git a/contrib/infback9/inftree9.c b/contrib/infback9/inftree9.c index 9b48bc54..7325873a 100644 --- a/contrib/infback9/inftree9.c +++ b/contrib/infback9/inftree9.c @@ -9,7 +9,7 @@ #define MAXBITS 15 const char inflate9_copyright[] = - " inflate9 1.2.2 Copyright 1995-2004 Mark Adler "; + " inflate9 1.2.2.1 Copyright 1995-2004 Mark Adler "; /* If you use the zlib library in a product, an acknowledgment is welcome in the documentation of your product. If for some reason you cannot @@ -64,7 +64,7 @@ unsigned short FAR *work; static const unsigned short lext[31] = { /* Length codes 257..285 extra */ 128, 128, 128, 128, 128, 128, 128, 128, 129, 129, 129, 129, 130, 130, 130, 130, 131, 131, 131, 131, 132, 132, 132, 132, - 133, 133, 133, 133, 144, 199, 198}; + 133, 133, 133, 133, 144, 77, 207}; static const unsigned short dbase[32] = { /* Distance codes 0..31 base */ 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, diff --git a/contrib/inflate86/inffas86.c b/contrib/inflate86/inffas86.c index 4534693a..6da76358 100644 --- a/contrib/inflate86/inffas86.c +++ b/contrib/inflate86/inffas86.c @@ -7,6 +7,15 @@ * Copyright (C) 2003 Chris Anderson * Please use the copyright conditions above. * + * Dec-29-2003 -- I added AMD64 inflate asm support. This version is also + * slightly quicker on x86 systems because, instead of using rep movsb to copy + * data, it uses rep movsw, which moves data in 2-byte chunks instead of single + * bytes. I've tested the AMD64 code on a Fedora Core 1 + the x86_64 updates + * from http://fedora.linux.duke.edu/fc1_x86_64 + * which is running on an Athlon 64 3000+ / Gigabyte GA-K8VT800M system with + * 1GB ram. The 64-bit version is about 4% faster than the 32-bit version, + * when decompressing mozilla-source-1.3.tar.gz. + * * Mar-13-2003 -- Most of this is derived from inffast.S which is derived from * the gcc -S output of zlib-1.2.0/inffast.c. Zlib-1.2.0 is in beta release at * the moment. I have successfully compiled and tested this code with gcc2.96, @@ -65,33 +74,44 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */ { struct inflate_state FAR *state; struct inffast_ar { - void *esp; /* esp save */ - unsigned char FAR *in; /* local strm->next_in */ - unsigned char FAR *last; /* while in < last, enough input available */ - unsigned char FAR *out; /* local strm->next_out */ - unsigned char FAR *beg; /* inflate()'s initial strm->next_out */ - unsigned char FAR *end; /* while out < end, enough space available */ - unsigned wsize; /* window size or zero if not using window */ - unsigned write; /* window write index */ - unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */ - unsigned long hold; /* local strm->hold */ - unsigned bits; /* local strm->bits */ - code const FAR *lcode; /* local strm->lencode */ - code const FAR *dcode; /* local strm->distcode */ - unsigned lmask; /* mask for first level of length codes */ - unsigned dmask; /* mask for first level of distance codes */ - unsigned len; /* match length, unused bytes */ - unsigned dist; /* match distance */ - unsigned status; /* this is set when state changes */ +/* 64 32 x86 x86_64 */ +/* ar offset register */ +/* 0 0 */ void *esp; /* esp save */ +/* 8 4 */ void *ebp; /* ebp save */ +/* 16 8 */ unsigned char FAR *in; /* esi rsi local strm->next_in */ +/* 24 12 */ unsigned char FAR *last; /* r9 while in < last */ +/* 32 16 */ unsigned char FAR *out; /* edi rdi local strm->next_out */ +/* 40 20 */ unsigned char FAR *beg; /* inflate()'s init next_out */ +/* 48 24 */ unsigned char FAR *end; /* r10 while out < end */ +/* 56 28 */ unsigned char FAR *window;/* size of window, wsize!=0 */ +/* 64 32 */ code const FAR *lcode; /* ebp rbp local strm->lencode */ +/* 72 36 */ code const FAR *dcode; /* r11 local strm->distcode */ +/* 80 40 */ unsigned long hold; /* edx rdx local strm->hold */ +/* 88 44 */ unsigned bits; /* ebx rbx local strm->bits */ +/* 92 48 */ unsigned wsize; /* window size */ +/* 96 52 */ unsigned write; /* window write index */ +/*100 56 */ unsigned lmask; /* r12 mask for lcode */ +/*104 60 */ unsigned dmask; /* r13 mask for dcode */ +/*108 64 */ unsigned len; /* r14 match length */ +/*112 68 */ unsigned dist; /* r15 match distance */ +/*116 72 */ unsigned status; /* set when state chng*/ } ar; +#if defined( __GNUC__ ) && defined( __amd64__ ) && ! defined( __i386 ) +#define PAD_AVAIL_IN 6 +#define PAD_AVAIL_OUT 258 +#else +#define PAD_AVAIL_IN 5 +#define PAD_AVAIL_OUT 257 +#endif + /* copy state to local variables */ state = (struct inflate_state FAR *)strm->state; ar.in = strm->next_in; - ar.last = ar.in + (strm->avail_in - 5); + ar.last = ar.in + (strm->avail_in - PAD_AVAIL_IN); ar.out = strm->next_out; ar.beg = ar.out - (start - strm->avail_out); - ar.end = ar.out + (strm->avail_out - 257); + ar.end = ar.out + (strm->avail_out - PAD_AVAIL_OUT); ar.wsize = state->wsize; ar.write = state->write; ar.window = state->window; @@ -105,32 +125,368 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */ /* decode literals and length/distances until end-of-block or not enough input data or output space */ - /* align in on 2 byte boundary */ - if (((unsigned long)(void *)ar.in & 0x1) != 0) { + /* align in on 1/2 hold size boundary */ + while (((unsigned long)(void *)ar.in & (sizeof(ar.hold) / 2 - 1)) != 0) { ar.hold += (unsigned long)*ar.in++ << ar.bits; ar.bits += 8; } -#if defined( __GNUC__ ) || defined( __ICC ) +#if defined( __GNUC__ ) && defined( __amd64__ ) && ! defined( __i386 ) + __asm__ __volatile__ ( +" leaq %0, %%rax\n" +" movq %%rbp, 8(%%rax)\n" /* save regs rbp and rsp */ +" movq %%rsp, (%%rax)\n" +" movq %%rax, %%rsp\n" /* make rsp point to &ar */ +" movq 16(%%rsp), %%rsi\n" /* rsi = in */ +" movq 32(%%rsp), %%rdi\n" /* rdi = out */ +" movq 24(%%rsp), %%r9\n" /* r9 = last */ +" movq 48(%%rsp), %%r10\n" /* r10 = end */ +" movq 64(%%rsp), %%rbp\n" /* rbp = lcode */ +" movq 72(%%rsp), %%r11\n" /* r11 = dcode */ +" movq 80(%%rsp), %%rdx\n" /* rdx = hold */ +" movl 88(%%rsp), %%ebx\n" /* ebx = bits */ +" movl 100(%%rsp), %%r12d\n" /* r12d = lmask */ +" movl 104(%%rsp), %%r13d\n" /* r13d = dmask */ + /* r14d = len */ + /* r15d = dist */ +" cld\n" +" cmpq %%rdi, %%r10\n" +" je .L_one_time\n" /* if only one decode left */ +" cmpq %%rsi, %%r9\n" +" je .L_one_time\n" +" jmp .L_do_loop\n" + +".L_one_time:\n" +" movq %%r12, %%r8\n" /* r8 = lmask */ +" cmpb $32, %%bl\n" +" ja .L_get_length_code_one_time\n" + +" lodsl\n" /* eax = *(uint *)in++ */ +" movb %%bl, %%cl\n" /* cl = bits, needs it for shifting */ +" addb $32, %%bl\n" /* bits += 32 */ +" shlq %%cl, %%rax\n" +" orq %%rax, %%rdx\n" /* hold |= *((uint *)in)++ << bits */ +" jmp .L_get_length_code_one_time\n" + +".align 32,0x90\n" +".L_while_test:\n" +" cmpq %%rdi, %%r10\n" +" jbe .L_break_loop\n" +" cmpq %%rsi, %%r9\n" +" jbe .L_break_loop\n" + +".L_do_loop:\n" +" movq %%r12, %%r8\n" /* r8 = lmask */ +" cmpb $32, %%bl\n" +" ja .L_get_length_code\n" /* if (32 < bits) */ + +" lodsl\n" /* eax = *(uint *)in++ */ +" movb %%bl, %%cl\n" /* cl = bits, needs it for shifting */ +" addb $32, %%bl\n" /* bits += 32 */ +" shlq %%cl, %%rax\n" +" orq %%rax, %%rdx\n" /* hold |= *((uint *)in)++ << bits */ + +".L_get_length_code:\n" +" andq %%rdx, %%r8\n" /* r8 &= hold */ +" movl (%%rbp,%%r8,4), %%eax\n" /* eax = lcode[hold & lmask] */ + +" movb %%ah, %%cl\n" /* cl = this.bits */ +" subb %%ah, %%bl\n" /* bits -= this.bits */ +" shrq %%cl, %%rdx\n" /* hold >>= this.bits */ + +" testb %%al, %%al\n" +" jnz .L_test_for_length_base\n" /* if (op != 0) 45.7% */ + +" movq %%r12, %%r8\n" /* r8 = lmask */ +" shrl $16, %%eax\n" /* output this.val char */ +" stosb\n" + +".L_get_length_code_one_time:\n" +" andq %%rdx, %%r8\n" /* r8 &= hold */ +" movl (%%rbp,%%r8,4), %%eax\n" /* eax = lcode[hold & lmask] */ + +".L_dolen:\n" +" movb %%ah, %%cl\n" /* cl = this.bits */ +" subb %%ah, %%bl\n" /* bits -= this.bits */ +" shrq %%cl, %%rdx\n" /* hold >>= this.bits */ + +" testb %%al, %%al\n" +" jnz .L_test_for_length_base\n" /* if (op != 0) 45.7% */ + +" shrl $16, %%eax\n" /* output this.val char */ +" stosb\n" +" jmp .L_while_test\n" + +".align 32,0x90\n" +".L_test_for_length_base:\n" +" movl %%eax, %%r14d\n" /* len = this */ +" shrl $16, %%r14d\n" /* len = this.val */ +" movb %%al, %%cl\n" + +" testb $16, %%al\n" +" jz .L_test_for_second_level_length\n" /* if ((op & 16) == 0) 8% */ +" andb $15, %%cl\n" /* op &= 15 */ +" jz .L_decode_distance\n" /* if (!op) */ + +".L_add_bits_to_len:\n" +" subb %%cl, %%bl\n" +" xorl %%eax, %%eax\n" +" incl %%eax\n" +" shll %%cl, %%eax\n" +" decl %%eax\n" +" andl %%edx, %%eax\n" /* eax &= hold */ +" shrq %%cl, %%rdx\n" +" addl %%eax, %%r14d\n" /* len += hold & mask[op] */ + +".L_decode_distance:\n" +" movq %%r13, %%r8\n" /* r8 = dmask */ +" cmpb $32, %%bl\n" +" ja .L_get_distance_code\n" /* if (32 < bits) */ + +" lodsl\n" /* eax = *(uint *)in++ */ +" movb %%bl, %%cl\n" /* cl = bits, needs it for shifting */ +" addb $32, %%bl\n" /* bits += 32 */ +" shlq %%cl, %%rax\n" +" orq %%rax, %%rdx\n" /* hold |= *((uint *)in)++ << bits */ + +".L_get_distance_code:\n" +" andq %%rdx, %%r8\n" /* r8 &= hold */ +" movl (%%r11,%%r8,4), %%eax\n" /* eax = dcode[hold & dmask] */ + +".L_dodist:\n" +" movl %%eax, %%r15d\n" /* dist = this */ +" shrl $16, %%r15d\n" /* dist = this.val */ +" movb %%ah, %%cl\n" +" subb %%ah, %%bl\n" /* bits -= this.bits */ +" shrq %%cl, %%rdx\n" /* hold >>= this.bits */ +" movb %%al, %%cl\n" /* cl = this.op */ + +" testb $16, %%al\n" /* if ((op & 16) == 0) */ +" jz .L_test_for_second_level_dist\n" +" andb $15, %%cl\n" /* op &= 15 */ +" jz .L_check_dist_one\n" + +".L_add_bits_to_dist:\n" +" subb %%cl, %%bl\n" +" xorl %%eax, %%eax\n" +" incl %%eax\n" +" shll %%cl, %%eax\n" +" decl %%eax\n" /* (1 << op) - 1 */ +" andl %%edx, %%eax\n" /* eax &= hold */ +" shrq %%cl, %%rdx\n" +" addl %%eax, %%r15d\n" /* dist += hold & ((1 << op) - 1) */ + +".L_check_window:\n" +" movq %%rsi, %%r8\n" /* save in so from can use it's reg */ +" movq %%rdi, %%rax\n" +" subq 40(%%rsp), %%rax\n" /* nbytes = out - beg */ + +" cmpl %%r15d, %%eax\n" +" jb .L_clip_window\n" /* if (dist > nbytes) 4.2% */ + +" movl %%r14d, %%ecx\n" /* ecx = len */ +" movq %%rdi, %%rsi\n" +" subq %%r15, %%rsi\n" /* from = out - dist */ + +" sarl %%ecx\n" +" jnc .L_copy_two\n" /* if len % 2 == 0 */ + +" rep movsw\n" +" movb (%%rsi), %%al\n" +" movb %%al, (%%rdi)\n" +" incq %%rdi\n" + +" movq %%r8, %%rsi\n" /* move in back to %rsi, toss from */ +" jmp .L_while_test\n" + +".L_copy_two:\n" +" rep movsw\n" +" movq %%r8, %%rsi\n" /* move in back to %rsi, toss from */ +" jmp .L_while_test\n" + +".align 32,0x90\n" +".L_check_dist_one:\n" +" cmpl $1, %%r15d\n" /* if dist 1, is a memset */ +" jne .L_check_window\n" +" cmpq %%rdi, 40(%%rsp)\n" /* if out == beg, outside window */ +" je .L_check_window\n" + +" movl %%r14d, %%ecx\n" /* ecx = len */ +" movb -1(%%rdi), %%al\n" +" movb %%al, %%ah\n" + +" sarl %%ecx\n" +" jnc .L_set_two\n" +" movb %%al, (%%rdi)\n" +" incq %%rdi\n" + +".L_set_two:\n" +" rep stosw\n" +" jmp .L_while_test\n" + +".align 32,0x90\n" +".L_test_for_second_level_length:\n" +" testb $64, %%al\n" +" jnz .L_test_for_end_of_block\n" /* if ((op & 64) != 0) */ + +" xorl %%eax, %%eax\n" +" incl %%eax\n" +" shll %%cl, %%eax\n" +" decl %%eax\n" +" andl %%edx, %%eax\n" /* eax &= hold */ +" addl %%r14d, %%eax\n" /* eax += len */ +" movl (%%rbp,%%rax,4), %%eax\n" /* eax = lcode[val+(hold&mask[op])]*/ +" jmp .L_dolen\n" + +".align 32,0x90\n" +".L_test_for_second_level_dist:\n" +" testb $64, %%al\n" +" jnz .L_invalid_distance_code\n" /* if ((op & 64) != 0) */ + +" xorl %%eax, %%eax\n" +" incl %%eax\n" +" shll %%cl, %%eax\n" +" decl %%eax\n" +" andl %%edx, %%eax\n" /* eax &= hold */ +" addl %%r15d, %%eax\n" /* eax += dist */ +" movl (%%r11,%%rax,4), %%eax\n" /* eax = dcode[val+(hold&mask[op])]*/ +" jmp .L_dodist\n" + +".align 32,0x90\n" +".L_clip_window:\n" +" movl %%eax, %%ecx\n" /* ecx = nbytes */ +" movl 92(%%rsp), %%eax\n" /* eax = wsize, prepare for dist cmp */ +" negl %%ecx\n" /* nbytes = -nbytes */ + +" cmpl %%r15d, %%eax\n" +" jb .L_invalid_distance_too_far\n" /* if (dist > wsize) */ + +" addl %%r15d, %%ecx\n" /* nbytes = dist - nbytes */ +" cmpl $0, 96(%%rsp)\n" +" jne .L_wrap_around_window\n" /* if (write != 0) */ + +" movq 56(%%rsp), %%rsi\n" /* from = window */ +" subl %%ecx, %%eax\n" /* eax -= nbytes */ +" addq %%rax, %%rsi\n" /* from += wsize - nbytes */ + +" movl %%r14d, %%eax\n" /* eax = len */ +" cmpl %%ecx, %%r14d\n" +" jbe .L_do_copy\n" /* if (nbytes >= len) */ + +" subl %%ecx, %%eax\n" /* eax -= nbytes */ +" rep movsb\n" +" movq %%rdi, %%rsi\n" +" subq %%r15, %%rsi\n" /* from = &out[ -dist ] */ +" jmp .L_do_copy\n" + +".align 32,0x90\n" +".L_wrap_around_window:\n" +" movl 96(%%rsp), %%eax\n" /* eax = write */ +" cmpl %%eax, %%ecx\n" +" jbe .L_contiguous_in_window\n" /* if (write >= nbytes) */ + +" movl 92(%%rsp), %%esi\n" /* from = wsize */ +" addq 56(%%rsp), %%rsi\n" /* from += window */ +" addq %%rax, %%rsi\n" /* from += write */ +" subq %%rcx, %%rsi\n" /* from -= nbytes */ +" subl %%eax, %%ecx\n" /* nbytes -= write */ + +" movl %%r14d, %%eax\n" /* eax = len */ +" cmpl %%ecx, %%eax\n" +" jbe .L_do_copy\n" /* if (nbytes >= len) */ + +" subl %%ecx, %%eax\n" /* len -= nbytes */ +" rep movsb\n" +" movq 56(%%rsp), %%rsi\n" /* from = window */ +" movl 96(%%rsp), %%ecx\n" /* nbytes = write */ +" cmpl %%ecx, %%eax\n" +" jbe .L_do_copy\n" /* if (nbytes >= len) */ + +" subl %%ecx, %%eax\n" /* len -= nbytes */ +" rep movsb\n" +" movq %%rdi, %%rsi\n" +" subq %%r15, %%rsi\n" /* from = out - dist */ +" jmp .L_do_copy\n" + +".align 32,0x90\n" +".L_contiguous_in_window:\n" +" movq 56(%%rsp), %%rsi\n" /* rsi = window */ +" addq %%rax, %%rsi\n" +" subq %%rcx, %%rsi\n" /* from += write - nbytes */ + +" movl %%r14d, %%eax\n" /* eax = len */ +" cmpl %%ecx, %%eax\n" +" jbe .L_do_copy\n" /* if (nbytes >= len) */ + +" subl %%ecx, %%eax\n" /* len -= nbytes */ +" rep movsb\n" +" movq %%rdi, %%rsi\n" +" subq %%r15, %%rsi\n" /* from = out - dist */ +" jmp .L_do_copy\n" /* if (nbytes >= len) */ + +".align 32,0x90\n" +".L_do_copy:\n" +" movl %%eax, %%ecx\n" /* ecx = len */ +" rep movsb\n" + +" movq %%r8, %%rsi\n" /* move in back to %esi, toss from */ +" jmp .L_while_test\n" + +".L_test_for_end_of_block:\n" +" testb $32, %%al\n" +" jz .L_invalid_literal_length_code\n" +" movl $1, 116(%%rsp)\n" +" jmp .L_break_loop_with_status\n" + +".L_invalid_literal_length_code:\n" +" movl $2, 116(%%rsp)\n" +" jmp .L_break_loop_with_status\n" + +".L_invalid_distance_code:\n" +" movl $3, 116(%%rsp)\n" +" jmp .L_break_loop_with_status\n" + +".L_invalid_distance_too_far:\n" +" movl $4, 116(%%rsp)\n" +" jmp .L_break_loop_with_status\n" + +".L_break_loop:\n" +" movl $0, 116(%%rsp)\n" + +".L_break_loop_with_status:\n" +/* put in, out, bits, and hold back into ar and pop esp */ +" movq %%rsi, 16(%%rsp)\n" /* in */ +" movq %%rdi, 32(%%rsp)\n" /* out */ +" movl %%ebx, 88(%%rsp)\n" /* bits */ +" movq %%rdx, 80(%%rsp)\n" /* hold */ +" movq (%%rsp), %%rax\n" /* restore rbp and rsp */ +" movq 8(%%rsp), %%rbp\n" +" movq %%rax, %%rsp\n" + : + : "m" (ar) + : "memory", "%rax", "%rbx", "%rcx", "%rdx", "%rsi", "%rdi", + "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15" + ); +#elif ( defined( __GNUC__ ) || defined( __ICC ) ) && defined( __i386 ) __asm__ __volatile__ ( " leal %0, %%eax\n" -" pushf\n" -" pushl %%ebp\n" -" movl %%esp, (%%eax)\n" +" movl %%esp, (%%eax)\n" /* save esp, ebp */ +" movl %%ebp, 4(%%eax)\n" " movl %%eax, %%esp\n" -" movl 4(%%esp), %%esi\n" /* esi = in */ -" movl 12(%%esp), %%edi\n" /* edi = out */ -" movl 36(%%esp), %%edx\n" /* edx = hold */ -" movl 40(%%esp), %%ebx\n" /* ebx = bits */ -" movl 44(%%esp), %%ebp\n" /* ebp = lcode */ +" movl 8(%%esp), %%esi\n" /* esi = in */ +" movl 16(%%esp), %%edi\n" /* edi = out */ +" movl 40(%%esp), %%edx\n" /* edx = hold */ +" movl 44(%%esp), %%ebx\n" /* ebx = bits */ +" movl 32(%%esp), %%ebp\n" /* ebp = lcode */ " cld\n" " jmp .L_do_loop\n" +".align 32,0x90\n" ".L_while_test:\n" -" cmpl %%edi, 20(%%esp)\n" +" cmpl %%edi, 24(%%esp)\n" /* out < end */ " jbe .L_break_loop\n" -" cmpl %%esi, 8(%%esp)\n" +" cmpl %%esi, 12(%%esp)\n" /* in < last */ " jbe .L_break_loop\n" ".L_do_loop:\n" @@ -145,7 +501,7 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */ " orl %%eax, %%edx\n" /* hold |= *((ushort *)in)++ << bits */ ".L_get_length_code:\n" -" movl 52(%%esp), %%eax\n" /* eax = lmask */ +" movl 56(%%esp), %%eax\n" /* eax = lmask */ " andl %%edx, %%eax\n" /* eax &= hold */ " movl (%%ebp,%%eax,4), %%eax\n" /* eax = lcode[hold & lmask] */ @@ -161,10 +517,11 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */ " stosb\n" " jmp .L_while_test\n" +".align 32,0x90\n" ".L_test_for_length_base:\n" " movl %%eax, %%ecx\n" /* len = this */ " shrl $16, %%ecx\n" /* len = this.val */ -" movl %%ecx, 60(%%esp)\n" /* len = this */ +" movl %%ecx, 64(%%esp)\n" /* save len */ " movb %%al, %%cl\n" " testb $16, %%al\n" @@ -184,13 +541,14 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */ " movb %%ch, %%cl\n" /* move op back to ecx */ ".L_add_bits_to_len:\n" -" movl $1, %%eax\n" +" subb %%cl, %%bl\n" +" xorl %%eax, %%eax\n" +" incl %%eax\n" " shll %%cl, %%eax\n" " decl %%eax\n" -" subb %%cl, %%bl\n" " andl %%edx, %%eax\n" /* eax &= hold */ " shrl %%cl, %%edx\n" -" addl %%eax, 60(%%esp)\n" /* len += hold & mask[op] */ +" addl %%eax, 64(%%esp)\n" /* len += hold & mask[op] */ ".L_decode_distance:\n" " cmpb $15, %%bl\n" @@ -204,8 +562,8 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */ " orl %%eax, %%edx\n" /* hold |= *((ushort *)in)++ << bits */ ".L_get_distance_code:\n" -" movl 56(%%esp), %%eax\n" /* eax = dmask */ -" movl 48(%%esp), %%ecx\n" /* ecx = dcode */ +" movl 60(%%esp), %%eax\n" /* eax = dmask */ +" movl 36(%%esp), %%ecx\n" /* ecx = dcode */ " andl %%edx, %%eax\n" /* eax &= hold */ " movl (%%ecx,%%eax,4), %%eax\n"/* eax = dcode[hold & dmask] */ @@ -234,223 +592,228 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */ " movb %%ch, %%cl\n" /* move op back to ecx */ ".L_add_bits_to_dist:\n" -" movl $1, %%eax\n" +" subb %%cl, %%bl\n" +" xorl %%eax, %%eax\n" +" incl %%eax\n" " shll %%cl, %%eax\n" " decl %%eax\n" /* (1 << op) - 1 */ -" subb %%cl, %%bl\n" " andl %%edx, %%eax\n" /* eax &= hold */ " shrl %%cl, %%edx\n" " addl %%eax, %%ebp\n" /* dist += hold & ((1 << op) - 1) */ ".L_check_window:\n" -" movl %%esi, 4(%%esp)\n" /* save in so from can use it's reg */ +" movl %%esi, 8(%%esp)\n" /* save in so from can use it's reg */ " movl %%edi, %%eax\n" -" subl 16(%%esp), %%eax\n" /* nbytes = out - beg */ +" subl 20(%%esp), %%eax\n" /* nbytes = out - beg */ " cmpl %%ebp, %%eax\n" " jb .L_clip_window\n" /* if (dist > nbytes) 4.2% */ -" movl 60(%%esp), %%ecx\n" +" movl 64(%%esp), %%ecx\n" /* ecx = len */ " movl %%edi, %%esi\n" " subl %%ebp, %%esi\n" /* from = out - dist */ -" subl $3, %%ecx\n" /* copy from to out */ +" sarl %%ecx\n" +" jnc .L_copy_two\n" /* if len % 2 == 0 */ + +" rep movsw\n" " movb (%%esi), %%al\n" " movb %%al, (%%edi)\n" -" movb 1(%%esi), %%al\n" -" movb 2(%%esi), %%ah\n" -" addl $3, %%esi\n" -" movb %%al, 1(%%edi)\n" -" movb %%ah, 2(%%edi)\n" -" addl $3, %%edi\n" -" rep movsb\n" +" incl %%edi\n" -" movl 4(%%esp), %%esi\n" /* move in back to %esi, toss from */ -" movl 44(%%esp), %%ebp\n" /* ebp = lcode */ +" movl 8(%%esp), %%esi\n" /* move in back to %esi, toss from */ +" movl 32(%%esp), %%ebp\n" /* ebp = lcode */ " jmp .L_while_test\n" +".L_copy_two:\n" +" rep movsw\n" +" movl 8(%%esp), %%esi\n" /* move in back to %esi, toss from */ +" movl 32(%%esp), %%ebp\n" /* ebp = lcode */ +" jmp .L_while_test\n" + +".align 32,0x90\n" ".L_check_dist_one:\n" " cmpl $1, %%ebp\n" /* if dist 1, is a memset */ " jne .L_check_window\n" -" cmpl %%edi, 16(%%esp)\n" -" je .L_check_window\n" +" cmpl %%edi, 20(%%esp)\n" +" je .L_check_window\n" /* out == beg, if outside window */ + +" movl 64(%%esp), %%ecx\n" /* ecx = len */ +" movb -1(%%edi), %%al\n" +" movb %%al, %%ah\n" + +" sarl %%ecx\n" +" jnc .L_set_two\n" +" movb %%al, (%%edi)\n" +" incl %%edi\n" -" decl %%edi\n" -" movl 60(%%esp), %%ecx\n" -" movb (%%edi), %%al\n" -" subl $3, %%ecx\n" - -" movb %%al, 1(%%edi)\n" /* memset out with from[-1] */ -" movb %%al, 2(%%edi)\n" -" movb %%al, 3(%%edi)\n" -" addl $4, %%edi\n" -" rep stosb\n" -" movl 44(%%esp), %%ebp\n" /* ebp = lcode */ +".L_set_two:\n" +" rep stosw\n" +" movl 32(%%esp), %%ebp\n" /* ebp = lcode */ " jmp .L_while_test\n" +".align 32,0x90\n" ".L_test_for_second_level_length:\n" " testb $64, %%al\n" " jnz .L_test_for_end_of_block\n" /* if ((op & 64) != 0) */ -" movl $1, %%eax\n" +" xorl %%eax, %%eax\n" +" incl %%eax\n" " shll %%cl, %%eax\n" " decl %%eax\n" " andl %%edx, %%eax\n" /* eax &= hold */ -" addl 60(%%esp), %%eax\n" /* eax += this.val */ +" addl 64(%%esp), %%eax\n" /* eax += len */ " movl (%%ebp,%%eax,4), %%eax\n" /* eax = lcode[val+(hold&mask[op])]*/ " jmp .L_dolen\n" +".align 32,0x90\n" ".L_test_for_second_level_dist:\n" " testb $64, %%al\n" " jnz .L_invalid_distance_code\n" /* if ((op & 64) != 0) */ -" movl $1, %%eax\n" +" xorl %%eax, %%eax\n" +" incl %%eax\n" " shll %%cl, %%eax\n" " decl %%eax\n" " andl %%edx, %%eax\n" /* eax &= hold */ -" addl %%ebp, %%eax\n" /* eax += this.val */ -" movl 48(%%esp), %%ecx\n" /* ecx = dcode */ +" addl %%ebp, %%eax\n" /* eax += dist */ +" movl 36(%%esp), %%ecx\n" /* ecx = dcode */ " movl (%%ecx,%%eax,4), %%eax\n" /* eax = dcode[val+(hold&mask[op])]*/ " jmp .L_dodist\n" +".align 32,0x90\n" ".L_clip_window:\n" " movl %%eax, %%ecx\n" -" movl 24(%%esp), %%eax\n" /* prepare for dist compare */ +" movl 48(%%esp), %%eax\n" /* eax = wsize */ " negl %%ecx\n" /* nbytes = -nbytes */ -" movl 32(%%esp), %%esi\n" /* from = window */ +" movl 28(%%esp), %%esi\n" /* from = window */ " cmpl %%ebp, %%eax\n" " jb .L_invalid_distance_too_far\n" /* if (dist > wsize) */ " addl %%ebp, %%ecx\n" /* nbytes = dist - nbytes */ -" cmpl $0, 28(%%esp)\n" +" cmpl $0, 52(%%esp)\n" " jne .L_wrap_around_window\n" /* if (write != 0) */ " subl %%ecx, %%eax\n" " addl %%eax, %%esi\n" /* from += wsize - nbytes */ -" movl 60(%%esp), %%eax\n" -" cmpl %%ecx, %%eax\n" -" jbe .L_do_copy1\n" /* if (nbytes >= len) */ - -" subl %%ecx, %%eax\n" /* len -= nbytes */ -" rep movsb\n" -" movl %%edi, %%esi\n" -" subl %%ebp, %%esi\n" /* from = out - dist */ -" jmp .L_do_copy1\n" - +" movl 64(%%esp), %%eax\n" /* eax = len */ " cmpl %%ecx, %%eax\n" -" jbe .L_do_copy1\n" /* if (nbytes >= len) */ +" jbe .L_do_copy\n" /* if (nbytes >= len) */ " subl %%ecx, %%eax\n" /* len -= nbytes */ " rep movsb\n" " movl %%edi, %%esi\n" " subl %%ebp, %%esi\n" /* from = out - dist */ -" jmp .L_do_copy1\n" +" jmp .L_do_copy\n" +".align 32,0x90\n" ".L_wrap_around_window:\n" -" movl 28(%%esp), %%eax\n" +" movl 52(%%esp), %%eax\n" /* eax = write */ " cmpl %%eax, %%ecx\n" " jbe .L_contiguous_in_window\n" /* if (write >= nbytes) */ -" addl 24(%%esp), %%esi\n" -" addl %%eax, %%esi\n" -" subl %%ecx, %%esi\n" /* from += wsize + write - nbytes */ +" addl 48(%%esp), %%esi\n" /* from += wsize */ +" addl %%eax, %%esi\n" /* from += write */ +" subl %%ecx, %%esi\n" /* from -= nbytes */ " subl %%eax, %%ecx\n" /* nbytes -= write */ -" movl 60(%%esp), %%eax\n" +" movl 64(%%esp), %%eax\n" /* eax = len */ " cmpl %%ecx, %%eax\n" -" jbe .L_do_copy1\n" /* if (nbytes >= len) */ +" jbe .L_do_copy\n" /* if (nbytes >= len) */ " subl %%ecx, %%eax\n" /* len -= nbytes */ " rep movsb\n" -" movl 32(%%esp), %%esi\n" /* from = window */ -" movl 28(%%esp), %%ecx\n" /* nbytes = write */ +" movl 28(%%esp), %%esi\n" /* from = window */ +" movl 52(%%esp), %%ecx\n" /* nbytes = write */ " cmpl %%ecx, %%eax\n" -" jbe .L_do_copy1\n" /* if (nbytes >= len) */ +" jbe .L_do_copy\n" /* if (nbytes >= len) */ " subl %%ecx, %%eax\n" /* len -= nbytes */ " rep movsb\n" " movl %%edi, %%esi\n" " subl %%ebp, %%esi\n" /* from = out - dist */ -" jmp .L_do_copy1\n" +" jmp .L_do_copy\n" +".align 32,0x90\n" ".L_contiguous_in_window:\n" " addl %%eax, %%esi\n" " subl %%ecx, %%esi\n" /* from += write - nbytes */ -" movl 60(%%esp), %%eax\n" +" movl 64(%%esp), %%eax\n" /* eax = len */ " cmpl %%ecx, %%eax\n" -" jbe .L_do_copy1\n" /* if (nbytes >= len) */ +" jbe .L_do_copy\n" /* if (nbytes >= len) */ " subl %%ecx, %%eax\n" /* len -= nbytes */ " rep movsb\n" " movl %%edi, %%esi\n" " subl %%ebp, %%esi\n" /* from = out - dist */ +" jmp .L_do_copy\n" /* if (nbytes >= len) */ -".L_do_copy1:\n" +".align 32,0x90\n" +".L_do_copy:\n" " movl %%eax, %%ecx\n" " rep movsb\n" -" movl 4(%%esp), %%esi\n" /* move in back to %esi, toss from */ -" movl 44(%%esp), %%ebp\n" /* ebp = lcode */ +" movl 8(%%esp), %%esi\n" /* move in back to %esi, toss from */ +" movl 32(%%esp), %%ebp\n" /* ebp = lcode */ " jmp .L_while_test\n" ".L_test_for_end_of_block:\n" " testb $32, %%al\n" " jz .L_invalid_literal_length_code\n" -" movl $1, 68(%%esp)\n" +" movl $1, 72(%%esp)\n" " jmp .L_break_loop_with_status\n" ".L_invalid_literal_length_code:\n" -" movl $2, 68(%%esp)\n" +" movl $2, 72(%%esp)\n" " jmp .L_break_loop_with_status\n" ".L_invalid_distance_code:\n" -" movl $3, 68(%%esp)\n" +" movl $3, 72(%%esp)\n" " jmp .L_break_loop_with_status\n" ".L_invalid_distance_too_far:\n" -" movl 4(%%esp), %%esi\n" -" movl $4, 68(%%esp)\n" +" movl 8(%%esp), %%esi\n" +" movl $4, 72(%%esp)\n" " jmp .L_break_loop_with_status\n" ".L_break_loop:\n" -" movl $0, 68(%%esp)\n" +" movl $0, 72(%%esp)\n" ".L_break_loop_with_status:\n" /* put in, out, bits, and hold back into ar and pop esp */ -" movl %%esi, 4(%%esp)\n" -" movl %%edi, 12(%%esp)\n" -" movl %%ebx, 40(%%esp)\n" -" movl %%edx, 36(%%esp)\n" +" movl %%esi, 8(%%esp)\n" /* save in */ +" movl %%edi, 16(%%esp)\n" /* save out */ +" movl %%ebx, 44(%%esp)\n" /* save bits */ +" movl %%edx, 40(%%esp)\n" /* save hold */ +" movl 4(%%esp), %%ebp\n" /* restore esp, ebp */ " movl (%%esp), %%esp\n" -" popl %%ebp\n" -" popf\n" : : "m" (ar) : "memory", "%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi" ); -#elif defined( _MSC_VER ) +#elif defined( _MSC_VER ) && ! defined( _M_AMD64 ) __asm { lea eax, ar - pushfd - push ebp - mov [eax], esp + mov [eax], esp /* save esp, ebp */ + mov [eax+4], ebp mov esp, eax - mov esi, [esp+4] /* esi = in */ - mov edi, [esp+12] /* edi = out */ - mov edx, [esp+36] /* edx = hold */ - mov ebx, [esp+40] /* ebx = bits */ - mov ebp, [esp+44] /* ebp = lcode */ + mov esi, [esp+8] /* esi = in */ + mov edi, [esp+16] /* edi = out */ + mov edx, [esp+40] /* edx = hold */ + mov ebx, [esp+44] /* ebx = bits */ + mov ebp, [esp+32] /* ebp = lcode */ cld jmp L_do_loop +ALIGN 4 L_while_test: - cmp [esp+20], edi + cmp [esp+24], edi jbe L_break_loop - cmp [esp+8], esi + cmp [esp+12], esi jbe L_break_loop L_do_loop: @@ -465,7 +828,7 @@ L_do_loop: or edx, eax /* hold |= *((ushort *)in)++ << bits */ L_get_length_code: - mov eax, [esp+52] /* eax = lmask */ + mov eax, [esp+56] /* eax = lmask */ and eax, edx /* eax &= hold */ mov eax, [ebp+eax*4] /* eax = lcode[hold & lmask] */ @@ -481,10 +844,11 @@ L_dolen: stosb jmp L_while_test +ALIGN 4 L_test_for_length_base: mov ecx, eax /* len = this */ shr ecx, 16 /* len = this.val */ - mov [esp+60], ecx /* len = this */ + mov [esp+64], ecx /* save len */ mov cl, al test al, 16 @@ -504,13 +868,14 @@ L_test_for_length_base: mov cl, ch /* move op back to ecx */ L_add_bits_to_len: - mov eax, 1 + sub bl, cl + xor eax, eax + inc eax shl eax, cl dec eax - sub bl, cl and eax, edx /* eax &= hold */ shr edx, cl - add [esp+60], eax /* len += hold & mask[op] */ + add [esp+64], eax /* len += hold & mask[op] */ L_decode_distance: cmp bl, 15 @@ -524,8 +889,8 @@ L_decode_distance: or edx, eax /* hold |= *((ushort *)in)++ << bits */ L_get_distance_code: - mov eax, [esp+56] /* eax = dmask */ - mov ecx, [esp+48] /* ecx = dcode */ + mov eax, [esp+60] /* eax = dmask */ + mov ecx, [esp+36] /* ecx = dcode */ and eax, edx /* eax &= hold */ mov eax, [ecx+eax*4]/* eax = dcode[hold & dmask] */ @@ -554,200 +919,207 @@ L_dodist: mov cl, ch /* move op back to ecx */ L_add_bits_to_dist: - mov eax, 1 + sub bl, cl + xor eax, eax + inc eax shl eax, cl dec eax /* (1 << op) - 1 */ - sub bl, cl and eax, edx /* eax &= hold */ shr edx, cl add ebp, eax /* dist += hold & ((1 << op) - 1) */ L_check_window: - mov [esp+4], esi /* save in so from can use it's reg */ + mov [esp+8], esi /* save in so from can use it's reg */ mov eax, edi - sub eax, [esp+16] /* nbytes = out - beg */ + sub eax, [esp+20] /* nbytes = out - beg */ cmp eax, ebp jb L_clip_window /* if (dist > nbytes) 4.2% */ - mov ecx, [esp+60] + mov ecx, [esp+64] /* ecx = len */ mov esi, edi sub esi, ebp /* from = out - dist */ - sub ecx, 3 /* copy from to out */ + sar ecx, 1 + jnc L_copy_two + + rep movsw mov al, [esi] mov [edi], al - mov al, [esi+1] - mov ah, [esi+2] - add esi, 3 - mov [edi+1], al - mov [edi+2], ah - add edi, 3 - rep movsb + inc edi + + mov esi, [esp+8] /* move in back to %esi, toss from */ + mov ebp, [esp+32] /* ebp = lcode */ + jmp L_while_test - mov esi, [esp+4] /* move in back to %esi, toss from */ - mov ebp, [esp+44] /* ebp = lcode */ +L_copy_two: + rep movsw + mov esi, [esp+8] /* move in back to %esi, toss from */ + mov ebp, [esp+32] /* ebp = lcode */ jmp L_while_test +ALIGN 4 L_check_dist_one: cmp ebp, 1 /* if dist 1, is a memset */ jne L_check_window - cmp [esp+16], edi - je L_check_window - - dec edi - mov ecx, [esp+60] - mov al, [edi] - sub ecx, 3 - - mov [edi+1], al /* memset out with from[-1] */ - mov [edi+2], al - mov [edi+3], al - add edi, 4 - rep stosb - mov ebp, [esp+44] /* ebp = lcode */ + cmp [esp+20], edi + je L_check_window /* out == beg, if outside window */ + + mov ecx, [esp+64] /* ecx = len */ + mov al, [edi-1] + mov ah, al + + sar ecx, 1 + jnc L_set_two + mov [edi], al /* memset out with from[-1] */ + inc edi + +L_set_two: + rep stosw + mov ebp, [esp+32] /* ebp = lcode */ jmp L_while_test +ALIGN 4 L_test_for_second_level_length: test al, 64 jnz L_test_for_end_of_block /* if ((op & 64) != 0) */ - mov eax, 1 + xor eax, eax + inc eax shl eax, cl dec eax and eax, edx /* eax &= hold */ - add eax, [esp+60] /* eax += this.val */ + add eax, [esp+64] /* eax += len */ mov eax, [ebp+eax*4] /* eax = lcode[val+(hold&mask[op])]*/ jmp L_dolen +ALIGN 4 L_test_for_second_level_dist: test al, 64 jnz L_invalid_distance_code /* if ((op & 64) != 0) */ - mov eax, 1 + xor eax, eax + inc eax shl eax, cl dec eax and eax, edx /* eax &= hold */ - add eax, ebp /* eax += this.val */ - mov ecx, [esp+48] /* ecx = dcode */ + add eax, ebp /* eax += dist */ + mov ecx, [esp+36] /* ecx = dcode */ mov eax, [ecx+eax*4] /* eax = dcode[val+(hold&mask[op])]*/ jmp L_dodist +ALIGN 4 L_clip_window: mov ecx, eax - mov eax, [esp+24] /* prepare for dist compare */ + mov eax, [esp+48] /* eax = wsize */ neg ecx /* nbytes = -nbytes */ - mov esi, [esp+32] /* from = window */ + mov esi, [esp+28] /* from = window */ cmp eax, ebp jb L_invalid_distance_too_far /* if (dist > wsize) */ add ecx, ebp /* nbytes = dist - nbytes */ - cmp dword ptr [esp+28], 0 + cmp dword ptr [esp+52], 0 jne L_wrap_around_window /* if (write != 0) */ sub eax, ecx add esi, eax /* from += wsize - nbytes */ - mov eax, [esp+60] - cmp eax, ecx - jbe L_do_copy1 /* if (nbytes >= len) */ - - sub eax, ecx /* len -= nbytes */ - rep movsb - mov esi, edi - sub esi, ebp /* from = out - dist */ - jmp L_do_copy1 - + mov eax, [esp+64] /* eax = len */ cmp eax, ecx - jbe L_do_copy1 /* if (nbytes >= len) */ + jbe L_do_copy /* if (nbytes >= len) */ sub eax, ecx /* len -= nbytes */ rep movsb mov esi, edi sub esi, ebp /* from = out - dist */ - jmp L_do_copy1 + jmp L_do_copy +ALIGN 4 L_wrap_around_window: - mov eax, [esp+28] + mov eax, [esp+52] /* eax = write */ cmp ecx, eax jbe L_contiguous_in_window /* if (write >= nbytes) */ - add esi, [esp+24] - add esi, eax - sub esi, ecx /* from += wsize + write - nbytes */ + add esi, [esp+48] /* from += wsize */ + add esi, eax /* from += write */ + sub esi, ecx /* from -= nbytes */ sub ecx, eax /* nbytes -= write */ - mov eax, [esp+60] + mov eax, [esp+64] /* eax = len */ cmp eax, ecx - jbe L_do_copy1 /* if (nbytes >= len) */ + jbe L_do_copy /* if (nbytes >= len) */ sub eax, ecx /* len -= nbytes */ rep movsb - mov esi, [esp+32] /* from = window */ - mov ecx, [esp+28] /* nbytes = write */ + mov esi, [esp+28] /* from = window */ + mov ecx, [esp+52] /* nbytes = write */ cmp eax, ecx - jbe L_do_copy1 /* if (nbytes >= len) */ + jbe L_do_copy /* if (nbytes >= len) */ sub eax, ecx /* len -= nbytes */ rep movsb mov esi, edi sub esi, ebp /* from = out - dist */ - jmp L_do_copy1 + jmp L_do_copy +ALIGN 4 L_contiguous_in_window: add esi, eax sub esi, ecx /* from += write - nbytes */ - mov eax, [esp+60] + mov eax, [esp+64] /* eax = len */ cmp eax, ecx - jbe L_do_copy1 /* if (nbytes >= len) */ + jbe L_do_copy /* if (nbytes >= len) */ sub eax, ecx /* len -= nbytes */ rep movsb mov esi, edi sub esi, ebp /* from = out - dist */ + jmp L_do_copy -L_do_copy1: +ALIGN 4 +L_do_copy: mov ecx, eax rep movsb - mov esi, [esp+4] /* move in back to %esi, toss from */ - mov ebp, [esp+44] /* ebp = lcode */ + mov esi, [esp+8] /* move in back to %esi, toss from */ + mov ebp, [esp+32] /* ebp = lcode */ jmp L_while_test L_test_for_end_of_block: test al, 32 jz L_invalid_literal_length_code - mov dword ptr [esp+68], 1 + mov dword ptr [esp+72], 1 jmp L_break_loop_with_status L_invalid_literal_length_code: - mov dword ptr [esp+68], 2 + mov dword ptr [esp+72], 2 jmp L_break_loop_with_status L_invalid_distance_code: - mov dword ptr [esp+68], 3 + mov dword ptr [esp+72], 3 jmp L_break_loop_with_status L_invalid_distance_too_far: mov esi, [esp+4] - mov dword ptr [esp+68], 4 + mov dword ptr [esp+72], 4 jmp L_break_loop_with_status L_break_loop: - mov dword ptr [esp+68], 0 + mov dword ptr [esp+72], 0 L_break_loop_with_status: /* put in, out, bits, and hold back into ar and pop esp */ - mov [esp+4], esi - mov [esp+12], edi - mov [esp+40], ebx - mov [esp+36], edx + mov [esp+8], esi /* save in */ + mov [esp+16], edi /* save out */ + mov [esp+44], ebx /* save bits */ + mov [esp+40], edx /* save hold */ + mov ebp, [esp+4] /* restore esp, ebp */ mov esp, [esp] - pop ebp - popfd } +#else +#error "x86 architecture not defined" #endif if (ar.status > 1) { @@ -772,10 +1144,12 @@ L_break_loop_with_status: /* update state and return */ strm->next_in = ar.in; strm->next_out = ar.out; - strm->avail_in = (unsigned)(ar.in < ar.last ? 5 + (ar.last - ar.in) : - 5 - (ar.in - ar.last)); - strm->avail_out = (unsigned)(ar.out < ar.end ? 257 + (ar.end - ar.out) : - 257 - (ar.out - ar.end)); + strm->avail_in = (unsigned)(ar.in < ar.last ? + PAD_AVAIL_IN + (ar.last - ar.in) : + PAD_AVAIL_IN - (ar.in - ar.last)); + strm->avail_out = (unsigned)(ar.out < ar.end ? + PAD_AVAIL_OUT + (ar.end - ar.out) : + PAD_AVAIL_OUT - (ar.out - ar.end)); state->hold = ar.hold; state->bits = ar.bits; return; diff --git a/contrib/inflate86/inffast.S b/contrib/inflate86/inffast.S index f9bffd5e..2245a290 100644 --- a/contrib/inflate86/inffast.S +++ b/contrib/inflate86/inffast.S @@ -188,17 +188,8 @@ /* * typedef enum inflate_mode consts, in inflate.h */ -#ifndef NO_GUNZIP -#define GUNZIP -#endif - -#ifdef GUNZIP #define INFLATE_MODE_TYPE 11 /* state->mode flags enum-ed in inflate.h */ #define INFLATE_MODE_BAD 26 -#else -#define INFLATE_MODE_TYPE 3 -#define INFLATE_MODE_BAD 17 -#endif #if ! defined( USE_MMX ) && ! defined( NO_MMX ) diff --git a/contrib/vstudio/vc7/zlib.rc b/contrib/vstudio/vc7/zlib.rc index 3ebe25bc..cb779f7c 100644 --- a/contrib/vstudio/vc7/zlib.rc +++ b/contrib/vstudio/vc7/zlib.rc @@ -2,8 +2,8 @@ #define IDR_VERSION1 1 IDR_VERSION1 VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE - FILEVERSION 1,2,2 - PRODUCTVERSION 1,2,2 + FILEVERSION 1,2,2,1 + PRODUCTVERSION 1,2,2,1 FILEFLAGSMASK VS_FFI_FILEFLAGSMASK FILEFLAGS 0 FILEOS VOS_DOS_WINDOWS32 @@ -17,7 +17,7 @@ BEGIN BEGIN VALUE "FileDescription", "zlib data compression library\0" - VALUE "FileVersion", "1.2.2\0" + VALUE "FileVersion", "1.2.2.1\0" VALUE "InternalName", "zlib\0" VALUE "OriginalFilename", "zlib.dll\0" VALUE "ProductName", "ZLib.DLL\0" diff --git a/crc32.c b/crc32.c index b39c7e12..a7fd3f86 100644 --- a/crc32.c +++ b/crc32.c @@ -1,12 +1,12 @@ /* crc32.c -- compute the CRC-32 of a data stream - * Copyright (C) 1995-2003 Mark Adler + * Copyright (C) 1995-2004 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h * * Thanks to Rodney Brown for his contribution of faster * CRC methods: exclusive-oring 32 bits of data at a time, and pre-computing * tables for updating the shift register in one step with three exclusive-ors - * instead of four steps with four exclusive-ors. This results about a factor - * of two increase in speed on a Power PC G4 (PPC7455) using gcc -O3. + * instead of four steps with four exclusive-ors. This results in about a + * factor of two increase in speed on a Power PC G4 (PPC7455) using gcc -O3. */ /* @(#) $Id$ */ @@ -72,6 +72,9 @@ local void make_crc_table OF((void)); #ifdef MAKECRCH local void write_table OF((FILE *, const unsigned long FAR *)); #endif /* MAKECRCH */ +local unsigned long gf2_matrix_times OF((unsigned long *mat, + unsigned long vec)); +local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat)); /* Generate tables for a byte-wise 32-bit CRC calculation on the polynomial: @@ -331,3 +334,89 @@ local unsigned long crc32_big(crc, buf, len) } #endif /* BYFOUR */ + +#define GF2_DIM 32 /* dimension of GF(2) vectors (length of CRC) */ + +/* ========================================================================= */ +local unsigned long gf2_matrix_times(mat, vec) + unsigned long *mat; + unsigned long vec; +{ + unsigned long sum; + + sum = 0; + while (vec) { + if (vec & 1) + sum ^= *mat; + vec >>= 1; + mat++; + } + return sum; +} + +/* ========================================================================= */ +local void gf2_matrix_square(square, mat) + unsigned long *square; + unsigned long *mat; +{ + int n; + + for (n = 0; n < GF2_DIM; n++) + square[n] = gf2_matrix_times(mat, mat[n]); +} + +/* ========================================================================= */ +uLong ZEXPORT crc32_combine(crc1, crc2, len2) + uLong crc1; + uLong crc2; + uLong len2; +{ + int n; + unsigned long row; + unsigned long even[GF2_DIM]; /* even-power-of-two zeros operator */ + unsigned long odd[GF2_DIM]; /* odd-power-of-two zeros operator */ + + /* degenerate case */ + if (len2 == 0) + return crc1; + + /* put operator for one zero bit in odd */ + odd[0] = 0xedb88320L; /* CRC-32 polynomial */ + row = 1; + for (n = 1; n < GF2_DIM; n++) { + odd[n] = row; + row <<= 1; + } + + /* put operator for two zero bits in even */ + gf2_matrix_square(even, odd); + + /* put operator for four zero bits in odd */ + gf2_matrix_square(odd, even); + + /* apply len2 zeros to crc1 (first square will put the operator for one + zero byte, eight zero bits, in even) */ + do { + /* apply zeros operator for this bit of len2 */ + gf2_matrix_square(even, odd); + if (len2 & 1) + crc1 = gf2_matrix_times(even, crc1); + len2 >>= 1; + + /* if no more bits set, then done */ + if (len2 == 0) + break; + + /* another iteration of the loop with odd and even swapped */ + gf2_matrix_square(odd, even); + if (len2 & 1) + crc1 = gf2_matrix_times(odd, crc1); + len2 >>= 1; + + /* if no more bits set, then done */ + } while (len2 != 0); + + /* return combined crc */ + crc1 ^= crc2; + return crc1; +} diff --git a/deflate.c b/deflate.c index 0fc53bc1..cb723a1d 100644 --- a/deflate.c +++ b/deflate.c @@ -52,7 +52,7 @@ #include "deflate.h" const char deflate_copyright[] = - " deflate 1.2.2 Copyright 1995-2004 Jean-loup Gailly "; + " deflate 1.2.2.1 Copyright 1995-2004 Jean-loup Gailly "; /* If you use the zlib library in a product, an acknowledgment is welcome in the documentation of your product. If for some reason you cannot @@ -274,6 +274,7 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy, s->strm = strm; s->wrap = wrap; + s->gzhead = Z_NULL; s->w_bits = windowBits; s->w_size = 1 << s->w_bits; s->w_mask = s->w_size - 1; @@ -390,6 +391,17 @@ int ZEXPORT deflateReset (strm) return Z_OK; } +/* ========================================================================= */ +int ZEXPORT deflateSetHeader (strm, head) + z_streamp strm; + gz_headerp head; +{ + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; + if (strm->state->wrap != 2) return Z_STREAM_ERROR; + strm->state->gzhead = head; + return Z_OK; +} + /* ========================================================================= */ int ZEXPORT deflatePrime (strm, bits, value) z_streamp strm; @@ -548,20 +560,47 @@ int ZEXPORT deflate (strm, flush) if (s->status == INIT_STATE) { #ifdef GZIP if (s->wrap == 2) { + strm->adler = crc32(0L, Z_NULL, 0); put_byte(s, 31); put_byte(s, 139); put_byte(s, 8); - put_byte(s, 0); - put_byte(s, 0); - put_byte(s, 0); - put_byte(s, 0); - put_byte(s, 0); - put_byte(s, s->level == 9 ? 2 : - (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ? - 4 : 0)); - put_byte(s, 255); - s->status = BUSY_STATE; - strm->adler = crc32(0L, Z_NULL, 0); + if (s->gzhead == NULL) { + put_byte(s, 0); + put_byte(s, 0); + put_byte(s, 0); + put_byte(s, 0); + put_byte(s, 0); + put_byte(s, s->level == 9 ? 2 : + (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ? + 4 : 0)); + put_byte(s, 255); + s->status = BUSY_STATE; + } + else { + put_byte(s, (s->gzhead->text ? 1 : 0) + + (s->gzhead->hcrc ? 2 : 0) + + (s->gzhead->extra == Z_NULL ? 0 : 4) + + (s->gzhead->name == Z_NULL ? 0 : 8) + + (s->gzhead->comment == Z_NULL ? 0 : 16) + ); + put_byte(s, s->gzhead->time & 0xff); + put_byte(s, (s->gzhead->time >> 8) & 0xff); + put_byte(s, (s->gzhead->time >> 16) & 0xff); + put_byte(s, (s->gzhead->time >> 24) & 0xff); + put_byte(s, s->level == 9 ? 2 : + (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ? + 4 : 0)); + put_byte(s, s->gzhead->os & 0xff); + if (s->gzhead->extra != NULL) { + put_byte(s, s->gzhead->extra_len & 0xff); + put_byte(s, (s->gzhead->extra_len >> 8) & 0xff); + } + if (s->gzhead->hcrc) + strm->adler = crc32(strm->adler, s->pending_buf, + s->pending); + s->gzindex = 0; + s->status = EXTRA_STATE; + } } else #endif @@ -592,6 +631,110 @@ int ZEXPORT deflate (strm, flush) strm->adler = adler32(0L, Z_NULL, 0); } } +#ifdef GZIP + if (s->status == EXTRA_STATE) { + if (s->gzhead->extra != NULL) { + int beg = s->pending; /* start of bytes to update crc */ + + while (s->gzindex < (s->gzhead->extra_len & 0xffff)) { + if (s->pending == s->pending_buf_size) { + if (s->gzhead->hcrc && s->pending > beg) + strm->adler = crc32(strm->adler, s->pending_buf + beg, + s->pending - beg); + flush_pending(strm); + beg = s->pending; + if (s->pending == s->pending_buf_size) + break; + } + put_byte(s, s->gzhead->extra[s->gzindex]); + s->gzindex++; + } + if (s->gzhead->hcrc && s->pending > beg) + strm->adler = crc32(strm->adler, s->pending_buf + beg, + s->pending - beg); + if (s->gzindex == s->gzhead->extra_len) { + s->gzindex = 0; + s->status = NAME_STATE; + } + } + else + s->status = NAME_STATE; + } + if (s->status == NAME_STATE) { + if (s->gzhead->name != NULL) { + int beg = s->pending; /* start of bytes to update crc */ + int val; + + do { + if (s->pending == s->pending_buf_size) { + if (s->gzhead->hcrc && s->pending > beg) + strm->adler = crc32(strm->adler, s->pending_buf + beg, + s->pending - beg); + flush_pending(strm); + beg = s->pending; + if (s->pending == s->pending_buf_size) { + val = 1; + break; + } + } + val = s->gzhead->name[s->gzindex++]; + put_byte(s, val); + } while (val != 0); + if (s->gzhead->hcrc && s->pending > beg) + strm->adler = crc32(strm->adler, s->pending_buf + beg, + s->pending - beg); + if (val == 0) { + s->gzindex = 0; + s->status = COMMENT_STATE; + } + } + else + s->status = COMMENT_STATE; + } + if (s->status == COMMENT_STATE) { + if (s->gzhead->comment != NULL) { + int beg = s->pending; /* start of bytes to update crc */ + int val; + + do { + if (s->pending == s->pending_buf_size) { + if (s->gzhead->hcrc && s->pending > beg) + strm->adler = crc32(strm->adler, s->pending_buf + beg, + s->pending - beg); + flush_pending(strm); + beg = s->pending; + if (s->pending == s->pending_buf_size) { + val = 1; + break; + } + } + val = s->gzhead->comment[s->gzindex++]; + put_byte(s, val); + } while (val != 0); + if (s->gzhead->hcrc && s->pending > beg) + strm->adler = crc32(strm->adler, s->pending_buf + beg, + s->pending - beg); + if (val == 0) + s->status = HCRC_STATE; + } + else + s->status = HCRC_STATE; + } + if (s->status == HCRC_STATE) { + if (s->gzhead->hcrc) { + if (s->pending + 2 > s->pending_buf_size) + flush_pending(strm); + if (s->pending + 2 <= s->pending_buf_size) { + put_byte(s, strm->adler & 0xff); + put_byte(s, (strm->adler >> 8) & 0xff); + strm->adler = crc32(0L, Z_NULL, 0); + s->status = BUSY_STATE; + } + } + else + s->status = BUSY_STATE; + } +#endif /* Flush as much pending output as possible */ if (s->pending != 0) { @@ -704,7 +847,12 @@ int ZEXPORT deflateEnd (strm) if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; status = strm->state->status; - if (status != INIT_STATE && status != BUSY_STATE && + if (status != INIT_STATE && + status != EXTRA_STATE && + status != NAME_STATE && + status != COMMENT_STATE && + status != HCRC_STATE && + status != BUSY_STATE && status != FINISH_STATE) { return Z_STREAM_ERROR; } diff --git a/deflate.h b/deflate.h index 410681d1..c7c3ffdb 100644 --- a/deflate.h +++ b/deflate.h @@ -1,5 +1,5 @@ /* deflate.h -- internal compression state - * Copyright (C) 1995-2002 Jean-loup Gailly + * Copyright (C) 1995-2004 Jean-loup Gailly * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -49,6 +49,10 @@ /* All codes must not exceed MAX_BITS bits */ #define INIT_STATE 42 +#define EXTRA_STATE 69 +#define NAME_STATE 73 +#define COMMENT_STATE 91 +#define HCRC_STATE 103 #define BUSY_STATE 113 #define FINISH_STATE 666 /* Stream status */ @@ -95,6 +99,8 @@ typedef struct internal_state { Bytef *pending_out; /* next pending byte to output to the stream */ int pending; /* nb of bytes in the pending buffer */ int wrap; /* bit 0 true for zlib, bit 1 true for gzip */ + gz_headerp gzhead; /* gzip header information to write */ + int gzindex; /* where in extra, name, or comment */ Byte method; /* STORED (for zip only) or DEFLATED */ int last_flush; /* value of flush param for previous deflate call */ diff --git a/example.c b/example.c index c2361f98..6c8a0ee7 100644 --- a/example.c +++ b/example.c @@ -1,5 +1,5 @@ /* example.c -- usage example of the zlib compression library - * Copyright (C) 1995-2003 Jean-loup Gailly. + * Copyright (C) 1995-2004 Jean-loup Gailly. * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -11,8 +11,6 @@ #ifdef STDC # include # include -#else - extern void exit OF((int)); #endif #if defined(VMS) || defined(RISCOS) diff --git a/gzio.c b/gzio.c index 5e71b0ab..ce55f2dc 100644 --- a/gzio.c +++ b/gzio.c @@ -1,5 +1,5 @@ /* gzio.c -- IO on .gz files - * Copyright (C) 1995-2003 Jean-loup Gailly. + * Copyright (C) 1995-2004 Jean-loup Gailly. * For conditions of distribution and use, see copyright notice in zlib.h * * Compile this file with -DNO_GZCOMPRESS to avoid the compression code. @@ -11,7 +11,7 @@ #include "zutil.h" -#ifdef NO_DEFLATE /* for compatiblity with old definition */ +#ifdef NO_DEFLATE /* for compatibility with old definition */ # define NO_GZCOMPRESS #endif @@ -941,7 +941,6 @@ local uLong getLong (s) int ZEXPORT gzclose (file) gzFile file; { - int err; gz_stream *s = (gz_stream*)file; if (s == NULL) return Z_STREAM_ERROR; @@ -950,8 +949,8 @@ int ZEXPORT gzclose (file) #ifdef NO_GZCOMPRESS return Z_STREAM_ERROR; #else - err = do_flush (file, Z_FINISH); - if (err != Z_OK) return destroy((gz_stream*)file); + if (do_flush (file, Z_FINISH) != Z_OK) + return destroy((gz_stream*)file); putLong (s->file, s->crc); putLong (s->file, (uLong)(s->in & 0xffffffff)); diff --git a/infback.c b/infback.c index 262f97c7..005ddec0 100644 --- a/infback.c +++ b/infback.c @@ -1,5 +1,5 @@ /* infback.c -- inflate using a call-back interface - * Copyright (C) 1995-2003 Mark Adler + * Copyright (C) 1995-2004 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -26,7 +26,7 @@ local void fixedtables OF((struct inflate_state FAR *state)); window and output buffer that is 2**windowBits bytes. */ int ZEXPORT inflateBackInit_(strm, windowBits, window, version, stream_size) -z_stream FAR *strm; +z_streamp strm; int windowBits; unsigned char FAR *window; const char *version; @@ -238,7 +238,7 @@ struct inflate_state FAR *state; are not correct, i.e. strm is Z_NULL or the state was not initialized. */ int ZEXPORT inflateBack(strm, in, in_desc, out, out_desc) -z_stream FAR *strm; +z_streamp strm; in_func in; void FAR *in_desc; out_func out; @@ -611,7 +611,7 @@ void FAR *out_desc; } int ZEXPORT inflateBackEnd(strm) -z_stream FAR *strm; +z_streamp strm; { if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0) return Z_STREAM_ERROR; diff --git a/inflate.c b/inflate.c index c6d38266..cca1d3b3 100644 --- a/inflate.c +++ b/inflate.c @@ -1,5 +1,5 @@ /* inflate.c -- zlib decompression - * Copyright (C) 1995-2003 Mark Adler + * Copyright (C) 1995-2004 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -113,6 +113,7 @@ z_streamp strm; state->mode = HEAD; state->last = 0; state->havedict = 0; + state->head = Z_NULL; state->wsize = 0; state->whave = 0; state->hold = 0; @@ -582,6 +583,8 @@ int flush; break; } state->flags = 0; /* expect zlib header */ + if (state->head != Z_NULL) + state->head->done = -1; if (!(state->wrap & 1) || /* check if zlib header allowed */ #else if ( @@ -621,16 +624,24 @@ int flush; state->mode = BAD; break; } + if (state->head != Z_NULL) + state->head->text = (int)((hold >> 8) & 1); if (state->flags & 0x0200) CRC2(state->check, hold); INITBITS(); state->mode = TIME; case TIME: NEEDBITS(32); + if (state->head != Z_NULL) + state->head->time = hold; if (state->flags & 0x0200) CRC4(state->check, hold); INITBITS(); state->mode = OS; case OS: NEEDBITS(16); + if (state->head != Z_NULL) { + state->head->xflags = (int)(hold & 0xff); + state->head->os = (int)(hold >> 8); + } if (state->flags & 0x0200) CRC2(state->check, hold); INITBITS(); state->mode = EXLEN; @@ -638,15 +649,26 @@ int flush; if (state->flags & 0x0400) { NEEDBITS(16); state->length = (unsigned)(hold); + if (state->head != Z_NULL) + state->head->extra_len = (unsigned)hold; if (state->flags & 0x0200) CRC2(state->check, hold); INITBITS(); } + else if (state->head != Z_NULL) + state->head->extra = Z_NULL; state->mode = EXTRA; case EXTRA: if (state->flags & 0x0400) { copy = state->length; if (copy > have) copy = have; if (copy) { + if (state->head != Z_NULL && + state->head->extra != Z_NULL) { + len = state->head->extra_len - state->length; + zmemcpy(state->head->extra + len, next, + len + copy > state->head->extra_max ? + state->head->extra_max - len : copy); + } if (state->flags & 0x0200) state->check = crc32(state->check, next, copy); have -= copy; @@ -655,6 +677,7 @@ int flush; } if (state->length) goto inf_leave; } + state->length = 0; state->mode = NAME; case NAME: if (state->flags & 0x0800) { @@ -662,13 +685,20 @@ int flush; copy = 0; do { len = (unsigned)(next[copy++]); + if (state->head != Z_NULL && + state->head->name != Z_NULL && + state->length < state->head->name_max) + state->head->name[state->length++] = len; } while (len && copy < have); - if (state->flags & 0x02000) + if (state->flags & 0x0200) state->check = crc32(state->check, next, copy); have -= copy; next += copy; if (len) goto inf_leave; } + else if (state->head != Z_NULL) + state->head->name = Z_NULL; + state->length = 0; state->mode = COMMENT; case COMMENT: if (state->flags & 0x1000) { @@ -676,13 +706,19 @@ int flush; copy = 0; do { len = (unsigned)(next[copy++]); + if (state->head != Z_NULL && + state->head->comment != Z_NULL && + state->length < state->head->comm_max) + state->head->comment[state->length++] = len; } while (len && copy < have); - if (state->flags & 0x02000) + if (state->flags & 0x0200) state->check = crc32(state->check, next, copy); have -= copy; next += copy; if (len) goto inf_leave; } + else if (state->head != Z_NULL) + state->head->comment = Z_NULL; state->mode = HCRC; case HCRC: if (state->flags & 0x0200) { @@ -694,6 +730,10 @@ int flush; } INITBITS(); } + if (state->head != Z_NULL) { + state->head->hcrc = (int)((state->flags >> 9) & 1); + state->head->done = 1; + } strm->adler = state->check = crc32(0L, Z_NULL, 0); state->mode = TYPE; break; @@ -1110,12 +1150,16 @@ uInt dictLength; /* check state */ if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; state = (struct inflate_state FAR *)strm->state; - if (state->mode != DICT) return Z_STREAM_ERROR; + if (state->wrap != 0 && state->mode != DICT) + return Z_STREAM_ERROR; /* check for correct dictionary id */ - id = adler32(0L, Z_NULL, 0); - id = adler32(id, dictionary, dictLength); - if (id != state->check) return Z_DATA_ERROR; + if (state->mode == DICT) { + id = adler32(0L, Z_NULL, 0); + id = adler32(id, dictionary, dictLength); + if (id != state->check) + return Z_DATA_ERROR; + } /* copy dictionary to window */ if (updatewindow(strm, strm->avail_out)) { @@ -1137,6 +1181,23 @@ uInt dictLength; return Z_OK; } +int ZEXPORT inflateGetHeader(strm, head) +z_streamp strm; +gz_headerp head; +{ + struct inflate_state FAR *state; + + /* check state */ + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; + state = (struct inflate_state FAR *)strm->state; + if ((state->wrap & 2) == 0) return Z_STREAM_ERROR; + + /* save header structure */ + state->head = head; + head->done = 0; + return Z_OK; +} + /* Search buf[0..len-1] for the pattern: 0, 0, 0xff, 0xff. Return when found or when out of input. When called, *have is the number of pattern bytes diff --git a/inflate.h b/inflate.h index 9a12c8fd..36286036 100644 --- a/inflate.h +++ b/inflate.h @@ -1,5 +1,5 @@ /* inflate.h -- internal inflate state definition - * Copyright (C) 1995-2003 Mark Adler + * Copyright (C) 1995-2004 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -19,7 +19,6 @@ /* Possible inflate modes between inflate() calls */ typedef enum { HEAD, /* i: waiting for magic header */ -#ifdef GUNZIP FLAGS, /* i: waiting for method and flags (gzip) */ TIME, /* i: waiting for modification time (gzip) */ OS, /* i: waiting for extra flags and operating system (gzip) */ @@ -28,7 +27,6 @@ typedef enum { NAME, /* i: waiting for end of file name (gzip) */ COMMENT, /* i: waiting for end of comment (gzip) */ HCRC, /* i: waiting for header crc (gzip) */ -#endif DICTID, /* i: waiting for dictionary check value */ DICT, /* waiting for inflateSetDictionary() call */ TYPE, /* i: waiting for type bits, including last-flag bit */ @@ -45,9 +43,7 @@ typedef enum { MATCH, /* o: waiting for output space to copy string */ LIT, /* o: waiting for output space to write literal */ CHECK, /* i: waiting for 32-bit check value */ -#ifdef GUNZIP LENGTH, /* i: waiting for 32-bit length (gzip) */ -#endif DONE, /* finished check, done -- remain here until reset */ BAD, /* got a data error -- remain here until reset */ MEM, /* got an inflate() memory error -- remain here until reset */ @@ -86,6 +82,7 @@ struct inflate_state { int flags; /* gzip header method and flags (0 if zlib) */ unsigned long check; /* protected copy of check value */ unsigned long total; /* protected copy of output count */ + gz_headerp head; /* where to save gzip header information */ /* sliding window */ unsigned wbits; /* log base 2 of requested window size */ unsigned wsize; /* window size or zero if not using window */ diff --git a/inftrees.c b/inftrees.c index 8a896b28..b5949958 100644 --- a/inftrees.c +++ b/inftrees.c @@ -9,7 +9,7 @@ #define MAXBITS 15 const char inflate_copyright[] = - " inflate 1.2.2 Copyright 1995-2004 Mark Adler "; + " inflate 1.2.2.1 Copyright 1995-2004 Mark Adler "; /* If you use the zlib library in a product, an acknowledgment is welcome in the documentation of your product. If for some reason you cannot @@ -62,7 +62,7 @@ unsigned short FAR *work; 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0}; static const unsigned short lext[31] = { /* Length codes 257..285 extra */ 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, - 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 199, 198}; + 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 77, 207}; static const unsigned short dbase[32] = { /* Distance codes 0..29 base */ 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, diff --git a/minigzip.c b/minigzip.c index 6de35dde..4ba5e50e 100644 --- a/minigzip.c +++ b/minigzip.c @@ -1,5 +1,5 @@ /* minigzip.c -- simulate gzip using the zlib compression library - * Copyright (C) 1995-2002 Jean-loup Gailly. + * Copyright (C) 1995-2004 Jean-loup Gailly. * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -21,8 +21,6 @@ #ifdef STDC # include # include -#else - extern void exit OF((int)); #endif #ifdef USE_MMAP diff --git a/projects/README.projects b/projects/README.projects index f32de76b..1c029e4a 100644 --- a/projects/README.projects +++ b/projects/README.projects @@ -10,18 +10,21 @@ please consider submitting the project to the contrib directory. Requirements ============ -- The project must build zlib using exclusively the source files from - the official zlib distribution. - -- If there are "official" makefiles in the zlib distribution, the builds - given by the makefiles must be compatible with the builds given by the - project. These builds are called "official" builds. - -- It is possible to add non-official pieces of code to the project, - if the resulting build remains compatible with an official build. - For example, it is possible to add an "ASM build" target besides - the regular target, by including ASM source files from the contrib - directory. +- The project must build zlib using the source files from the official + zlib source distribution, exclusively. + +- If the project produces redistributable builds (e.g. shared objects + or DLL files), these builds must be compatible to those produced by + makefiles, if such makefiles exist in the zlib distribution. + In particular, if the project produces a DLL build for the Win32 + platform, this build must comply to the officially-ammended Win32 DLL + Application Binary Interface (ABI), described in win32/DLL_FAQ.txt. + +- The project may provide additional build targets, which depend on + 3rd-party (unofficially-supported) software, present in the contrib + directory. For example, it is possible to provide an "ASM build", + besides the officially-supported build, and have ASM source files + among its dependencies. - If there are significant differences between the project files created by different versions of an IDE (e.g. Visual C++ 6.0 vs. 7.0), the name diff --git a/projects/visualc6/README.txt b/projects/visualc6/README.txt index 71d6105c..d0296c27 100644 --- a/projects/visualc6/README.txt +++ b/projects/visualc6/README.txt @@ -5,7 +5,23 @@ Copyright (C) 2004 Cosmin Truta. For conditions of distribution and use, see copyright notice in zlib.h. -To use: +This project builds the zlib binaries as follows: + +* Win32_DLL_Release\zlib1.dll DLL build +* Win32_DLL_Debug\zlib1d.dll DLL build (debug version) +* Win32_DLL_ASM_Release\zlib1.dll DLL build using ASM code +* Win32_DLL_ASM_Debug\zlib1d.dll DLL build using ASM code (debug version) +* Win32_LIB_Release\zlib.lib static build +* Win32_LIB_Debug\zlibd.lib static build (debug version) +* Win32_LIB_ASM_Release\zlib.lib static build using ASM code +* Win32_LIB_ASM_Debug\zlibd.lib static build using ASM code (debug version) + + +For more information regarding the DLL builds, please see the DLL FAQ +in ..\..\win32\DLL_FAQ.txt. + + +To build and test: 1) On the main menu, select "File | Open Workspace". Open "zlib.dsw". @@ -22,17 +38,36 @@ To use: select "Build | Execute ... (Ctrl+F5)". -This project builds the zlib binaries as follows: +To use: -* Win32_DLL_Release\zlib1.dll DLL build -* Win32_DLL_Debug\zlib1d.dll DLL build (debug version) -* Win32_DLL_ASM_Release\zlib1.dll DLL build using ASM code -* Win32_DLL_ASM_Debug\zlib1d.dll DLL build using ASM code (debug version) -* Win32_LIB_Release\zlib.lib static build -* Win32_LIB_Debug\zlibd.lib static build (debug version) -* Win32_LIB_ASM_Release\zlib.lib static build using ASM code -* Win32_LIB_ASM_Debug\zlibd.lib static build using ASM code (debug version) +1) Select "Project | Settings (Alt+F7)". + Make note of the configuration names used in your project. + Usually, these names are "Win32 Release" and "Win32 Debug". +2) In the Workspace window, select the "FileView" tab. + Right-click on the root item "Workspace '...'". + Select "Insert Project into Workspace". + Switch on the checkbox "Dependency of:", and select the name + of your project. Open "zlib.dsp". -For more information regarding the DLL builds, please see the DLL FAQ -in ..\..\win32\DLL_FAQ.txt. +3) Select "Build | Configurations". + For each configuration of your project: + 3.1) Choose the zlib configuration you wish to use. + 3.2) Click on "Add". + 3.3) Set the new zlib configuration name to the name used by + the configuration from the current iteration. + +4) Select "Build | Set Active Configuration". + Choose the configuration you wish to build. + +5) Select "Build | Build ... (F7)". + +6) If you built an executable program, select + "Build | Execute ... (Ctrl+F5)". + + +Note: + +To build the ASM-enabled code, you need Microsoft Assembler +(ML.EXE). You can get it by downloading and installing the +latest Processor Pack for Visual C++ 6.0. diff --git a/projects/visualc6/example.dsp b/projects/visualc6/example.dsp index 308a82c8..e072a37f 100644 --- a/projects/visualc6/example.dsp +++ b/projects/visualc6/example.dsp @@ -47,7 +47,7 @@ RSC=rc.exe # PROP Intermediate_Dir "Win32_DLL_Release" # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c +# ADD BASE CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c # SUBTRACT BASE CPP /YX # ADD CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c # SUBTRACT CPP /YX @@ -58,7 +58,7 @@ BSC32=bscmake.exe # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 -# ADD LINK32 zlib1.lib /nologo /subsystem:console /machine:I386 /libpath:"Win32_DLL_Release" +# ADD LINK32 /nologo /subsystem:console /machine:I386 !ELSEIF "$(CFG)" == "example - Win32 DLL Debug" @@ -73,7 +73,7 @@ LINK32=link.exe # PROP Intermediate_Dir "Win32_DLL_Debug" # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c +# ADD BASE CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c # SUBTRACT BASE CPP /YX # ADD CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c # SUBTRACT CPP /YX @@ -84,7 +84,7 @@ BSC32=bscmake.exe # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept -# ADD LINK32 zlib1d.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /libpath:"Win32_DLL_Debug" +# ADD LINK32 /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept !ELSEIF "$(CFG)" == "example - Win32 DLL ASM Release" @@ -99,7 +99,7 @@ LINK32=link.exe # PROP Intermediate_Dir "Win32_DLL_ASM_Release" # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c +# ADD BASE CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c # SUBTRACT BASE CPP /YX # ADD CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c # SUBTRACT CPP /YX @@ -110,7 +110,7 @@ BSC32=bscmake.exe # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 -# ADD LINK32 zlib1.lib /nologo /subsystem:console /machine:I386 /libpath:"Win32_DLL_ASM_Release" +# ADD LINK32 /nologo /subsystem:console /machine:I386 !ELSEIF "$(CFG)" == "example - Win32 DLL ASM Debug" @@ -125,7 +125,7 @@ LINK32=link.exe # PROP Intermediate_Dir "Win32_DLL_ASM_Debug" # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c +# ADD BASE CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c # SUBTRACT BASE CPP /YX # ADD CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c # SUBTRACT CPP /YX @@ -136,7 +136,7 @@ BSC32=bscmake.exe # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept -# ADD LINK32 zlib1d.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /libpath:"Win32_DLL_ASM_Debug" +# ADD LINK32 /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept !ELSEIF "$(CFG)" == "example - Win32 LIB Release" @@ -151,7 +151,7 @@ LINK32=link.exe # PROP Intermediate_Dir "Win32_LIB_Release" # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c +# ADD BASE CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c # SUBTRACT BASE CPP /YX # ADD CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c # SUBTRACT CPP /YX @@ -162,7 +162,7 @@ BSC32=bscmake.exe # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 -# ADD LINK32 zlib.lib /nologo /subsystem:console /machine:I386 /libpath:"Win32_LIB_Release" +# ADD LINK32 /nologo /subsystem:console /machine:I386 !ELSEIF "$(CFG)" == "example - Win32 LIB Debug" @@ -177,7 +177,7 @@ LINK32=link.exe # PROP Intermediate_Dir "Win32_LIB_Debug" # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c +# ADD BASE CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c # SUBTRACT BASE CPP /YX # ADD CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c # SUBTRACT CPP /YX @@ -188,7 +188,7 @@ BSC32=bscmake.exe # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept -# ADD LINK32 zlibd.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /libpath:"Win32_LIB_Debug" +# ADD LINK32 /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept !ELSEIF "$(CFG)" == "example - Win32 LIB ASM Release" @@ -203,7 +203,7 @@ LINK32=link.exe # PROP Intermediate_Dir "Win32_LIB_ASM_Release" # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c +# ADD BASE CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c # SUBTRACT BASE CPP /YX # ADD CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c # SUBTRACT CPP /YX @@ -214,7 +214,7 @@ BSC32=bscmake.exe # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 -# ADD LINK32 zlib.lib /nologo /subsystem:console /machine:I386 /libpath:"Win32_LIB_ASM_Release" +# ADD LINK32 /nologo /subsystem:console /machine:I386 !ELSEIF "$(CFG)" == "example - Win32 LIB ASM Debug" @@ -229,7 +229,7 @@ LINK32=link.exe # PROP Intermediate_Dir "Win32_LIB_ASM_Debug" # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c +# ADD BASE CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c # SUBTRACT BASE CPP /YX # ADD CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c # SUBTRACT CPP /YX @@ -240,7 +240,7 @@ BSC32=bscmake.exe # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept -# ADD LINK32 zlibd.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /libpath:"Win32_LIB_ASM_Debug" +# ADD LINK32 /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept !ENDIF diff --git a/projects/visualc6/minigzip.dsp b/projects/visualc6/minigzip.dsp index 91d981d4..f32024ea 100644 --- a/projects/visualc6/minigzip.dsp +++ b/projects/visualc6/minigzip.dsp @@ -47,7 +47,7 @@ RSC=rc.exe # PROP Intermediate_Dir "Win32_DLL_Release" # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c +# ADD BASE CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c # SUBTRACT BASE CPP /YX # ADD CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c # SUBTRACT CPP /YX @@ -58,7 +58,7 @@ BSC32=bscmake.exe # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 -# ADD LINK32 zlib1.lib /nologo /subsystem:console /machine:I386 /libpath:"Win32_DLL_Release" +# ADD LINK32 /nologo /subsystem:console /machine:I386 !ELSEIF "$(CFG)" == "minigzip - Win32 DLL Debug" @@ -73,7 +73,7 @@ LINK32=link.exe # PROP Intermediate_Dir "Win32_DLL_Debug" # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c +# ADD BASE CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c # SUBTRACT BASE CPP /YX # ADD CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c # SUBTRACT CPP /YX @@ -84,7 +84,7 @@ BSC32=bscmake.exe # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept -# ADD LINK32 zlib1d.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /libpath:"Win32_DLL_Debug" +# ADD LINK32 /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept !ELSEIF "$(CFG)" == "minigzip - Win32 DLL ASM Release" @@ -99,7 +99,7 @@ LINK32=link.exe # PROP Intermediate_Dir "Win32_DLL_ASM_Release" # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c +# ADD BASE CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c # SUBTRACT BASE CPP /YX # ADD CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c # SUBTRACT CPP /YX @@ -110,7 +110,7 @@ BSC32=bscmake.exe # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 -# ADD LINK32 zlib1.lib /nologo /subsystem:console /machine:I386 /libpath:"Win32_DLL_ASM_Release" +# ADD LINK32 /nologo /subsystem:console /machine:I386 !ELSEIF "$(CFG)" == "minigzip - Win32 DLL ASM Debug" @@ -125,7 +125,7 @@ LINK32=link.exe # PROP Intermediate_Dir "Win32_DLL_ASM_Debug" # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c +# ADD BASE CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c # SUBTRACT BASE CPP /YX # ADD CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c # SUBTRACT CPP /YX @@ -136,7 +136,7 @@ BSC32=bscmake.exe # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept -# ADD LINK32 zlib1d.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /libpath:"Win32_DLL_ASM_Debug" +# ADD LINK32 /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept !ELSEIF "$(CFG)" == "minigzip - Win32 LIB Release" @@ -151,7 +151,7 @@ LINK32=link.exe # PROP Intermediate_Dir "Win32_LIB_Release" # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c +# ADD BASE CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c # SUBTRACT BASE CPP /YX # ADD CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c # SUBTRACT CPP /YX @@ -162,7 +162,7 @@ BSC32=bscmake.exe # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 -# ADD LINK32 zlib.lib /nologo /subsystem:console /machine:I386 /libpath:"Win32_LIB_Release" +# ADD LINK32 /nologo /subsystem:console /machine:I386 !ELSEIF "$(CFG)" == "minigzip - Win32 LIB Debug" @@ -177,7 +177,7 @@ LINK32=link.exe # PROP Intermediate_Dir "Win32_LIB_Debug" # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c +# ADD BASE CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c # SUBTRACT BASE CPP /YX # ADD CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c # SUBTRACT CPP /YX @@ -188,7 +188,7 @@ BSC32=bscmake.exe # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept -# ADD LINK32 zlibd.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /libpath:"Win32_LIB_Debug" +# ADD LINK32 /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept !ELSEIF "$(CFG)" == "minigzip - Win32 LIB ASM Release" @@ -203,7 +203,7 @@ LINK32=link.exe # PROP Intermediate_Dir "Win32_LIB_ASM_Release" # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c +# ADD BASE CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c # SUBTRACT BASE CPP /YX # ADD CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c # SUBTRACT CPP /YX @@ -214,7 +214,7 @@ BSC32=bscmake.exe # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 -# ADD LINK32 zlib.lib /nologo /subsystem:console /machine:I386 /libpath:"Win32_LIB_ASM_Release" +# ADD LINK32 /nologo /subsystem:console /machine:I386 !ELSEIF "$(CFG)" == "minigzip - Win32 LIB ASM Debug" @@ -229,7 +229,7 @@ LINK32=link.exe # PROP Intermediate_Dir "Win32_LIB_ASM_Debug" # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c +# ADD BASE CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c # SUBTRACT BASE CPP /YX # ADD CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c # SUBTRACT CPP /YX @@ -240,7 +240,7 @@ BSC32=bscmake.exe # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept -# ADD LINK32 zlibd.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /libpath:"Win32_LIB_ASM_Debug" +# ADD LINK32 /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept !ENDIF diff --git a/projects/visualc6/zlib.dsp b/projects/visualc6/zlib.dsp index 8f16513f..0fe0604c 100644 --- a/projects/visualc6/zlib.dsp +++ b/projects/visualc6/zlib.dsp @@ -435,7 +435,7 @@ InputPath=..\..\contrib\masmx86\gvmat32.asm InputName=gvmat32 "$(IntDir)\$(InputName).obj" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" - ml /nologo /c /Cx /coff /Zi /Fo"$(IntDir)\$(InputName).obj" "$(InputPath)" + ml.exe /nologo /c /coff /Cx /Fo"$(IntDir)\$(InputName).obj" "$(InputPath)" # End Custom Build @@ -447,7 +447,7 @@ InputPath=..\..\contrib\masmx86\gvmat32.asm InputName=gvmat32 "$(IntDir)\$(InputName).obj" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" - ml /nologo /c /Cx /coff /Zi /Fo"$(IntDir)\$(InputName).obj" "$(InputPath)" + ml.exe /nologo /c /coff /Cx /Zi /Fo"$(IntDir)\$(InputName).obj" "$(InputPath)" # End Custom Build @@ -467,7 +467,7 @@ InputPath=..\..\contrib\masmx86\gvmat32.asm InputName=gvmat32 "$(IntDir)\$(InputName).obj" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" - ml /nologo /c /Cx /coff /Zi /Fo"$(IntDir)\$(InputName).obj" "$(InputPath)" + ml.exe /nologo /c /coff /Cx /Fo"$(IntDir)\$(InputName).obj" "$(InputPath)" # End Custom Build @@ -479,7 +479,7 @@ InputPath=..\..\contrib\masmx86\gvmat32.asm InputName=gvmat32 "$(IntDir)\$(InputName).obj" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" - ml /nologo /c /Cx /coff /Zi /Fo"$(IntDir)\$(InputName).obj" "$(InputPath)" + ml.exe /nologo /c /coff /Cx /Zi /Fo"$(IntDir)\$(InputName).obj" "$(InputPath)" # End Custom Build @@ -549,7 +549,7 @@ InputPath=..\..\contrib\masmx86\inffas32.asm InputName=inffas32 "$(IntDir)\$(InputName).obj" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" - ml /nologo /c /Cx /coff /Zi /Fo"$(IntDir)\$(InputName).obj" "$(InputPath)" + ml.exe /nologo /c /coff /Cx /Fo"$(IntDir)\$(InputName).obj" "$(InputPath)" # End Custom Build @@ -561,7 +561,7 @@ InputPath=..\..\contrib\masmx86\inffas32.asm InputName=inffas32 "$(IntDir)\$(InputName).obj" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" - ml /nologo /c /Cx /coff /Zi /Fo"$(IntDir)\$(InputName).obj" "$(InputPath)" + ml.exe /nologo /c /coff /Cx /Zi /Fo"$(IntDir)\$(InputName).obj" "$(InputPath)" # End Custom Build @@ -581,7 +581,7 @@ InputPath=..\..\contrib\masmx86\inffas32.asm InputName=inffas32 "$(IntDir)\$(InputName).obj" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" - ml /nologo /c /Cx /coff /Zi /Fo"$(IntDir)\$(InputName).obj" "$(InputPath)" + ml.exe /nologo /c /coff /Cx /Fo"$(IntDir)\$(InputName).obj" "$(InputPath)" # End Custom Build @@ -593,7 +593,7 @@ InputPath=..\..\contrib\masmx86\inffas32.asm InputName=inffas32 "$(IntDir)\$(InputName).obj" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" - ml /nologo /c /Cx /coff /Zi /Fo"$(IntDir)\$(InputName).obj" "$(InputPath)" + ml.exe /nologo /c /coff /Cx /Zi /Fo"$(IntDir)\$(InputName).obj" "$(InputPath)" # End Custom Build diff --git a/qnx/package.qpg b/qnx/package.qpg index bf142801..e80311ca 100644 --- a/qnx/package.qpg +++ b/qnx/package.qpg @@ -25,10 +25,10 @@ - - - - + + + + @@ -63,7 +63,7 @@ - 1.2.2 + 1.2.2.1 Medium Stable diff --git a/trees.c b/trees.c index 52c820fa..e5c66f61 100644 --- a/trees.c +++ b/trees.c @@ -1,5 +1,5 @@ /* trees.c -- output deflated data using Huffman coding - * Copyright (C) 1995-2003 Jean-loup Gailly + * Copyright (C) 1995-2004 Jean-loup Gailly * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -930,8 +930,25 @@ void _tr_flush_block(s, buf, stored_len, eof) /* Build the Huffman trees unless a stored block is forced */ if (s->level > 0) { - /* Check if the file is ascii or binary */ - if (s->strm->data_type == Z_UNKNOWN) set_data_type(s); + /* Check if the file is binary or text */ + if (stored_len > 0 && s->strm->data_type == Z_UNKNOWN) + set_data_type(s); + +#ifdef DEBUG + /* Write out literal/length frequencies for benchmarking */ + if (z_verbose) { + FILE *freq; + freq = fopen("defreq.txt", "a"); + if (freq != NULL) { + int n; + fputs("ltree:", freq); + for (n = 0; n < L_CODES; n++) + fprintf(freq, " %d", s->dyn_ltree[n].Freq); + putc('\n', freq); + fclose(freq); + } + } +#endif /* Construct the literal and distance trees */ build_tree(s, (tree_desc *)(&(s->l_desc))); @@ -1117,21 +1134,24 @@ local void compress_block(s, ltree, dtree) } /* =========================================================================== - * Set the data type to ASCII or BINARY, using a crude approximation: - * binary if more than 20% of the bytes are <= 6 or >= 128, ascii otherwise. - * IN assertion: the fields freq of dyn_ltree are set and the total of all - * frequencies does not exceed 64K (to fit in an int on 16 bit machines). + * Set the data type to BINARY or TEXT, using a crude approximation: + * set it to Z_TEXT if all symbols are either printable characters (33 to 255) + * or white spaces (9 to 13, or 32); or set it to Z_BINARY otherwise. + * IN assertion: the fields Freq of dyn_ltree are set. */ local void set_data_type(s) deflate_state *s; { - int n = 0; - unsigned ascii_freq = 0; - unsigned bin_freq = 0; - while (n < 7) bin_freq += s->dyn_ltree[n++].Freq; - while (n < 128) ascii_freq += s->dyn_ltree[n++].Freq; - while (n < LITERALS) bin_freq += s->dyn_ltree[n++].Freq; - s->strm->data_type = bin_freq > (ascii_freq >> 2) ? Z_BINARY : Z_ASCII; + int n; + + for (n = 0; n < 9; n++) + if (s->dyn_ltree[n].Freq != 0) + break; + if (n == 9) + for (n = 14; n < 32; n++) + if (s->dyn_ltree[n].Freq != 0) + break; + s->strm->data_type = (n == 32) ? Z_TEXT : Z_BINARY; } /* =========================================================================== diff --git a/win32/DLL_FAQ.txt b/win32/DLL_FAQ.txt index 1746a951..fb18e071 100644 --- a/win32/DLL_FAQ.txt +++ b/win32/DLL_FAQ.txt @@ -175,7 +175,7 @@ in the zlib distribution, or at the following location: zlib in other programming languages. Some of them, like Ada (GNAT) and Fortran (GNU G77), have C bindings implemented initially on Unix, and relying on the C calling convention. - On the other hand, the pre- .Net versions of Microsoft Visual + On the other hand, the pre- .NET versions of Microsoft Visual Basic require STDCALL, while Borland Delphi prefers, although it does not require, FASTCALL. @@ -203,10 +203,10 @@ in the zlib distribution, or at the following location: zlib distribution. - 8. I need to use zlib in my Microsoft .Net project. What can I + 8. I need to use zlib in my Microsoft .NET project. What can I do? - - Henrik Ravn has contributed a .Net wrapper around zlib. Look + - Henrik Ravn has contributed a .NET wrapper around zlib. Look into contrib/dotzlib/, inside the zlib distribution. @@ -225,8 +225,8 @@ in the zlib distribution, or at the following location: depend on it should also be linked to MSVCRT.DLL. -10. Why are you saying that ZLIB1.DLL and my application must be - linked to the same C run-time (CRT) library? I linked my +10. Why are you saying that ZLIB1.DLL and my application should + be linked to the same C run-time (CRT) library? I linked my application and my DLLs to different C libraries (e.g. my application to a static library, and my DLLs to MSVCRT.DLL), and everything works fine. @@ -277,12 +277,6 @@ in the zlib distribution, or at the following location: even run on it. Furthermore, no serious user should run Windows 95 without a proper update installed. - There is also the fact that the mainstream C compilers for - Windows are Microsoft Visual C++ 6.0, and gcc/MinGW. Both - are producing executables that link to MSVCRT.DLL by default, - without offering other dynamic CRTs as alternatives easy to - select by users. - 12. Why are you not linking ZLIB1.DLL to <> ? @@ -295,27 +289,60 @@ in the zlib distribution, or at the following location: to a static C library, you may as well consider linking zlib in statically, too. - * Linking ZLIB1.DLL to CRTDLL.DLL looks very appealing, - because CRTDLL.DLL is present on every Win32 installation. - Unfortunately, it has a series of problems: it raises - difficulties when using it with C++ code, it does not work - with 64-bit file offsets, (and so on...), and Microsoft - discontinued its support a long time ago. - - * Linking ZLIB1.DLL to MSVCR70.DLL, supplied with the - Microsoft .NET platform and Visual C++ 7.0 or newer, is not - a good option. Although it is available for free download - and distribution, its presence is scarce on today's Win32 - installations. If it will ever become more popular than - MSVCRT.DLL and will be pre-installed on the future Win32 - systems, we will probably think again about it. - - * Linking ZLIB1.DLL to NTDLL.DLL is not possible. - NTDLL.DLL exports only a part of the C library, and only on - Windows NT systems. - - -13. I need to link my own DLL build to a CRT different than + * Linking ZLIB1.DLL to CRTDLL.DLL looks appealing, because + CRTDLL.DLL is present on every Win32 installation. + Unfortunately, it has a series of problems: it does not + work properly with Microsoft's C++ libraries, it does not + provide support for 64-bit file offsets, (and so on...), + and Microsoft discontinued its support a long time ago. + + * Linking ZLIB1.DLL to MSVCR70.DLL or MSVCR71.DLL, supplied + with the Microsoft .NET platform, and Visual C++ 7.0/7.1, + raises problems related to the status of ZLIB1.DLL as a + system component. According to the Microsoft Knowledge Base + article KB326922 "INFO: Redistribution of the Shared C + Runtime Component in Visual C++ .NET", MSVCR70.DLL and + MSVCR71.DLL are not supposed to function as system DLLs, + because they may clash with MSVCRT.DLL. Instead, the + application's installer is supposed to put these DLLs + (if needed) in the application's private directory. + If ZLIB1.DLL depends on a non-system runtime, it cannot + function as a redistributable system component. + + * Linking ZLIB1.DLL to non-Microsoft runtimes, such as + Borland's, or Cygwin's, raises problems related to the + reliable presence of these runtimes on Win32 systems. + It's easier to let the DLL build of zlib up to the people + who distribute these runtimes, and who may proceed as + explained in the answer to Question 14. + + +13. If ZLIB1.DLL cannot be linked to MSVCR70.DLL or MSVCR71.DLL, + how can I build/use ZLIB1.DLL in Microsoft Visual C++ 7.0 + (Visual Studio .NET) or newer? + + - Due to the problems explained in the Microsoft Knowledge Base + article KB326922 (see the previous answer), the C runtime that + comes with the VC7 environment is no longer considered a + system component. That is, it should not be assumed that this + runtime exists, or may be installed in a system directory. + Since ZLIB1.DLL is supposed to be a system component, it may + not depend on a non-system component. + + In order to link ZLIB1.DLL and your application to MSVCRT.DLL + in VC7, you need the library of Visual C++ 6.0 or older. If + you don't have this library at hand, it's probably best not to + use ZLIB1.DLL. + + We are hoping that, in the future, Microsoft will provide a + way to build applications linked to a proper system runtime, + from the Visual C++ environment. Until then, you have a + couple of alternatives, such as linking zlib in statically. + If your application requires dynamic linking, you may proceed + as explained in the answer to Question 14. + + +14. I need to link my own DLL build to a CRT different than MSVCRT.DLL. What can I do? - Feel free to rebuild the DLL from the zlib sources, and link @@ -331,7 +358,7 @@ in the zlib distribution, or at the following location: CYGWIN1.DLL, and it is distributed under the name CYGZ.DLL. -14. May I include additional pieces of code that I find useful, +15. May I include additional pieces of code that I find useful, link them in ZLIB1.DLL, and export them? - No. A legitimate build of ZLIB1.DLL must not include code @@ -344,7 +371,7 @@ in the zlib distribution, or at the following location: is a redistributable file, named VCLxx.DLL. -15. May I remove some functionality out of ZLIB1.DLL, by enabling +16. May I remove some functionality out of ZLIB1.DLL, by enabling macros like NO_GZCOMPRESS or NO_GZIP at compile time? - No. A legitimate build of ZLIB1.DLL must provide the complete @@ -353,7 +380,7 @@ in the zlib distribution, or at the following location: different file name, as suggested in the previous answer. -16. I made my own ZLIB1.DLL build. Can I test it for compliance? +17. I made my own ZLIB1.DLL build. Can I test it for compliance? - We prefer that you download the official DLL from the zlib web site. If you need something peculiar from this DLL, you diff --git a/win32/zlib1.rc b/win32/zlib1.rc index 162ab8fc..2e985422 100644 --- a/win32/zlib1.rc +++ b/win32/zlib1.rc @@ -5,8 +5,8 @@ VS_VERSION_INFO VERSIONINFO #else VS_VERSION_INFO VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE #endif - FILEVERSION 1,2,2 - PRODUCTVERSION 1,2,2 + FILEVERSION 1,2,2,1 + PRODUCTVERSION 1,2,2,1 FILEFLAGSMASK VS_FFI_FILEFLAGSMASK #ifdef _DEBUG FILEFLAGS 1 @@ -23,12 +23,12 @@ BEGIN //language ID = U.S. English, char set = Windows, Multilingual BEGIN VALUE "FileDescription", "zlib data compression library\0" - VALUE "FileVersion", "1.2.2\0" + VALUE "FileVersion", "1.2.2.1\0" VALUE "InternalName", "zlib1.dll\0" VALUE "LegalCopyright", "(C) 1995-2004 Jean-loup Gailly & Mark Adler\0" VALUE "OriginalFilename", "zlib1.dll\0" VALUE "ProductName", "zlib\0" - VALUE "ProductVersion", "1.2.2\0" + VALUE "ProductVersion", "1.2.2.1\0" VALUE "Comments","DLL support by Alessandro Iacopetti & Gilles Vollant\0" END END diff --git a/zconf.h b/zconf.h index 3c21403f..6897bf02 100644 --- a/zconf.h +++ b/zconf.h @@ -43,6 +43,10 @@ # define get_crc_table z_get_crc_table # define zError z_zError +# define alloc_func z_alloc_func +# define free_func z_free_func +# define in_func z_in_func +# define out_func z_out_func # define Byte z_Byte # define uInt z_uInt # define uLong z_uLong diff --git a/zconf.in.h b/zconf.in.h index 3c21403f..6897bf02 100644 --- a/zconf.in.h +++ b/zconf.in.h @@ -43,6 +43,10 @@ # define get_crc_table z_get_crc_table # define zError z_zError +# define alloc_func z_alloc_func +# define free_func z_free_func +# define in_func z_in_func +# define out_func z_out_func # define Byte z_Byte # define uInt z_uInt # define uLong z_uLong diff --git a/zlib.3 b/zlib.3 index 3139e246..0e8d7350 100644 --- a/zlib.3 +++ b/zlib.3 @@ -1,4 +1,4 @@ -.TH ZLIB 3 "3 October 2004" +.TH ZLIB 3 "31 October 2004" .SH NAME zlib \- compression/decompression library .SH SYNOPSIS @@ -133,7 +133,7 @@ before asking for help. Send questions and/or comments to zlib@gzip.org, or (for the Windows DLL version) to Gilles Vollant (info@winimage.com). .SH AUTHORS -Version 1.2.2 +Version 1.2.2.1 Copyright (C) 1995-2004 Jean-loup Gailly (jloup@gzip.org) and Mark Adler (madler@alumni.caltech.edu). .LP diff --git a/zlib.h b/zlib.h index b4ddd343..64176503 100644 --- a/zlib.h +++ b/zlib.h @@ -1,5 +1,5 @@ /* zlib.h -- interface of the 'zlib' general purpose compression library - version 1.2.2, October 3rd, 2004 + version 1.2.2.1, October 31st, 2004 Copyright (C) 1995-2004 Jean-loup Gailly and Mark Adler @@ -37,8 +37,8 @@ extern "C" { #endif -#define ZLIB_VERSION "1.2.2" -#define ZLIB_VERNUM 0x1220 +#define ZLIB_VERSION "1.2.2.1" +#define ZLIB_VERNUM 0x1221 /* The 'zlib' compression library provides in-memory compression and @@ -95,13 +95,36 @@ typedef struct z_stream_s { free_func zfree; /* used to free the internal state */ voidpf opaque; /* private data object passed to zalloc and zfree */ - int data_type; /* best guess about the data type: ascii or binary */ + int data_type; /* best guess about the data type: binary or text */ uLong adler; /* adler32 value of the uncompressed data */ uLong reserved; /* reserved for future use */ } z_stream; typedef z_stream FAR *z_streamp; +/* + gzip header information passed to and from zlib routines. See RFC 1952 + for more details on the meanings of these fields. +*/ +typedef struct gz_header_s { + int text; /* true if compressed data believed to be text */ + uLong time; /* modification time */ + int xflags; /* extra flags (not used when writing a gzip file) */ + int os; /* operating system */ + Bytef *extra; /* pointer to extra field or Z_NULL if none */ + uInt extra_len; /* extra field length (valid if extra != Z_NULL) */ + uInt extra_max; /* space at extra (only when reading header) */ + Bytef *name; /* pointer to zero-terminated file name or Z_NULL */ + uInt name_max; /* space at name (only when reading header) */ + Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */ + uInt comm_max; /* space at comment (only when reading header) */ + int hcrc; /* true if there was or will be a header crc */ + int done; /* true when done reading gzip header (not used + when writing a gzip file) */ +} gz_header; + +typedef gz_header FAR *gz_headerp; + /* The application must update next_in and avail_in when avail_in has dropped to zero. It must update next_out and avail_out when avail_out @@ -170,7 +193,8 @@ typedef z_stream FAR *z_streamp; /* compression strategy; see deflateInit2() below for details */ #define Z_BINARY 0 -#define Z_ASCII 1 +#define Z_TEXT 1 +#define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */ #define Z_UNKNOWN 2 /* Possible values of the data_type field (though see inflate()) */ @@ -244,6 +268,10 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); and with zero avail_out, it must be called again after making room in the output buffer because there might be more output pending. + Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to + decide how much data to accumualte before producing output, in order to + maximize compression. + If the parameter flush is set to Z_SYNC_FLUSH, all pending output is flushed to the output buffer and the output is aligned on a byte boundary, so that the decompressor can get all input data available so far. (In particular @@ -255,7 +283,7 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); Z_SYNC_FLUSH, and the compression state is reset so that decompression can restart from this point if previous compressed data has been damaged or if random access is desired. Using Z_FULL_FLUSH too often can seriously degrade - the compression. + compression. If deflate returns with avail_out == 0, this function must be called again with the same value of the flush parameter and more output space (updated @@ -280,8 +308,8 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); deflate() sets strm->adler to the adler32 checksum of all input read so far (that is, total_in bytes). - deflate() may update data_type if it can make a good guess about - the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered + deflate() may update strm->data_type if it can make a good guess about + the input data type (Z_BINARY or Z_TEXT). In doubt, the data is considered binary. This field is only for information purposes and does not affect the compression algorithm in any manner. @@ -616,6 +644,30 @@ ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm, stream state was inconsistent. */ +ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm, + gz_headerp head)); +/* + deflateSetHeader() provides gzip header information for when a gzip + stream is requested by deflateInit2(). deflateSetHeader() may be called + after deflateInit2() or deflateReset() and before the first call of + deflate(). The text, time, os, extra field, name, and comment information + in the provided gz_header structure are written to the gzip header (xflag is + ignored -- the extra flags are set according to the compression level). The + caller must assure that, if not Z_NULL, name and comment are terminated with + a zero byte, and that if extra is not Z_NULL, that extra_len bytes are + available there. If hcrc is true, a gzip header crc is included. Note that + the current versions of the command-line version of gzip (up through version + 1.3.x) do not support header crc's, and will report that it is a "multi-part + gzip file" and give up. + + If deflateSetHeader is not used, the default gzip header has text false, + the time set to zero, and os set to 255, with no extra, name, or comment + fields. The gzip header is returned to the default state by deflateReset(). + + deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent. +*/ + /* ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm, int windowBits)); @@ -664,11 +716,14 @@ ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm, uInt dictLength)); /* Initializes the decompression dictionary from the given uncompressed byte - sequence. This function must be called immediately after a call of inflate - if this call returned Z_NEED_DICT. The dictionary chosen by the compressor - can be determined from the adler32 value returned by this call of - inflate. The compressor and decompressor must use exactly the same - dictionary (see deflateSetDictionary). + sequence. This function must be called immediately after a call of inflate, + if that call returned Z_NEED_DICT. The dictionary chosen by the compressor + can be determined from the adler32 value returned by that call of inflate. + The compressor and decompressor must use exactly the same dictionary (see + deflateSetDictionary). For raw inflate, this function can be called + immediately after inflateInit2() or inflateReset() and before any call of + inflate() to set the dictionary. The application must insure that the + dictionary that was used for compression is provided. inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a parameter is invalid (such as NULL dictionary) or the stream state is @@ -719,8 +774,48 @@ ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm)); stream state was inconsistent (such as zalloc or state being NULL). */ +ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm, + gz_headerp head)); +/* + inflateGetHeader() requests that gzip header information be stored in the + provided gz_header structure. inflateGetHeader() may be called after + inflateInit2() or inflateReset(), and before the first call of inflate(). + As inflate() processes the gzip stream, head->done is zero until the header + is completed, at which time head->done is set to one. If a zlib stream is + being decoded, then head->done is set to -1 to indicate that there will be + no gzip header information forthcoming. Note that Z_BLOCK can be used to + force inflate() to return immediately after header processing is complete + and before any actual data is decompressed. + + The text, time, xflags, and os fields are filled in with the gzip header + contents. hcrc is set to true if there is a header CRC. (The header CRC + was valid if done is set to one.) If extra is not Z_NULL, then extra_max + contains the maximum number of bytes to write to extra. Once done is true, + extra_len contains the actual extra field length, and extra contains the + extra field, or that field truncated if extra_max is less than extra_len. + If name is not Z_NULL, then up to name_max characters are written there, + terminated with a zero unless the length is greater than name_max. If + comment is not Z_NULL, then up to comm_max characters are written there, + terminated with a zero unless the length is greater than comm_max. When + any of extra, name, or comment are not Z_NULL and the respective field is + not present in the header, then that field is set to Z_NULL to signal its + absence. This allows the use of deflateSetHeader() with the returned + structure to duplicate the header. However if those fields are set to + allocated memory, then the application will need to save those pointers + elsewhere so that they can be eventually freed. + + If inflateGetHeader is not used, then the header information is simply + discarded. The header is always checked for validity, including the header + CRC if present. inflateReset() will reset the process to discard the header + information. The application would need to call inflateGetHeader() again to + retrieve the header from the next gzip stream. + + inflateGetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent. +*/ + /* -ZEXTERN int ZEXPORT inflateBackInit OF((z_stream FAR *strm, int windowBits, +ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits, unsigned char FAR *window)); Initialize the internal stream state for decompression using inflateBack() @@ -744,7 +839,7 @@ ZEXTERN int ZEXPORT inflateBackInit OF((z_stream FAR *strm, int windowBits, typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *)); typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned)); -ZEXTERN int ZEXPORT inflateBack OF((z_stream FAR *strm, +ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm, in_func in, void FAR *in_desc, out_func out, void FAR *out_desc)); /* @@ -813,7 +908,7 @@ ZEXTERN int ZEXPORT inflateBack OF((z_stream FAR *strm, that inflateBack() cannot return Z_OK. */ -ZEXTERN int ZEXPORT inflateBackEnd OF((z_stream FAR *strm)); +ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm)); /* All memory allocated by inflateBackInit() is freed. @@ -1119,7 +1214,6 @@ ZEXTERN void ZEXPORT gzclearerr OF((gzFile file)); */ ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); - /* Update a running Adler-32 checksum with the bytes buf[0..len-1] and return the updated checksum. If buf is NULL, this function returns @@ -1135,12 +1229,21 @@ ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); if (adler != original_adler) error(); */ +ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2, + uLong len2)); +/* + Combine two Adler-32 checksums into one. For two sequences of bytes, seq1 + and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for + each, adler1 and adler2. adler32_combine() returns the Adler-32 checksum of + seq1 and seq2 concatenated, requiring only adler1, adler2, and len2. +*/ + ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); /* - Update a running crc with the bytes buf[0..len-1] and return the updated - crc. If buf is NULL, this function returns the required initial value - for the crc. Pre- and post-conditioning (one's complement) is performed - within this function so it shouldn't be done by the application. + Update a running CRC-32 with the bytes buf[0..len-1] and return the + updated CRC-32. If buf is NULL, this function returns the required initial + value for the for the crc. Pre- and post-conditioning (one's complement) is + performed within this function so it shouldn't be done by the application. Usage example: uLong crc = crc32(0L, Z_NULL, 0); @@ -1151,6 +1254,16 @@ ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); if (crc != original_crc) error(); */ +ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, uLong len2)); + +/* + Combine two CRC-32 check values into one. For two sequences of bytes, + seq1 and seq2 with lengths len1 and len2, CRC-32 check values were + calculated for each, crc1 and crc2. crc32_combine() returns the CRC-32 + check value of seq1 and seq2 concatenated, requiring only crc1, crc2, and + len2. +*/ + /* various hacks, don't look :) */ @@ -1167,7 +1280,7 @@ ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method, int stream_size)); ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits, const char *version, int stream_size)); -ZEXTERN int ZEXPORT inflateBackInit_ OF((z_stream FAR *strm, int windowBits, +ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits, unsigned char FAR *window, const char *version, int stream_size)); diff --git a/zutil.c b/zutil.c index 0ef4f99f..6c08d13e 100644 --- a/zutil.c +++ b/zutil.c @@ -1,5 +1,5 @@ /* zutil.c -- target dependent utility functions for the compression library - * Copyright (C) 1995-2003 Jean-loup Gailly. + * Copyright (C) 1995-2004 Jean-loup Gailly. * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -11,10 +11,6 @@ struct internal_state {int dummy;}; /* for buggy compilers */ #endif -#ifndef STDC -extern void exit OF((int)); -#endif - const char * const z_errmsg[10] = { "need dictionary", /* Z_NEED_DICT 2 */ "stream end", /* Z_STREAM_END 1 */ diff --git a/zutil.h b/zutil.h index 7b42edca..579e9fc1 100644 --- a/zutil.h +++ b/zutil.h @@ -1,5 +1,5 @@ /* zutil.h -- internal interface and configuration of the compression library - * Copyright (C) 1995-2003 Jean-loup Gailly. + * Copyright (C) 1995-2004 Jean-loup Gailly. * For conditions of distribution and use, see copyright notice in zlib.h */