Changeset 6121dc77 in rtems


Ignore:
Timestamp:
Mar 18, 2011, 10:11:29 AM (9 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.11, master
Children:
a9503cc
Parents:
41ca776f
Message:

2010-03-22 Joel Sherrill <joel.sherrill@…>

  • ChangeLog?.zlib, FAQ, Makefile.am, README, adler32.c, compress.c, crc32.c, deflate.c, deflate.h, infback.c, inffast.c, inflate.c, inflate.h, inftrees.c, inftrees.h, trees.c, uncompr.c, zconf.h, zlib.3, zlib.h, zutil.c, zutil.h: Update to zlib 1.2.4.
  • gzclose.c, gzguts.h, gzlib.c, gzread.c, gzwrite.c, doc/algorithm.txt: New files.
  • algorithm.txt, gzio.c: Removed.
Location:
cpukit/zlib
Files:
5 added
1 deleted
21 edited
1 moved

Legend:

Unmodified
Added
Removed
  • cpukit/zlib/ChangeLog

    r41ca776f r6121dc77  
     12010-03-22      Joel Sherrill <joel.sherrill@oarcorp.com>
     2
     3        * ChangeLog.zlib, FAQ, Makefile.am, README, adler32.c, compress.c,
     4        crc32.c, deflate.c, deflate.h, infback.c, inffast.c, inflate.c,
     5        inflate.h, inftrees.c, inftrees.h, trees.c, uncompr.c, zconf.h,
     6        zlib.3, zlib.h, zutil.c, zutil.h: Update to zlib 1.2.4.
     7        * gzclose.c, gzguts.h, gzlib.c, gzread.c, gzwrite.c, doc/algorithm.txt:
     8        New files.
     9        * algorithm.txt, gzio.c: Removed.
     10
    1112008-12-18      Joel Sherrill <joel.sherrill@oarcorp.com>
    212
  • cpukit/zlib/ChangeLog.zlib

    r41ca776f r6121dc77  
    11
    22                ChangeLog file for zlib
     3
     4Changes in 1.2.4 (14 Mar 2010)
     5- Fix VER3 extraction in configure for no fourth subversion
     6- Update zlib.3, add docs to Makefile.in to make .pdf out of it
     7- Add zlib.3.pdf to distribution
     8- Don't set error code in gzerror() if passed pointer is NULL
     9- Apply destination directory fixes to CMakeLists.txt [Lowman]
     10- Move #cmakedefine's to a new zconf.in.cmakein
     11- Restore zconf.h for builds that don't use configure or cmake
     12- Add distclean to dummy Makefile for convenience
     13- Update and improve INDEX, README, and FAQ
     14- Update CMakeLists.txt for the return of zconf.h [Lowman]
     15- Update contrib/vstudio/vc9 and vc10 [Vollant]
     16- Change libz.dll.a back to libzdll.a in win32/Makefile.gcc
     17- Apply license and readme changes to contrib/asm686 [Raiter]
     18- Check file name lengths and add -c option in minigzip.c [Li]
     19- Update contrib/amd64 and contrib/masmx86/ [Vollant]
     20- Avoid use of "eof" parameter in trees.c to not shadow library variable
     21- Update make_vms.com for removal of zlibdefs.h [Zinser]
     22- Update assembler code and vstudio projects in contrib [Vollant]
     23- Remove outdated assembler code contrib/masm686 and contrib/asm586
     24- Remove old vc7 and vc8 from contrib/vstudio
     25- Update win32/Makefile.msc, add ZLIB_VER_SUBREVISION [Rowe]
     26- Fix memory leaks in gzclose_r() and gzclose_w(), file leak in gz_open()
     27- Add contrib/gcc_gvmat64 for longest_match and inflate_fast [Vollant]
     28- Remove *64 functions from win32/zlib.def (they're not 64-bit yet)
     29- Fix bug in void-returning vsprintf() case in gzwrite.c
     30- Fix name change from inflate.h in contrib/inflate86/inffas86.c
     31- Check if temporary file exists before removing in make_vms.com [Zinser]
     32- Fix make install and uninstall for --static option
     33- Fix usage of _MSC_VER in gzguts.h and zutil.h [Truta]
     34- Update readme.txt in contrib/masmx64 and masmx86 to assemble
     35
     36Changes in 1.2.3.9 (21 Feb 2010)
     37- Expunge gzio.c
     38- Move as400 build information to old
     39- Fix updates in contrib/minizip and contrib/vstudio
     40- Add const to vsnprintf test in configure to avoid warnings [Weigelt]
     41- Delete zconf.h (made by configure) [Weigelt]
     42- Change zconf.in.h to zconf.h.in per convention [Weigelt]
     43- Check for NULL buf in gzgets()
     44- Return empty string for gzgets() with len == 1 (like fgets())
     45- Fix description of gzgets() in zlib.h for end-of-file, NULL return
     46- Update minizip to 1.1 [Vollant]
     47- Avoid MSVC loss of data warnings in gzread.c, gzwrite.c
     48- Note in zlib.h that gzerror() should be used to distinguish from EOF
     49- Remove use of snprintf() from gzlib.c
     50- Fix bug in gzseek()
     51- Update contrib/vstudio, adding vc9 and vc10 [Kuno, Vollant]
     52- Fix zconf.h generation in CMakeLists.txt [Lowman]
     53- Improve comments in zconf.h where modified by configure
     54
     55Changes in 1.2.3.8 (13 Feb 2010)
     56- Clean up text files (tabs, trailing whitespace, etc.) [Oberhumer]
     57- Use z_off64_t in gz_zero() and gz_skip() to match state->skip
     58- Avoid comparison problem when sizeof(int) == sizeof(z_off64_t)
     59- Revert to Makefile.in from 1.2.3.6 (live with the clutter)
     60- Fix missing error return in gzflush(), add zlib.h note
     61- Add *64 functions to zlib.map [Levin]
     62- Fix signed/unsigned comparison in gz_comp()
     63- Use SFLAGS when testing shared linking in configure
     64- Add --64 option to ./configure to use -m64 with gcc
     65- Fix ./configure --help to correctly name options
     66- Have make fail if a test fails [Levin]
     67- Avoid buffer overrun in contrib/masmx64/gvmat64.asm [Simpson]
     68- Remove assembler object files from contrib
     69
     70Changes in 1.2.3.7 (24 Jan 2010)
     71- Always gzopen() with O_LARGEFILE if available
     72- Fix gzdirect() to work immediately after gzopen() or gzdopen()
     73- Make gzdirect() more precise when the state changes while reading
     74- Improve zlib.h documentation in many places
     75- Catch memory allocation failure in gz_open()
     76- Complete close operation if seek forward in gzclose_w() fails
     77- Return Z_ERRNO from gzclose_r() if close() fails
     78- Return Z_STREAM_ERROR instead of EOF for gzclose() being passed NULL
     79- Return zero for gzwrite() errors to match zlib.h description
     80- Return -1 on gzputs() error to match zlib.h description
     81- Add zconf.in.h to allow recovery from configure modification [Weigelt]
     82- Fix static library permissions in Makefile.in [Weigelt]
     83- Avoid warnings in configure tests that hide functionality [Weigelt]
     84- Add *BSD and DragonFly to Linux case in configure [gentoo 123571]
     85- Change libzdll.a to libz.dll.a in win32/Makefile.gcc [gentoo 288212]
     86- Avoid access of uninitialized data for first inflateReset2 call [Gomes]
     87- Keep object files in subdirectories to reduce the clutter somewhat
     88- Remove default Makefile and zlibdefs.h, add dummy Makefile
     89- Add new external functions to Z_PREFIX, remove duplicates, z_z_ -> z_
     90- Remove zlibdefs.h completely -- modify zconf.h instead
     91
     92Changes in 1.2.3.6 (17 Jan 2010)
     93- Avoid void * arithmetic in gzread.c and gzwrite.c
     94- Make compilers happier with const char * for gz_error message
     95- Avoid unused parameter warning in inflate.c
     96- Avoid signed-unsigned comparison warning in inflate.c
     97- Indent #pragma's for traditional C
     98- Fix usage of strwinerror() in glib.c, change to gz_strwinerror()
     99- Correct email address in configure for system options
     100- Update make_vms.com and add make_vms.com to contrib/minizip [Zinser]
     101- Update zlib.map [Brown]
     102- Fix Makefile.in for Solaris 10 make of example64 and minizip64 [Tšršk]
     103- Apply various fixes to CMakeLists.txt [Lowman]
     104- Add checks on len in gzread() and gzwrite()
     105- Add error message for no more room for gzungetc()
     106- Remove zlib version check in gzwrite()
     107- Defer compression of gzprintf() result until need to
     108- Use snprintf() in gzdopen() if available
     109- Remove USE_MMAP configuration determination (only used by minigzip)
     110- Remove examples/pigz.c (available separately)
     111- Update examples/gun.c to 1.6
     112
     113Changes in 1.2.3.5 (8 Jan 2010)
     114- Add space after #if in zutil.h for some compilers
     115- Fix relatively harmless bug in deflate_fast() [Exarevsky]
     116- Fix same problem in deflate_slow()
     117- Add $(SHAREDLIBV) to LIBS in Makefile.in [Brown]
     118- Add deflate_rle() for faster Z_RLE strategy run-length encoding
     119- Add deflate_huff() for faster Z_HUFFMAN_ONLY encoding
     120- Change name of "write" variable in inffast.c to avoid library collisions
     121- Fix premature EOF from gzread() in gzio.c [Brown]
     122- Use zlib header window size if windowBits is 0 in inflateInit2()
     123- Remove compressBound() call in deflate.c to avoid linking compress.o
     124- Replace use of errno in gz* with functions, support WinCE [Alves]
     125- Provide alternative to perror() in minigzip.c for WinCE [Alves]
     126- Don't use _vsnprintf on later versions of MSVC [Lowman]
     127- Add CMake build script and input file [Lowman]
     128- Update contrib/minizip to 1.1 [Svensson, Vollant]
     129- Moved nintendods directory from contrib to .
     130- Replace gzio.c with a new set of routines with the same functionality
     131- Add gzbuffer(), gzoffset(), gzclose_r(), gzclose_w() as part of above
     132- Update contrib/minizip to 1.1b
     133- Change gzeof() to return 0 on error instead of -1 to agree with zlib.h
     134
     135Changes in 1.2.3.4 (21 Dec 2009)
     136- Use old school .SUFFIXES in Makefile.in for FreeBSD compatibility
     137- Update comments in configure and Makefile.in for default --shared
     138- Fix test -z's in configure [Marquess]
     139- Build examplesh and minigzipsh when not testing
     140- Change NULL's to Z_NULL's in deflate.c and in comments in zlib.h
     141- Import LDFLAGS from the environment in configure
     142- Fix configure to populate SFLAGS with discovered CFLAGS options
     143- Adapt make_vms.com to the new Makefile.in [Zinser]
     144- Add zlib2ansi script for C++ compilation [Marquess]
     145- Add _FILE_OFFSET_BITS=64 test to make test (when applicable)
     146- Add AMD64 assembler code for longest match to contrib [Teterin]
     147- Include options from $SFLAGS when doing $LDSHARED
     148- Simplify 64-bit file support by introducing z_off64_t type
     149- Make shared object files in objs directory to work around old Sun cc
     150- Use only three-part version number for Darwin shared compiles
     151- Add rc option to ar in Makefile.in for when ./configure not run
     152- Add -WI,-rpath,. to LDFLAGS for OSF 1 V4*
     153- Set LD_LIBRARYN32_PATH for SGI IRIX shared compile
     154- Protect against _FILE_OFFSET_BITS being defined when compiling zlib
     155- Rename Makefile.in targets allstatic to static and allshared to shared
     156- Fix static and shared Makefile.in targets to be independent
     157- Correct error return bug in gz_open() by setting state [Brown]
     158- Put spaces before ;;'s in configure for better sh compatibility
     159- Add pigz.c (parallel implementation of gzip) to examples/
     160- Correct constant in crc32.c to UL [Leventhal]
     161- Reject negative lengths in crc32_combine()
     162- Add inflateReset2() function to work like inflateEnd()/inflateInit2()
     163- Include sys/types.h for _LARGEFILE64_SOURCE [Brown]
     164- Correct typo in doc/algorithm.txt [Janik]
     165- Fix bug in adler32_combine() [Zhu]
     166- Catch missing-end-of-block-code error in all inflates and in puff
     167    Assures that random input to inflate eventually results in an error
     168- Added enough.c (calculation of ENOUGH for inftrees.h) to examples/
     169- Update ENOUGH and its usage to reflect discovered bounds
     170- Fix gzerror() error report on empty input file [Brown]
     171- Add ush casts in trees.c to avoid pedantic runtime errors
     172- Fix typo in zlib.h uncompress() description [Reiss]
     173- Correct inflate() comments with regard to automatic header detection
     174- Remove deprecation comment on Z_PARTIAL_FLUSH (it stays)
     175- Put new version of gzlog (2.0) in examples with interruption recovery
     176- Add puff compile option to permit invalid distance-too-far streams
     177- Add puff TEST command options, ability to read piped input
     178- Prototype the *64 functions in zlib.h when _FILE_OFFSET_BITS == 64, but
     179  _LARGEFILE64_SOURCE not defined
     180- Fix Z_FULL_FLUSH to truly erase the past by resetting s->strstart
     181- Fix deflateSetDictionary() to use all 32K for output consistency
     182- Remove extraneous #define MIN_LOOKAHEAD in deflate.c (in deflate.h)
     183- Clear bytes after deflate lookahead to avoid use of uninitialized data
     184- Change a limit in inftrees.c to be more transparent to Coverity Prevent
     185- Update win32/zlib.def with exported symbols from zlib.h
     186- Correct spelling error in zlib.h [Willem]
     187- Allow Z_BLOCK for deflate() to force a new block
     188- Allow negative bits in inflatePrime() to delete existing bit buffer
     189- Add Z_TREES flush option to inflate() to return at end of trees
     190- Add inflateMark() to return current state information for random access
     191- Add Makefile for NintendoDS to contrib [Costa]
     192- Add -w in configure compile tests to avoid spurious warnings [Beucler]
     193- Fix typos in zlib.h comments for deflateSetDictionary()
     194- Fix EOF detection in transparent gzread() [Maier]
     195
     196Changes in 1.2.3.3 (2 October 2006)
     197- Make --shared the default for configure, add a --static option
     198- Add compile option to permit invalid distance-too-far streams
     199- Add inflateUndermine() function which is required to enable above
     200- Remove use of "this" variable name for C++ compatibility [Marquess]
     201- Add testing of shared library in make test, if shared library built
     202- Use ftello() and fseeko() if available instead of ftell() and fseek()
     203- Provide two versions of all functions that use the z_off_t type for
     204  binary compatibility -- a normal version and a 64-bit offset version,
     205  per the Large File Support Extension when _LARGEFILE64_SOURCE is
     206  defined; use the 64-bit versions by default when _FILE_OFFSET_BITS
     207  is defined to be 64
     208- Add a --uname= option to configure to perhaps help with cross-compiling
     209
     210Changes in 1.2.3.2 (3 September 2006)
     211- Turn off silly Borland warnings [Hay]
     212- Use off64_t and define _LARGEFILE64_SOURCE when present
     213- Fix missing dependency on inffixed.h in Makefile.in
     214- Rig configure --shared to build both shared and static [Teredesai, Truta]
     215- Remove zconf.in.h and instead create a new zlibdefs.h file
     216- Fix contrib/minizip/unzip.c non-encrypted after encrypted [Vollant]
     217- Add treebuild.xml (see http://treebuild.metux.de/) [Weigelt]
     218
     219Changes in 1.2.3.1 (16 August 2006)
     220- Add watcom directory with OpenWatcom make files [Daniel]
     221- Remove #undef of FAR in zconf.in.h for MVS [Fedtke]
     222- Update make_vms.com [Zinser]
     223- Use -fPIC for shared build in configure [Teredesai, Nicholson]
     224- Use only major version number for libz.so on IRIX and OSF1 [Reinholdtsen]
     225- Use fdopen() (not _fdopen()) for Interix in zutil.h [BŠck]
     226- Add some FAQ entries about the contrib directory
     227- Update the MVS question in the FAQ
     228- Avoid extraneous reads after EOF in gzio.c [Brown]
     229- Correct spelling of "successfully" in gzio.c [Randers-Pehrson]
     230- Add comments to zlib.h about gzerror() usage [Brown]
     231- Set extra flags in gzip header in gzopen() like deflate() does
     232- Make configure options more compatible with double-dash conventions
     233  [Weigelt]
     234- Clean up compilation under Solaris SunStudio cc [Rowe, Reinholdtsen]
     235- Fix uninstall target in Makefile.in [Truta]
     236- Add pkgconfig support [Weigelt]
     237- Use $(DESTDIR) macro in Makefile.in [Reinholdtsen, Weigelt]
     238- Replace set_data_type() with a more accurate detect_data_type() in
     239  trees.c, according to the txtvsbin.txt document [Truta]
     240- Swap the order of #include <stdio.h> and #include "zlib.h" in
     241  gzio.c, example.c and minigzip.c [Truta]
     242- Shut up annoying VS2005 warnings about standard C deprecation [Rowe,
     243  Truta] (where?)
     244- Fix target "clean" from win32/Makefile.bor [Truta]
     245- Create .pdb and .manifest files in win32/makefile.msc [Ziegler, Rowe]
     246- Update zlib www home address in win32/DLL_FAQ.txt [Truta]
     247- Update contrib/masmx86/inffas32.asm for VS2005 [Vollant, Van Wassenhove]
     248- Enable browse info in the "Debug" and "ASM Debug" configurations in
     249  the Visual C++ 6 project, and set (non-ASM) "Debug" as default [Truta]
     250- Add pkgconfig support [Weigelt]
     251- Add ZLIB_VER_MAJOR, ZLIB_VER_MINOR and ZLIB_VER_REVISION in zlib.h,
     252  for use in win32/zlib1.rc [Polushin, Rowe, Truta]
     253- Add a document that explains the new text detection scheme to
     254  doc/txtvsbin.txt [Truta]
     255- Add rfc1950.txt, rfc1951.txt and rfc1952.txt to doc/ [Truta]
     256- Move algorithm.txt into doc/ [Truta]
     257- Synchronize FAQ with website
     258- Fix compressBound(), was low for some pathological cases [Fearnley]
     259- Take into account wrapper variations in deflateBound()
     260- Set examples/zpipe.c input and output to binary mode for Windows
     261- Update examples/zlib_how.html with new zpipe.c (also web site)
     262- Fix some warnings in examples/gzlog.c and examples/zran.c (it seems
     263  that gcc became pickier in 4.0)
     264- Add zlib.map for Linux: "All symbols from zlib-1.1.4 remain
     265  un-versioned, the patch adds versioning only for symbols introduced in
     266  zlib-1.2.0 or later.  It also declares as local those symbols which are
     267  not designed to be exported." [Levin]
     268- Update Z_PREFIX list in zconf.in.h, add --zprefix option to configure
     269- Do not initialize global static by default in trees.c, add a response
     270  NO_INIT_GLOBAL_POINTERS to initialize them if needed [Marquess]
     271- Don't use strerror() in gzio.c under WinCE [Yakimov]
     272- Don't use errno.h in zutil.h under WinCE [Yakimov]
     273- Move arguments for AR to its usage to allow replacing ar [Marot]
     274- Add HAVE_VISIBILITY_PRAGMA in zconf.in.h for Mozilla [Randers-Pehrson]
     275- Improve inflateInit() and inflateInit2() documentation
     276- Fix structure size comment in inflate.h
     277- Change configure help option from --h* to --help [Santos]
    3278
    4279Changes in 1.2.3 (18 July 2005)
     
    14289- Fix some spelling errors in comments [Betts]
    15290- Correct inflateInit2() error return documentation in zlib.h
    16 - Added zran.c example of compressed data random access to examples
     291- Add zran.c example of compressed data random access to examples
    17292  directory, shows use of inflatePrime()
    18293- Fix cast for assignments to strm->state in inflate.c and infback.c
  • cpukit/zlib/Makefile.am

    r41ca776f r6121dc77  
    1111libz_a_SOURCES += crc32.c crc32.h
    1212libz_a_SOURCES += deflate.c deflate.h
    13 libz_a_SOURCES += gzio.c
     13libz_a_SOURCES += gzclose.c gzguts.h gzlib.c gzread.c gzwrite.c
    1414libz_a_SOURCES += infback.c
    1515libz_a_SOURCES += inffast.c inffast.h
  • cpukit/zlib/README

    r41ca776f r6121dc77  
    11ZLIB DATA COMPRESSION LIBRARY
    22
    3 zlib 1.2.3 is a general purpose data compression library.  All the code is
     3zlib 1.2.4 is a general purpose data compression library.  All the code is
    44thread safe.  The data format used by the zlib library is described by RFCs
    55(Request for Comments) 1950 to 1952 in the files
    66http://www.ietf.org/rfc/rfc1950.txt (zlib format), rfc1951.txt (deflate format)
    7 and rfc1952.txt (gzip format). These documents are also available in other
    8 formats from ftp://ftp.uu.net/graphics/png/documents/zlib/zdoc-index.html
     7and rfc1952.txt (gzip format).
    98
    109All functions of the compression library are documented in the file zlib.h
    11 (volunteer to write man pages welcome, contact zlib@gzip.org). A usage example
     10(volunteer to write man pages welcome, contact zlib@gzip.org).  A usage example
    1211of the library is given in the file example.c which also tests that the library
    13 is working correctly. Another example is given in the file minigzip.c. The
     12is working correctly.  Another example is given in the file minigzip.c. The
    1413compression library itself is composed of all source files except example.c and
    1514minigzip.c.
    1615
    1716To compile all files and run the test program, follow the instructions given at
    18 the top of Makefile. In short "make test; make install" should work for most
    19 machines. For Unix: "./configure; make test; make install". For MSDOS, use one
    20 of the special makefiles such as Makefile.msc. For VMS, use make_vms.com.
     17the top of Makefile.in.  In short "./configure; make test", and if that goes
     18well, "make install" should work for most flavors of Unix.  For Windows, use one
     19of the special makefiles in win32/ or projects/ . For VMS, use make_vms.com.
    2120
    2221Questions about zlib should be sent to <zlib@gzip.org>, or to Gilles Vollant
    23 <info@winimage.com> for the Windows DLL version. The zlib home page is
    24 http://www.zlib.org or http://www.gzip.org/zlib/ Before reporting a problem,
    25 please check this site to verify that you have the latest version of zlib;
    26 otherwise get the latest version and check whether the problem still exists or
    27 not.
     22<info@winimage.com> for the Windows DLL version.  The zlib home page is
     23http://zlib.net/ .  Before reporting a problem, please check this site to
     24verify that you have the latest version of zlib; otherwise get the latest
     25version and check whether the problem still exists or not.
    2826
    29 PLEASE read the zlib FAQ http://www.gzip.org/zlib/zlib_faq.html before asking
    30 for help.
     27PLEASE read the zlib FAQ http://zlib.net/zlib_faq.html before asking for help.
    3128
    32 Mark Nelson <markn@ieee.org> wrote an article about zlib for the Jan. 1997
    33 issue of  Dr. Dobb's Journal; a copy of the article is available in
    34 http://dogma.net/markn/articles/zlibtool/zlibtool.htm
     29Mark Nelson <markn@ieee.org> wrote an article about zlib for the Jan.  1997
     30issue of Dr.  Dobb's Journal; a copy of the article is available at
     31http://marknelson.us/1997/01/01/zlib-engine/ .
    3532
    36 The changes made in version 1.2.3 are documented in the file ChangeLog.
     33The changes made in version 1.2.4 are documented in the file ChangeLog.
    3734
    38 Unsupported third party contributions are provided in directory "contrib".
     35Unsupported third party contributions are provided in directory contrib/ .
    3936
    40 A Java implementation of zlib is available in the Java Development Kit
    41 http://java.sun.com/j2se/1.4.2/docs/api/java/util/zip/package-summary.html
    42 See the zlib home page http://www.zlib.org for details.
     37zlib is available in Java using the java.util.zip package, documented at
     38http://java.sun.com/developer/technicalArticles/Programming/compression/ .
    4339
    44 A Perl interface to zlib written by Paul Marquess <pmqs@cpan.org> is in the
    45 CPAN (Comprehensive Perl Archive Network) sites
    46 http://www.cpan.org/modules/by-module/Compress/
     40A Perl interface to zlib written by Paul Marquess <pmqs@cpan.org> is available
     41at CPAN (Comprehensive Perl Archive Network) sites, including
     42http://search.cpan.org/~pmqs/IO-Compress-Zlib/ .
    4743
    4844A Python interface to zlib written by A.M. Kuchling <amk@amk.ca> is
    4945available in Python 1.5 and later versions, see
    50 http://www.python.org/doc/lib/module-zlib.html
     46http://www.python.org/doc/lib/module-zlib.html .
    5147
    52 A zlib binding for TCL written by Andreas Kupries <a.kupries@westend.com> is
    53 availlable at http://www.oche.de/~akupries/soft/trf/trf_zip.html
     48zlib is built into tcl: http://wiki.tcl.tk/4610 .
    5449
    5550An experimental package to read and write files in .zip format, written on top
     
    7570  other compilers. Use "make test" to check your compiler.
    7671
    77 - gzdopen is not supported on RISCOS, BEOS and by some Mac compilers.
     72- gzdopen is not supported on RISCOS or BEOS.
    7873
    7974- For PalmOs, see http://palmzlib.sourceforge.net/
    80 
    81 - When building a shared, i.e. dynamic library on Mac OS X, the library must be
    82   installed before testing (do "make install" before "make test"), since the
    83   library location is specified in the library.
    8475
    8576
    8677Acknowledgments:
    8778
    88   The deflate format used by zlib was defined by Phil Katz. The deflate
    89   and zlib specifications were written by L. Peter Deutsch. Thanks to all the
    90   people who reported problems and suggested various improvements in zlib;
    91   they are too numerous to cite here.
     79  The deflate format used by zlib was defined by Phil Katz.  The deflate and
     80  zlib specifications were written by L.  Peter Deutsch. Thanks to all the
     81  people who reported problems and suggested various improvements in zlib; they
     82  are too numerous to cite here.
    9283
    9384Copyright notice:
    9485
    95  (C) 1995-2004 Jean-loup Gailly and Mark Adler
     86 (C) 1995-2010 Jean-loup Gailly and Mark Adler
    9687
    9788  This software is provided 'as-is', without any express or implied
     
    114105  jloup@gzip.org          madler@alumni.caltech.edu
    115106
    116 If you use the zlib library in a product, we would appreciate *not*
    117 receiving lengthy legal documents to sign. The sources are provided
    118 for free but without warranty of any kind.  The library has been
    119 entirely written by Jean-loup Gailly and Mark Adler; it does not
    120 include third-party code.
     107If you use the zlib library in a product, we would appreciate *not* receiving
     108lengthy legal documents to sign.  The sources are provided for free but without
     109warranty of any kind.  The library has been entirely written by Jean-loup
     110Gailly and Mark Adler; it does not include third-party code.
    121111
    122 If you redistribute modified sources, we would appreciate that you include
    123 in the file ChangeLog history information documenting your changes. Please
    124 read the FAQ for more information on the distribution of modified source
    125 versions.
     112If you redistribute modified sources, we would appreciate that you include in
     113the file ChangeLog history information documenting your changes.  Please read
     114the FAQ for more information on the distribution of modified source versions.
  • cpukit/zlib/adler32.c

    r41ca776f r6121dc77  
    11/* adler32.c -- compute the Adler-32 checksum of a data stream
    2  * Copyright (C) 1995-2004 Mark Adler
     2 * Copyright (C) 1995-2007 Mark Adler
    33 * For conditions of distribution and use, see copyright notice in zlib.h
    44 */
     
    66/* @(#) $Id$ */
    77
    8 #define ZLIB_INTERNAL
    9 #include "zlib.h"
     8#include "zutil.h"
     9
     10#define local static
     11
     12local uLong adler32_combine_(uLong adler1, uLong adler2, z_off64_t len2);
    1013
    1114#define BASE 65521UL    /* largest prime smaller than 65536 */
     
    5558
    5659/* ========================================================================= */
    57 uLong ZEXPORT adler32(
    58     uLong adler,
    59     const Bytef *buf,
    60     uInt len)
     60uLong ZEXPORT adler32(adler, buf, len)
     61    uLong adler;
     62    const Bytef *buf;
     63    uInt len;
    6164{
    6265    unsigned long sum2;
     
    126129
    127130/* ========================================================================= */
    128 uLong ZEXPORT adler32_combine(
    129     uLong adler1,
    130     uLong adler2,
    131     z_off_t len2)
     131local uLong adler32_combine_(adler1, adler2, len2)
     132    uLong adler1;
     133    uLong adler2;
     134    z_off64_t len2;
    132135{
    133136    unsigned long sum1;
     
    142145    sum1 += (adler2 & 0xffff) + BASE - 1;
    143146    sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
    144     if (sum1 > BASE) sum1 -= BASE;
    145     if (sum1 > BASE) sum1 -= BASE;
    146     if (sum2 > (BASE << 1)) sum2 -= (BASE << 1);
    147     if (sum2 > BASE) sum2 -= BASE;
     147    if (sum1 >= BASE) sum1 -= BASE;
     148    if (sum1 >= BASE) sum1 -= BASE;
     149    if (sum2 >= (BASE << 1)) sum2 -= (BASE << 1);
     150    if (sum2 >= BASE) sum2 -= BASE;
    148151    return sum1 | (sum2 << 16);
    149152}
     153
     154/* ========================================================================= */
     155uLong ZEXPORT adler32_combine(adler1, adler2, len2)
     156    uLong adler1;
     157    uLong adler2;
     158    z_off_t len2;
     159{
     160    return adler32_combine_(adler1, adler2, len2);
     161}
     162
     163uLong ZEXPORT adler32_combine64(adler1, adler2, len2)
     164    uLong adler1;
     165    uLong adler2;
     166    z_off64_t len2;
     167{
     168    return adler32_combine_(adler1, adler2, len2);
     169}
  • cpukit/zlib/compress.c

    r41ca776f r6121dc77  
    11/* compress.c -- compress a memory buffer
    2  * Copyright (C) 1995-2003 Jean-loup Gailly.
     2 * Copyright (C) 1995-2005 Jean-loup Gailly.
    33 * For conditions of distribution and use, see copyright notice in zlib.h
    44 */
     
    2020   Z_STREAM_ERROR if the level parameter is invalid.
    2121*/
    22 int ZEXPORT compress2 (
    23     Bytef *dest,
    24     uLongf *destLen,
    25     const Bytef *source,
    26     uLong sourceLen,
    27     int level)
     22int ZEXPORT compress2 (dest, destLen, source, sourceLen, level)
     23    Bytef *dest;
     24    uLongf *destLen;
     25    const Bytef *source;
     26    uLong sourceLen;
     27    int level;
    2828{
    2929    z_stream stream;
     
    6060/* ===========================================================================
    6161 */
    62 int ZEXPORT compress (
    63     Bytef *dest,
    64     uLongf *destLen,
    65     const Bytef *source,
    66     uLong sourceLen)
     62int ZEXPORT compress (dest, destLen, source, sourceLen)
     63    Bytef *dest;
     64    uLongf *destLen;
     65    const Bytef *source;
     66    uLong sourceLen;
    6767{
    6868    return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
     
    7373   this function needs to be updated.
    7474 */
    75 uLong ZEXPORT compressBound (
    76     uLong sourceLen)
     75uLong ZEXPORT compressBound (sourceLen)
     76    uLong sourceLen;
    7777{
    78     return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + 11;
     78    return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) +
     79           (sourceLen >> 25) + 13;
    7980}
  • cpukit/zlib/crc32.c

    r41ca776f r6121dc77  
    11/* crc32.c -- compute the CRC-32 of a data stream
    2  * Copyright (C) 1995-2005 Mark Adler
     2 * Copyright (C) 1995-2006 Mark Adler
    33 * For conditions of distribution and use, see copyright notice in zlib.h
    44 *
     
    5454/* Definitions for doing the crc four data bytes at a time. */
    5555#ifdef BYFOUR
    56 #  define REV(w) (((w)>>24)+(((w)>>8)&0xff00)+ \
     56#  define REV(w) ((((w)>>24)&0xff)+(((w)>>8)&0xff00)+ \
    5757                (((w)&0xff00)<<8)+(((w)&0xff)<<24))
    5858   local unsigned long crc32_little OF((unsigned long,
     
    6969                                         unsigned long vec));
    7070local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat));
     71local uLong crc32_combine_(uLong crc1, uLong crc2, z_off64_t len2);
     72
    7173
    7274#ifdef DYNAMIC_CRC_TABLE
     
    203205 * This function can be used by asm versions of crc32()
    204206 */
    205 const unsigned long FAR * ZEXPORT get_crc_table(void)
     207const unsigned long FAR * ZEXPORT get_crc_table()
    206208{
    207209#ifdef DYNAMIC_CRC_TABLE
     
    217219
    218220/* ========================================================================= */
    219 unsigned long ZEXPORT crc32(
    220     uLong crc,
    221     const Bytef *buf,
    222     uInt len)
     221unsigned long ZEXPORT crc32(crc, buf, len)
     222    unsigned long crc;
     223    const unsigned char FAR *buf;
     224    uInt len;
    223225{
    224226    if (buf == Z_NULL) return 0UL;
     
    260262
    261263/* ========================================================================= */
    262 local unsigned long crc32_little(
    263     unsigned long crc,
    264     const unsigned char FAR *buf,
    265     unsigned len)
     264local unsigned long crc32_little(crc, buf, len)
     265    unsigned long crc;
     266    const unsigned char FAR *buf;
     267    unsigned len;
    266268{
    267269    register u4 c;
     
    300302
    301303/* ========================================================================= */
    302 local unsigned long crc32_big(
    303     unsigned long crc,
    304     const unsigned char FAR *buf,
    305     unsigned len)
     304local unsigned long crc32_big(crc, buf, len)
     305    unsigned long crc;
     306    const unsigned char FAR *buf;
     307    unsigned len;
    306308{
    307309    register u4 c;
     
    340342
    341343/* ========================================================================= */
    342 local unsigned long gf2_matrix_times(
    343     unsigned long *mat,
    344     unsigned long vec)
     344local unsigned long gf2_matrix_times(mat, vec)
     345    unsigned long *mat;
     346    unsigned long vec;
    345347{
    346348    unsigned long sum;
     
    357359
    358360/* ========================================================================= */
    359 local void gf2_matrix_square(
    360     unsigned long *square,
    361     unsigned long *mat)
     361local void gf2_matrix_square(square, mat)
     362    unsigned long *square;
     363    unsigned long *mat;
    362364{
    363365    int n;
     
    368370
    369371/* ========================================================================= */
    370 uLong ZEXPORT crc32_combine(
    371     uLong crc1,
    372     uLong crc2,
    373     z_off_t len2)
     372local uLong crc32_combine_(crc1, crc2, len2)
     373    uLong crc1;
     374    uLong crc2;
     375    z_off64_t len2;
    374376{
    375377    int n;
     
    378380    unsigned long odd[GF2_DIM];     /* odd-power-of-two zeros operator */
    379381
    380     /* degenerate case */
    381     if (len2 == 0)
     382    /* degenerate case (also disallow negative lengths) */
     383    if (len2 <= 0)
    382384        return crc1;
    383385
    384386    /* put operator for one zero bit in odd */
    385     odd[0] = 0xedb88320L;           /* CRC-32 polynomial */
     387    odd[0] = 0xedb88320UL;          /* CRC-32 polynomial */
    386388    row = 1;
    387389    for (n = 1; n < GF2_DIM; n++) {
     
    422424    return crc1;
    423425}
     426
     427/* ========================================================================= */
     428uLong ZEXPORT crc32_combine(crc1, crc2, len2)
     429    uLong crc1;
     430    uLong crc2;
     431    z_off_t len2;
     432{
     433    return crc32_combine_(crc1, crc2, len2);
     434}
     435
     436uLong ZEXPORT crc32_combine64(crc1, crc2, len2)
     437    uLong crc1;
     438    uLong crc2;
     439    z_off64_t len2;
     440{
     441    return crc32_combine_(crc1, crc2, len2);
     442}
  • cpukit/zlib/deflate.c

    r41ca776f r6121dc77  
    11/* deflate.c -- compress data using the deflation algorithm
    2  * Copyright (C) 1995-2005 Jean-loup Gailly.
     2 * Copyright (C) 1995-2010 Jean-loup Gailly and Mark Adler
    33 * For conditions of distribution and use, see copyright notice in zlib.h
    44 */
     
    5353
    5454const char deflate_copyright[] =
    55    " deflate 1.2.3 Copyright 1995-2005 Jean-loup Gailly ";
     55   " deflate 1.2.4 Copyright 1995-2010 Jean-loup Gailly and Mark Adler ";
    5656/*
    5757  If you use the zlib library in a product, an acknowledgment is welcome
     
    8080local block_state deflate_slow   OF((deflate_state *s, int flush));
    8181#endif
     82local block_state deflate_rle    OF((deflate_state *s, int flush));
     83local block_state deflate_huff   OF((deflate_state *s, int flush));
    8284local void lm_init        OF((deflate_state *s));
    8385local void putShortMSB    OF((deflate_state *s, uInt b));
    8486local void flush_pending  OF((z_streamp strm));
    8587local int read_buf        OF((z_streamp strm, Bytef *buf, unsigned size));
    86 #ifndef FASTEST
    8788#ifdef ASMV
    8889      void match_init OF((void)); /* asm code initialization */
     
    9192local uInt longest_match  OF((deflate_state *s, IPos cur_match));
    9293#endif
    93 #endif
    94 local uInt longest_match_fast OF((deflate_state *s, IPos cur_match));
    9594
    9695#ifdef DEBUG
     
    110109#endif
    111110/* Matches of length 3 are discarded if their distance exceeds TOO_FAR */
    112 
    113 #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
    114 /* Minimum amount of lookahead, except at the end of the input file.
    115  * See deflate.c for comments about the MIN_MATCH+1.
    116  */
    117111
    118112/* Values for max_lazy_match, good_match and max_chain_length, depending on
     
    202196
    203197/* ========================================================================= */
    204 int ZEXPORT deflateInit_(
    205     z_streamp strm,
    206     int level,
    207     const char *version,
    208     int stream_size)
     198int ZEXPORT deflateInit_(strm, level, version, stream_size)
     199    z_streamp strm;
     200    int level;
     201    const char *version;
     202    int stream_size;
    209203{
    210204    return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL,
     
    214208
    215209/* ========================================================================= */
    216 int ZEXPORT deflateInit2_(
    217     z_streamp strm,
    218     int  level,
    219     int  method,
    220     int  windowBits,
    221     int  memLevel,
    222     int  strategy,
    223     const char *version,
    224     int stream_size)
     210int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
     211                  version, stream_size)
     212    z_streamp strm;
     213    int  level;
     214    int  method;
     215    int  windowBits;
     216    int  memLevel;
     217    int  strategy;
     218    const char *version;
     219    int stream_size;
    225220{
    226221    deflate_state *s;
     
    287282    s->prev   = (Posf *)  ZALLOC(strm, s->w_size, sizeof(Pos));
    288283    s->head   = (Posf *)  ZALLOC(strm, s->hash_size, sizeof(Pos));
     284
     285    s->high_water = 0;      /* nothing written to s->window yet */
    289286
    290287    s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
     
    312309
    313310/* ========================================================================= */
    314 int ZEXPORT deflateSetDictionary (
    315     z_streamp strm,
    316     const Bytef *dictionary,
    317     uInt  dictLength)
     311int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength)
     312    z_streamp strm;
     313    const Bytef *dictionary;
     314    uInt  dictLength;
    318315{
    319316    deflate_state *s;
     
    332329
    333330    if (length < MIN_MATCH) return Z_OK;
    334     if (length > MAX_DIST(s)) {
    335         length = MAX_DIST(s);
     331    if (length > s->w_size) {
     332        length = s->w_size;
    336333        dictionary += dictLength - length; /* use the tail of the dictionary */
    337334    }
     
    354351
    355352/* ========================================================================= */
    356 int ZEXPORT deflateReset (
    357     z_streamp strm)
     353int ZEXPORT deflateReset (strm)
     354    z_streamp strm;
    358355{
    359356    deflate_state *s;
     
    390387
    391388/* ========================================================================= */
    392 int ZEXPORT deflateSetHeader (
    393     z_streamp strm,
    394     gz_headerp head)
     389int ZEXPORT deflateSetHeader (strm, head)
     390    z_streamp strm;
     391    gz_headerp head;
    395392{
    396393    if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
     
    401398
    402399/* ========================================================================= */
    403 int ZEXPORT deflatePrime (
    404     z_streamp strm,
    405     int bits,
    406     int value)
     400int ZEXPORT deflatePrime (strm, bits, value)
     401    z_streamp strm;
     402    int bits;
     403    int value;
    407404{
    408405    if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
     
    413410
    414411/* ========================================================================= */
    415 int ZEXPORT deflateParams(
    416     z_streamp strm,
    417     int level,
    418     int strategy)
     412int ZEXPORT deflateParams(strm, level, strategy)
     413    z_streamp strm;
     414    int level;
     415    int strategy;
    419416{
    420417    deflate_state *s;
     
    435432    func = configuration_table[s->level].func;
    436433
    437     if (func != configuration_table[level].func && strm->total_in != 0) {
     434    if ((strategy != s->strategy || func != configuration_table[level].func) &&
     435        strm->total_in != 0) {
    438436        /* Flush the last buffer: */
    439         err = deflate(strm, Z_PARTIAL_FLUSH);
     437        err = deflate(strm, Z_BLOCK);
    440438    }
    441439    if (s->level != level) {
     
    451449
    452450/* ========================================================================= */
    453 int ZEXPORT deflateTune(
    454     z_streamp strm,
    455     int good_length,
    456     int max_lazy,
    457     int nice_length,
    458     int max_chain)
     451int ZEXPORT deflateTune(strm, good_length, max_lazy, nice_length, max_chain)
     452    z_streamp strm;
     453    int good_length;
     454    int max_lazy;
     455    int nice_length;
     456    int max_chain;
    459457{
    460458    deflate_state *s;
     
    481479 * can emit on compressed data for some combinations of the parameters.
    482480 *
    483  * This function could be more sophisticated to provide closer upper bounds
    484  * for every combination of windowBits and memLevel, as well as wrap.
    485  * But even the conservative upper bound of about 14% expansion does not
    486  * seem onerous for output buffer allocation.
    487  */
    488 uLong ZEXPORT deflateBound(
    489     z_streamp strm,
    490     uLong sourceLen)
     481 * This function could be more sophisticated to provide closer upper bounds for
     482 * every combination of windowBits and memLevel.  But even the conservative
     483 * upper bound of about 14% expansion does not seem onerous for output buffer
     484 * allocation.
     485 */
     486uLong ZEXPORT deflateBound(strm, sourceLen)
     487    z_streamp strm;
     488    uLong sourceLen;
    491489{
    492490    deflate_state *s;
    493     uLong destLen;
    494 
    495     /* conservative upper bound */
    496     destLen = sourceLen +
    497               ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 11;
    498 
    499     /* if can't get parameters, return conservative bound */
     491    uLong complen, wraplen;
     492    Bytef *str;
     493
     494    /* conservative upper bound for compressed data */
     495    complen = sourceLen +
     496              ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 5;
     497
     498    /* if can't get parameters, return conservative bound plus zlib wrapper */
    500499    if (strm == Z_NULL || strm->state == Z_NULL)
    501         return destLen;
     500        return complen + 6;
     501
     502    /* compute wrapper length */
     503    s = strm->state;
     504    switch (s->wrap) {
     505    case 0:                                 /* raw deflate */
     506        wraplen = 0;
     507        break;
     508    case 1:                                 /* zlib wrapper */
     509        wraplen = 6 + (s->strstart ? 4 : 0);
     510        break;
     511    case 2:                                 /* gzip wrapper */
     512        wraplen = 18;
     513        if (s->gzhead != Z_NULL) {          /* user-supplied gzip header */
     514            if (s->gzhead->extra != Z_NULL)
     515                wraplen += 2 + s->gzhead->extra_len;
     516            str = s->gzhead->name;
     517            if (str != Z_NULL)
     518                do {
     519                    wraplen++;
     520                } while (*str++);
     521            str = s->gzhead->comment;
     522            if (str != Z_NULL)
     523                do {
     524                    wraplen++;
     525                } while (*str++);
     526            if (s->gzhead->hcrc)
     527                wraplen += 2;
     528        }
     529        break;
     530    default:                                /* for compiler happiness */
     531        wraplen = 6;
     532    }
    502533
    503534    /* if not default parameters, return conservative bound */
    504     s = strm->state;
    505535    if (s->w_bits != 15 || s->hash_bits != 8 + 7)
    506         return destLen;
     536        return complen + wraplen;
    507537
    508538    /* default settings: return tight bound for that case */
    509     return compressBound(sourceLen);
     539    return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) +
     540           (sourceLen >> 25) + 13 - 6 + wraplen;
    510541}
    511542
     
    515546 * pending_buf.
    516547 */
    517 local void putShortMSB (
    518     deflate_state *s,
    519     uInt b)
     548local void putShortMSB (s, b)
     549    deflate_state *s;
     550    uInt b;
    520551{
    521552    put_byte(s, (Byte)(b >> 8));
     
    529560 * (See also read_buf()).
    530561 */
    531 local void flush_pending(
    532     z_streamp strm)
     562local void flush_pending(strm)
     563    z_streamp strm;
    533564{
    534565    unsigned len = strm->state->pending;
     
    549580
    550581/* ========================================================================= */
    551 int ZEXPORT deflate (
    552     z_streamp strm,
    553     int flush)
     582int ZEXPORT deflate (strm, flush)
     583    z_streamp strm;
     584    int flush;
    554585{
    555586    int old_flush; /* value of flush param for previous deflate call */
     
    557588
    558589    if (strm == Z_NULL || strm->state == Z_NULL ||
    559         flush > Z_FINISH || flush < 0) {
     590        flush > Z_BLOCK || flush < 0) {
    560591        return Z_STREAM_ERROR;
    561592    }
     
    581612            put_byte(s, 139);
    582613            put_byte(s, 8);
    583             if (s->gzhead == NULL) {
     614            if (s->gzhead == Z_NULL) {
    584615                put_byte(s, 0);
    585616                put_byte(s, 0);
     
    608639                             4 : 0));
    609640                put_byte(s, s->gzhead->os & 0xff);
    610                 if (s->gzhead->extra != NULL) {
     641                if (s->gzhead->extra != Z_NULL) {
    611642                    put_byte(s, s->gzhead->extra_len & 0xff);
    612643                    put_byte(s, (s->gzhead->extra_len >> 8) & 0xff);
     
    650681#ifdef GZIP
    651682    if (s->status == EXTRA_STATE) {
    652         if (s->gzhead->extra != NULL) {
     683        if (s->gzhead->extra != Z_NULL) {
    653684            uInt beg = s->pending;  /* start of bytes to update crc */
    654685
     
    678709    }
    679710    if (s->status == NAME_STATE) {
    680         if (s->gzhead->name != NULL) {
     711        if (s->gzhead->name != Z_NULL) {
    681712            uInt beg = s->pending;  /* start of bytes to update crc */
    682713            int val;
     
    709740    }
    710741    if (s->status == COMMENT_STATE) {
    711         if (s->gzhead->comment != NULL) {
     742        if (s->gzhead->comment != Z_NULL) {
    712743            uInt beg = s->pending;  /* start of bytes to update crc */
    713744            int val;
     
    787818        block_state bstate;
    788819
    789         bstate = (*(configuration_table[s->level].func))(s, flush);
     820        bstate = s->strategy == Z_HUFFMAN_ONLY ? deflate_huff(s, flush) :
     821                    (s->strategy == Z_RLE ? deflate_rle(s, flush) :
     822                        (*(configuration_table[s->level].func))(s, flush));
    790823
    791824        if (bstate == finish_started || bstate == finish_done) {
     
    808841            if (flush == Z_PARTIAL_FLUSH) {
    809842                _tr_align(s);
    810             } else { /* FULL_FLUSH or SYNC_FLUSH */
     843            } else if (flush != Z_BLOCK) { /* FULL_FLUSH or SYNC_FLUSH */
    811844                _tr_stored_block(s, (char*)0, 0L, 0);
    812845                /* For a full flush, this empty block will be recognized
     
    815848                if (flush == Z_FULL_FLUSH) {
    816849                    CLEAR_HASH(s);             /* forget history */
     850                    if (s->lookahead == 0) {
     851                        s->strstart = 0;
     852                        s->block_start = 0L;
     853                    }
    817854                }
    818855            }
     
    856893
    857894/* ========================================================================= */
    858 int ZEXPORT deflateEnd (
    859     z_streamp strm)
     895int ZEXPORT deflateEnd (strm)
     896    z_streamp strm;
    860897{
    861898    int status;
     
    891928 * doesn't have enough memory anyway to duplicate compression states).
    892929 */
    893 int ZEXPORT deflateCopy (
    894     z_streamp dest,
    895     z_streamp source)
     930int ZEXPORT deflateCopy (dest, source)
     931    z_streamp dest;
     932    z_streamp source;
    896933{
    897934#ifdef MAXSEG_64K
     
    953990 * (See also flush_pending()).
    954991 */
    955 local int read_buf(
    956     z_streamp strm,
    957     Bytef *buf,
    958     unsigned size)
     992local int read_buf(strm, buf, size)
     993    z_streamp strm;
     994    Bytef *buf;
     995    unsigned size;
    959996{
    960997    unsigned len = strm->avail_in;
     
    9831020 * Initialize the "longest match" routines for a new zlib stream
    9841021 */
    985 local void lm_init (
    986     deflate_state *s)
     1022local void lm_init (s)
     1023    deflate_state *s;
    9871024{
    9881025    s->window_size = (ulg)2L*s->w_size;
     
    10241061 * match.S. The code will be functionally equivalent.
    10251062 */
    1026 local uInt longest_match(
    1027     deflate_state *s,
    1028     IPos cur_match)                             /* current match */
     1063local uInt longest_match(s, cur_match)
     1064    deflate_state *s;
     1065    IPos cur_match;                             /* current match */
    10291066{
    10301067    unsigned chain_length = s->max_chain_length;/* max hash chain length */
     
    11671204}
    11681205#endif /* ASMV */
    1169 #endif /* FASTEST */
     1206
     1207#else /* FASTEST */
    11701208
    11711209/* ---------------------------------------------------------------------------
    1172  * Optimized version for level == 1 or strategy == Z_RLE only
    1173  */
    1174 local uInt longest_match_fast(
    1175     deflate_state *s,
    1176     IPos cur_match)                             /* current match */
     1210 * Optimized version for FASTEST only
     1211 */
     1212local uInt longest_match(s, cur_match)
     1213    deflate_state *s;
     1214    IPos cur_match;                             /* current match */
    11771215{
    11781216    register Bytef *scan = s->window + s->strstart; /* current string */
     
    12251263}
    12261264
     1265#endif /* FASTEST */
     1266
    12271267#ifdef DEBUG
    12281268/* ===========================================================================
    12291269 * Check that the match at match_start is indeed a match.
    12301270 */
    1231 local void check_match(
    1232     deflate_state *s,
    1233     IPos start, IPos match,
    1234     int length)
     1271local void check_match(s, start, match, length)
     1272    deflate_state *s;
     1273    IPos start, match;
     1274    int length;
    12351275{
    12361276    /* check that the match is indeed a match */
     
    12631303 *    option -- not supported here).
    12641304 */
    1265 local void fill_window(
    1266     deflate_state *s)
     1305local void fill_window(s)
     1306    deflate_state *s;
    12671307{
    12681308    register unsigned n, m;
     
    13031343               zlib, so we don't care about this pathological case.)
    13041344             */
    1305             /* %%% avoid this when Z_RLE */
    13061345            n = s->hash_size;
    13071346            p = &s->head[n];
     
    13551394
    13561395    } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0);
     1396
     1397    /* If the WIN_INIT bytes after the end of the current data have never been
     1398     * written, then zero those bytes in order to avoid memory check reports of
     1399     * the use of uninitialized (or uninitialised as Julian writes) bytes by
     1400     * the longest match routines.  Update the high water mark for the next
     1401     * time through here.  WIN_INIT is set to MAX_MATCH since the longest match
     1402     * routines allow scanning to strstart + MAX_MATCH, ignoring lookahead.
     1403     */
     1404    if (s->high_water < s->window_size) {
     1405        ulg curr = s->strstart + (ulg)(s->lookahead);
     1406        ulg init;
     1407
     1408        if (s->high_water < curr) {
     1409            /* Previous high water mark below current data -- zero WIN_INIT
     1410             * bytes or up to end of window, whichever is less.
     1411             */
     1412            init = s->window_size - curr;
     1413            if (init > WIN_INIT)
     1414                init = WIN_INIT;
     1415            zmemzero(s->window + curr, (unsigned)init);
     1416            s->high_water = curr + init;
     1417        }
     1418        else if (s->high_water < (ulg)curr + WIN_INIT) {
     1419            /* High water mark at or above current data, but below current data
     1420             * plus WIN_INIT -- zero out to current data plus WIN_INIT, or up
     1421             * to end of window, whichever is less.
     1422             */
     1423            init = (ulg)curr + WIN_INIT - s->high_water;
     1424            if (init > s->window_size - s->high_water)
     1425                init = s->window_size - s->high_water;
     1426            zmemzero(s->window + s->high_water, (unsigned)init);
     1427            s->high_water += init;
     1428        }
     1429    }
    13571430}
    13581431
     
    13611434 * IN assertion: strstart is set to the end of the current match.
    13621435 */
    1363 #define FLUSH_BLOCK_ONLY(s, eof) { \
     1436#define FLUSH_BLOCK_ONLY(s, last) { \
    13641437   _tr_flush_block(s, (s->block_start >= 0L ? \
    13651438                   (charf *)&s->window[(unsigned)s->block_start] : \
    13661439                   (charf *)Z_NULL), \
    13671440                (ulg)((long)s->strstart - s->block_start), \
    1368                 (eof)); \
     1441                (last)); \
    13691442   s->block_start = s->strstart; \
    13701443   flush_pending(s->strm); \
     
    13731446
    13741447/* Same but force premature exit if necessary. */
    1375 #define FLUSH_BLOCK(s, eof) { \
    1376    FLUSH_BLOCK_ONLY(s, eof); \
    1377    if (s->strm->avail_out == 0) return (eof) ? finish_started : need_more; \
     1448#define FLUSH_BLOCK(s, last) { \
     1449   FLUSH_BLOCK_ONLY(s, last); \
     1450   if (s->strm->avail_out == 0) return (last) ? finish_started : need_more; \
    13781451}
    13791452
     
    13871460 * window to pending_buf.
    13881461 */
    1389 local block_state deflate_stored(
    1390     deflate_state *s,
    1391     int flush)
     1462local block_state deflate_stored(s, flush)
     1463    deflate_state *s;
     1464    int flush;
    13921465{
    13931466    /* Stored blocks are limited to 0xffff bytes, pending_buf is limited
     
    14451518 * matches. It is used only for the fast compression options.
    14461519 */
    1447 local block_state deflate_fast(
    1448     deflate_state *s,
    1449     int flush)
    1450 {
    1451     IPos hash_head = NIL; /* head of the hash chain */
     1520local block_state deflate_fast(s, flush)
     1521    deflate_state *s;
     1522    int flush;
     1523{
     1524    IPos hash_head;      /* head of the hash chain */
    14521525    int bflush;           /* set if current block must be flushed */
    14531526
     
    14691542         * dictionary, and set hash_head to the head of the hash chain:
    14701543         */
     1544        hash_head = NIL;
    14711545        if (s->lookahead >= MIN_MATCH) {
    14721546            INSERT_STRING(s, s->strstart, hash_head);
     
    14811555             * of the string with itself at the start of the input file).
    14821556             */
    1483 #ifdef FASTEST
    1484             if ((s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) ||
    1485                 (s->strategy == Z_RLE && s->strstart - hash_head == 1)) {
    1486                 s->match_length = longest_match_fast (s, hash_head);
    1487             }
    1488 #else
    1489             if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) {
    1490                 s->match_length = longest_match (s, hash_head);
    1491             } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
    1492                 s->match_length = longest_match_fast (s, hash_head);
    1493             }
    1494 #endif
    1495             /* longest_match() or longest_match_fast() sets match_start */
     1557            s->match_length = longest_match (s, hash_head);
     1558            /* longest_match() sets match_start */
    14961559        }
    14971560        if (s->match_length >= MIN_MATCH) {
     
    15511614 * no better match at the next window position.
    15521615 */
    1553 local block_state deflate_slow(
    1554     deflate_state *s,
    1555     int flush)
    1556 {
    1557     IPos hash_head = NIL;    /* head of hash chain */
     1616local block_state deflate_slow(s, flush)
     1617    deflate_state *s;
     1618    int flush;
     1619{
     1620    IPos hash_head;          /* head of hash chain */
    15581621    int bflush;              /* set if current block must be flushed */
    15591622
     
    15761639         * dictionary, and set hash_head to the head of the hash chain:
    15771640         */
     1641        hash_head = NIL;
    15781642        if (s->lookahead >= MIN_MATCH) {
    15791643            INSERT_STRING(s, s->strstart, hash_head);
     
    15911655             * of the string with itself at the start of the input file).
    15921656             */
    1593             if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) {
    1594                 s->match_length = longest_match (s, hash_head);
    1595             } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
    1596                 s->match_length = longest_match_fast (s, hash_head);
    1597             }
    1598             /* longest_match() or longest_match_fast() sets match_start */
     1657            s->match_length = longest_match (s, hash_head);
     1658            /* longest_match() sets match_start */
    15991659
    16001660            if (s->match_length <= 5 && (s->strategy == Z_FILTERED
     
    16741734#endif /* FASTEST */
    16751735
    1676 #if 0
    16771736/* ===========================================================================
    16781737 * For Z_RLE, simply look for runs of bytes, generate matches only of distance
     
    16801739 * deflate switches away from Z_RLE.)
    16811740 */
    1682 local block_state deflate_rle(
    1683     deflate_state *s,
    1684     int flush)
    1685 {
    1686     int bflush;         /* set if current block must be flushed */
    1687     uInt run;           /* length of run */
    1688     uInt max;           /* maximum length of run */
    1689     uInt prev;          /* byte at distance one to match */
    1690     Bytef *scan;        /* scan for end of run */
     1741local block_state deflate_rle(s, flush)
     1742    deflate_state *s;
     1743    int flush;
     1744{
     1745    int bflush;             /* set if current block must be flushed */
     1746    uInt prev;              /* byte at distance one to match */
     1747    Bytef *scan, *strend;   /* scan goes up to strend for length of run */
    16911748
    16921749    for (;;) {
     
    17041761
    17051762        /* See how many times the previous byte repeats */
    1706         run = 0;
    1707         if (s->strstart > 0) {      /* if there is a previous byte, that is */
    1708             max = s->lookahead < MAX_MATCH ? s->lookahead : MAX_MATCH;
     1763        s->match_length = 0;
     1764        if (s->lookahead >= MIN_MATCH && s->strstart > 0) {
    17091765            scan = s->window + s->strstart - 1;
    1710             prev = *scan++;
    1711             do {
    1712                 if (*scan++ != prev)
    1713                     break;
    1714             } while (++run < max);
     1766            prev = *scan;
     1767            if (prev == *++scan && prev == *++scan && prev == *++scan) {
     1768                strend = s->window + s->strstart + MAX_MATCH;
     1769                do {
     1770                } while (prev == *++scan && prev == *++scan &&
     1771                         prev == *++scan && prev == *++scan &&
     1772                         prev == *++scan && prev == *++scan &&
     1773                         prev == *++scan && prev == *++scan &&
     1774                         scan < strend);
     1775                s->match_length = MAX_MATCH - (int)(strend - scan);
     1776                if (s->match_length > s->lookahead)
     1777                    s->match_length = s->lookahead;
     1778            }
    17151779        }
    17161780
    17171781        /* Emit match if have run of MIN_MATCH or longer, else emit literal */
    1718         if (run >= MIN_MATCH) {
    1719             check_match(s, s->strstart, s->strstart - 1, run);
    1720             _tr_tally_dist(s, 1, run - MIN_MATCH, bflush);
    1721             s->lookahead -= run;
    1722             s->strstart += run;
     1782        if (s->match_length >= MIN_MATCH) {
     1783            check_match(s, s->strstart, s->strstart - 1, s->match_length);
     1784
     1785            _tr_tally_dist(s, 1, s->match_length - MIN_MATCH, bflush);
     1786
     1787            s->lookahead -= s->match_length;
     1788            s->strstart += s->match_length;
     1789            s->match_length = 0;
    17231790        } else {
    17241791            /* No match, output a literal byte */
     
    17331800    return flush == Z_FINISH ? finish_done : block_done;
    17341801}
    1735 #endif
     1802
     1803/* ===========================================================================
     1804 * For Z_HUFFMAN_ONLY, do not look for matches.  Do not maintain a hash table.
     1805 * (It will be regenerated if this run of deflate switches away from Huffman.)
     1806 */
     1807local block_state deflate_huff(s, flush)
     1808    deflate_state *s;
     1809    int flush;
     1810{
     1811    int bflush;             /* set if current block must be flushed */
     1812
     1813    for (;;) {
     1814        /* Make sure that we have a literal to write. */
     1815        if (s->lookahead == 0) {
     1816            fill_window(s);
     1817            if (s->lookahead == 0) {
     1818                if (flush == Z_NO_FLUSH)
     1819                    return need_more;
     1820                break;      /* flush the current block */
     1821            }
     1822        }
     1823
     1824        /* Output a literal byte */
     1825        s->match_length = 0;
     1826        Tracevv((stderr,"%c", s->window[s->strstart]));
     1827        _tr_tally_lit (s, s->window[s->strstart], bflush);
     1828        s->lookahead--;
     1829        s->strstart++;
     1830        if (bflush) FLUSH_BLOCK(s, 0);
     1831    }
     1832    FLUSH_BLOCK(s, flush == Z_FINISH);
     1833    return flush == Z_FINISH ? finish_done : block_done;
     1834}
  • cpukit/zlib/deflate.h

    r41ca776f r6121dc77  
    11/* deflate.h -- internal compression state
    2  * Copyright (C) 1995-2004 Jean-loup Gailly
     2 * Copyright (C) 1995-2009 Jean-loup Gailly
    33 * For conditions of distribution and use, see copyright notice in zlib.h
    44 */
     
    261261     */
    262262
     263    ulg high_water;
     264    /* High water mark offset in window for initialized bytes -- bytes above
     265     * this are set to zero in order to avoid memory check warnings when
     266     * longest match routines access bytes past the input.  This is then
     267     * updated to the new high water mark.
     268     */
     269
    263270} FAR deflate_state;
    264271
     
    278285 * distances are limited to MAX_DIST instead of WSIZE.
    279286 */
     287
     288#define WIN_INIT MAX_MATCH
     289/* Number of bytes after end of data in window to initialize in order to avoid
     290   memory checker errors from longest match routines */
    280291
    281292        /* in trees.c */
     
    283294int  _tr_tally        OF((deflate_state *s, unsigned dist, unsigned lc));
    284295void _tr_flush_block  OF((deflate_state *s, charf *buf, ulg stored_len,
    285                           int eof));
     296                          int last));
    286297void _tr_align        OF((deflate_state *s));
    287298void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len,
    288                           int eof));
     299                          int last));
    289300
    290301#define d_code(dist) \
  • cpukit/zlib/doc/algorithm.txt

    r41ca776f r6121dc77  
    122122would take too long if you're only decoding several thousand symbols.  At the
    123123other extreme, you could make a new table for every bit in the code.  In fact,
    124 that's essentially a Huffman tree.  But then you spend two much time
     124that's essentially a Huffman tree.  But then you spend too much time
    125125traversing the tree while decoding, even for short symbols.
    126126
  • cpukit/zlib/infback.c

    r41ca776f r6121dc77  
    11/* infback.c -- inflate using a call-back interface
    2  * Copyright (C) 1995-2005 Mark Adler
     2 * Copyright (C) 1995-2009 Mark Adler
    33 * For conditions of distribution and use, see copyright notice in zlib.h
    44 */
     
    2626   window and output buffer that is 2**windowBits bytes.
    2727 */
    28 int ZEXPORT inflateBackInit_(
    29     z_streamp strm,
    30     int windowBits,
    31     unsigned char FAR *window,
    32     const char *version,
    33     int stream_size)
     28int ZEXPORT inflateBackInit_(strm, windowBits, window, version, stream_size)
     29z_streamp strm;
     30int windowBits;
     31unsigned char FAR *window;
     32const char *version;
     33int stream_size;
    3434{
    3535    struct inflate_state FAR *state;
     
    5656    state->wsize = 1U << windowBits;
    5757    state->window = window;
    58     state->write = 0;
     58    state->wnext = 0;
    5959    state->whave = 0;
    6060    return Z_OK;
     
    7171   may not be thread-safe.
    7272 */
    73 local void fixedtables(
    74     struct inflate_state FAR *state)
     73local void fixedtables(state)
     74struct inflate_state FAR *state;
    7575{
    7676#ifdef BUILDFIXED
     
    239239   are not correct, i.e. strm is Z_NULL or the state was not initialized.
    240240 */
    241 int ZEXPORT inflateBack(
    242     z_streamp strm,
    243     in_func in,
    244     void FAR *in_desc,
    245     out_func out,
    246     void FAR *out_desc)
     241int ZEXPORT inflateBack(strm, in, in_desc, out, out_desc)
     242z_streamp strm;
     243in_func in;
     244void FAR *in_desc;
     245out_func out;
     246void FAR *out_desc;
    247247{
    248248    struct inflate_state FAR *state;
     
    254254    unsigned copy;              /* number of stored or match bytes to copy */
    255255    unsigned char FAR *from;    /* where to copy match bytes from */
    256     code this;                  /* current decoding table entry */
     256    code here;                  /* current decoding table entry */
    257257    code last;                  /* parent table entry */
    258258    unsigned len;               /* length to copy for repeats, bits to drop */
     
    390390            while (state->have < state->nlen + state->ndist) {
    391391                for (;;) {
    392                     this = state->lencode[BITS(state->lenbits)];
    393                     if ((unsigned)(this.bits) <= bits) break;
     392                    here = state->lencode[BITS(state->lenbits)];
     393                    if ((unsigned)(here.bits) <= bits) break;
    394394                    PULLBYTE();
    395395                }
    396                 if (this.val < 16) {
    397                     NEEDBITS(this.bits);
    398                     DROPBITS(this.bits);
    399                     state->lens[state->have++] = this.val;
     396                if (here.val < 16) {
     397                    NEEDBITS(here.bits);
     398                    DROPBITS(here.bits);
     399                    state->lens[state->have++] = here.val;
    400400                }
    401401                else {
    402                     if (this.val == 16) {
    403                         NEEDBITS(this.bits + 2);
    404                         DROPBITS(this.bits);
     402                    if (here.val == 16) {
     403                        NEEDBITS(here.bits + 2);
     404                        DROPBITS(here.bits);
    405405                        if (state->have == 0) {
    406406                            strm->msg = (char *)"invalid bit length repeat";
     
    412412                        DROPBITS(2);
    413413                    }
    414                     else if (this.val == 17) {
    415                         NEEDBITS(this.bits + 3);
    416                         DROPBITS(this.bits);
     414                    else if (here.val == 17) {
     415                        NEEDBITS(here.bits + 3);
     416                        DROPBITS(here.bits);
    417417                        len = 0;
    418418                        copy = 3 + BITS(3);
     
    420420                    }
    421421                    else {
    422                         NEEDBITS(this.bits + 7);
    423                         DROPBITS(this.bits);
     422                        NEEDBITS(here.bits + 7);
     423                        DROPBITS(here.bits);
    424424                        len = 0;
    425425                        copy = 11 + BITS(7);
     
    439439            if (state->mode == BAD) break;
    440440
    441             /* build code tables */
     441            /* check for end-of-block code (better have one) */
     442            if (state->lens[256] == 0) {
     443                strm->msg = (char *)"invalid code -- missing end-of-block";
     444                state->mode = BAD;
     445                break;
     446            }
     447
     448            /* build code tables -- note: do not change the lenbits or distbits
     449               values here (9 and 6) without reading the comments in inftrees.h
     450               concerning the ENOUGH constants, which depend on those values */
    442451            state->next = state->codes;
    443452            state->lencode = (code const FAR *)(state->next);
     
    475484            /* get a literal, length, or end-of-block code */
    476485            for (;;) {
    477                 this = state->lencode[BITS(state->lenbits)];
    478                 if ((unsigned)(this.bits) <= bits) break;
     486                here = state->lencode[BITS(state->lenbits)];
     487                if ((unsigned)(here.bits) <= bits) break;
    479488                PULLBYTE();
    480489            }
    481             if (this.op && (this.op & 0xf0) == 0) {
    482                 last = this;
     490            if (here.op && (here.op & 0xf0) == 0) {
     491                last = here;
    483492                for (;;) {
    484                     this = state->lencode[last.val +
     493                    here = state->lencode[last.val +
    485494                            (BITS(last.bits + last.op) >> last.bits)];
    486                     if ((unsigned)(last.bits + this.bits) <= bits) break;
     495                    if ((unsigned)(last.bits + here.bits) <= bits) break;
    487496                    PULLBYTE();
    488497                }
    489498                DROPBITS(last.bits);
    490499            }
    491             DROPBITS(this.bits);
    492             state->length = (unsigned)this.val;
     500            DROPBITS(here.bits);
     501            state->length = (unsigned)here.val;
    493502
    494503            /* process literal */
    495             if (this.op == 0) {
    496                 Tracevv((stderr, this.val >= 0x20 && this.val < 0x7f ?
     504            if (here.op == 0) {
     505                Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
    497506                        "inflate:         literal '%c'\n" :
    498                         "inflate:         literal 0x%02x\n", this.val));
     507                        "inflate:         literal 0x%02x\n", here.val));
    499508                ROOM();
    500509                *put++ = (unsigned char)(state->length);
     
    505514
    506515            /* process end of block */
    507             if (this.op & 32) {
     516            if (here.op & 32) {
    508517                Tracevv((stderr, "inflate:         end of block\n"));
    509518                state->mode = TYPE;
     
    512521
    513522            /* invalid code */
    514             if (this.op & 64) {
     523            if (here.op & 64) {
    515524                strm->msg = (char *)"invalid literal/length code";
    516525                state->mode = BAD;
     
    519528
    520529            /* length code -- get extra bits, if any */
    521             state->extra = (unsigned)(this.op) & 15;
     530            state->extra = (unsigned)(here.op) & 15;
    522531            if (state->extra != 0) {
    523532                NEEDBITS(state->extra);
     
    529538            /* get distance code */
    530539            for (;;) {
    531                 this = state->distcode[BITS(state->distbits)];
    532                 if ((unsigned)(this.bits) <= bits) break;
     540                here = state->distcode[BITS(state->distbits)];
     541                if ((unsigned)(here.bits) <= bits) break;
    533542                PULLBYTE();
    534543            }
    535             if ((this.op & 0xf0) == 0) {
    536                 last = this;
     544            if ((here.op & 0xf0) == 0) {
     545                last = here;
    537546                for (;;) {
    538                     this = state->distcode[last.val +
     547                    here = state->distcode[last.val +
    539548                            (BITS(last.bits + last.op) >> last.bits)];
    540                     if ((unsigned)(last.bits + this.bits) <= bits) break;
     549                    if ((unsigned)(last.bits + here.bits) <= bits) break;
    541550                    PULLBYTE();
    542551                }
    543552                DROPBITS(last.bits);
    544553            }
    545             DROPBITS(this.bits);
    546             if (this.op & 64) {
     554            DROPBITS(here.bits);
     555            if (here.op & 64) {
    547556                strm->msg = (char *)"invalid distance code";
    548557                state->mode = BAD;
    549558                break;
    550559            }
    551             state->offset = (unsigned)this.val;
     560            state->offset = (unsigned)here.val;
    552561
    553562            /* get distance extra bits, if any */
    554             state->extra = (unsigned)(this.op) & 15;
     563            state->extra = (unsigned)(here.op) & 15;
    555564            if (state->extra != 0) {
    556565                NEEDBITS(state->extra);
     
    612621}
    613622
    614 int ZEXPORT inflateBackEnd(
    615     z_streamp strm)
     623int ZEXPORT inflateBackEnd(strm)
     624z_streamp strm;
    616625{
    617626    if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
  • cpukit/zlib/inffast.c

    r41ca776f r6121dc77  
    11/* inffast.c -- fast decoding
    2  * Copyright (C) 1995-2004 Mark Adler
     2 * Copyright (C) 1995-2008 Mark Adler
    33 * For conditions of distribution and use, see copyright notice in zlib.h
    44 */
     
    6565      output space.
    6666 */
    67 void inflate_fast(
    68     z_streamp strm,
    69     unsigned start)         /* inflate()'s starting value for strm->avail_out */
     67void inflate_fast(strm, start)
     68z_streamp strm;
     69unsigned start;         /* inflate()'s starting value for strm->avail_out */
    7070{
    7171    struct inflate_state FAR *state;
     
    8080    unsigned wsize;             /* window size or zero if not using window */
    8181    unsigned whave;             /* valid bytes in the window */
    82     unsigned write;             /* window write index */
     82    unsigned wnext;             /* window write index */
    8383    unsigned char FAR *window;  /* allocated sliding window, if wsize != 0 */
    8484    unsigned long hold;         /* local strm->hold */
     
    8888    unsigned lmask;             /* mask for first level of length codes */
    8989    unsigned dmask;             /* mask for first level of distance codes */
    90     code this;                  /* retrieved table entry */
     90    code here;                  /* retrieved table entry */
    9191    unsigned op;                /* code bits, operation, extra bits, or */
    9292                                /*  window position, window bytes to copy */
     
    107107    wsize = state->wsize;
    108108    whave = state->whave;
    109     write = state->write;
     109    wnext = state->wnext;
    110110    window = state->window;
    111111    hold = state->hold;
     
    125125            bits += 8;
    126126        }
    127         this = lcode[hold & lmask];
     127        here = lcode[hold & lmask];
    128128      dolen:
    129         op = (unsigned)(this.bits);
     129        op = (unsigned)(here.bits);
    130130        hold >>= op;
    131131        bits -= op;
    132         op = (unsigned)(this.op);
     132        op = (unsigned)(here.op);
    133133        if (op == 0) {                          /* literal */
    134             Tracevv((stderr, this.val >= 0x20 && this.val < 0x7f ?
     134            Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
    135135                    "inflate:         literal '%c'\n" :
    136                     "inflate:         literal 0x%02x\n", this.val));
    137             PUP(out) = (unsigned char)(this.val);
     136                    "inflate:         literal 0x%02x\n", here.val));
     137            PUP(out) = (unsigned char)(here.val);
    138138        }
    139139        else if (op & 16) {                     /* length base */
    140             len = (unsigned)(this.val);
     140            len = (unsigned)(here.val);
    141141            op &= 15;                           /* number of extra bits */
    142142            if (op) {
     
    156156                bits += 8;
    157157            }
    158             this = dcode[hold & dmask];
     158            here = dcode[hold & dmask];
    159159          dodist:
    160             op = (unsigned)(this.bits);
     160            op = (unsigned)(here.bits);
    161161            hold >>= op;
    162162            bits -= op;
    163             op = (unsigned)(this.op);
     163            op = (unsigned)(here.op);
    164164            if (op & 16) {                      /* distance base */
    165                 dist = (unsigned)(this.val);
     165                dist = (unsigned)(here.val);
    166166                op &= 15;                       /* number of extra bits */
    167167                if (bits < op) {
     
    188188                    op = dist - op;             /* distance back in window */
    189189                    if (op > whave) {
    190                         strm->msg = (char *)"invalid distance too far back";
    191                         state->mode = BAD;
    192                         break;
     190                        if (state->sane) {
     191                            strm->msg =
     192                                (char *)"invalid distance too far back";
     193                            state->mode = BAD;
     194                            break;
     195                        }
     196#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
     197                        if (len <= op - whave) {
     198                            do {
     199                                PUP(out) = 0;
     200                            } while (--len);
     201                            continue;
     202                        }
     203                        len -= op - whave;
     204                        do {
     205                            PUP(out) = 0;
     206                        } while (--op > whave);
     207                        if (op == 0) {
     208                            from = out - dist;
     209                            do {
     210                                PUP(out) = PUP(from);
     211                            } while (--len);
     212                            continue;
     213                        }
     214#endif
    193215                    }
    194216                    from = window - OFF;
    195                     if (write == 0) {           /* very common case */
     217                    if (wnext == 0) {           /* very common case */
    196218                        from += wsize - op;
    197219                        if (op < len) {         /* some from window */
     
    203225                        }
    204226                    }
    205                     else if (write < op) {      /* wrap around window */
    206                         from += wsize + write - op;
    207                         op -= write;
     227                    else if (wnext < op) {      /* wrap around window */
     228                        from += wsize + wnext - op;
     229                        op -= wnext;
    208230                        if (op < len) {         /* some from end of window */
    209231                            len -= op;
     
    212234                            } while (--op);
    213235                            from = window - OFF;
    214                             if (write < len) {  /* some from start of window */
    215                                 op = write;
     236                            if (wnext < len) {  /* some from start of window */
     237                                op = wnext;
    216238                                len -= op;
    217239                                do {
     
    223245                    }
    224246                    else {                      /* contiguous in window */
    225                         from += write - op;
     247                        from += wnext - op;
    226248                        if (op < len) {         /* some from window */
    227249                            len -= op;
     
    260282            }
    261283            else if ((op & 64) == 0) {          /* 2nd level distance code */
    262                 this = dcode[this.val + (hold & ((1U << op) - 1))];
     284                here = dcode[here.val + (hold & ((1U << op) - 1))];
    263285                goto dodist;
    264286            }
     
    270292        }
    271293        else if ((op & 64) == 0) {              /* 2nd level length code */
    272             this = lcode[this.val + (hold & ((1U << op) - 1))];
     294            here = lcode[here.val + (hold & ((1U << op) - 1))];
    273295            goto dolen;
    274296        }
     
    306328   - Using bit fields for code structure
    307329   - Different op definition to avoid & for extra bits (do & for table bits)
    308    - Three separate decoding do-loops for direct, window, and write == 0
     330   - Three separate decoding do-loops for direct, window, and wnext == 0
    309331   - Special case for distance > 1 copies to do overlapped load and store copy
    310332   - Explicit branch predictions (based on measured branch probabilities)
  • cpukit/zlib/inflate.c

    r41ca776f r6121dc77  
    11/* inflate.c -- zlib decompression
    2  * Copyright (C) 1995-2005 Mark Adler
     2 * Copyright (C) 1995-2010 Mark Adler
    33 * For conditions of distribution and use, see copyright notice in zlib.h
    44 */
     
    4646 * - Unroll last copy for window match in inflate_fast()
    4747 * - Use local copies of window variables in inflate_fast() for speed
    48  * - Pull out common write == 0 case for speed in inflate_fast()
     48 * - Pull out common wnext == 0 case for speed in inflate_fast()
    4949 * - Make op and len in inflate_fast() unsigned for consistency
    5050 * - Add FAR to lcode and dcode declarations in inflate_fast()
     
    101101                              unsigned len));
    102102
    103 int ZEXPORT inflateReset(
    104     z_streamp strm)
     103int ZEXPORT inflateReset(strm)
     104z_streamp strm;
    105105{
    106106    struct inflate_state FAR *state;
     
    118118    state->wsize = 0;
    119119    state->whave = 0;
    120     state->write = 0;
     120    state->wnext = 0;
    121121    state->hold = 0;
    122122    state->bits = 0;
    123123    state->lencode = state->distcode = state->next = state->codes;
     124    state->sane = 1;
     125    state->back = -1;
    124126    Tracev((stderr, "inflate: reset\n"));
    125127    return Z_OK;
    126128}
    127129
    128 int ZEXPORT inflatePrime(
    129     z_streamp strm,
    130     int bits,
    131     int value)
    132 {
     130int ZEXPORT inflateReset2(strm, windowBits)
     131z_streamp strm;
     132int windowBits;
     133{
     134    int wrap;
    133135    struct inflate_state FAR *state;
    134136
     137    /* get the state */
    135138    if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
    136139    state = (struct inflate_state FAR *)strm->state;
    137     if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR;
    138     value &= (1L << bits) - 1;
    139     state->hold += value << state->bits;
    140     state->bits += bits;
    141     return Z_OK;
    142 }
    143 
    144 int ZEXPORT inflateInit2_(
    145     z_streamp strm,
    146     int windowBits,
    147     const char *version,
    148     int stream_size)
    149 {
     140
     141    /* extract wrap request from windowBits parameter */
     142    if (windowBits < 0) {
     143        wrap = 0;
     144        windowBits = -windowBits;
     145    }
     146    else {
     147        wrap = (windowBits >> 4) + 1;
     148#ifdef GUNZIP
     149        if (windowBits < 48)
     150            windowBits &= 15;
     151#endif
     152    }
     153
     154    /* set number of window bits, free window if different */
     155    if (windowBits && (windowBits < 8 || windowBits > 15))
     156        return Z_STREAM_ERROR;
     157    if (state->window != Z_NULL && state->wbits != (unsigned)windowBits) {
     158        ZFREE(strm, state->window);
     159        state->window = Z_NULL;
     160    }
     161
     162    /* update state and reset the rest of it */
     163    state->wrap = wrap;
     164    state->wbits = (unsigned)windowBits;
     165    return inflateReset(strm);
     166}
     167
     168int ZEXPORT inflateInit2_(strm, windowBits, version, stream_size)
     169z_streamp strm;
     170int windowBits;
     171const char *version;
     172int stream_size;
     173{
     174    int ret;
    150175    struct inflate_state FAR *state;
    151176
     
    165190    Tracev((stderr, "inflate: allocated\n"));
    166191    strm->state = (struct internal_state FAR *)state;
    167     if (windowBits < 0) {
    168         state->wrap = 0;
    169         windowBits = -windowBits;
    170     }
    171     else {
    172         state->wrap = (windowBits >> 4) + 1;
    173 #ifdef GUNZIP
    174         if (windowBits < 48) windowBits &= 15;
    175 #endif
    176     }
    177     if (windowBits < 8 || windowBits > 15) {
     192    state->window = Z_NULL;
     193    ret = inflateReset2(strm, windowBits);
     194    if (ret != Z_OK) {
    178195        ZFREE(strm, state);
    179196        strm->state = Z_NULL;
    180         return Z_STREAM_ERROR;
    181     }
    182     state->wbits = (unsigned)windowBits;
    183     state->window = Z_NULL;
    184     return inflateReset(strm);
    185 }
    186 
    187 int ZEXPORT inflateInit_(
    188      z_streamp strm,
    189      const char *version,
    190      int stream_size)
     197    }
     198    return ret;
     199}
     200
     201int ZEXPORT inflateInit_(strm, version, stream_size)
     202z_streamp strm;
     203const char *version;
     204int stream_size;
    191205{
    192206    return inflateInit2_(strm, DEF_WBITS, version, stream_size);
     207}
     208
     209int ZEXPORT inflatePrime(strm, bits, value)
     210z_streamp strm;
     211int bits;
     212int value;
     213{
     214    struct inflate_state FAR *state;
     215
     216    if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
     217    state = (struct inflate_state FAR *)strm->state;
     218    if (bits < 0) {
     219        state->hold = 0;
     220        state->bits = 0;
     221        return Z_OK;
     222    }
     223    if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR;
     224    value &= (1L << bits) - 1;
     225    state->hold += value << state->bits;
     226    state->bits += bits;
     227    return Z_OK;
    193228}
    194229
     
    203238   may not be thread-safe.
    204239 */
    205 local void fixedtables(
    206     struct inflate_state FAR *state)
     240local void fixedtables(state)
     241struct inflate_state FAR *state;
    207242{
    208243#ifdef BUILDFIXED
     
    321356   The advantage may be dependent on the size of the processor's data caches.
    322357 */
    323 local int updatewindow(
    324    z_streamp strm,
    325    unsigned out)
     358local int updatewindow(strm, out)
     359z_streamp strm;
     360unsigned out;
    326361{
    327362    struct inflate_state FAR *state;
     
    341376    if (state->wsize == 0) {
    342377        state->wsize = 1U << state->wbits;
    343         state->write = 0;
     378        state->wnext = 0;
    344379        state->whave = 0;
    345380    }
     
    349384    if (copy >= state->wsize) {
    350385        zmemcpy(state->window, strm->next_out - state->wsize, state->wsize);
    351         state->write = 0;
     386        state->wnext = 0;
    352387        state->whave = state->wsize;
    353388    }
    354389    else {
    355         dist = state->wsize - state->write;
     390        dist = state->wsize - state->wnext;
    356391        if (dist > copy) dist = copy;
    357         zmemcpy(state->window + state->write, strm->next_out - copy, dist);
     392        zmemcpy(state->window + state->wnext, strm->next_out - copy, dist);
    358393        copy -= dist;
    359394        if (copy) {
    360395            zmemcpy(state->window, strm->next_out - copy, copy);
    361             state->write = copy;
     396            state->wnext = copy;
    362397            state->whave = state->wsize;
    363398        }
    364399        else {
    365             state->write += dist;
    366             if (state->write == state->wsize) state->write = 0;
     400            state->wnext += dist;
     401            if (state->wnext == state->wsize) state->wnext = 0;
    367402            if (state->whave < state->wsize) state->whave += dist;
    368403        }
     
    552587 */
    553588
    554 int ZEXPORT inflate(
    555     z_streamp strm,
    556     int flush)
     589int ZEXPORT inflate(strm, flush)
     590z_streamp strm;
     591int flush;
    557592{
    558593    struct inflate_state FAR *state;
     
    565600    unsigned copy;              /* number of stored or match bytes to copy */
    566601    unsigned char FAR *from;    /* where to copy match bytes from */
    567     code this;                  /* current decoding table entry */
     602    code here;                  /* current decoding table entry */
    568603    code last;                  /* parent table entry */
    569604    unsigned len;               /* length to copy for repeats, bits to drop */
     
    620655            DROPBITS(4);
    621656            len = BITS(4) + 8;
    622             if (len > state->wbits) {
     657            if (state->wbits == 0)
     658                state->wbits = len;
     659            else if (len > state->wbits) {
    623660                strm->msg = (char *)"invalid window size";
    624661                state->mode = BAD;
     
    772809            state->mode = TYPE;
    773810        case TYPE:
    774             if (flush == Z_BLOCK) goto inf_leave;
     811            if (flush == Z_BLOCK || flush == Z_TREES) goto inf_leave;
    775812        case TYPEDO:
    776813            if (state->last) {
     
    792829                Tracev((stderr, "inflate:     fixed codes block%s\n",
    793830                        state->last ? " (last)" : ""));
    794                 state->mode = LEN;              /* decode codes */
     831                state->mode = LEN_;             /* decode codes */
     832                if (flush == Z_TREES) {
     833                    DROPBITS(2);
     834                    goto inf_leave;
     835                }
    795836                break;
    796837            case 2:                             /* dynamic block */
     
    817858                    state->length));
    818859            INITBITS();
     860            state->mode = COPY_;
     861            if (flush == Z_TREES) goto inf_leave;
     862        case COPY_:
    819863            state->mode = COPY;
    820864        case COPY:
     
    877921            while (state->have < state->nlen + state->ndist) {
    878922                for (;;) {
    879                     this = state->lencode[BITS(state->lenbits)];
    880                     if ((unsigned)(this.bits) <= bits) break;
     923                    here = state->lencode[BITS(state->lenbits)];
     924                    if ((unsigned)(here.bits) <= bits) break;
    881925                    PULLBYTE();
    882926                }
    883                 if (this.val < 16) {
    884                     NEEDBITS(this.bits);
    885                     DROPBITS(this.bits);
    886                     state->lens[state->have++] = this.val;
     927                if (here.val < 16) {
     928                    NEEDBITS(here.bits);
     929                    DROPBITS(here.bits);
     930                    state->lens[state->have++] = here.val;
    887931                }
    888932                else {
    889                     if (this.val == 16) {
    890                         NEEDBITS(this.bits + 2);
    891                         DROPBITS(this.bits);
     933                    if (here.val == 16) {
     934                        NEEDBITS(here.bits + 2);
     935                        DROPBITS(here.bits);
    892936                        if (state->have == 0) {
    893937                            strm->msg = (char *)"invalid bit length repeat";
     
    899943                        DROPBITS(2);
    900944                    }
    901                     else if (this.val == 17) {
    902                         NEEDBITS(this.bits + 3);
    903                         DROPBITS(this.bits);
     945                    else if (here.val == 17) {
     946                        NEEDBITS(here.bits + 3);
     947                        DROPBITS(here.bits);
    904948                        len = 0;
    905949                        copy = 3 + BITS(3);
     
    907951                    }
    908952                    else {
    909                         NEEDBITS(this.bits + 7);
    910                         DROPBITS(this.bits);
     953                        NEEDBITS(here.bits + 7);
     954                        DROPBITS(here.bits);
    911955                        len = 0;
    912956                        copy = 11 + BITS(7);
     
    926970            if (state->mode == BAD) break;
    927971
    928             /* build code tables */
     972            /* check for end-of-block code (better have one) */
     973            if (state->lens[256] == 0) {
     974                strm->msg = (char *)"invalid code -- missing end-of-block";
     975                state->mode = BAD;
     976                break;
     977            }
     978
     979            /* build code tables -- note: do not change the lenbits or distbits
     980               values here (9 and 6) without reading the comments in inftrees.h
     981               concerning the ENOUGH constants, which depend on those values */
    929982            state->next = state->codes;
    930983            state->lencode = (code const FAR *)(state->next);
     
    9471000            }
    9481001            Tracev((stderr, "inflate:       codes ok\n"));
     1002            state->mode = LEN_;
     1003            if (flush == Z_TREES) goto inf_leave;
     1004        case LEN_:
    9491005            state->mode = LEN;
    9501006        case LEN:
     
    9531009                inflate_fast(strm, out);
    9541010                LOAD();
    955                 break;
    956             }
     1011                if (state->mode == TYPE)
     1012                    state->back = -1;
     1013                break;
     1014            }
     1015            state->back = 0;
    9571016            for (;;) {
    958                 this = state->lencode[BITS(state->lenbits)];
    959                 if ((unsigned)(this.bits) <= bits) break;
     1017                here = state->lencode[BITS(state->lenbits)];
     1018                if ((unsigned)(here.bits) <= bits) break;
    9601019                PULLBYTE();
    9611020            }
    962             if (this.op && (this.op & 0xf0) == 0) {
    963                 last = this;
     1021            if (here.op && (here.op & 0xf0) == 0) {
     1022                last = here;
    9641023                for (;;) {
    965                     this = state->lencode[last.val +
     1024                    here = state->lencode[last.val +
    9661025                            (BITS(last.bits + last.op) >> last.bits)];
    967                     if ((unsigned)(last.bits + this.bits) <= bits) break;
     1026                    if ((unsigned)(last.bits + here.bits) <= bits) break;
    9681027                    PULLBYTE();
    9691028                }
    9701029                DROPBITS(last.bits);
    971             }
    972             DROPBITS(this.bits);
    973             state->length = (unsigned)this.val;
    974             if ((int)(this.op) == 0) {
    975                 Tracevv((stderr, this.val >= 0x20 && this.val < 0x7f ?
     1030                state->back += last.bits;
     1031            }
     1032            DROPBITS(here.bits);
     1033            state->back += here.bits;
     1034            state->length = (unsigned)here.val;
     1035            if ((int)(here.op) == 0) {
     1036                Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
    9761037                        "inflate:         literal '%c'\n" :
    977                         "inflate:         literal 0x%02x\n", this.val));
     1038                        "inflate:         literal 0x%02x\n", here.val));
    9781039                state->mode = LIT;
    9791040                break;
    9801041            }
    981             if (this.op & 32) {
     1042            if (here.op & 32) {
    9821043                Tracevv((stderr, "inflate:         end of block\n"));
     1044                state->back = -1;
    9831045                state->mode = TYPE;
    9841046                break;
    9851047            }
    986             if (this.op & 64) {
     1048            if (here.op & 64) {
    9871049                strm->msg = (char *)"invalid literal/length code";
    9881050                state->mode = BAD;
    9891051                break;
    9901052            }
    991             state->extra = (unsigned)(this.op) & 15;
     1053            state->extra = (unsigned)(here.op) & 15;
    9921054            state->mode = LENEXT;
    9931055        case LENEXT:
     
    9961058                state->length += BITS(state->extra);
    9971059                DROPBITS(state->extra);
     1060                state->back += state->extra;
    9981061            }
    9991062            Tracevv((stderr, "inflate:         length %u\n", state->length));
     1063            state->was = state->length;
    10001064            state->mode = DIST;
    10011065        case DIST:
    10021066            for (;;) {
    1003                 this = state->distcode[BITS(state->distbits)];
    1004                 if ((unsigned)(this.bits) <= bits) break;
     1067                here = state->distcode[BITS(state->distbits)];
     1068                if ((unsigned)(here.bits) <= bits) break;
    10051069                PULLBYTE();
    10061070            }
    1007             if ((this.op & 0xf0) == 0) {
    1008                 last = this;
     1071            if ((here.op & 0xf0) == 0) {
     1072                last = here;
    10091073                for (;;) {
    1010                     this = state->distcode[last.val +
     1074                    here = state->distcode[last.val +
    10111075                            (BITS(last.bits + last.op) >> last.bits)];
    1012                     if ((unsigned)(last.bits + this.bits) <= bits) break;
     1076                    if ((unsigned)(last.bits + here.bits) <= bits) break;
    10131077                    PULLBYTE();
    10141078                }
    10151079                DROPBITS(last.bits);
    1016             }
    1017             DROPBITS(this.bits);
    1018             if (this.op & 64) {
     1080                state->back += last.bits;
     1081            }
     1082            DROPBITS(here.bits);
     1083            state->back += here.bits;
     1084            if (here.op & 64) {
    10191085                strm->msg = (char *)"invalid distance code";
    10201086                state->mode = BAD;
    10211087                break;
    10221088            }
    1023             state->offset = (unsigned)this.val;
    1024             state->extra = (unsigned)(this.op) & 15;
     1089            state->offset = (unsigned)here.val;
     1090            state->extra = (unsigned)(here.op) & 15;
    10251091            state->mode = DISTEXT;
    10261092        case DISTEXT:
     
    10291095                state->offset += BITS(state->extra);
    10301096                DROPBITS(state->extra);
     1097                state->back += state->extra;
    10311098            }
    10321099#ifdef INFLATE_STRICT
     
    10371104            }
    10381105#endif
    1039             if (state->offset > state->whave + out - left) {
    1040                 strm->msg = (char *)"invalid distance too far back";
    1041                 state->mode = BAD;
    1042                 break;
    1043             }
    10441106            Tracevv((stderr, "inflate:         distance %u\n", state->offset));
    10451107            state->mode = MATCH;
     
    10491111            if (state->offset > copy) {         /* copy from window */
    10501112                copy = state->offset - copy;
    1051                 if (copy > state->write) {
    1052                     copy -= state->write;
     1113                if (copy > state->whave) {
     1114                    if (state->sane) {
     1115                        strm->msg = (char *)"invalid distance too far back";
     1116                        state->mode = BAD;
     1117                        break;
     1118                    }
     1119#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
     1120                    Trace((stderr, "inflate.c too far\n"));
     1121                    copy -= state->whave;
     1122                    if (copy > state->length) copy = state->length;
     1123                    if (copy > left) copy = left;
     1124                    left -= copy;
     1125                    state->length -= copy;
     1126                    do {
     1127                        *put++ = 0;
     1128                    } while (--copy);
     1129                    if (state->length == 0) state->mode = LEN;
     1130                    break;
     1131#endif
     1132                }
     1133                if (copy > state->wnext) {
     1134                    copy -= state->wnext;
    10531135                    from = state->window + (state->wsize - copy);
    10541136                }
    10551137                else
    1056                     from = state->window + (state->write - copy);
     1138                    from = state->window + (state->wnext - copy);
    10571139                if (copy > state->length) copy = state->length;
    10581140            }
     
    11471229            UPDATE(state->check, strm->next_out - out, out);
    11481230    strm->data_type = state->bits + (state->last ? 64 : 0) +
    1149                       (state->mode == TYPE ? 128 : 0);
     1231                      (state->mode == TYPE ? 128 : 0) +
     1232                      (state->mode == LEN_ || state->mode == COPY_ ? 256 : 0);
    11501233    if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK)
    11511234        ret = Z_BUF_ERROR;
     
    11531236}
    11541237
    1155 int ZEXPORT inflateEnd(
    1156   z_streamp strm)
     1238int ZEXPORT inflateEnd(strm)
     1239z_streamp strm;
    11571240{
    11581241    struct inflate_state FAR *state;
     
    11671250}
    11681251
    1169 int ZEXPORT inflateSetDictionary(
    1170     z_streamp strm,
    1171     const Bytef *dictionary,
    1172     uInt dictLength)
     1252int ZEXPORT inflateSetDictionary(strm, dictionary, dictLength)
     1253z_streamp strm;
     1254const Bytef *dictionary;
     1255uInt dictLength;
    11731256{
    11741257    struct inflate_state FAR *state;
     
    12091292}
    12101293
    1211 int ZEXPORT inflateGetHeader(
    1212     z_streamp strm,
    1213     gz_headerp head)
     1294int ZEXPORT inflateGetHeader(strm, head)
     1295z_streamp strm;
     1296gz_headerp head;
    12141297{
    12151298    struct inflate_state FAR *state;
     
    12371320   zero for the first call.
    12381321 */
    1239 local unsigned syncsearch(
    1240     unsigned FAR *have,
    1241     unsigned char FAR *buf,
    1242     unsigned len)
     1322local unsigned syncsearch(have, buf, len)
     1323unsigned FAR *have;
     1324unsigned char FAR *buf;
     1325unsigned len;
    12431326{
    12441327    unsigned got;
     
    12601343}
    12611344
    1262 int ZEXPORT inflateSync(
    1263     z_streamp strm)
     1345int ZEXPORT inflateSync(strm)
     1346z_streamp strm;
    12641347{
    12651348    unsigned len;               /* number of bytes to look at or looked at */
     
    13111394   inflate is waiting for these length bytes.
    13121395 */
    1313 int ZEXPORT inflateSyncPoint(
    1314     z_streamp strm)
     1396int ZEXPORT inflateSyncPoint(strm)
     1397z_streamp strm;
    13151398{
    13161399    struct inflate_state FAR *state;
     
    13211404}
    13221405
    1323 int ZEXPORT inflateCopy(
    1324     z_streamp dest,
    1325     z_streamp source)
     1406int ZEXPORT inflateCopy(dest, source)
     1407z_streamp dest;
     1408z_streamp source;
    13261409{
    13271410    struct inflate_state FAR *state;
     
    13671450    return Z_OK;
    13681451}
     1452
     1453int ZEXPORT inflateUndermine(strm, subvert)
     1454z_streamp strm;
     1455int subvert;
     1456{
     1457    struct inflate_state FAR *state;
     1458
     1459    if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
     1460    state = (struct inflate_state FAR *)strm->state;
     1461    state->sane = !subvert;
     1462#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
     1463    return Z_OK;
     1464#else
     1465    state->sane = 1;
     1466    return Z_DATA_ERROR;
     1467#endif
     1468}
     1469
     1470long ZEXPORT inflateMark(strm)
     1471z_streamp strm;
     1472{
     1473    struct inflate_state FAR *state;
     1474
     1475    if (strm == Z_NULL || strm->state == Z_NULL) return -1L << 16;
     1476    state = (struct inflate_state FAR *)strm->state;
     1477    return ((long)(state->back) << 16) +
     1478        (state->mode == COPY ? state->length :
     1479            (state->mode == MATCH ? state->was - state->length : 0));
     1480}
  • cpukit/zlib/inftrees.c

    r41ca776f r6121dc77  
    11/* inftrees.c -- generate Huffman trees for efficient decoding
    2  * Copyright (C) 1995-2005 Mark Adler
     2 * Copyright (C) 1995-2010 Mark Adler
    33 * For conditions of distribution and use, see copyright notice in zlib.h
    44 */
     
    1010
    1111const char inflate_copyright[] =
    12    " inflate 1.2.3 Copyright 1995-2005 Mark Adler ";
     12   " inflate 1.2.4 Copyright 1995-2010 Mark Adler ";
    1313/*
    1414  If you use the zlib library in a product, an acknowledgment is welcome
     
    3030   longest code or if it is less than the shortest code.
    3131 */
    32 int inflate_table(
    33   codetype type,
    34   unsigned short FAR *lens,
    35   unsigned codes,
    36   code FAR * FAR *table,
    37   unsigned FAR *bits,
    38   unsigned short FAR *work)
     32int inflate_table(type, lens, codes, table, bits, work)
     33codetype type;
     34unsigned short FAR *lens;
     35unsigned codes;
     36code FAR * FAR *table;
     37unsigned FAR *bits;
     38unsigned short FAR *work;
    3939{
    4040    unsigned len;               /* a code's length in bits */
     
    5151    unsigned low;               /* low bits for current root entry */
    5252    unsigned mask;              /* mask for low root bits */
    53     code this;                  /* table entry for duplication */
     53    code here;                  /* table entry for duplication */
    5454    code FAR *next;             /* next available space in table */
    5555    const unsigned short FAR *base;     /* base value table to use */
     
    6363    static const unsigned short lext[31] = { /* Length codes 257..285 extra */
    6464        16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
    65         19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 201, 196};
     65        19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 64, 195};
    6666    static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
    6767        1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
     
    116116    if (root > max) root = max;
    117117    if (max == 0) {                     /* no symbols to code at all */
    118         this.op = (unsigned char)64;    /* invalid code marker */
    119         this.bits = (unsigned char)1;
    120         this.val = (unsigned short)0;
    121         *(*table)++ = this;             /* make a table to force an error */
    122         *(*table)++ = this;
     118        here.op = (unsigned char)64;    /* invalid code marker */
     119        here.bits = (unsigned char)1;
     120        here.val = (unsigned short)0;
     121        *(*table)++ = here;             /* make a table to force an error */
     122        *(*table)++ = here;
    123123        *bits = 1;
    124124        return 0;     /* no symbols, but wait for decoding to report error */
    125125    }
    126     for (min = 1; min <= MAXBITS; min++)
     126    for (min = 1; min < max; min++)
    127127        if (count[min] != 0) break;
    128128    if (root < min) root = min;
     
    167167
    168168       used keeps track of how many table entries have been allocated from the
    169        provided *table space.  It is checked when a LENS table is being made
    170        against the space in *table, ENOUGH, minus the maximum space needed by
    171        the worst case distance code, MAXD.  This should never happen, but the
    172        sufficiency of ENOUGH has not been proven exhaustively, hence the check.
    173        This assumes that when type == LENS, bits == 9.
     169       provided *table space.  It is checked for LENS and DIST tables against
     170       the constants ENOUGH_LENS and ENOUGH_DISTS to guard against changes in
     171       the initial root table size constants.  See the comments in inftrees.h
     172       for more information.
    174173
    175174       sym increments through all symbols, and the loop terminates when
     
    210209
    211210    /* check available table space */
    212     if (type == LENS && used >= ENOUGH - MAXD)
     211    if ((type == LENS && used >= ENOUGH_LENS) ||
     212        (type == DISTS && used >= ENOUGH_DISTS))
    213213        return 1;
    214214
     
    216216    for (;;) {
    217217        /* create table entry */
    218         this.bits = (unsigned char)(len - drop);
     218        here.bits = (unsigned char)(len - drop);
    219219        if ((int)(work[sym]) < end) {
    220             this.op = (unsigned char)0;
    221             this.val = work[sym];
     220            here.op = (unsigned char)0;
     221            here.val = work[sym];
    222222        }
    223223        else if ((int)(work[sym]) > end) {
    224             this.op = (unsigned char)(extra[work[sym]]);
    225             this.val = base[work[sym]];
     224            here.op = (unsigned char)(extra[work[sym]]);
     225            here.val = base[work[sym]];
    226226        }
    227227        else {
    228             this.op = (unsigned char)(32 + 64);         /* end of block */
    229             this.val = 0;
     228            here.op = (unsigned char)(32 + 64);         /* end of block */
     229            here.val = 0;
    230230        }
    231231
     
    236236        do {
    237237            fill -= incr;
    238             next[(huff >> drop) + fill] = this;
     238            next[(huff >> drop) + fill] = here;
    239239        } while (fill != 0);
    240240
     
    278278            /* check for enough space */
    279279            used += 1U << curr;
    280             if (type == LENS && used >= ENOUGH - MAXD)
     280            if ((type == LENS && used >= ENOUGH_LENS) ||
     281                (type == DISTS && used >= ENOUGH_DISTS))
    281282                return 1;
    282283
     
    296297       drops back to the root table to fill in any remaining entries there.
    297298     */
    298     this.op = (unsigned char)64;                /* invalid code marker */
    299     this.bits = (unsigned char)(len - drop);
    300     this.val = (unsigned short)0;
     299    here.op = (unsigned char)64;                /* invalid code marker */
     300    here.bits = (unsigned char)(len - drop);
     301    here.val = (unsigned short)0;
    301302    while (huff != 0) {
    302303        /* when done with sub-table, drop back to root table */
     
    305306            len = root;
    306307            next = *table;
    307             this.bits = (unsigned char)len;
     308            here.bits = (unsigned char)len;
    308309        }
    309310
    310311        /* put invalid code marker in table */
    311         next[huff >> drop] = this;
     312        next[huff >> drop] = here;
    312313
    313314        /* backwards increment the len-bit code huff */
  • cpukit/zlib/inftrees.h

    r41ca776f r6121dc77  
    3636 */
    3737
    38 /* Maximum size of dynamic tree.  The maximum found in a long but non-
    39    exhaustive search was 1444 code structures (852 for length/literals
    40    and 592 for distances, the latter actually the result of an
    41    exhaustive search).  The true maximum is not known, but the value
    42    below is more than safe. */
    43 #define ENOUGH 2048
    44 #define MAXD 592
     38/* Maximum size of the dynamic table.  The maximum number of code structures is
     39   1444, which is the sum of 852 for literal/length codes and 592 for distance
     40   codes.  These values were found by exhaustive searches using the program
     41   examples/enough.c found in the zlib distribtution.  The arguments to that
     42   program are the number of symbols, the initial root table size, and the
     43   maximum bit length of a code.  "enough 286 9 15" for literal/length codes
     44   returns returns 852, and "enough 30 6 15" for distance codes returns 592.
     45   The initial root table size (9 or 6) is found in the fifth argument of the
     46   inflate_table() calls in inflate.c and infback.c.  If the root table size is
     47   changed, then these maximum sizes would be need to be recalculated and
     48   updated. */
     49#define ENOUGH_LENS 852
     50#define ENOUGH_DISTS 592
     51#define ENOUGH (ENOUGH_LENS+ENOUGH_DISTS)
    4552
    46 /* Type of code to build for inftable() */
     53/* Type of code to build for inflate_table() */
    4754typedef enum {
    4855    CODES,
  • cpukit/zlib/trees.c

    r41ca776f r6121dc77  
    11/* trees.c -- output deflated data using Huffman coding
    2  * Copyright (C) 1995-2005 Jean-loup Gailly
     2 * Copyright (C) 1995-2009 Jean-loup Gailly
     3 * detect_data_type() function provided freely by Cosmin Truta, 2006
    34 * For conditions of distribution and use, see copyright notice in zlib.h
    45 */
     
    153154local void compress_block OF((deflate_state *s, ct_data *ltree,
    154155                              ct_data *dtree));
    155 local void set_data_type OF((deflate_state *s));
     156local int  detect_data_type OF((deflate_state *s));
    156157local unsigned bi_reverse OF((unsigned value, int length));
    157158local void bi_windup      OF((deflate_state *s));
     
    204205     */
    205206    if (s->bi_valid > (int)Buf_size - length) {
    206         s->bi_buf |= (value << s->bi_valid);
     207        s->bi_buf |= (ush)value << s->bi_valid;
    207208        put_short(s, s->bi_buf);
    208209        s->bi_buf = (ush)value >> (Buf_size - s->bi_valid);
    209210        s->bi_valid += length - Buf_size;
    210211    } else {
    211         s->bi_buf |= value << s->bi_valid;
     212        s->bi_buf |= (ush)value << s->bi_valid;
    212213        s->bi_valid += length;
    213214    }
     
    219220  if (s->bi_valid > (int)Buf_size - len) {\
    220221    int val = value;\
    221     s->bi_buf |= (val << s->bi_valid);\
     222    s->bi_buf |= (ush)val << s->bi_valid;\
    222223    put_short(s, s->bi_buf);\
    223224    s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\
    224225    s->bi_valid += len - Buf_size;\
    225226  } else {\
    226     s->bi_buf |= (value) << s->bi_valid;\
     227    s->bi_buf |= (ush)(value) << s->bi_valid;\
    227228    s->bi_valid += len;\
    228229  }\
     
    236237 * Initialize the various 'constant' tables.
    237238 */
    238 local void tr_static_init(void)
     239local void tr_static_init()
    239240{
    240241#if defined(GEN_TREES_H) || !defined(STDC)
     
    251252
    252253    /* For some embedded targets, global variables are not initialized: */
     254#ifdef NO_INIT_GLOBAL_POINTERS
    253255    static_l_desc.static_tree = static_ltree;
    254256    static_l_desc.extra_bits = extra_lbits;
     
    256258    static_d_desc.extra_bits = extra_dbits;
    257259    static_bl_desc.extra_bits = extra_blbits;
     260#endif
    258261
    259262    /* Initialize the mapping length (0..255) -> length code (0..28) */
     
    380383 * Initialize the tree data structures for a new zlib stream.
    381384 */
    382 void _tr_init(
    383     deflate_state *s)
     385void _tr_init(s)
     386    deflate_state *s;
    384387{
    385388    tr_static_init();
     
    409412 * Initialize a new block.
    410413 */
    411 local void init_block(
    412     deflate_state *s)
     414local void init_block(s)
     415    deflate_state *s;
    413416{
    414417    int n; /* iterates over tree elements */
     
    453456 * two sons).
    454457 */
    455 local void pqdownheap(
    456     deflate_state *s,
    457     ct_data *tree,  /* the tree to restore */
    458     int k)               /* node to move down */
     458local void pqdownheap(s, tree, k)
     459    deflate_state *s;
     460    ct_data *tree;  /* the tree to restore */
     461    int k;               /* node to move down */
    459462{
    460463    int v = s->heap[k];
     
    488491 *     not null.
    489492 */
    490 local void gen_bitlen(
    491     deflate_state *s,
    492     tree_desc *desc)    /* the tree descriptor */
     493local void gen_bitlen(s, desc)
     494    deflate_state *s;
     495    tree_desc *desc;    /* the tree descriptor */
    493496{
    494497    ct_data *tree        = desc->dyn_tree;
     
    575578 *     zero code length.
    576579 */
    577 local void gen_codes (
    578     ct_data *tree,             /* the tree to decorate */
    579     int max_code,              /* largest code with non zero frequency */
    580     ushf *bl_count)            /* number of codes at each bit length */
     580local void gen_codes (tree, max_code, bl_count)
     581    ct_data *tree;             /* the tree to decorate */
     582    int max_code;              /* largest code with non zero frequency */
     583    ushf *bl_count;            /* number of codes at each bit length */
    581584{
    582585    ush next_code[MAX_BITS+1]; /* next code value for each bit length */
     
    617620 *     also updated if stree is not null. The field max_code is set.
    618621 */
    619 local void build_tree(
    620     deflate_state *s,
    621     tree_desc *desc) /* the tree descriptor */
     622local void build_tree(s, desc)
     623    deflate_state *s;
     624    tree_desc *desc; /* the tree descriptor */
    622625{
    623626    ct_data *tree         = desc->dyn_tree;
     
    705708 * in the bit length tree.
    706709 */
    707 local void scan_tree (
    708     deflate_state *s,
    709     ct_data *tree,   /* the tree to be scanned */
    710     int max_code)    /* and its largest code of non zero frequency */
     710local void scan_tree (s, tree, max_code)
     711    deflate_state *s;
     712    ct_data *tree;   /* the tree to be scanned */
     713    int max_code;    /* and its largest code of non zero frequency */
    711714{
    712715    int n;                     /* iterates over all tree elements */
     
    750753 * bl_tree.
    751754 */
    752 local void send_tree (
    753     deflate_state *s,
    754     ct_data *tree, /* the tree to be scanned */
    755     int max_code)       /* and its largest code of non zero frequency */
     755local void send_tree (s, tree, max_code)
     756    deflate_state *s;
     757    ct_data *tree; /* the tree to be scanned */
     758    int max_code;       /* and its largest code of non zero frequency */
    756759{
    757760    int n;                     /* iterates over all tree elements */
     
    801804 * bl_order of the last bit length code to send.
    802805 */
    803 local int build_bl_tree(
    804     deflate_state *s)
     806local int build_bl_tree(s)
     807    deflate_state *s;
    805808{
    806809    int max_blindex;  /* index of last bit length code of non zero freq */
     
    836839 * IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4.
    837840 */
    838 local void send_all_trees(
    839     deflate_state *s,
    840     int lcodes, int dcodes, int blcodes) /* number of codes for each tree */
     841local void send_all_trees(s, lcodes, dcodes, blcodes)
     842    deflate_state *s;
     843    int lcodes, dcodes, blcodes; /* number of codes for each tree */
    841844{
    842845    int rank;                    /* index in bl_order */
     
    865868 * Send a stored block
    866869 */
    867 void _tr_stored_block(
    868     deflate_state *s,
    869     charf *buf,       /* input block */
    870     ulg stored_len,   /* length of input block */
    871     int eof)          /* true if this is the last block for a file */
    872 {
    873     send_bits(s, (STORED_BLOCK<<1)+eof, 3);  /* send block type */
     870void _tr_stored_block(s, buf, stored_len, last)
     871    deflate_state *s;
     872    charf *buf;       /* input block */
     873    ulg stored_len;   /* length of input block */
     874    int last;         /* one if this is the last block for a file */
     875{
     876    send_bits(s, (STORED_BLOCK<<1)+last, 3);    /* send block type */
    874877#ifdef DEBUG
    875878    s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L;
     
    890893 * on one bit only.
    891894 */
    892 void _tr_align(
    893     deflate_state *s)
     895void _tr_align(s)
     896    deflate_state *s;
    894897{
    895898    send_bits(s, STATIC_TREES<<1, 3);
     
    919922 * trees or store, and output the encoded block to the zip file.
    920923 */
    921 void _tr_flush_block(
    922     deflate_state *s,
    923     charf *buf,       /* input block, or NULL if too old */
    924     ulg stored_len,   /* length of input block */
    925     int eof)          /* true if this is the last block for a file */
     924void _tr_flush_block(s, buf, stored_len, last)
     925    deflate_state *s;
     926    charf *buf;       /* input block, or NULL if too old */
     927    ulg stored_len;   /* length of input block */
     928    int last;         /* one if this is the last block for a file */
    926929{
    927930    ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */
     
    932935
    933936        /* Check if the file is binary or text */
    934         if (stored_len > 0 && s->strm->data_type == Z_UNKNOWN)
    935             set_data_type(s);
     937        if (s->strm->data_type == Z_UNKNOWN)
     938            s->strm->data_type = detect_data_type(s);
    936939
    937940        /* Construct the literal and distance trees */
     
    979982         * transform a block into a stored block.
    980983         */
    981         _tr_stored_block(s, buf, stored_len, eof);
     984        _tr_stored_block(s, buf, stored_len, last);
    982985
    983986#ifdef FORCE_STATIC
     
    986989    } else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) {
    987990#endif
    988         send_bits(s, (STATIC_TREES<<1)+eof, 3);
     991        send_bits(s, (STATIC_TREES<<1)+last, 3);
    989992        compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree);
    990993#ifdef DEBUG
     
    992995#endif
    993996    } else {
    994         send_bits(s, (DYN_TREES<<1)+eof, 3);
     997        send_bits(s, (DYN_TREES<<1)+last, 3);
    995998        send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1,
    996999                       max_blindex+1);
     
    10061009    init_block(s);
    10071010
    1008     if (eof) {
     1011    if (last) {
    10091012        bi_windup(s);
    10101013#ifdef DEBUG
     
    10131016    }
    10141017    Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,
    1015            s->compressed_len-7*eof));
     1018           s->compressed_len-7*last));
    10161019}
    10171020
     
    10201023 * the current block must be flushed.
    10211024 */
    1022 int _tr_tally (
    1023     deflate_state *s,
    1024     unsigned dist,  /* distance of matched string */
    1025     unsigned lc)    /* match length-MIN_MATCH or unmatched char (if dist==0) */
     1025int _tr_tally (s, dist, lc)
     1026    deflate_state *s;
     1027    unsigned dist;  /* distance of matched string */
     1028    unsigned lc;    /* match length-MIN_MATCH or unmatched char (if dist==0) */
    10261029{
    10271030    s->d_buf[s->last_lit] = (ush)dist;
     
    10701073 * Send the block data compressed using the given Huffman trees
    10711074 */
    1072 local void compress_block(
    1073     deflate_state *s,
    1074     ct_data *ltree, /* literal tree */
    1075     ct_data *dtree) /* distance tree */
     1075local void compress_block(s, ltree, dtree)
     1076    deflate_state *s;
     1077    ct_data *ltree; /* literal tree */
     1078    ct_data *dtree; /* distance tree */
    10761079{
    10771080    unsigned dist;      /* distance of matched string */
     
    11191122
    11201123/* ===========================================================================
    1121  * Set the data type to BINARY or TEXT, using a crude approximation:
    1122  * set it to Z_TEXT if all symbols are either printable characters (33 to 255)
    1123  * or white spaces (9 to 13, or 32); or set it to Z_BINARY otherwise.
     1124 * Check if the data type is TEXT or BINARY, using the following algorithm:
     1125 * - TEXT if the two conditions below are satisfied:
     1126 *    a) There are no non-portable control characters belonging to the
     1127 *       "black list" (0..6, 14..25, 28..31).
     1128 *    b) There is at least one printable character belonging to the
     1129 *       "white list" (9 {TAB}, 10 {LF}, 13 {CR}, 32..255).
     1130 * - BINARY otherwise.
     1131 * - The following partially-portable control characters form a
     1132 *   "gray list" that is ignored in this detection algorithm:
     1133 *   (7 {BEL}, 8 {BS}, 11 {VT}, 12 {FF}, 26 {SUB}, 27 {ESC}).
    11241134 * IN assertion: the fields Freq of dyn_ltree are set.
    11251135 */
    1126 local void set_data_type(
    1127     deflate_state *s)
    1128 {
     1136local int detect_data_type(s)
     1137    deflate_state *s;
     1138{
     1139    /* black_mask is the bit mask of black-listed bytes
     1140     * set bits 0..6, 14..25, and 28..31
     1141     * 0xf3ffc07f = binary 11110011111111111100000001111111
     1142     */
     1143    unsigned long black_mask = 0xf3ffc07fUL;
    11291144    int n;
    11301145
    1131     for (n = 0; n < 9; n++)
     1146    /* Check for non-textual ("black-listed") bytes. */
     1147    for (n = 0; n <= 31; n++, black_mask >>= 1)
     1148        if ((black_mask & 1) && (s->dyn_ltree[n].Freq != 0))
     1149            return Z_BINARY;
     1150
     1151    /* Check for textual ("white-listed") bytes. */
     1152    if (s->dyn_ltree[9].Freq != 0 || s->dyn_ltree[10].Freq != 0
     1153            || s->dyn_ltree[13].Freq != 0)
     1154        return Z_TEXT;
     1155    for (n = 32; n < LITERALS; n++)
    11321156        if (s->dyn_ltree[n].Freq != 0)
    1133             break;
    1134     if (n == 9)
    1135         for (n = 14; n < 32; n++)
    1136             if (s->dyn_ltree[n].Freq != 0)
    1137                 break;
    1138     s->strm->data_type = (n == 32) ? Z_TEXT : Z_BINARY;
     1157            return Z_TEXT;
     1158
     1159    /* There are no "black-listed" or "white-listed" bytes:
     1160     * this stream either is empty or has tolerated ("gray-listed") bytes only.
     1161     */
     1162    return Z_BINARY;
    11391163}
    11401164
     
    11441168 * IN assertion: 1 <= len <= 15
    11451169 */
    1146 local unsigned bi_reverse(
    1147     unsigned code, /* the value to invert */
    1148     int len)       /* its bit length */
     1170local unsigned bi_reverse(code, len)
     1171    unsigned code; /* the value to invert */
     1172    int len;       /* its bit length */
    11491173{
    11501174    register unsigned res = 0;
     
    11591183 * Flush the bit buffer, keeping at most 7 bits in it.
    11601184 */
    1161 local void bi_flush(
    1162     deflate_state *s)
     1185local void bi_flush(s)
     1186    deflate_state *s;
    11631187{
    11641188    if (s->bi_valid == 16) {
     
    11761200 * Flush the bit buffer and align the output on a byte boundary
    11771201 */
    1178 local void bi_windup(
    1179     deflate_state *s)
     1202local void bi_windup(s)
     1203    deflate_state *s;
    11801204{
    11811205    if (s->bi_valid > 8) {
     
    11951219 * one's complement if requested.
    11961220 */
    1197 local void copy_block(
    1198     deflate_state *s,
    1199     charf    *buf,    /* the input data */
    1200     unsigned len,     /* its length */
    1201     int      header)  /* true if block header must be written */
     1221local void copy_block(s, buf, len, header)
     1222    deflate_state *s;
     1223    charf    *buf;    /* the input data */
     1224    unsigned len;     /* its length */
     1225    int      header;  /* true if block header must be written */
    12021226{
    12031227    bi_windup(s);        /* align on byte boundary */
  • cpukit/zlib/uncompr.c

    r41ca776f r6121dc77  
    11/* uncompr.c -- decompress a memory buffer
    2  * Copyright (C) 1995-2003 Jean-loup Gailly.
     2 * Copyright (C) 1995-2003, 2010 Jean-loup Gailly.
    33 * For conditions of distribution and use, see copyright notice in zlib.h
    44 */
     
    1717   by some mechanism outside the scope of this compression library.)
    1818   Upon exit, destLen is the actual size of the compressed buffer.
    19      This function can be used to decompress a whole file at once if the
    20    input file is mmap'ed.
    2119
    2220     uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
     
    2422   buffer, or Z_DATA_ERROR if the input data was corrupted.
    2523*/
    26 int ZEXPORT uncompress (
    27     Bytef *dest,
    28     uLongf *destLen,
    29     const Bytef *source,
    30     uLong sourceLen)
     24int ZEXPORT uncompress (dest, destLen, source, sourceLen)
     25    Bytef *dest;
     26    uLongf *destLen;
     27    const Bytef *source;
     28    uLong sourceLen;
    3129{
    3230    z_stream stream;
  • cpukit/zlib/zconf.h

    r41ca776f r6121dc77  
    11/* zconf.h -- configuration of the zlib compression library
    2  * Copyright (C) 1995-2005 Jean-loup Gailly.
     2 * Copyright (C) 1995-2010 Jean-loup Gailly.
    33 * For conditions of distribution and use, see copyright notice in zlib.h
    44 */
     
    88#ifndef ZCONF_H
    99#define ZCONF_H
    10 
    11 #define Z_PREFIX 1
    1210
    1311/*
    1412 * If you *really* need a unique prefix for all types and library functions,
    1513 * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
     14 * Even better than compiling with -DZ_PREFIX would be to use configure to set
     15 * this permanently in zconf.h using "./configure --zprefix".
    1616 */
    17 #ifdef Z_PREFIX
     17#ifdef Z_PREFIX     /* may be set to #if 1 by ./configure */
     18
     19/* all linked symbols */
     20#  define _dist_code            z__dist_code
     21#  define _length_code          z__length_code
     22#  define _tr_align             z__tr_align
     23#  define _tr_flush_block       z__tr_flush_block
     24#  define _tr_init              z__tr_init
     25#  define _tr_stored_block      z__tr_stored_block
     26#  define _tr_tally             z__tr_tally
     27#  define adler32               z_adler32
     28#  define adler32_combine       z_adler32_combine
     29#  define adler32_combine64     z_adler32_combine64
     30#  define compress              z_compress
     31#  define compress2             z_compress2
     32#  define compressBound         z_compressBound
     33#  define crc32                 z_crc32
     34#  define crc32_combine         z_crc32_combine
     35#  define crc32_combine64       z_crc32_combine64
     36#  define deflate               z_deflate
     37#  define deflateBound          z_deflateBound
     38#  define deflateCopy           z_deflateCopy
     39#  define deflateEnd            z_deflateEnd
     40#  define deflateInit2_         z_deflateInit2_
    1841#  define deflateInit_          z_deflateInit_
    19 #  define deflate               z_deflate
    20 #  define deflateEnd            z_deflateEnd
     42#  define deflateParams         z_deflateParams
     43#  define deflatePrime          z_deflatePrime
     44#  define deflateReset          z_deflateReset
     45#  define deflateSetDictionary  z_deflateSetDictionary
     46#  define deflateSetHeader      z_deflateSetHeader
     47#  define deflateTune           z_deflateTune
     48#  define deflate_copyright     z_deflate_copyright
     49#  define get_crc_table         z_get_crc_table
     50#  define gz_error              z_gz_error
     51#  define gz_intmax             z_gz_intmax
     52#  define gz_strwinerror        z_gz_strwinerror
     53#  define gzbuffer              z_gzbuffer
     54#  define gzclearerr            z_gzclearerr
     55#  define gzclose               z_gzclose
     56#  define gzclose_r             z_gzclose_r
     57#  define gzclose_w             z_gzclose_w
     58#  define gzdirect              z_gzdirect
     59#  define gzdopen               z_gzdopen
     60#  define gzeof                 z_gzeof
     61#  define gzerror               z_gzerror
     62#  define gzflush               z_gzflush
     63#  define gzgetc                z_gzgetc
     64#  define gzgets                z_gzgets
     65#  define gzoffset              z_gzoffset
     66#  define gzoffset64            z_gzoffset64
     67#  define gzopen                z_gzopen
     68#  define gzopen64              z_gzopen64
     69#  define gzprintf              z_gzprintf
     70#  define gzputc                z_gzputc
     71#  define gzputs                z_gzputs
     72#  define gzread                z_gzread
     73#  define gzrewind              z_gzrewind
     74#  define gzseek                z_gzseek
     75#  define gzseek64              z_gzseek64
     76#  define gzsetparams           z_gzsetparams
     77#  define gztell                z_gztell
     78#  define gztell64              z_gztell64
     79#  define gzungetc              z_gzungetc
     80#  define gzwrite               z_gzwrite
     81#  define inflate               z_inflate
     82#  define inflateBack           z_inflateBack
     83#  define inflateBackEnd        z_inflateBackEnd
     84#  define inflateBackInit_      z_inflateBackInit_
     85#  define inflateCopy           z_inflateCopy
     86#  define inflateEnd            z_inflateEnd
     87#  define inflateGetHeader      z_inflateGetHeader
     88#  define inflateInit2_         z_inflateInit2_
    2189#  define inflateInit_          z_inflateInit_
    22 #  define inflate               z_inflate
    23 #  define inflateEnd            z_inflateEnd
    24 #  define deflateInit2_         z_deflateInit2_
    25 #  define deflateSetDictionary  z_deflateSetDictionary
    26 #  define deflateCopy           z_deflateCopy
    27 #  define deflateReset          z_deflateReset
    28 #  define deflateParams         z_deflateParams
    29 #  define deflateBound          z_deflateBound
    30 #  define deflatePrime          z_deflatePrime
    31 #  define inflateInit2_         z_inflateInit2_
     90#  define inflateMark           z_inflateMark
     91#  define inflatePrime          z_inflatePrime
     92#  define inflateReset          z_inflateReset
     93#  define inflateReset2         z_inflateReset2
    3294#  define inflateSetDictionary  z_inflateSetDictionary
    3395#  define inflateSync           z_inflateSync
    3496#  define inflateSyncPoint      z_inflateSyncPoint
    35 #  define inflateCopy           z_inflateCopy
    36 #  define inflateReset          z_inflateReset
    37 #  define inflateBack           z_inflateBack
    38 #  define inflateBackEnd        z_inflateBackEnd
    39 #  define compress              z_compress
    40 #  define compress2             z_compress2
    41 #  define compressBound         z_compressBound
     97#  define inflateUndermine      z_inflateUndermine
     98#  define inflate_copyright     z_inflate_copyright
     99#  define inflate_fast          z_inflate_fast
     100#  define inflate_table         z_inflate_table
    42101#  define uncompress            z_uncompress
    43 #  define adler32               z_adler32
    44 #  define crc32                 z_crc32
    45 #  define get_crc_table         z_get_crc_table
    46102#  define zError                z_zError
    47 
     103#  define zcalloc               z_zcalloc
     104#  define zcfree                z_zcfree
     105#  define zlibCompileFlags      z_zlibCompileFlags
     106#  define zlibVersion           z_zlibVersion
     107
     108/* all zlib typedefs in zlib.h and zconf.h */
     109#  define Byte                  z_Byte
     110#  define Bytef                 z_Bytef
    48111#  define alloc_func            z_alloc_func
     112#  define charf                 z_charf
    49113#  define free_func             z_free_func
     114#  define gzFile                z_gzFile
     115#  define gz_header             z_gz_header
     116#  define gz_headerp            z_gz_headerp
    50117#  define in_func               z_in_func
     118#  define intf                  z_intf
    51119#  define out_func              z_out_func
    52 #  define Byte                  z_Byte
    53120#  define uInt                  z_uInt
     121#  define uIntf                 z_uIntf
    54122#  define uLong                 z_uLong
    55 #  define Bytef                 z_Bytef
    56 #  define charf                 z_charf
    57 #  define intf                  z_intf
    58 #  define uIntf                 z_uIntf
    59123#  define uLongf                z_uLongf
     124#  define voidp                 z_voidp
     125#  define voidpc                z_voidpc
    60126#  define voidpf                z_voidpf
    61 #  define voidp                 z_voidp
     127
     128/* all zlib structs in zlib.h and zconf.h */
     129#  define gz_header_s           z_gz_header_s
     130#  define internal_state        z_internal_state
     131
    62132#endif
    63133
     
    246316#endif
    247317
     318#ifdef HAVE_VISIBILITY_PRAGMA
     319#  define ZEXTERN __attribute__((visibility ("default"))) extern
     320#endif
     321
    248322#ifndef ZEXTERN
    249323#  define ZEXTERN extern
     
    296370#endif
    297371
    298 #if 1           /* HAVE_UNISTD_H -- this line is updated by ./configure */
    299 #  include <sys/types.h> /* for off_t */
    300 #  include <unistd.h>    /* for SEEK_* and off_t */
     372#ifdef HAVE_UNISTD_H    /* may be set to #if 1 by ./configure */
     373#  define Z_HAVE_UNISTD_H
     374#endif
     375
     376#ifdef Z_HAVE_UNISTD_H
     377#  include <sys/types.h>    /* for off_t */
     378#  include <unistd.h>       /* for SEEK_* and off_t */
    301379#  ifdef VMS
    302 #    include <unixio.h>   /* for off_t */
    303 #  endif
    304 #  define z_off_t off_t
    305 #endif
     380#    include <unixio.h>     /* for off_t */
     381#  endif
     382#  ifndef z_off_t
     383#    define z_off_t off_t
     384#  endif
     385#endif
     386
     387#ifdef _LARGEFILE64_SOURCE
     388#  include <sys/types.h>
     389#endif
     390
    306391#ifndef SEEK_SET
    307392#  define SEEK_SET        0       /* Seek from beginning of file.  */
     
    319404#if defined(__MVS__)
    320405#  define NO_vsnprintf
    321 #  ifdef FAR
    322 #    undef FAR
    323 #  endif
    324406#endif
    325407
    326408/* MVS linker does not support external names larger than 8 bytes */
    327409#if defined(__MVS__)
    328 #   pragma map(deflateInit_,"DEIN")
    329 #   pragma map(deflateInit2_,"DEIN2")
    330 #   pragma map(deflateEnd,"DEEND")
    331 #   pragma map(deflateBound,"DEBND")
    332 #   pragma map(inflateInit_,"ININ")
    333 #   pragma map(inflateInit2_,"ININ2")
    334 #   pragma map(inflateEnd,"INEND")
    335 #   pragma map(inflateSync,"INSY")
    336 #   pragma map(inflateSetDictionary,"INSEDI")
    337 #   pragma map(compressBound,"CMBND")
    338 #   pragma map(inflate_table,"INTABL")
    339 #   pragma map(inflate_fast,"INFA")
    340 #   pragma map(inflate_copyright,"INCOPY")
     410  #pragma map(deflateInit_,"DEIN")
     411  #pragma map(deflateInit2_,"DEIN2")
     412  #pragma map(deflateEnd,"DEEND")
     413  #pragma map(deflateBound,"DEBND")
     414  #pragma map(inflateInit_,"ININ")
     415  #pragma map(inflateInit2_,"ININ2")
     416  #pragma map(inflateEnd,"INEND")
     417  #pragma map(inflateSync,"INSY")
     418  #pragma map(inflateSetDictionary,"INSEDI")
     419  #pragma map(compressBound,"CMBND")
     420  #pragma map(inflate_table,"INTABL")
     421  #pragma map(inflate_fast,"INFA")
     422  #pragma map(inflate_copyright,"INCOPY")
    341423#endif
    342424
  • cpukit/zlib/zlib.3

    r41ca776f r6121dc77  
    1 .TH ZLIB 3 "18 July 2005"
     1.TH ZLIB 3 "14 March 2010"
    22.SH NAME
    33zlib \- compression/decompression library
     
    1010.I zlib
    1111library is a general purpose data compression library.
    12 The code is thread safe.
     12The code is thread safe, assuming that the standard library functions
     13used are thread safe, such as memory allocation routines.
    1314It provides in-memory compression and decompression functions,
    1415including integrity checks of the uncompressed data.
    1516This version of the library supports only one compression method (deflation)
    16 but other algorithms will be added later
    17 and will have the same stream interface.
     17but other algorithms may be added later
     18with the same stream interface.
    1819.LP
    1920Compression can be done in a single step if the buffers are large enough
    20 (for example if an input file is mmap'ed),
    2121or can be done by repeated calls of the compression function.
    2222In the latter case,
     
    3131The library does not install any signal handler.
    3232The decoder checks the consistency of the compressed data,
    33 so the library should never crash even in case of corrupted input.
     33so the library should never crash even in the case of corrupted input.
    3434.LP
    3535All functions of the compression library are documented in the file
     
    3939.I example.c
    4040and
    41 .IR minigzip.c .
     41.IR minigzip.c,
     42as well as other examples in the
     43.IR examples/
     44directory.
    4245.LP
    4346Changes to this version are documented in the file
    4447.I ChangeLog
    45 that accompanies the source,
    46 and are concerned primarily with bug fixes and portability enhancements.
     48that accompanies the source.
    4749.LP
    48 A Java implementation of
    4950.I zlib
    50 is available in the Java Development Kit 1.1:
     51is available in Java using the java.util.zip package:
    5152.IP
    52 http://www.javasoft.com/products/JDK/1.1/docs/api/Package-java.util.zip.html
     53http://java.sun.com/developer/technicalArticles/Programming/compression/
    5354.LP
    5455A Perl interface to
     
    5859including:
    5960.IP
    60 http://www.cpan.org/modules/by-module/Compress/
     61http://search.cpan.org/~pmqs/IO-Compress-Zlib/
    6162.LP
    6263A Python interface to
     
    6768http://www.python.org/doc/lib/module-zlib.html
    6869.LP
    69 A
    7070.I zlib
    71 binding for
    72 .IR tcl (1),
    73 written by Andreas Kupries (a.kupries@westend.com),
    74 is availlable at:
     71is built into
     72.IR tcl:
    7573.IP
    76 http://www.westend.com/~kupries/doc/trf/man/man.html
     74http://wiki.tcl.tk/4610
    7775.LP
    7876An experimental package to read and write files in .zip format,
     
    8280is available at:
    8381.IP
    84 http://www.winimage.com/zLibDll/unzip.html
     82http://www.winimage.com/zLibDll/minizip.html
    8583and also in the
    8684.I contrib/minizip
    8785directory of the main
    8886.I zlib
    89 web site.
     87source distribution.
    9088.SH "SEE ALSO"
    9189The
    9290.I zlib
    93 web site can be found at either of these locations:
     91web site can be found at:
    9492.IP
    95 http://www.zlib.org
    96 .br
    97 http://www.gzip.org/zlib/
     93http://zlib.net/
    9894.LP
    9995The data format used by the zlib library is described by RFC
    10096(Request for Comments) 1950 to 1952 in the files:
    10197.IP
    102 http://www.ietf.org/rfc/rfc1950.txt (concerning zlib format)
     98http://www.ietf.org/rfc/rfc1950.txt (for the zlib header and trailer format)
    10399.br
    104 http://www.ietf.org/rfc/rfc1951.txt (concerning deflate format)
     100http://www.ietf.org/rfc/rfc1951.txt (for the deflate compressed data format)
    105101.br
    106 http://www.ietf.org/rfc/rfc1952.txt (concerning gzip format)
     102http://www.ietf.org/rfc/rfc1952.txt (for the gzip header and trailer format)
    107103.LP
    108 These documents are also available in other formats from:
    109 .IP
    110 ftp://ftp.uu.net/graphics/png/documents/zlib/zdoc-index.html
    111 .LP
    112 Mark Nelson (markn@ieee.org) wrote an article about
     104Mark Nelson wrote an article about
    113105.I zlib
    114106for the Jan. 1997 issue of  Dr. Dobb's Journal;
    115107a copy of the article is available at:
    116108.IP
    117 http://dogma.net/markn/articles/zlibtool/zlibtool.htm
     109http://marknelson.us/1997/01/01/zlib-engine/
    118110.SH "REPORTING PROBLEMS"
    119111Before reporting a problem,
     
    128120FAQ at:
    129121.IP
    130 http://www.gzip.org/zlib/zlib_faq.html
     122http://zlib.net/zlib_faq.html
    131123.LP
    132124before asking for help.
     
    134126or (for the Windows DLL version) to Gilles Vollant (info@winimage.com).
    135127.SH AUTHORS
    136 Version 1.2.3
    137 Copyright (C) 1995-2005 Jean-loup Gailly (jloup@gzip.org)
     128Version 1.2.4
     129Copyright (C) 1995-2010 Jean-loup Gailly (jloup@gzip.org)
    138130and Mark Adler (madler@alumni.caltech.edu).
    139131.LP
  • cpukit/zlib/zlib.h

    r41ca776f r6121dc77  
    11/* zlib.h -- interface of the 'zlib' general purpose compression library
    2   version 1.2.3, July 18th, 2005
    3 
    4   Copyright (C) 1995-2005 Jean-loup Gailly and Mark Adler
     2  version 1.2.4, Mar 14th, 2010
     3
     4  Copyright (C) 1995-2010 Jean-loup Gailly and Mark Adler
    55
    66  This software is provided 'as-is', without any express or implied
     
    3838#endif
    3939
    40 #define ZLIB_VERSION "1.2.3"
    41 #define ZLIB_VERNUM 0x1230
    42 
    43 /*
    44      The 'zlib' compression library provides in-memory compression and
    45   decompression functions, including integrity checks of the uncompressed
    46   data.  This version of the library supports only one compression method
    47   (deflation) but other algorithms will be added later and will have the same
    48   stream interface.
    49 
    50      Compression can be done in a single step if the buffers are large
    51   enough (for example if an input file is mmap'ed), or can be done by
    52   repeated calls of the compression function.  In the latter case, the
    53   application must provide more input and/or consume the output
     40#define ZLIB_VERSION "1.2.4"
     41#define ZLIB_VERNUM 0x1240
     42#define ZLIB_VER_MAJOR 1
     43#define ZLIB_VER_MINOR 2
     44#define ZLIB_VER_REVISION 4
     45#define ZLIB_VER_SUBREVISION 0
     46
     47/*
     48    The 'zlib' compression library provides in-memory compression and
     49  decompression functions, including integrity checks of the uncompressed data.
     50  This version of the library supports only one compression method (deflation)
     51  but other algorithms will be added later and will have the same stream
     52  interface.
     53
     54    Compression can be done in a single step if the buffers are large enough,
     55  or can be done by repeated calls of the compression function.  In the latter
     56  case, the application must provide more input and/or consume the output
    5457  (providing more output space) before each call.
    5558
    56      The compressed data format used by default by the in-memory functions is
     59    The compressed data format used by default by the in-memory functions is
    5760  the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped
    5861  around a deflate stream, which is itself documented in RFC 1951.
    5962
    60      The library also supports reading and writing files in gzip (.gz) format
     63    The library also supports reading and writing files in gzip (.gz) format
    6164  with an interface similar to that of stdio using the functions that start
    6265  with "gz".  The gzip format is different from the zlib format.  gzip is a
    6366  gzip wrapper, documented in RFC 1952, wrapped around a deflate stream.
    6467
    65      This library can optionally read and write gzip streams in memory as well.
    66 
    67      The zlib format was designed to be compact and fast for use in memory
     68    This library can optionally read and write gzip streams in memory as well.
     69
     70    The zlib format was designed to be compact and fast for use in memory
    6871  and on communications channels.  The gzip format was designed for single-
    6972  file compression on file systems, has a larger header than zlib to maintain
    7073  directory information, and uses a different, slower check method than zlib.
    7174
    72      The library does not install any signal handler. The decoder checks
    73   the consistency of the compressed data, so the library should never
    74   crash even in case of corrupted input.
     75    The library does not install any signal handler. The decoder checks
     76  the consistency of the compressed data, so the library should never crash
     77  even in case of corrupted input.
    7578*/
    7679
     
    127130
    128131/*
    129    The application must update next_in and avail_in when avail_in has
    130    dropped to zero. It must update next_out and avail_out when avail_out
    131    has dropped to zero. The application must initialize zalloc, zfree and
    132    opaque before calling the init function. All other fields are set by the
    133    compression library and must not be updated by the application.
    134 
    135    The opaque value provided by the application will be passed as the first
    136    parameter for calls of zalloc and zfree. This can be useful for custom
    137    memory management. The compression library attaches no meaning to the
     132     The application must update next_in and avail_in when avail_in has dropped
     133   to zero.  It must update next_out and avail_out when avail_out has dropped
     134   to zero.  The application must initialize zalloc, zfree and opaque before
     135   calling the init function.  All other fields are set by the compression
     136   library and must not be updated by the application.
     137
     138     The opaque value provided by the application will be passed as the first
     139   parameter for calls of zalloc and zfree.  This can be useful for custom
     140   memory management.  The compression library attaches no meaning to the
    138141   opaque value.
    139142
    140    zalloc must return Z_NULL if there is not enough memory for the object.
     143     zalloc must return Z_NULL if there is not enough memory for the object.
    141144   If zlib is used in a multi-threaded application, zalloc and zfree must be
    142145   thread safe.
    143146
    144    On 16-bit systems, the functions zalloc and zfree must be able to allocate
    145    exactly 65536 bytes, but will not be required to allocate more than this
    146    if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS,
    147    pointers returned by zalloc for objects of exactly 65536 bytes *must*
    148    have their offset normalized to zero. The default allocation function
    149    provided by this library ensures this (see zutil.c). To reduce memory
    150    requirements and avoid any allocation of 64K objects, at the expense of
    151    compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h).
    152 
    153    The fields total_in and total_out can be used for statistics or
    154    progress reports. After compression, total_in holds the total size of
    155    the uncompressed data and may be saved for use in the decompressor
    156    (particularly if the decompressor wants to decompress everything in
    157    a single step).
     147     On 16-bit systems, the functions zalloc and zfree must be able to allocate
     148   exactly 65536 bytes, but will not be required to allocate more than this if
     149   the symbol MAXSEG_64K is defined (see zconf.h).  WARNING: On MSDOS, pointers
     150   returned by zalloc for objects of exactly 65536 bytes *must* have their
     151   offset normalized to zero.  The default allocation function provided by this
     152   library ensures this (see zutil.c).  To reduce memory requirements and avoid
     153   any allocation of 64K objects, at the expense of compression ratio, compile
     154   the library with -DMAX_WBITS=14 (see zconf.h).
     155
     156     The fields total_in and total_out can be used for statistics or progress
     157   reports.  After compression, total_in holds the total size of the
     158   uncompressed data and may be saved for use in the decompressor (particularly
     159   if the decompressor wants to decompress everything in a single step).
    158160*/
    159161
     
    161163
    162164#define Z_NO_FLUSH      0
    163 #define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
     165#define Z_PARTIAL_FLUSH 1
    164166#define Z_SYNC_FLUSH    2
    165167#define Z_FULL_FLUSH    3
    166168#define Z_FINISH        4
    167169#define Z_BLOCK         5
     170#define Z_TREES         6
    168171/* Allowed flush values; see deflate() and inflate() below for details */
    169172
     
    177180#define Z_BUF_ERROR    (-5)
    178181#define Z_VERSION_ERROR (-6)
    179 /* Return codes for the compression/decompression functions. Negative
    180  * values are errors, positive values are used for special but normal events.
     182/* Return codes for the compression/decompression functions. Negative values
     183 * are errors, positive values are used for special but normal events.
    181184 */
    182185
     
    208211/* for compatibility with versions < 1.0.2 */
    209212
     213
    210214                        /* basic functions */
    211215
    212216ZEXTERN const char * ZEXPORT zlibVersion OF((void));
    213217/* The application can compare zlibVersion and ZLIB_VERSION for consistency.
    214    If the first character differs, the library code actually used is
    215    not compatible with the zlib.h header file used by the application.
    216    This check is automatically made by deflateInit and inflateInit.
     218   If the first character differs, the library code actually used is not
     219   compatible with the zlib.h header file used by the application.  This check
     220   is automatically made by deflateInit and inflateInit.
    217221 */
    218222
     
    220224ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level));
    221225
    222      Initializes the internal stream state for compression. The fields
    223    zalloc, zfree and opaque must be initialized before by the caller.
    224    If zalloc and zfree are set to Z_NULL, deflateInit updates them to
    225    use default allocation functions.
     226     Initializes the internal stream state for compression.  The fields
     227   zalloc, zfree and opaque must be initialized before by the caller.  If
     228   zalloc and zfree are set to Z_NULL, deflateInit updates them to use default
     229   allocation functions.
    226230
    227231     The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
    228    1 gives best speed, 9 gives best compression, 0 gives no compression at
    229    all (the input data is simply copied a block at a time).
    230    Z_DEFAULT_COMPRESSION requests a default compromise between speed and
    231    compression (currently equivalent to level 6).
    232 
    233      deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
    234    enough memory, Z_STREAM_ERROR if level is not a valid compression level,
     232   1 gives best speed, 9 gives best compression, 0 gives no compression at all
     233   (the input data is simply copied a block at a time).  Z_DEFAULT_COMPRESSION
     234   requests a default compromise between speed and compression (currently
     235   equivalent to level 6).
     236
     237     deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough
     238   memory, Z_STREAM_ERROR if level is not a valid compression level, or
    235239   Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible
    236    with the version assumed by the caller (ZLIB_VERSION).
    237    msg is set to null if there is no error message.  deflateInit does not
    238    perform any compression: this will be done by deflate().
     240   with the version assumed by the caller (ZLIB_VERSION).  msg is set to null
     241   if there is no error message.  deflateInit does not perform any compression:
     242   this will be done by deflate().
    239243*/
    240244
     
    243247/*
    244248    deflate compresses as much data as possible, and stops when the input
    245   buffer becomes empty or the output buffer becomes full. It may introduce some
    246   output latency (reading input without producing any output) except when
     249  buffer becomes empty or the output buffer becomes full.  It may introduce
     250  some output latency (reading input without producing any output) except when
    247251  forced to flush.
    248252
    249     The detailed semantics are as follows. deflate performs one or both of the
     253    The detailed semantics are as follows.  deflate performs one or both of the
    250254  following actions:
    251255
    252256  - Compress more input starting at next_in and update next_in and avail_in
    253     accordingly. If not all input can be processed (because there is not
     257    accordingly.  If not all input can be processed (because there is not
    254258    enough room in the output buffer), next_in and avail_in are updated and
    255259    processing will resume at this point for the next call of deflate().
    256260
    257261  - Provide more output starting at next_out and update next_out and avail_out
    258     accordingly. This action is forced if the parameter flush is non zero.
     262    accordingly.  This action is forced if the parameter flush is non zero.
    259263    Forcing flush frequently degrades the compression ratio, so this parameter
    260     should be set only when necessary (in interactive applications).
    261     Some output may be provided even if flush is not set.
    262 
    263   Before the call of deflate(), the application should ensure that at least
    264   one of the actions is possible, by providing more input and/or consuming
    265   more output, and updating avail_in or avail_out accordingly; avail_out
    266   should never be zero before the call. The application can consume the
    267   compressed output when it wants, for example when the output buffer is full
    268   (avail_out == 0), or after each call of deflate(). If deflate returns Z_OK
    269   and with zero avail_out, it must be called again after making room in the
    270   output buffer because there might be more output pending.
     264    should be set only when necessary (in interactive applications).  Some
     265    output may be provided even if flush is not set.
     266
     267    Before the call of deflate(), the application should ensure that at least
     268  one of the actions is possible, by providing more input and/or consuming more
     269  output, and updating avail_in or avail_out accordingly; avail_out should
     270  never be zero before the call.  The application can consume the compressed
     271  output when it wants, for example when the output buffer is full (avail_out
     272  == 0), or after each call of deflate().  If deflate returns Z_OK and with
     273  zero avail_out, it must be called again after making room in the output
     274  buffer because there might be more output pending.
    271275
    272276    Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to
    273   decide how much data to accumualte before producing output, in order to
     277  decide how much data to accumulate before producing output, in order to
    274278  maximize compression.
    275279
    276280    If the parameter flush is set to Z_SYNC_FLUSH, all pending output is
    277281  flushed to the output buffer and the output is aligned on a byte boundary, so
    278   that the decompressor can get all input data available so far. (In particular
    279   avail_in is zero after the call if enough output space has been provided
    280   before the call.)  Flushing may degrade compression for some compression
    281   algorithms and so it should be used only when necessary.
     282  that the decompressor can get all input data available so far.  (In
     283  particular avail_in is zero after the call if enough output space has been
     284  provided before the call.) Flushing may degrade compression for some
     285  compression algorithms and so it should be used only when necessary.  This
     286  completes the current deflate block and follows it with an empty stored block
     287  that is three bits plus filler bits to the next byte, followed by four bytes
     288  (00 00 ff ff).
     289
     290    If flush is set to Z_PARTIAL_FLUSH, all pending output is flushed to the
     291  output buffer, but the output is not aligned to a byte boundary.  All of the
     292  input data so far will be available to the decompressor, as for Z_SYNC_FLUSH.
     293  This completes the current deflate block and follows it with an empty fixed
     294  codes block that is 10 bits long.  This assures that enough bytes are output
     295  in order for the decompressor to finish the block before the empty fixed code
     296  block.
     297
     298    If flush is set to Z_BLOCK, a deflate block is completed and emitted, as
     299  for Z_SYNC_FLUSH, but the output is not aligned on a byte boundary, and up to
     300  seven bits of the current block are held to be written as the next byte after
     301  the next deflate block is completed.  In this case, the decompressor may not
     302  be provided enough bits at this point in order to complete decompression of
     303  the data provided so far to the compressor.  It may need to wait for the next
     304  block to be emitted.  This is for advanced applications that need to control
     305  the emission of deflate blocks.
    282306
    283307    If flush is set to Z_FULL_FLUSH, all output is flushed as with
    284308  Z_SYNC_FLUSH, and the compression state is reset so that decompression can
    285309  restart from this point if previous compressed data has been damaged or if
    286   random access is desired. Using Z_FULL_FLUSH too often can seriously degrade
     310  random access is desired.  Using Z_FULL_FLUSH too often can seriously degrade
    287311  compression.
    288312
     
    290314  with the same value of the flush parameter and more output space (updated
    291315  avail_out), until the flush is complete (deflate returns with non-zero
    292   avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that
     316  avail_out).  In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that
    293317  avail_out is greater than six to avoid repeated flush markers due to
    294318  avail_out == 0 on return.
    295319
    296320    If the parameter flush is set to Z_FINISH, pending input is processed,
    297   pending output is flushed and deflate returns with Z_STREAM_END if there
    298   was enough output space; if deflate returns with Z_OK, this function must be
     321  pending output is flushed and deflate returns with Z_STREAM_END if there was
     322  enough output space; if deflate returns with Z_OK, this function must be
    299323  called again with Z_FINISH and more output space (updated avail_out) but no
    300   more input data, until it returns with Z_STREAM_END or an error. After
    301   deflate has returned Z_STREAM_END, the only possible operations on the
    302   stream are deflateReset or deflateEnd.
     324  more input data, until it returns with Z_STREAM_END or an error.  After
     325  deflate has returned Z_STREAM_END, the only possible operations on the stream
     326  are deflateReset or deflateEnd.
    303327
    304328    Z_FINISH can be used immediately after deflateInit if all the compression
    305   is to be done in a single step. In this case, avail_out must be at least
    306   the value returned by deflateBound (see below). If deflate does not return
     329  is to be done in a single step.  In this case, avail_out must be at least the
     330  value returned by deflateBound (see below). If deflate does not return
    307331  Z_STREAM_END, then it must be called again as described above.
    308332
     
    311335
    312336    deflate() may update strm->data_type if it can make a good guess about
    313   the input data type (Z_BINARY or Z_TEXT). In doubt, the data is considered
    314   binary. This field is only for information purposes and does not affect
    315   the compression algorithm in any manner.
     337  the input data type (Z_BINARY or Z_TEXT).  In doubt, the data is considered
     338  binary.  This field is only for information purposes and does not affect the
     339  compression algorithm in any manner.
    316340
    317341    deflate() returns Z_OK if some progress has been made (more input
     
    319343  consumed and all output has been produced (only when flush is set to
    320344  Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example
    321   if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible
    322   (for example avail_in or avail_out was zero). Note that Z_BUF_ERROR is not
     345  if next_in or next_out was Z_NULL), Z_BUF_ERROR if no progress is possible
     346  (for example avail_in or avail_out was zero).  Note that Z_BUF_ERROR is not
    323347  fatal, and deflate() can be called again with more input and more output
    324348  space to continue compressing.
     
    329353/*
    330354     All dynamically allocated data structures for this stream are freed.
    331    This function discards any unprocessed input and does not flush any
    332    pending output.
     355   This function discards any unprocessed input and does not flush any pending
     356   output.
    333357
    334358     deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the
    335359   stream state was inconsistent, Z_DATA_ERROR if the stream was freed
    336    prematurely (some input or output was discarded). In the error case,
    337    msg may be set but then points to a static string (which must not be
     360   prematurely (some input or output was discarded).  In the error case, msg
     361   may be set but then points to a static string (which must not be
    338362   deallocated).
    339363*/
     
    343367ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm));
    344368
    345      Initializes the internal stream state for decompression. The fields
     369     Initializes the internal stream state for decompression.  The fields
    346370   next_in, avail_in, zalloc, zfree and opaque must be initialized before by
    347    the caller. If next_in is not Z_NULL and avail_in is large enough (the exact
    348    value depends on the compression method), inflateInit determines the
     371   the caller.  If next_in is not Z_NULL and avail_in is large enough (the
     372   exact value depends on the compression method), inflateInit determines the
    349373   compression method from the zlib header and allocates all data structures
    350374   accordingly; otherwise the allocation will be deferred to the first call of
     
    354378     inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough
    355379   memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
    356    version assumed by the caller.  msg is set to null if there is no error
    357    message. inflateInit does not perform any decompression apart from reading
    358    the zlib header if present: this will be done by inflate().  (So next_in and
    359    avail_in may be modified, but next_out and avail_out are unchanged.)
     380   version assumed by the caller, or Z_STREAM_ERROR if the parameters are
     381   invalid, such as a null pointer to the structure.  msg is set to null if
     382   there is no error message.  inflateInit does not perform any decompression
     383   apart from possibly reading the zlib header if present: actual decompression
     384   will be done by inflate().  (So next_in and avail_in may be modified, but
     385   next_out and avail_out are unused and unchanged.) The current implementation
     386   of inflateInit() does not process any header information -- that is deferred
     387   until inflate() is called.
    360388*/
    361389
     
    364392/*
    365393    inflate decompresses as much data as possible, and stops when the input
    366   buffer becomes empty or the output buffer becomes full. It may introduce
     394  buffer becomes empty or the output buffer becomes full.  It may introduce
    367395  some output latency (reading input without producing any output) except when
    368396  forced to flush.
    369397
    370   The detailed semantics are as follows. inflate performs one or both of the
     398  The detailed semantics are as follows.  inflate performs one or both of the
    371399  following actions:
    372400
    373401  - Decompress more input starting at next_in and update next_in and avail_in
    374     accordingly. If not all input can be processed (because there is not
    375     enough room in the output buffer), next_in is updated and processing
    376     will resume at this point for the next call of inflate().
     402    accordingly.  If not all input can be processed (because there is not
     403    enough room in the output buffer), next_in is updated and processing will
     404    resume at this point for the next call of inflate().
    377405
    378406  - Provide more output starting at next_out and update next_out and avail_out
    379     accordingly.  inflate() provides as much output as possible, until there
    380     is no more input data or no more space in the output buffer (see below
    381     about the flush parameter).
    382 
    383   Before the call of inflate(), the application should ensure that at least
    384   one of the actions is possible, by providing more input and/or consuming
    385   more output, and updating the next_* and avail_* values accordingly.
    386   The application can consume the uncompressed output when it wants, for
    387   example when the output buffer is full (avail_out == 0), or after each
    388   call of inflate(). If inflate returns Z_OK and with zero avail_out, it
    389   must be called again after making room in the output buffer because there
    390   might be more output pending.
    391 
    392     The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH,
    393   Z_FINISH, or Z_BLOCK. Z_SYNC_FLUSH requests that inflate() flush as much
    394   output as possible to the output buffer. Z_BLOCK requests that inflate() stop
    395   if and when it gets to the next deflate block boundary. When decoding the
    396   zlib or gzip format, this will cause inflate() to return immediately after
    397   the header and before the first block. When doing a raw inflate, inflate()
    398   will go ahead and process the first block, and will return when it gets to
    399   the end of that block, or when it runs out of data.
     407    accordingly.  inflate() provides as much output as possible, until there is
     408    no more input data or no more space in the output buffer (see below about
     409    the flush parameter).
     410
     411    Before the call of inflate(), the application should ensure that at least
     412  one of the actions is possible, by providing more input and/or consuming more
     413  output, and updating the next_* and avail_* values accordingly.  The
     414  application can consume the uncompressed output when it wants, for example
     415  when the output buffer is full (avail_out == 0), or after each call of
     416  inflate().  If inflate returns Z_OK and with zero avail_out, it must be
     417  called again after making room in the output buffer because there might be
     418  more output pending.
     419
     420    The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH, Z_FINISH,
     421  Z_BLOCK, or Z_TREES. Z_SYNC_FLUSH requests that inflate() flush as much
     422  output as possible to the output buffer.  Z_BLOCK requests that inflate()
     423  stop if and when it gets to the next deflate block boundary.  When decoding
     424  the zlib or gzip format, this will cause inflate() to return immediately
     425  after the header and before the first block.  When doing a raw inflate,
     426  inflate() will go ahead and process the first block, and will return when it
     427  gets to the end of that block, or when it runs out of data.
    400428
    401429    The Z_BLOCK option assists in appending to or combining deflate streams.
    402430  Also to assist in this, on return inflate() will set strm->data_type to the
    403   number of unused bits in the last byte taken from strm->next_in, plus 64
    404   if inflate() is currently decoding the last block in the deflate stream,
    405   plus 128 if inflate() returned immediately after decoding an end-of-block
    406   code or decoding the complete header up to just before the first byte of the
    407   deflate stream. The end-of-block will not be indicated until all of the
    408   uncompressed data from that block has been written to strm->next_out.  The
    409   number of unused bits may in general be greater than seven, except when
    410   bit 7 of data_type is set, in which case the number of unused bits will be
    411   less than eight.
     431  number of unused bits in the last byte taken from strm->next_in, plus 64 if
     432  inflate() is currently decoding the last block in the deflate stream, plus
     433  128 if inflate() returned immediately after decoding an end-of-block code or
     434  decoding the complete header up to just before the first byte of the deflate
     435  stream.  The end-of-block will not be indicated until all of the uncompressed
     436  data from that block has been written to strm->next_out.  The number of
     437  unused bits may in general be greater than seven, except when bit 7 of
     438  data_type is set, in which case the number of unused bits will be less than
     439  eight.  data_type is set as noted here every time inflate() returns for all
     440  flush options, and so can be used to determine the amount of currently
     441  consumed input in bits.
     442
     443    The Z_TREES option behaves as Z_BLOCK does, but it also returns when the
     444  end of each deflate block header is reached, before any actual data in that
     445  block is decoded.  This allows the caller to determine the length of the
     446  deflate block header for later use in random access within a deflate block.
     447  256 is added to the value of strm->data_type when inflate() returns
     448  immediately after reaching the end of the deflate block header.
    412449
    413450    inflate() should normally be called until it returns Z_STREAM_END or an
    414   error. However if all decompression is to be performed in a single step
    415   (a single call of inflate), the parameter flush should be set to
    416   Z_FINISH. In this case all pending input is processed and all pending
    417   output is flushed; avail_out must be large enough to hold all the
    418   uncompressed data. (The size of the uncompressed data may have been saved
    419   by the compressor for this purpose.) The next operation on this stream must
    420   be inflateEnd to deallocate the decompression state. The use of Z_FINISH
    421   is never required, but can be used to inform inflate that a faster approach
    422   may be used for the single inflate() call.
     451  error.  However if all decompression is to be performed in a single step (a
     452  single call of inflate), the parameter flush should be set to Z_FINISH.  In
     453  this case all pending input is processed and all pending output is flushed;
     454  avail_out must be large enough to hold all the uncompressed data.  (The size
     455  of the uncompressed data may have been saved by the compressor for this
     456  purpose.) The next operation on this stream must be inflateEnd to deallocate
     457  the decompression state.  The use of Z_FINISH is never required, but can be
     458  used to inform inflate that a faster approach may be used for the single
     459  inflate() call.
    423460
    424461     In this implementation, inflate() always flushes as much output as
    425462  possible to the output buffer, and always uses the faster approach on the
    426   first call. So the only effect of the flush parameter in this implementation
     463  first call.  So the only effect of the flush parameter in this implementation
    427464  is on the return value of inflate(), as noted below, or when it returns early
    428   because Z_BLOCK is used.
     465  because Z_BLOCK or Z_TREES is used.
    429466
    430467     If a preset dictionary is needed after this call (see inflateSetDictionary
     
    433470  strm->adler to the adler32 checksum of all output produced so far (that is,
    434471  total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described
    435   below. At the end of the stream, inflate() checks that its computed adler32
     472  below.  At the end of the stream, inflate() checks that its computed adler32
    436473  checksum is equal to that saved by the compressor and returns Z_STREAM_END
    437474  only if the checksum is correct.
    438475
    439     inflate() will decompress and check either zlib-wrapped or gzip-wrapped
    440   deflate data.  The header type is detected automatically.  Any information
    441   contained in the gzip header is not retained, so applications that need that
    442   information should instead use raw inflate, see inflateInit2() below, or
    443   inflateBack() and perform their own processing of the gzip header and
    444   trailer.
     476    inflate() can decompress and check either zlib-wrapped or gzip-wrapped
     477  deflate data.  The header type is detected automatically, if requested when
     478  initializing with inflateInit2().  Any information contained in the gzip
     479  header is not retained, so applications that need that information should
     480  instead use raw inflate, see inflateInit2() below, or inflateBack() and
     481  perform their own processing of the gzip header and trailer.
    445482
    446483    inflate() returns Z_OK if some progress has been made (more input processed
     
    450487  corrupted (input stream not conforming to the zlib format or incorrect check
    451488  value), Z_STREAM_ERROR if the stream structure was inconsistent (for example
    452   if next_in or next_out was NULL), Z_MEM_ERROR if there was not enough memory,
     489  next_in or next_out was Z_NULL), Z_MEM_ERROR if there was not enough memory,
    453490  Z_BUF_ERROR if no progress is possible or if there was not enough room in the
    454   output buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and
     491  output buffer when Z_FINISH is used.  Note that Z_BUF_ERROR is not fatal, and
    455492  inflate() can be called again with more input and more output space to
    456   continue decompressing. If Z_DATA_ERROR is returned, the application may then
    457   call inflateSync() to look for a good compression block if a partial recovery
    458   of the data is desired.
     493  continue decompressing.  If Z_DATA_ERROR is returned, the application may
     494  then call inflateSync() to look for a good compression block if a partial
     495  recovery of the data is desired.
    459496*/
    460497
     
    463500/*
    464501     All dynamically allocated data structures for this stream are freed.
    465    This function discards any unprocessed input and does not flush any
    466    pending output.
     502   This function discards any unprocessed input and does not flush any pending
     503   output.
    467504
    468505     inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state
    469    was inconsistent. In the error case, msg may be set but then points to a
     506   was inconsistent.  In the error case, msg may be set but then points to a
    470507   static string (which must not be deallocated).
    471508*/
     509
    472510
    473511                        /* Advanced functions */
     
    485523                                     int  strategy));
    486524
    487      This is another version of deflateInit with more compression options. The
    488    fields next_in, zalloc, zfree and opaque must be initialized before by
    489    the caller.
    490 
    491      The method parameter is the compression method. It must be Z_DEFLATED in
     525     This is another version of deflateInit with more compression options.  The
     526   fields next_in, zalloc, zfree and opaque must be initialized before by the
     527   caller.
     528
     529     The method parameter is the compression method.  It must be Z_DEFLATED in
    492530   this version of the library.
    493531
    494532     The windowBits parameter is the base two logarithm of the window size
    495    (the size of the history buffer). It should be in the range 8..15 for this
    496    version of the library. Larger values of this parameter result in better
    497    compression at the expense of memory usage. The default value is 15 if
     533   (the size of the history buffer).  It should be in the range 8..15 for this
     534   version of the library.  Larger values of this parameter result in better
     535   compression at the expense of memory usage.  The default value is 15 if
    498536   deflateInit is used instead.
    499537
    500      windowBits can also be -8..-15 for raw deflate. In this case, -windowBits
    501    determines the window size. deflate() will then generate raw deflate data
     538     windowBits can also be -8..-15 for raw deflate.  In this case, -windowBits
     539   determines the window size.  deflate() will then generate raw deflate data
    502540   with no zlib header or trailer, and will not compute an adler32 check value.
    503541
    504      windowBits can also be greater than 15 for optional gzip encoding. Add
     542     windowBits can also be greater than 15 for optional gzip encoding.  Add
    505543   16 to windowBits to write a simple gzip header and trailer around the
    506    compressed data instead of a zlib wrapper. The gzip header will have no
    507    file name, no extra data, no comment, no modification time (set to zero),
    508    no header crc, and the operating system will be set to 255 (unknown).  If a
     544   compressed data instead of a zlib wrapper.  The gzip header will have no
     545   file name, no extra data, no comment, no modification time (set to zero), no
     546   header crc, and the operating system will be set to 255 (unknown).  If a
    509547   gzip stream is being written, strm->adler is a crc32 instead of an adler32.
    510548
    511549     The memLevel parameter specifies how much memory should be allocated
    512    for the internal compression state. memLevel=1 uses minimum memory but
    513    is slow and reduces compression ratio; memLevel=9 uses maximum memory
    514    for optimal speed. The default value is 8. See zconf.h for total memory
    515    usage as a function of windowBits and memLevel.
    516 
    517      The strategy parameter is used to tune the compression algorithm. Use the
     550   for the internal compression state.  memLevel=1 uses minimum memory but is
     551   slow and reduces compression ratio; memLevel=9 uses maximum memory for
     552   optimal speed.  The default value is 8.  See zconf.h for total memory usage
     553   as a function of windowBits and memLevel.
     554
     555     The strategy parameter is used to tune the compression algorithm.  Use the
    518556   value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a
    519557   filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no
    520558   string match), or Z_RLE to limit match distances to one (run-length
    521    encoding). Filtered data consists mostly of small values with a somewhat
    522    random distribution. In this case, the compression algorithm is tuned to
    523    compress them better. The effect of Z_FILTERED is to force more Huffman
     559   encoding).  Filtered data consists mostly of small values with a somewhat
     560   random distribution.  In this case, the compression algorithm is tuned to
     561   compress them better.  The effect of Z_FILTERED is to force more Huffman
    524562   coding and less string matching; it is somewhat intermediate between
    525    Z_DEFAULT and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as fast as
    526    Z_HUFFMAN_ONLY, but give better compression for PNG image data. The strategy
    527    parameter only affects the compression ratio but not the correctness of the
    528    compressed output even if it is not set appropriately.  Z_FIXED prevents the
    529    use of dynamic Huffman codes, allowing for a simpler decoder for special
    530    applications.
    531 
    532       deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
    533    memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid
    534    method). msg is set to null if there is no error message.  deflateInit2 does
    535    not perform any compression: this will be done by deflate().
     563   Z_DEFAULT_STRATEGY and Z_HUFFMAN_ONLY.  Z_RLE is designed to be almost as
     564   fast as Z_HUFFMAN_ONLY, but give better compression for PNG image data.  The
     565   strategy parameter only affects the compression ratio but not the
     566   correctness of the compressed output even if it is not set appropriately.
     567   Z_FIXED prevents the use of dynamic Huffman codes, allowing for a simpler
     568   decoder for special applications.
     569
     570     deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
     571   memory, Z_STREAM_ERROR if any parameter is invalid (such as an invalid
     572   method), or Z_VERSION_ERROR if the zlib library version (zlib_version) is
     573   incompatible with the version assumed by the caller (ZLIB_VERSION).  msg is
     574   set to null if there is no error message.  deflateInit2 does not perform any
     575   compression: this will be done by deflate().
    536576*/
    537577
     
    541581/*
    542582     Initializes the compression dictionary from the given byte sequence
    543    without producing any compressed output. This function must be called
    544    immediately after deflateInit, deflateInit2 or deflateReset, before any
    545    call of deflate. The compressor and decompressor must use exactly the same
     583   without producing any compressed output.  This function must be called
     584   immediately after deflateInit, deflateInit2 or deflateReset, before any call
     585   of deflate. The compressor and decompressor must use exactly the same
    546586   dictionary (see inflateSetDictionary).
    547587
    548588     The dictionary should consist of strings (byte sequences) that are likely
    549589   to be encountered later in the data to be compressed, with the most commonly
    550    used strings preferably put towards the end of the dictionary. Using a
     590   used strings preferably put towards the end of the dictionary.  Using a
    551591   dictionary is most useful when the data to be compressed is short and can be
    552592   predicted with good accuracy; the data can then be compressed better than
     
    555595     Depending on the size of the compression data structures selected by
    556596   deflateInit or deflateInit2, a part of the dictionary may in effect be
    557    discarded, for example if the dictionary is larger than the window size in
    558    deflate or deflate2. Thus the strings most likely to be useful should be
    559    put at the end of the dictionary, not at the front. In addition, the
    560    current implementation of deflate will use at most the window size minus
    561    262 bytes of the provided dictionary.
     597   discarded, for example if the dictionary is larger than the window size
     598   provided in deflateInit or deflateInit2.  Thus the strings most likely to be
     599   useful should be put at the end of the dictionary, not at the front.  In
     600   addition, the current implementation of deflate will use at most the window
     601   size minus 262 bytes of the provided dictionary.
    562602
    563603     Upon return of this function, strm->adler is set to the adler32 value
    564604   of the dictionary; the decompressor may later use this value to determine
    565    which dictionary has been used by the compressor. (The adler32 value
     605   which dictionary has been used by the compressor.  (The adler32 value
    566606   applies to the whole dictionary even if only a subset of the dictionary is
    567607   actually used by the compressor.) If a raw deflate was requested, then the
     
    569609
    570610     deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a
    571    parameter is invalid (such as NULL dictionary) or the stream state is
     611   parameter is invalid (e.g.  dictionary being Z_NULL) or the stream state is
    572612   inconsistent (for example if deflate has already been called for this stream
    573    or if the compression method is bsort). deflateSetDictionary does not
     613   or if the compression method is bsort).  deflateSetDictionary does not
    574614   perform any compression: this will be done by deflate().
    575615*/
     
    582622     This function can be useful when several compression strategies will be
    583623   tried, for example when there are several ways of pre-processing the input
    584    data with a filter. The streams that will be discarded should then be freed
     624   data with a filter.  The streams that will be discarded should then be freed
    585625   by calling deflateEnd.  Note that deflateCopy duplicates the internal
    586    compression state which can be quite large, so this strategy is slow and
    587    can consume lots of memory.
     626   compression state which can be quite large, so this strategy is slow and can
     627   consume lots of memory.
    588628
    589629     deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
    590630   enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
    591    (such as zalloc being NULL). msg is left unchanged in both source and
     631   (such as zalloc being Z_NULL). msg is left unchanged in both source and
    592632   destination.
    593633*/
     
    596636/*
    597637     This function is equivalent to deflateEnd followed by deflateInit,
    598    but does not free and reallocate all the internal compression state.
    599    The stream will keep the same compression level and any other attributes
    600    that may have been set by deflateInit2.
    601 
    602       deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
    603    stream state was inconsistent (such as zalloc or state being NULL).
     638   but does not free and reallocate all the internal compression state.  The
     639   stream will keep the same compression level and any other attributes that
     640   may have been set by deflateInit2.
     641
     642     deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
     643   stream state was inconsistent (such as zalloc or state being Z_NULL).
    604644*/
    605645
     
    611651   interpretation of level and strategy is as in deflateInit2.  This can be
    612652   used to switch between compression and straight copy of the input data, or
    613    to switch to a different kind of input data requiring a different
    614    strategy. If the compression level is changed, the input available so far
    615    is compressed with the old level (and may be flushed); the new level will
    616    take effect only at the next call of deflate().
     653   to switch to a different kind of input data requiring a different strategy.
     654   If the compression level is changed, the input available so far is
     655   compressed with the old level (and may be flushed); the new level will take
     656   effect only at the next call of deflate().
    617657
    618658     Before the call of deflateParams, the stream state must be set as for
    619    a call of deflate(), since the currently available input may have to
    620    be compressed and flushed. In particular, strm->avail_out must be non-zero.
     659   a call of deflate(), since the currently available input may have to be
     660   compressed and flushed. In particular, strm->avail_out must be non-zero.
    621661
    622662     deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source
    623    stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR
    624    if strm->avail_out was zero.
     663   stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR if
     664   strm->avail_out was zero.
    625665*/
    626666
     
    646686/*
    647687     deflateBound() returns an upper bound on the compressed size after
    648    deflation of sourceLen bytes.  It must be called after deflateInit()
    649    or deflateInit2().  This would be used to allocate an output buffer
    650    for deflation in a single pass, and so would be called before deflate().
     688   deflation of sourceLen bytes.  It must be called after deflateInit() or
     689   deflateInit2(), and after deflateSetHeader(), if used.  This would be used
     690   to allocate an output buffer for deflation in a single pass, and so would be
     691   called before deflate().
    651692*/
    652693
     
    656697/*
    657698     deflatePrime() inserts bits in the deflate output stream.  The intent
    658   is that this function is used to start off the deflate output with the
    659   bits leftover from a previous deflate stream when appending to it.  As such,
    660   this function can only be used for raw deflate, and must be used before the
    661   first deflate() call after a deflateInit2() or deflateReset().  bits must be
    662   less than or equal to 16, and that many of the least significant bits of
    663   value will be inserted in the output.
    664 
    665       deflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source
     699   is that this function is used to start off the deflate output with the bits
     700   leftover from a previous deflate stream when appending to it.  As such, this
     701   function can only be used for raw deflate, and must be used before the first
     702   deflate() call after a deflateInit2() or deflateReset().  bits must be less
     703   than or equal to 16, and that many of the least significant bits of value
     704  will be inserted in the output.
     705
     706     deflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source
    666707   stream state was inconsistent.
    667708*/
     
    670711                                         gz_headerp head));
    671712/*
    672       deflateSetHeader() provides gzip header information for when a gzip
     713     deflateSetHeader() provides gzip header information for when a gzip
    673714   stream is requested by deflateInit2().  deflateSetHeader() may be called
    674715   after deflateInit2() or deflateReset() and before the first call of
     
    683724   gzip file" and give up.
    684725
    685       If deflateSetHeader is not used, the default gzip header has text false,
     726     If deflateSetHeader is not used, the default gzip header has text false,
    686727   the time set to zero, and os set to 255, with no extra, name, or comment
    687728   fields.  The gzip header is returned to the default state by deflateReset().
    688729
    689       deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source
     730     deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source
    690731   stream state was inconsistent.
    691732*/
     
    695736                                     int  windowBits));
    696737
    697      This is another version of inflateInit with an extra parameter. The
     738     This is another version of inflateInit with an extra parameter.  The
    698739   fields next_in, avail_in, zalloc, zfree and opaque must be initialized
    699740   before by the caller.
     
    701742     The windowBits parameter is the base two logarithm of the maximum window
    702743   size (the size of the history buffer).  It should be in the range 8..15 for
    703    this version of the library. The default value is 15 if inflateInit is used
    704    instead. windowBits must be greater than or equal to the windowBits value
     744   this version of the library.  The default value is 15 if inflateInit is used
     745   instead.  windowBits must be greater than or equal to the windowBits value
    705746   provided to deflateInit2() while compressing, or it must be equal to 15 if
    706    deflateInit2() was not used. If a compressed stream with a larger window
     747   deflateInit2() was not used.  If a compressed stream with a larger window
    707748   size is given as input, inflate() will return with the error code
    708749   Z_DATA_ERROR instead of trying to allocate a larger window.
    709750
    710      windowBits can also be -8..-15 for raw inflate. In this case, -windowBits
    711    determines the window size. inflate() will then process raw deflate data,
     751     windowBits can also be zero to request that inflate use the window size in
     752   the zlib header of the compressed stream.
     753
     754     windowBits can also be -8..-15 for raw inflate.  In this case, -windowBits
     755   determines the window size.  inflate() will then process raw deflate data,
    712756   not looking for a zlib or gzip header, not generating a check value, and not
    713    looking for any check values for comparison at the end of the stream. This
     757   looking for any check values for comparison at the end of the stream.  This
    714758   is for use with other formats that use the deflate compressed data format
    715    such as zip.  Those formats provide their own check values. If a custom
     759   such as zip.  Those formats provide their own check values.  If a custom
    716760   format is developed using the raw deflate format for compressed data, it is
    717761   recommended that a check value such as an adler32 or a crc32 be applied to
    718762   the uncompressed data as is done in the zlib, gzip, and zip formats.  For
    719    most applications, the zlib format should be used as is. Note that comments
     763   most applications, the zlib format should be used as is.  Note that comments
    720764   above on the use in deflateInit2() applies to the magnitude of windowBits.
    721765
    722      windowBits can also be greater than 15 for optional gzip decoding. Add
     766     windowBits can also be greater than 15 for optional gzip decoding.  Add
    723767   32 to windowBits to enable zlib and gzip decoding with automatic header
    724768   detection, or add 16 to decode only the gzip format (the zlib format will
    725    return a Z_DATA_ERROR).  If a gzip stream is being decoded, strm->adler is
    726    a crc32 instead of an adler32.
     769   return a Z_DATA_ERROR).  If a gzip stream is being decoded, strm->adler is a
     770   crc32 instead of an adler32.
    727771
    728772     inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
    729    memory, Z_STREAM_ERROR if a parameter is invalid (such as a null strm). msg
    730    is set to null if there is no error message.  inflateInit2 does not perform
    731    any decompression apart from reading the zlib header if present: this will
    732    be done by inflate(). (So next_in and avail_in may be modified, but next_out
    733    and avail_out are unchanged.)
     773   memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
     774   version assumed by the caller, or Z_STREAM_ERROR if the parameters are
     775   invalid, such as a null pointer to the structure.  msg is set to null if
     776   there is no error message.  inflateInit2 does not perform any decompression
     777   apart from possibly reading the zlib header if present: actual decompression
     778   will be done by inflate().  (So next_in and avail_in may be modified, but
     779   next_out and avail_out are unused and unchanged.) The current implementation
     780   of inflateInit2() does not process any header information -- that is
     781   deferred until inflate() is called.
    734782*/
    735783
     
    739787/*
    740788     Initializes the decompression dictionary from the given uncompressed byte
    741    sequence. This function must be called immediately after a call of inflate,
    742    if that call returned Z_NEED_DICT. The dictionary chosen by the compressor
     789   sequence.  This function must be called immediately after a call of inflate,
     790   if that call returned Z_NEED_DICT.  The dictionary chosen by the compressor
    743791   can be determined from the adler32 value returned by that call of inflate.
    744792   The compressor and decompressor must use exactly the same dictionary (see
     
    749797
    750798     inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
    751    parameter is invalid (such as NULL dictionary) or the stream state is
     799   parameter is invalid (e.g.  dictionary being Z_NULL) or the stream state is
    752800   inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the
    753    expected one (incorrect adler32 value). inflateSetDictionary does not
     801   expected one (incorrect adler32 value).  inflateSetDictionary does not
    754802   perform any decompression: this will be done by subsequent calls of
    755803   inflate().
     
    758806ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
    759807/*
    760     Skips invalid compressed data until a full flush point (see above the
    761   description of deflate with Z_FULL_FLUSH) can be found, or until all
    762   available input is skipped. No output is provided.
    763 
    764     inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR
    765   if no more input was provided, Z_DATA_ERROR if no flush point has been found,
    766   or Z_STREAM_ERROR if the stream structure was inconsistent. In the success
    767   case, the application may save the current current value of total_in which
    768   indicates where valid compressed data was found. In the error case, the
    769   application may repeatedly call inflateSync, providing more input each time,
    770   until success or end of the input data.
     808     Skips invalid compressed data until a full flush point (see above the
     809   description of deflate with Z_FULL_FLUSH) can be found, or until all
     810   available input is skipped. No output is provided.
     811
     812     inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR
     813   if no more input was provided, Z_DATA_ERROR if no flush point has been
     814   found, or Z_STREAM_ERROR if the stream structure was inconsistent.  In the
     815   success case, the application may save the current current value of total_in
     816   which indicates where valid compressed data was found.  In the error case,
     817   the application may repeatedly call inflateSync, providing more input each
     818   time, until success or end of the input data.
    771819*/
    772820
     
    783831     inflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
    784832   enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
    785    (such as zalloc being NULL). msg is left unchanged in both source and
     833   (such as zalloc being Z_NULL). msg is left unchanged in both source and
    786834   destination.
    787835*/
     
    790838/*
    791839     This function is equivalent to inflateEnd followed by inflateInit,
    792    but does not free and reallocate all the internal decompression state.
    793    The stream will keep attributes that may have been set by inflateInit2.
    794 
    795       inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
    796    stream state was inconsistent (such as zalloc or state being NULL).
     840   but does not free and reallocate all the internal decompression state.  The
     841   stream will keep attributes that may have been set by inflateInit2.
     842
     843     inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
     844   stream state was inconsistent (such as zalloc or state being Z_NULL).
     845*/
     846
     847ZEXTERN int ZEXPORT inflateReset2 OF((z_streamp strm,
     848                                      int windowBits));
     849/*
     850     This function is the same as inflateReset, but it also permits changing
     851   the wrap and window size requests.  The windowBits parameter is interpreted
     852   the same as it is for inflateInit2.
     853
     854     inflateReset2 returns Z_OK if success, or Z_STREAM_ERROR if the source
     855   stream state was inconsistent (such as zalloc or state being Z_NULL), or if
     856   the windowBits parameter is invalid.
    797857*/
    798858
     
    802862/*
    803863     This function inserts bits in the inflate input stream.  The intent is
    804   that this function is used to start inflating at a bit position in the
    805   middle of a byte.  The provided bits will be used before any bytes are used
    806   from next_in.  This function should only be used with raw inflate, and
    807   should be used before the first inflate() call after inflateInit2() or
    808   inflateReset().  bits must be less than or equal to 16, and that many of the
    809   least significant bits of value will be inserted in the input.
    810 
    811       inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source
     864   that this function is used to start inflating at a bit position in the
     865   middle of a byte.  The provided bits will be used before any bytes are used
     866   from next_in.  This function should only be used with raw inflate, and
     867   should be used before the first inflate() call after inflateInit2() or
     868   inflateReset().  bits must be less than or equal to 16, and that many of the
     869   least significant bits of value will be inserted in the input.
     870
     871     If bits is negative, then the input stream bit buffer is emptied.  Then
     872   inflatePrime() can be called again to put bits in the buffer.  This is used
     873   to clear out bits leftover after feeding inflate a block description prior
     874   to feeding inflate codes.
     875
     876     inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source
    812877   stream state was inconsistent.
     878*/
     879
     880ZEXTERN long ZEXPORT inflateMark OF((z_streamp strm));
     881/*
     882     This function returns two values, one in the lower 16 bits of the return
     883   value, and the other in the remaining upper bits, obtained by shifting the
     884   return value down 16 bits.  If the upper value is -1 and the lower value is
     885   zero, then inflate() is currently decoding information outside of a block.
     886   If the upper value is -1 and the lower value is non-zero, then inflate is in
     887   the middle of a stored block, with the lower value equaling the number of
     888   bytes from the input remaining to copy.  If the upper value is not -1, then
     889   it is the number of bits back from the current bit position in the input of
     890   the code (literal or length/distance pair) currently being processed.  In
     891   that case the lower value is the number of bytes already emitted for that
     892   code.
     893
     894     A code is being processed if inflate is waiting for more input to complete
     895   decoding of the code, or if it has completed decoding but is waiting for
     896   more output space to write the literal or match data.
     897
     898     inflateMark() is used to mark locations in the input data for random
     899   access, which may be at bit positions, and to note those cases where the
     900   output of a code may span boundaries of random access blocks.  The current
     901   location in the input stream can be determined from avail_in and data_type
     902   as noted in the description for the Z_BLOCK flush parameter for inflate.
     903
     904     inflateMark returns the value noted above or -1 << 16 if the provided
     905   source stream state was inconsistent.
    813906*/
    814907
     
    816909                                         gz_headerp head));
    817910/*
    818       inflateGetHeader() requests that gzip header information be stored in the
     911     inflateGetHeader() requests that gzip header information be stored in the
    819912   provided gz_header structure.  inflateGetHeader() may be called after
    820913   inflateInit2() or inflateReset(), and before the first call of inflate().
     
    822915   is completed, at which time head->done is set to one.  If a zlib stream is
    823916   being decoded, then head->done is set to -1 to indicate that there will be
    824    no gzip header information forthcoming.  Note that Z_BLOCK can be used to
    825    force inflate() to return immediately after header processing is complete
    826    and before any actual data is decompressed.
    827 
    828       The text, time, xflags, and os fields are filled in with the gzip header
     917   no gzip header information forthcoming.  Note that Z_BLOCK or Z_TREES can be
     918   used to force inflate() to return immediately after header processing is
     919   complete and before any actual data is decompressed.
     920
     921     The text, time, xflags, and os fields are filled in with the gzip header
    829922   contents.  hcrc is set to true if there is a header CRC.  (The header CRC
    830    was valid if done is set to one.)  If extra is not Z_NULL, then extra_max
     923   was valid if done is set to one.) If extra is not Z_NULL, then extra_max
    831924   contains the maximum number of bytes to write to extra.  Once done is true,
    832925   extra_len contains the actual extra field length, and extra contains the
     
    835928   terminated with a zero unless the length is greater than name_max.  If
    836929   comment is not Z_NULL, then up to comm_max characters are written there,
    837    terminated with a zero unless the length is greater than comm_max.  When
    838    any of extra, name, or comment are not Z_NULL and the respective field is
    839    not present in the header, then that field is set to Z_NULL to signal its
     930   terminated with a zero unless the length is greater than comm_max.  When any
     931   of extra, name, or comment are not Z_NULL and the respective field is not
     932   present in the header, then that field is set to Z_NULL to signal its
    840933   absence.  This allows the use of deflateSetHeader() with the returned
    841934   structure to duplicate the header.  However if those fields are set to
     
    843936   elsewhere so that they can be eventually freed.
    844937
    845       If inflateGetHeader is not used, then the header information is simply
     938     If inflateGetHeader is not used, then the header information is simply
    846939   discarded.  The header is always checked for validity, including the header
    847940   CRC if present.  inflateReset() will reset the process to discard the header
     
    849942   retrieve the header from the next gzip stream.
    850943
    851       inflateGetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source
     944     inflateGetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source
    852945   stream state was inconsistent.
    853946*/
     
    870963
    871964     inflateBackInit will return Z_OK on success, Z_STREAM_ERROR if any of
    872    the paramaters are invalid, Z_MEM_ERROR if the internal state could not
    873    be allocated, or Z_VERSION_ERROR if the version of the library does not
    874    match the version of the header file.
     965   the paramaters are invalid, Z_MEM_ERROR if the internal state could not be
     966   allocated, or Z_VERSION_ERROR if the version of the library does not match
     967   the version of the header file.
    875968*/
    876969
     
    892985   and to initialize the state with the user-provided window buffer.
    893986   inflateBack() may then be used multiple times to inflate a complete, raw
    894    deflate stream with each call.  inflateBackEnd() is then called to free
    895    the allocated state.
     987   deflate stream with each call.  inflateBackEnd() is then called to free the
     988   allocated state.
    896989
    897990     A raw deflate stream is one with no zlib or gzip header or trailer.
    898991   This routine would normally be used in a utility that reads zip or gzip
    899992   files and writes out uncompressed files.  The utility would decode the
    900    header and process the trailer on its own, hence this routine expects
    901    only the raw deflate stream to decompress.  This is different from the
    902    normal behavior of inflate(), which expects either a zlib or gzip header and
     993   header and process the trailer on its own, hence this routine expects only
     994   the raw deflate stream to decompress.  This is different from the normal
     995   behavior of inflate(), which expects either a zlib or gzip header and
    903996   trailer around the deflate stream.
    904997
     
    9261019   immediately for input.  If strm->next_in is not Z_NULL, then strm->avail_in
    9271020   must also be initialized, and then if strm->avail_in is not zero, input will
    928    initially be taken from strm->next_in[0 .. strm->avail_in - 1].
     1021   initially be taken from strm->next_in[0 ..  strm->avail_in - 1].
    9291022
    9301023     The in_desc and out_desc parameters of inflateBack() is passed as the
     
    9361029   pass back any unused input that was provided by the last in() call.  The
    9371030   return values of inflateBack() can be Z_STREAM_END on success, Z_BUF_ERROR
    938    if in() or out() returned an error, Z_DATA_ERROR if there was a format
    939    error in the deflate stream (in which case strm->msg is set to indicate the
    940    nature of the error), or Z_STREAM_ERROR if the stream was not properly
    941    initialized.  In the case of Z_BUF_ERROR, an input or output error can be
    942    distinguished using strm->next_in which will be Z_NULL only if in() returned
    943    an error.  If strm->next is not Z_NULL, then the Z_BUF_ERROR was due to
    944    out() returning non-zero.  (in() will always be called before out(), so
    945    strm->next_in is assured to be defined if out() returns non-zero.)  Note
    946    that inflateBack() cannot return Z_OK.
     1031   if in() or out() returned an error, Z_DATA_ERROR if there was a format error
     1032   in the deflate stream (in which case strm->msg is set to indicate the nature
     1033   of the error), or Z_STREAM_ERROR if the stream was not properly initialized.
     1034   In the case of Z_BUF_ERROR, an input or output error can be distinguished
     1035   using strm->next_in which will be Z_NULL only if in() returned an error.  If
     1036   strm->next_in is not Z_NULL, then the Z_BUF_ERROR was due to out() returning
     1037   non-zero.  (in() will always be called before out(), so strm->next_in is
     1038   assured to be defined if out() returns non-zero.) Note that inflateBack()
     1039   cannot return Z_OK.
    9471040*/
    9481041
     
    10001093
    10011094/*
    1002      The following utility functions are implemented on top of the
    1003    basic stream-oriented functions. To simplify the interface, some
    1004    default options are assumed (compression level and memory usage,
    1005    standard memory allocation functions). The source code of these
    1006    utility functions can easily be modified if you need special options.
     1095     The following utility functions are implemented on top of the basic
     1096   stream-oriented functions.  To simplify the interface, some default options
     1097   are assumed (compression level and memory usage, standard memory allocation
     1098   functions).  The source code of these utility functions can be modified if
     1099   you need special options.
    10071100*/
    10081101
     
    10111104/*
    10121105     Compresses the source buffer into the destination buffer.  sourceLen is
    1013    the byte length of the source buffer. Upon entry, destLen is the total
    1014    size of the destination buffer, which must be at least the value returned
    1015    by compressBound(sourceLen). Upon exit, destLen is the actual size of the
     1106   the byte length of the source buffer.  Upon entry, destLen is the total size
     1107   of the destination buffer, which must be at least the value returned by
     1108   compressBound(sourceLen). Upon exit, destLen is the actual size of the
    10161109   compressed buffer.
    1017      This function can be used to compress a whole file at once if the
    1018    input file is mmap'ed.
     1110
    10191111     compress returns Z_OK if success, Z_MEM_ERROR if there was not
    10201112   enough memory, Z_BUF_ERROR if there was not enough room in the output
     
    10261118                                  int level));
    10271119/*
    1028      Compresses the source buffer into the destination buffer. The level
     1120     Compresses the source buffer into the destination buffer.  The level
    10291121   parameter has the same meaning as in deflateInit.  sourceLen is the byte
    1030    length of the source buffer. Upon entry, destLen is the total size of the
     1122   length of the source buffer.  Upon entry, destLen is the total size of the
    10311123   destination buffer, which must be at least the value returned by
    1032    compressBound(sourceLen). Upon exit, destLen is the actual size of the
     1124   compressBound(sourceLen).  Upon exit, destLen is the actual size of the
    10331125   compressed buffer.
    10341126
     
    10411133/*
    10421134     compressBound() returns an upper bound on the compressed size after
    1043    compress() or compress2() on sourceLen bytes.  It would be used before
    1044    a compress() or compress2() call to allocate the destination buffer.
     1135   compress() or compress2() on sourceLen bytes.  It would be used before a
     1136   compress() or compress2() call to allocate the destination buffer.
    10451137*/
    10461138
     
    10491141/*
    10501142     Decompresses the source buffer into the destination buffer.  sourceLen is
    1051    the byte length of the source buffer. Upon entry, destLen is the total
    1052    size of the destination buffer, which must be large enough to hold the
    1053    entire uncompressed data. (The size of the uncompressed data must have
    1054    been saved previously by the compressor and transmitted to the decompressor
    1055    by some mechanism outside the scope of this compression library.)
    1056    Upon exit, destLen is the actual size of the compressed buffer.
    1057      This function can be used to decompress a whole file at once if the
    1058    input file is mmap'ed.
     1143   the byte length of the source buffer.  Upon entry, destLen is the total size
     1144   of the destination buffer, which must be large enough to hold the entire
     1145   uncompressed data.  (The size of the uncompressed data must have been saved
     1146   previously by the compressor and transmitted to the decompressor by some
     1147   mechanism outside the scope of this compression library.) Upon exit, destLen
     1148   is the actual size of the uncompressed buffer.
    10591149
    10601150     uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
     
    10641154
    10651155
    1066 typedef voidp gzFile;
    1067 
    1068 ZEXTERN gzFile ZEXPORT gzopen  OF((const char *path, const char *mode));
    1069 /*
    1070      Opens a gzip (.gz) file for reading or writing. The mode parameter
    1071    is as in fopen ("rb" or "wb") but can also include a compression level
    1072    ("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for
    1073    Huffman only compression as in "wb1h", or 'R' for run-length encoding
    1074    as in "wb1R". (See the description of deflateInit2 for more information
    1075    about the strategy parameter.)
     1156                        /* gzip file access functions */
     1157
     1158/*
     1159     This library supports reading and writing files in gzip (.gz) format with
     1160   an interface similar to that of stdio, using the functions that start with
     1161   "gz".  The gzip format is different from the zlib format.  gzip is a gzip
     1162   wrapper, documented in RFC 1952, wrapped around a deflate stream.
     1163*/
     1164
     1165typedef voidp gzFile;       /* opaque gzip file descriptor */
     1166
     1167/*
     1168ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
     1169
     1170     Opens a gzip (.gz) file for reading or writing.  The mode parameter is as
     1171   in fopen ("rb" or "wb") but can also include a compression level ("wb9") or
     1172   a strategy: 'f' for filtered data as in "wb6f", 'h' for Huffman-only
     1173   compression as in "wb1h", 'R' for run-length encoding as in "wb1R", or 'F'
     1174   for fixed code compression as in "wb9F".  (See the description of
     1175   deflateInit2 for more information about the strategy parameter.) Also "a"
     1176   can be used instead of "w" to request that the gzip stream that will be
     1177   written be appended to the file.  "+" will result in an error, since reading
     1178   and writing to the same gzip file is not supported.
    10761179
    10771180     gzopen can be used to read a file which is not in gzip format; in this
    10781181   case gzread will directly read from the file without decompression.
    10791182
    1080      gzopen returns NULL if the file could not be opened or if there was
    1081    insufficient memory to allocate the (de)compression state; errno
    1082    can be checked to distinguish the two cases (if errno is zero, the
    1083    zlib error is Z_MEM_ERROR).  */
    1084 
    1085 ZEXTERN gzFile ZEXPORT gzdopen  OF((int fd, const char *mode));
    1086 /*
    1087      gzdopen() associates a gzFile with the file descriptor fd.  File
    1088    descriptors are obtained from calls like open, dup, creat, pipe or
    1089    fileno (in the file has been previously opened with fopen).
    1090    The mode parameter is as in gzopen.
    1091      The next call of gzclose on the returned gzFile will also close the
    1092    file descriptor fd, just like fclose(fdopen(fd), mode) closes the file
    1093    descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode).
    1094      gzdopen returns NULL if there was insufficient memory to allocate
    1095    the (de)compression state.
     1183     gzopen returns NULL if the file could not be opened, if there was
     1184   insufficient memory to allocate the gzFile state, or if an invalid mode was
     1185   specified (an 'r', 'w', or 'a' was not provided, or '+' was provided).
     1186   errno can be checked to determine if the reason gzopen failed was that the
     1187   file could not be opened.
     1188*/
     1189
     1190ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
     1191/*
     1192     gzdopen associates a gzFile with the file descriptor fd.  File descriptors
     1193   are obtained from calls like open, dup, creat, pipe or fileno (if the file
     1194   has been previously opened with fopen).  The mode parameter is as in gzopen.
     1195
     1196     The next call of gzclose on the returned gzFile will also close the file
     1197   descriptor fd, just like fclose(fdopen(fd, mode)) closes the file descriptor
     1198   fd.  If you want to keep fd open, use fd = dup(fd_keep); gz = gzdopen(fd,
     1199   mode);.  The duplicated descriptor should be saved to avoid a leak, since
     1200   gzdopen does not close fd if it fails.
     1201
     1202     gzdopen returns NULL if there was insufficient memory to allocate the
     1203   gzFile state, if an invalid mode was specified (an 'r', 'w', or 'a' was not
     1204   provided, or '+' was provided), or if fd is -1.  The file descriptor is not
     1205   used until the next gz* read, write, seek, or close operation, so gzdopen
     1206   will not detect if fd is invalid (unless fd is -1).
     1207*/
     1208
     1209ZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned size));
     1210/*
     1211     Set the internal buffer size used by this library's functions.  The
     1212   default buffer size is 8192 bytes.  This function must be called after
     1213   gzopen() or gzdopen(), and before any other calls that read or write the
     1214   file.  The buffer memory allocation is always deferred to the first read or
     1215   write.  Two buffers are allocated, either both of the specified size when
     1216   writing, or one of the specified size and the other twice that size when
     1217   reading.  A larger buffer size of, for example, 64K or 128K bytes will
     1218   noticeably increase the speed of decompression (reading).
     1219
     1220     The new buffer size also affects the maximum length for gzprintf().
     1221
     1222     gzbuffer() returns 0 on success, or -1 on failure, such as being called
     1223   too late.
    10961224*/
    10971225
    10981226ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
    10991227/*
    1100      Dynamically update the compression level or strategy. See the description
     1228     Dynamically update the compression level or strategy.  See the description
    11011229   of deflateInit2 for the meaning of these parameters.
     1230
    11021231     gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not
    11031232   opened for writing.
    11041233*/
    11051234
    1106 ZEXTERN int ZEXPORT    gzread  OF((gzFile file, voidp buf, unsigned len));
    1107 /*
    1108      Reads the given number of uncompressed bytes from the compressed file.
    1109    If the input file was not in gzip format, gzread copies the given number
    1110    of bytes into the buffer.
    1111      gzread returns the number of uncompressed bytes actually read (0 for
    1112    end of file, -1 for error). */
    1113 
    1114 ZEXTERN int ZEXPORT    gzwrite OF((gzFile file,
    1115                                    voidpc buf, unsigned len));
     1235ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
     1236/*
     1237     Reads the given number of uncompressed bytes from the compressed file.  If
     1238   the input file was not in gzip format, gzread copies the given number of
     1239   bytes into the buffer.
     1240
     1241     After reaching the end of a gzip stream in the input, gzread will continue
     1242   to read, looking for another gzip stream, or failing that, reading the rest
     1243   of the input file directly without decompression.  The entire input file
     1244   will be read if gzread is called until it returns less than the requested
     1245   len.
     1246
     1247     gzread returns the number of uncompressed bytes actually read, less than
     1248   len for end of file, or -1 for error.
     1249*/
     1250
     1251ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
     1252                                voidpc buf, unsigned len));
    11161253/*
    11171254     Writes the given number of uncompressed bytes into the compressed file.
    1118    gzwrite returns the number of uncompressed bytes actually written
    1119    (0 in case of error).
    1120 */
    1121 
    1122 ZEXTERN int ZEXPORTVA   gzprintf OF((gzFile file, const char *format, ...));
    1123 /*
    1124      Converts, formats, and writes the args to the compressed file under
    1125    control of the format string, as in fprintf. gzprintf returns the number of
    1126    uncompressed bytes actually written (0 in case of error).  The number of
    1127    uncompressed bytes written is limited to 4095. The caller should assure that
    1128    this limit is not exceeded. If it is exceeded, then gzprintf() will return
    1129    return an error (0) with nothing written. In this case, there may also be a
    1130    buffer overflow with unpredictable consequences, which is possible only if
    1131    zlib was compiled with the insecure functions sprintf() or vsprintf()
    1132    because the secure snprintf() or vsnprintf() functions were not available.
     1255   gzwrite returns the number of uncompressed bytes written or 0 in case of
     1256   error.
     1257*/
     1258
     1259ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...));
     1260/*
     1261     Converts, formats, and writes the arguments to the compressed file under
     1262   control of the format string, as in fprintf.  gzprintf returns the number of
     1263   uncompressed bytes actually written, or 0 in case of error.  The number of
     1264   uncompressed bytes written is limited to 8191, or one less than the buffer
     1265   size given to gzbuffer().  The caller should assure that this limit is not
     1266   exceeded.  If it is exceeded, then gzprintf() will return an error (0) with
     1267   nothing written.  In this case, there may also be a buffer overflow with
     1268   unpredictable consequences, which is possible only if zlib was compiled with
     1269   the insecure functions sprintf() or vsprintf() because the secure snprintf()
     1270   or vsnprintf() functions were not available.  This can be determined using
     1271   zlibCompileFlags().
    11331272*/
    11341273
    11351274ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
    11361275/*
    1137       Writes the given null-terminated string to the compressed file, excluding
     1276     Writes the given null-terminated string to the compressed file, excluding
    11381277   the terminating null character.
    1139       gzputs returns the number of characters written, or -1 in case of error.
     1278
     1279     gzputs returns the number of characters written, or -1 in case of error.
    11401280*/
    11411281
    11421282ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
    11431283/*
    1144       Reads bytes from the compressed file until len-1 characters are read, or
    1145    a newline character is read and transferred to buf, or an end-of-file
    1146    condition is encountered.  The string is then terminated with a null
    1147    character.
    1148       gzgets returns buf, or Z_NULL in case of error.
    1149 */
    1150 
    1151 ZEXTERN int ZEXPORT    gzputc OF((gzFile file, int c));
    1152 /*
    1153       Writes c, converted to an unsigned char, into the compressed file.
    1154    gzputc returns the value that was written, or -1 in case of error.
    1155 */
    1156 
    1157 ZEXTERN int ZEXPORT    gzgetc OF((gzFile file));
    1158 /*
    1159       Reads one byte from the compressed file. gzgetc returns this byte
    1160    or -1 in case of end of file or error.
    1161 */
    1162 
    1163 ZEXTERN int ZEXPORT    gzungetc OF((int c, gzFile file));
    1164 /*
    1165       Push one character back onto the stream to be read again later.
    1166    Only one character of push-back is allowed.  gzungetc() returns the
    1167    character pushed, or -1 on failure.  gzungetc() will fail if a
    1168    character has been pushed but not read yet, or if c is -1. The pushed
    1169    character will be discarded if the stream is repositioned with gzseek()
    1170    or gzrewind().
    1171 */
    1172 
    1173 ZEXTERN int ZEXPORT    gzflush OF((gzFile file, int flush));
    1174 /*
    1175      Flushes all pending output into the compressed file. The parameter
    1176    flush is as in the deflate() function. The return value is the zlib
    1177    error number (see function gzerror below). gzflush returns Z_OK if
    1178    the flush parameter is Z_FINISH and all output could be flushed.
    1179      gzflush should be called only when strictly necessary because it can
    1180    degrade compression.
    1181 */
    1182 
    1183 ZEXTERN z_off_t ZEXPORT    gzseek OF((gzFile file,
    1184                                       z_off_t offset, int whence));
    1185 /*
    1186       Sets the starting position for the next gzread or gzwrite on the
    1187    given compressed file. The offset represents a number of bytes in the
    1188    uncompressed data stream. The whence parameter is defined as in lseek(2);
     1284     Reads bytes from the compressed file until len-1 characters are read, or a
     1285   newline character is read and transferred to buf, or an end-of-file
     1286   condition is encountered.  If any characters are read or if len == 1, the
     1287   string is terminated with a null character.  If no characters are read due
     1288   to an end-of-file or len < 1, then the buffer is left untouched.
     1289
     1290     gzgets returns buf which is a null-terminated string, or it returns NULL
     1291   for end-of-file or in case of error.  If there was an error, the contents at
     1292   buf are indeterminate.
     1293*/
     1294
     1295ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c));
     1296/*
     1297     Writes c, converted to an unsigned char, into the compressed file.  gzputc
     1298   returns the value that was written, or -1 in case of error.
     1299*/
     1300
     1301ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
     1302/*
     1303     Reads one byte from the compressed file.  gzgetc returns this byte or -1
     1304   in case of end of file or error.
     1305*/
     1306
     1307ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file));
     1308/*
     1309     Push one character back onto the stream to be read as the first character
     1310   on the next read.  At least one character of push-back is allowed.
     1311   gzungetc() returns the character pushed, or -1 on failure.  gzungetc() will
     1312   fail if c is -1, and may fail if a character has been pushed but not read
     1313   yet.  If gzungetc is used immediately after gzopen or gzdopen, at least the
     1314   output buffer size of pushed characters is allowed.  (See gzbuffer above.)
     1315   The pushed character will be discarded if the stream is repositioned with
     1316   gzseek() or gzrewind().
     1317*/
     1318
     1319ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
     1320/*
     1321     Flushes all pending output into the compressed file.  The parameter flush
     1322   is as in the deflate() function.  The return value is the zlib error number
     1323   (see function gzerror below).  gzflush is only permitted when writing.
     1324
     1325     If the flush parameter is Z_FINISH, the remaining data is written and the
     1326   gzip stream is completed in the output.  If gzwrite() is called again, a new
     1327   gzip stream will be started in the output.  gzread() is able to read such
     1328   concatented gzip streams.
     1329
     1330     gzflush should be called only when strictly necessary because it will
     1331   degrade compression if called too often.
     1332*/
     1333
     1334/*
     1335ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,
     1336                                   z_off_t offset, int whence));
     1337
     1338     Sets the starting position for the next gzread or gzwrite on the given
     1339   compressed file.  The offset represents a number of bytes in the
     1340   uncompressed data stream.  The whence parameter is defined as in lseek(2);
    11891341   the value SEEK_END is not supported.
     1342
    11901343     If the file is opened for reading, this function is emulated but can be
    1191    extremely slow. If the file is opened for writing, only forward seeks are
     1344   extremely slow.  If the file is opened for writing, only forward seeks are
    11921345   supported; gzseek then compresses a sequence of zeroes up to the new
    11931346   starting position.
    11941347
    1195       gzseek returns the resulting offset location as measured in bytes from
     1348     gzseek returns the resulting offset location as measured in bytes from
    11961349   the beginning of the uncompressed stream, or -1 in case of error, in
    11971350   particular if the file is opened for writing and the new starting position
     
    12031356     Rewinds the given file. This function is supported only for reading.
    12041357
    1205    gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET)
    1206 */
    1207 
     1358     gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET)
     1359*/
     1360
     1361/*
    12081362ZEXTERN z_off_t ZEXPORT    gztell OF((gzFile file));
    1209 /*
    1210      Returns the starting position for the next gzread or gzwrite on the
    1211    given compressed file. This position represents a number of bytes in the
    1212    uncompressed data stream.
    1213 
    1214    gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR)
     1363
     1364     Returns the starting position for the next gzread or gzwrite on the given
     1365   com