jdk/src/share/native/java/util/zip/zlib-1.2.5/inflate.c
author katleman
Wed, 04 Jun 2014 20:20:02 -0700
changeset 24716 51596e763410
parent 13409 fe3ab27ef1a6
permissions -rw-r--r--
Added tag jdk9-b16 for changeset 87bc69dea937
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11112
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
     1
/*
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
     2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
     3
 *
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
     4
 * This code is free software; you can redistribute it and/or modify it
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
     5
 * under the terms of the GNU General Public License version 2 only, as
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
     6
 * published by the Free Software Foundation.  Oracle designates this
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
     7
 * particular file as subject to the "Classpath" exception as provided
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
     8
 * by Oracle in the LICENSE file that accompanied this code.
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
     9
 *
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    14
 * accompanied this code).
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    15
 *
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    19
 *
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    22
 * questions.
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    23
 */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    24
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    25
/* inflate.c -- zlib decompression
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    26
 * Copyright (C) 1995-2010 Mark Adler
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    27
 * For conditions of distribution and use, see copyright notice in zlib.h
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    28
 */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    29
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    30
/*
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    31
 * Change history:
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    32
 *
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    33
 * 1.2.beta0    24 Nov 2002
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    34
 * - First version -- complete rewrite of inflate to simplify code, avoid
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    35
 *   creation of window when not needed, minimize use of window when it is
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    36
 *   needed, make inffast.c even faster, implement gzip decoding, and to
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    37
 *   improve code readability and style over the previous zlib inflate code
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    38
 *
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    39
 * 1.2.beta1    25 Nov 2002
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    40
 * - Use pointers for available input and output checking in inffast.c
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    41
 * - Remove input and output counters in inffast.c
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    42
 * - Change inffast.c entry and loop from avail_in >= 7 to >= 6
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    43
 * - Remove unnecessary second byte pull from length extra in inffast.c
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    44
 * - Unroll direct copy to three copies per loop in inffast.c
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    45
 *
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    46
 * 1.2.beta2    4 Dec 2002
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    47
 * - Change external routine names to reduce potential conflicts
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    48
 * - Correct filename to inffixed.h for fixed tables in inflate.c
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    49
 * - Make hbuf[] unsigned char to match parameter type in inflate.c
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    50
 * - Change strm->next_out[-state->offset] to *(strm->next_out - state->offset)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    51
 *   to avoid negation problem on Alphas (64 bit) in inflate.c
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    52
 *
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    53
 * 1.2.beta3    22 Dec 2002
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    54
 * - Add comments on state->bits assertion in inffast.c
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    55
 * - Add comments on op field in inftrees.h
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    56
 * - Fix bug in reuse of allocated window after inflateReset()
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    57
 * - Remove bit fields--back to byte structure for speed
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    58
 * - Remove distance extra == 0 check in inflate_fast()--only helps for lengths
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    59
 * - Change post-increments to pre-increments in inflate_fast(), PPC biased?
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    60
 * - Add compile time option, POSTINC, to use post-increments instead (Intel?)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    61
 * - Make MATCH copy in inflate() much faster for when inflate_fast() not used
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    62
 * - Use local copies of stream next and avail values, as well as local bit
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    63
 *   buffer and bit count in inflate()--for speed when inflate_fast() not used
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    64
 *
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    65
 * 1.2.beta4    1 Jan 2003
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    66
 * - Split ptr - 257 statements in inflate_table() to avoid compiler warnings
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    67
 * - Move a comment on output buffer sizes from inffast.c to inflate.c
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    68
 * - Add comments in inffast.c to introduce the inflate_fast() routine
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    69
 * - Rearrange window copies in inflate_fast() for speed and simplification
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    70
 * - Unroll last copy for window match in inflate_fast()
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    71
 * - Use local copies of window variables in inflate_fast() for speed
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    72
 * - Pull out common wnext == 0 case for speed in inflate_fast()
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    73
 * - Make op and len in inflate_fast() unsigned for consistency
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    74
 * - Add FAR to lcode and dcode declarations in inflate_fast()
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    75
 * - Simplified bad distance check in inflate_fast()
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    76
 * - Added inflateBackInit(), inflateBack(), and inflateBackEnd() in new
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    77
 *   source file infback.c to provide a call-back interface to inflate for
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    78
 *   programs like gzip and unzip -- uses window as output buffer to avoid
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    79
 *   window copying
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    80
 *
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    81
 * 1.2.beta5    1 Jan 2003
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    82
 * - Improved inflateBack() interface to allow the caller to provide initial
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    83
 *   input in strm.
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    84
 * - Fixed stored blocks bug in inflateBack()
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    85
 *
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    86
 * 1.2.beta6    4 Jan 2003
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    87
 * - Added comments in inffast.c on effectiveness of POSTINC
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    88
 * - Typecasting all around to reduce compiler warnings
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    89
 * - Changed loops from while (1) or do {} while (1) to for (;;), again to
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    90
 *   make compilers happy
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    91
 * - Changed type of window in inflateBackInit() to unsigned char *
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    92
 *
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    93
 * 1.2.beta7    27 Jan 2003
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    94
 * - Changed many types to unsigned or unsigned short to avoid warnings
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    95
 * - Added inflateCopy() function
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    96
 *
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    97
 * 1.2.0        9 Mar 2003
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    98
 * - Changed inflateBack() interface to provide separate opaque descriptors
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    99
 *   for the in() and out() functions
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   100
 * - Changed inflateBack() argument and in_func typedef to swap the length
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   101
 *   and buffer address return values for the input function
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   102
 * - Check next_in and next_out for Z_NULL on entry to inflate()
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   103
 *
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   104
 * The history for versions after 1.2.0 are in ChangeLog in zlib distribution.
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   105
 */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   106
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   107
#include "zutil.h"
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   108
#include "inftrees.h"
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   109
#include "inflate.h"
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   110
#include "inffast.h"
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   111
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   112
#ifdef MAKEFIXED
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   113
#  ifndef BUILDFIXED
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   114
#    define BUILDFIXED
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   115
#  endif
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   116
#endif
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   117
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   118
/* function prototypes */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   119
local void fixedtables OF((struct inflate_state FAR *state));
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   120
local int updatewindow OF((z_streamp strm, unsigned out));
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   121
#ifdef BUILDFIXED
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   122
   void makefixed OF((void));
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   123
#endif
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   124
local unsigned syncsearch OF((unsigned FAR *have, unsigned char FAR *buf,
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   125
                              unsigned len));
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   126
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   127
int ZEXPORT inflateReset(strm)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   128
z_streamp strm;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   129
{
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   130
    struct inflate_state FAR *state;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   131
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   132
    if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   133
    state = (struct inflate_state FAR *)strm->state;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   134
    strm->total_in = strm->total_out = state->total = 0;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   135
    strm->msg = Z_NULL;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   136
    strm->adler = 1;        /* to support ill-conceived Java test suite */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   137
    state->mode = HEAD;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   138
    state->last = 0;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   139
    state->havedict = 0;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   140
    state->dmax = 32768U;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   141
    state->head = Z_NULL;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   142
    state->wsize = 0;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   143
    state->whave = 0;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   144
    state->wnext = 0;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   145
    state->hold = 0;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   146
    state->bits = 0;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   147
    state->lencode = state->distcode = state->next = state->codes;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   148
    state->sane = 1;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   149
    state->back = -1;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   150
    Tracev((stderr, "inflate: reset\n"));
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   151
    return Z_OK;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   152
}
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   153
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   154
int ZEXPORT inflateReset2(strm, windowBits)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   155
z_streamp strm;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   156
int windowBits;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   157
{
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   158
    int wrap;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   159
    struct inflate_state FAR *state;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   160
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   161
    /* get the state */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   162
    if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   163
    state = (struct inflate_state FAR *)strm->state;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   164
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   165
    /* extract wrap request from windowBits parameter */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   166
    if (windowBits < 0) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   167
        wrap = 0;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   168
        windowBits = -windowBits;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   169
    }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   170
    else {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   171
        wrap = (windowBits >> 4) + 1;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   172
#ifdef GUNZIP
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   173
        if (windowBits < 48)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   174
            windowBits &= 15;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   175
#endif
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   176
    }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   177
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   178
    /* set number of window bits, free window if different */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   179
    if (windowBits && (windowBits < 8 || windowBits > 15))
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   180
        return Z_STREAM_ERROR;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   181
    if (state->window != Z_NULL && state->wbits != (unsigned)windowBits) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   182
        ZFREE(strm, state->window);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   183
        state->window = Z_NULL;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   184
    }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   185
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   186
    /* update state and reset the rest of it */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   187
    state->wrap = wrap;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   188
    state->wbits = (unsigned)windowBits;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   189
    return inflateReset(strm);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   190
}
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   191
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   192
int ZEXPORT inflateInit2_(strm, windowBits, version, stream_size)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   193
z_streamp strm;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   194
int windowBits;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   195
const char *version;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   196
int stream_size;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   197
{
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   198
    int ret;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   199
    struct inflate_state FAR *state;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   200
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   201
    if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   202
        stream_size != (int)(sizeof(z_stream)))
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   203
        return Z_VERSION_ERROR;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   204
    if (strm == Z_NULL) return Z_STREAM_ERROR;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   205
    strm->msg = Z_NULL;                 /* in case we return an error */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   206
    if (strm->zalloc == (alloc_func)0) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   207
        strm->zalloc = zcalloc;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   208
        strm->opaque = (voidpf)0;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   209
    }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   210
    if (strm->zfree == (free_func)0) strm->zfree = zcfree;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   211
    state = (struct inflate_state FAR *)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   212
            ZALLOC(strm, 1, sizeof(struct inflate_state));
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   213
    if (state == Z_NULL) return Z_MEM_ERROR;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   214
    Tracev((stderr, "inflate: allocated\n"));
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   215
    strm->state = (struct internal_state FAR *)state;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   216
    state->window = Z_NULL;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   217
    ret = inflateReset2(strm, windowBits);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   218
    if (ret != Z_OK) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   219
        ZFREE(strm, state);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   220
        strm->state = Z_NULL;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   221
    }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   222
    return ret;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   223
}
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   224
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   225
int ZEXPORT inflateInit_(strm, version, stream_size)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   226
z_streamp strm;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   227
const char *version;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   228
int stream_size;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   229
{
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   230
    return inflateInit2_(strm, DEF_WBITS, version, stream_size);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   231
}
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   232
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   233
int ZEXPORT inflatePrime(strm, bits, value)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   234
z_streamp strm;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   235
int bits;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   236
int value;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   237
{
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   238
    struct inflate_state FAR *state;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   239
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   240
    if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   241
    state = (struct inflate_state FAR *)strm->state;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   242
    if (bits < 0) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   243
        state->hold = 0;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   244
        state->bits = 0;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   245
        return Z_OK;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   246
    }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   247
    if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   248
    value &= (1L << bits) - 1;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   249
    state->hold += value << state->bits;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   250
    state->bits += bits;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   251
    return Z_OK;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   252
}
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   253
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   254
/*
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   255
   Return state with length and distance decoding tables and index sizes set to
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   256
   fixed code decoding.  Normally this returns fixed tables from inffixed.h.
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   257
   If BUILDFIXED is defined, then instead this routine builds the tables the
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   258
   first time it's called, and returns those tables the first time and
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   259
   thereafter.  This reduces the size of the code by about 2K bytes, in
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   260
   exchange for a little execution time.  However, BUILDFIXED should not be
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   261
   used for threaded applications, since the rewriting of the tables and virgin
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   262
   may not be thread-safe.
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   263
 */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   264
local void fixedtables(state)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   265
struct inflate_state FAR *state;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   266
{
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   267
#ifdef BUILDFIXED
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   268
    static int virgin = 1;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   269
    static code *lenfix, *distfix;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   270
    static code fixed[544];
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   271
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   272
    /* build fixed huffman tables if first call (may not be thread safe) */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   273
    if (virgin) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   274
        unsigned sym, bits;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   275
        static code *next;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   276
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   277
        /* literal/length table */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   278
        sym = 0;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   279
        while (sym < 144) state->lens[sym++] = 8;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   280
        while (sym < 256) state->lens[sym++] = 9;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   281
        while (sym < 280) state->lens[sym++] = 7;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   282
        while (sym < 288) state->lens[sym++] = 8;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   283
        next = fixed;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   284
        lenfix = next;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   285
        bits = 9;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   286
        inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   287
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   288
        /* distance table */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   289
        sym = 0;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   290
        while (sym < 32) state->lens[sym++] = 5;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   291
        distfix = next;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   292
        bits = 5;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   293
        inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   294
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   295
        /* do this just once */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   296
        virgin = 0;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   297
    }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   298
#else /* !BUILDFIXED */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   299
#   include "inffixed.h"
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   300
#endif /* BUILDFIXED */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   301
    state->lencode = lenfix;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   302
    state->lenbits = 9;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   303
    state->distcode = distfix;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   304
    state->distbits = 5;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   305
}
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   306
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   307
#ifdef MAKEFIXED
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   308
#include <stdio.h>
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   309
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   310
/*
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   311
   Write out the inffixed.h that is #include'd above.  Defining MAKEFIXED also
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   312
   defines BUILDFIXED, so the tables are built on the fly.  makefixed() writes
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   313
   those tables to stdout, which would be piped to inffixed.h.  A small program
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   314
   can simply call makefixed to do this:
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   315
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   316
    void makefixed(void);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   317
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   318
    int main(void)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   319
    {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   320
        makefixed();
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   321
        return 0;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   322
    }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   323
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   324
   Then that can be linked with zlib built with MAKEFIXED defined and run:
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   325
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   326
    a.out > inffixed.h
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   327
 */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   328
void makefixed()
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   329
{
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   330
    unsigned low, size;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   331
    struct inflate_state state;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   332
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   333
    fixedtables(&state);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   334
    puts("    /* inffixed.h -- table for decoding fixed codes");
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   335
    puts("     * Generated automatically by makefixed().");
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   336
    puts("     */");
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   337
    puts("");
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   338
    puts("    /* WARNING: this file should *not* be used by applications.");
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   339
    puts("       It is part of the implementation of this library and is");
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   340
    puts("       subject to change. Applications should only use zlib.h.");
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   341
    puts("     */");
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   342
    puts("");
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   343
    size = 1U << 9;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   344
    printf("    static const code lenfix[%u] = {", size);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   345
    low = 0;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   346
    for (;;) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   347
        if ((low % 7) == 0) printf("\n        ");
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   348
        printf("{%u,%u,%d}", state.lencode[low].op, state.lencode[low].bits,
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   349
               state.lencode[low].val);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   350
        if (++low == size) break;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   351
        putchar(',');
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   352
    }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   353
    puts("\n    };");
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   354
    size = 1U << 5;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   355
    printf("\n    static const code distfix[%u] = {", size);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   356
    low = 0;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   357
    for (;;) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   358
        if ((low % 6) == 0) printf("\n        ");
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   359
        printf("{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits,
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   360
               state.distcode[low].val);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   361
        if (++low == size) break;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   362
        putchar(',');
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   363
    }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   364
    puts("\n    };");
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   365
}
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   366
#endif /* MAKEFIXED */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   367
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   368
/*
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   369
   Update the window with the last wsize (normally 32K) bytes written before
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   370
   returning.  If window does not exist yet, create it.  This is only called
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   371
   when a window is already in use, or when output has been written during this
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   372
   inflate call, but the end of the deflate stream has not been reached yet.
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   373
   It is also called to create a window for dictionary data when a dictionary
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   374
   is loaded.
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   375
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   376
   Providing output buffers larger than 32K to inflate() should provide a speed
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   377
   advantage, since only the last 32K of output is copied to the sliding window
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   378
   upon return from inflate(), and since all distances after the first 32K of
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   379
   output will fall in the output data, making match copies simpler and faster.
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   380
   The advantage may be dependent on the size of the processor's data caches.
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   381
 */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   382
local int updatewindow(strm, out)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   383
z_streamp strm;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   384
unsigned out;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   385
{
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   386
    struct inflate_state FAR *state;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   387
    unsigned copy, dist;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   388
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   389
    state = (struct inflate_state FAR *)strm->state;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   390
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   391
    /* if it hasn't been done already, allocate space for the window */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   392
    if (state->window == Z_NULL) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   393
        state->window = (unsigned char FAR *)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   394
                        ZALLOC(strm, 1U << state->wbits,
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   395
                               sizeof(unsigned char));
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   396
        if (state->window == Z_NULL) return 1;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   397
    }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   398
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   399
    /* if window not in use yet, initialize */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   400
    if (state->wsize == 0) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   401
        state->wsize = 1U << state->wbits;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   402
        state->wnext = 0;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   403
        state->whave = 0;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   404
    }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   405
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   406
    /* copy state->wsize or less output bytes into the circular window */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   407
    copy = out - strm->avail_out;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   408
    if (copy >= state->wsize) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   409
        zmemcpy(state->window, strm->next_out - state->wsize, state->wsize);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   410
        state->wnext = 0;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   411
        state->whave = state->wsize;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   412
    }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   413
    else {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   414
        dist = state->wsize - state->wnext;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   415
        if (dist > copy) dist = copy;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   416
        zmemcpy(state->window + state->wnext, strm->next_out - copy, dist);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   417
        copy -= dist;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   418
        if (copy) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   419
            zmemcpy(state->window, strm->next_out - copy, copy);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   420
            state->wnext = copy;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   421
            state->whave = state->wsize;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   422
        }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   423
        else {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   424
            state->wnext += dist;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   425
            if (state->wnext == state->wsize) state->wnext = 0;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   426
            if (state->whave < state->wsize) state->whave += dist;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   427
        }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   428
    }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   429
    return 0;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   430
}
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   431
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   432
/* Macros for inflate(): */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   433
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   434
/* check function to use adler32() for zlib or crc32() for gzip */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   435
#ifdef GUNZIP
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   436
#  define UPDATE(check, buf, len) \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   437
    (state->flags ? crc32(check, buf, len) : adler32(check, buf, len))
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   438
#else
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   439
#  define UPDATE(check, buf, len) adler32(check, buf, len)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   440
#endif
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   441
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   442
/* check macros for header crc */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   443
#ifdef GUNZIP
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   444
#  define CRC2(check, word) \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   445
    do { \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   446
        hbuf[0] = (unsigned char)(word); \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   447
        hbuf[1] = (unsigned char)((word) >> 8); \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   448
        check = crc32(check, hbuf, 2); \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   449
    } while (0)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   450
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   451
#  define CRC4(check, word) \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   452
    do { \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   453
        hbuf[0] = (unsigned char)(word); \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   454
        hbuf[1] = (unsigned char)((word) >> 8); \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   455
        hbuf[2] = (unsigned char)((word) >> 16); \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   456
        hbuf[3] = (unsigned char)((word) >> 24); \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   457
        check = crc32(check, hbuf, 4); \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   458
    } while (0)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   459
#endif
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   460
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   461
/* Load registers with state in inflate() for speed */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   462
#define LOAD() \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   463
    do { \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   464
        put = strm->next_out; \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   465
        left = strm->avail_out; \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   466
        next = strm->next_in; \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   467
        have = strm->avail_in; \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   468
        hold = state->hold; \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   469
        bits = state->bits; \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   470
    } while (0)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   471
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   472
/* Restore state from registers in inflate() */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   473
#define RESTORE() \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   474
    do { \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   475
        strm->next_out = put; \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   476
        strm->avail_out = left; \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   477
        strm->next_in = next; \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   478
        strm->avail_in = have; \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   479
        state->hold = hold; \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   480
        state->bits = bits; \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   481
    } while (0)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   482
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   483
/* Clear the input bit accumulator */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   484
#define INITBITS() \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   485
    do { \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   486
        hold = 0; \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   487
        bits = 0; \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   488
    } while (0)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   489
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   490
/* Get a byte of input into the bit accumulator, or return from inflate()
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   491
   if there is no input available. */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   492
#define PULLBYTE() \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   493
    do { \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   494
        if (have == 0) goto inf_leave; \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   495
        have--; \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   496
        hold += (unsigned long)(*next++) << bits; \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   497
        bits += 8; \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   498
    } while (0)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   499
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   500
/* Assure that there are at least n bits in the bit accumulator.  If there is
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   501
   not enough available input to do that, then return from inflate(). */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   502
#define NEEDBITS(n) \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   503
    do { \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   504
        while (bits < (unsigned)(n)) \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   505
            PULLBYTE(); \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   506
    } while (0)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   507
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   508
/* Return the low n bits of the bit accumulator (n < 16) */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   509
#define BITS(n) \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   510
    ((unsigned)hold & ((1U << (n)) - 1))
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   511
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   512
/* Remove n bits from the bit accumulator */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   513
#define DROPBITS(n) \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   514
    do { \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   515
        hold >>= (n); \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   516
        bits -= (unsigned)(n); \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   517
    } while (0)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   518
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   519
/* Remove zero to seven bits as needed to go to a byte boundary */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   520
#define BYTEBITS() \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   521
    do { \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   522
        hold >>= bits & 7; \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   523
        bits -= bits & 7; \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   524
    } while (0)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   525
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   526
/* Reverse the bytes in a 32-bit value */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   527
#define REVERSE(q) \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   528
    ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   529
     (((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   530
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   531
/*
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   532
   inflate() uses a state machine to process as much input data and generate as
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   533
   much output data as possible before returning.  The state machine is
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   534
   structured roughly as follows:
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   535
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   536
    for (;;) switch (state) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   537
    ...
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   538
    case STATEn:
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   539
        if (not enough input data or output space to make progress)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   540
            return;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   541
        ... make progress ...
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   542
        state = STATEm;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   543
        break;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   544
    ...
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   545
    }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   546
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   547
   so when inflate() is called again, the same case is attempted again, and
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   548
   if the appropriate resources are provided, the machine proceeds to the
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   549
   next state.  The NEEDBITS() macro is usually the way the state evaluates
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   550
   whether it can proceed or should return.  NEEDBITS() does the return if
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   551
   the requested bits are not available.  The typical use of the BITS macros
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   552
   is:
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   553
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   554
        NEEDBITS(n);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   555
        ... do something with BITS(n) ...
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   556
        DROPBITS(n);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   557
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   558
   where NEEDBITS(n) either returns from inflate() if there isn't enough
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   559
   input left to load n bits into the accumulator, or it continues.  BITS(n)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   560
   gives the low n bits in the accumulator.  When done, DROPBITS(n) drops
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   561
   the low n bits off the accumulator.  INITBITS() clears the accumulator
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   562
   and sets the number of available bits to zero.  BYTEBITS() discards just
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   563
   enough bits to put the accumulator on a byte boundary.  After BYTEBITS()
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   564
   and a NEEDBITS(8), then BITS(8) would return the next byte in the stream.
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   565
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   566
   NEEDBITS(n) uses PULLBYTE() to get an available byte of input, or to return
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   567
   if there is no input available.  The decoding of variable length codes uses
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   568
   PULLBYTE() directly in order to pull just enough bytes to decode the next
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   569
   code, and no more.
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   570
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   571
   Some states loop until they get enough input, making sure that enough
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   572
   state information is maintained to continue the loop where it left off
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   573
   if NEEDBITS() returns in the loop.  For example, want, need, and keep
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   574
   would all have to actually be part of the saved state in case NEEDBITS()
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   575
   returns:
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   576
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   577
    case STATEw:
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   578
        while (want < need) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   579
            NEEDBITS(n);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   580
            keep[want++] = BITS(n);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   581
            DROPBITS(n);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   582
        }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   583
        state = STATEx;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   584
    case STATEx:
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   585
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   586
   As shown above, if the next state is also the next case, then the break
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   587
   is omitted.
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   588
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   589
   A state may also return if there is not enough output space available to
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   590
   complete that state.  Those states are copying stored data, writing a
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   591
   literal byte, and copying a matching string.
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   592
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   593
   When returning, a "goto inf_leave" is used to update the total counters,
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   594
   update the check value, and determine whether any progress has been made
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   595
   during that inflate() call in order to return the proper return code.
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   596
   Progress is defined as a change in either strm->avail_in or strm->avail_out.
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   597
   When there is a window, goto inf_leave will update the window with the last
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   598
   output written.  If a goto inf_leave occurs in the middle of decompression
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   599
   and there is no window currently, goto inf_leave will create one and copy
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   600
   output to the window for the next call of inflate().
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   601
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   602
   In this implementation, the flush parameter of inflate() only affects the
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   603
   return code (per zlib.h).  inflate() always writes as much as possible to
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   604
   strm->next_out, given the space available and the provided input--the effect
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   605
   documented in zlib.h of Z_SYNC_FLUSH.  Furthermore, inflate() always defers
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   606
   the allocation of and copying into a sliding window until necessary, which
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   607
   provides the effect documented in zlib.h for Z_FINISH when the entire input
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   608
   stream available.  So the only thing the flush parameter actually does is:
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   609
   when flush is set to Z_FINISH, inflate() cannot return Z_OK.  Instead it
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   610
   will return Z_BUF_ERROR if it has not reached the end of the stream.
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   611
 */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   612
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   613
int ZEXPORT inflate(strm, flush)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   614
z_streamp strm;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   615
int flush;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   616
{
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   617
    struct inflate_state FAR *state;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   618
    unsigned char FAR *next;    /* next input */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   619
    unsigned char FAR *put;     /* next output */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   620
    unsigned have, left;        /* available input and output */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   621
    unsigned long hold;         /* bit buffer */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   622
    unsigned bits;              /* bits in bit buffer */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   623
    unsigned in, out;           /* save starting available input and output */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   624
    unsigned copy;              /* number of stored or match bytes to copy */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   625
    unsigned char FAR *from;    /* where to copy match bytes from */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   626
    code here;                  /* current decoding table entry */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   627
    code last;                  /* parent table entry */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   628
    unsigned len;               /* length to copy for repeats, bits to drop */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   629
    int ret;                    /* return code */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   630
#ifdef GUNZIP
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   631
    unsigned char hbuf[4];      /* buffer for gzip header crc calculation */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   632
#endif
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   633
    static const unsigned short order[19] = /* permutation of code lengths */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   634
        {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   635
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   636
    if (strm == Z_NULL || strm->state == Z_NULL || strm->next_out == Z_NULL ||
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   637
        (strm->next_in == Z_NULL && strm->avail_in != 0))
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   638
        return Z_STREAM_ERROR;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   639
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   640
    state = (struct inflate_state FAR *)strm->state;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   641
    if (state->mode == TYPE) state->mode = TYPEDO;      /* skip check */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   642
    LOAD();
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   643
    in = have;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   644
    out = left;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   645
    ret = Z_OK;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   646
    for (;;)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   647
        switch (state->mode) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   648
        case HEAD:
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   649
            if (state->wrap == 0) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   650
                state->mode = TYPEDO;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   651
                break;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   652
            }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   653
            NEEDBITS(16);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   654
#ifdef GUNZIP
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   655
            if ((state->wrap & 2) && hold == 0x8b1f) {  /* gzip header */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   656
                state->check = crc32(0L, Z_NULL, 0);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   657
                CRC2(state->check, hold);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   658
                INITBITS();
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   659
                state->mode = FLAGS;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   660
                break;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   661
            }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   662
            state->flags = 0;           /* expect zlib header */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   663
            if (state->head != Z_NULL)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   664
                state->head->done = -1;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   665
            if (!(state->wrap & 1) ||   /* check if zlib header allowed */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   666
#else
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   667
            if (
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   668
#endif
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   669
                ((BITS(8) << 8) + (hold >> 8)) % 31) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   670
                strm->msg = (char *)"incorrect header check";
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   671
                state->mode = BAD;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   672
                break;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   673
            }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   674
            if (BITS(4) != Z_DEFLATED) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   675
                strm->msg = (char *)"unknown compression method";
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   676
                state->mode = BAD;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   677
                break;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   678
            }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   679
            DROPBITS(4);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   680
            len = BITS(4) + 8;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   681
            if (state->wbits == 0)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   682
                state->wbits = len;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   683
            else if (len > state->wbits) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   684
                strm->msg = (char *)"invalid window size";
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   685
                state->mode = BAD;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   686
                break;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   687
            }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   688
            state->dmax = 1U << len;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   689
            Tracev((stderr, "inflate:   zlib header ok\n"));
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   690
            strm->adler = state->check = adler32(0L, Z_NULL, 0);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   691
            state->mode = hold & 0x200 ? DICTID : TYPE;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   692
            INITBITS();
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   693
            break;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   694
#ifdef GUNZIP
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   695
        case FLAGS:
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   696
            NEEDBITS(16);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   697
            state->flags = (int)(hold);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   698
            if ((state->flags & 0xff) != Z_DEFLATED) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   699
                strm->msg = (char *)"unknown compression method";
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   700
                state->mode = BAD;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   701
                break;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   702
            }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   703
            if (state->flags & 0xe000) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   704
                strm->msg = (char *)"unknown header flags set";
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   705
                state->mode = BAD;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   706
                break;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   707
            }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   708
            if (state->head != Z_NULL)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   709
                state->head->text = (int)((hold >> 8) & 1);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   710
            if (state->flags & 0x0200) CRC2(state->check, hold);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   711
            INITBITS();
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   712
            state->mode = TIME;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   713
        case TIME:
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   714
            NEEDBITS(32);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   715
            if (state->head != Z_NULL)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   716
                state->head->time = hold;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   717
            if (state->flags & 0x0200) CRC4(state->check, hold);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   718
            INITBITS();
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   719
            state->mode = OS;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   720
        case OS:
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   721
            NEEDBITS(16);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   722
            if (state->head != Z_NULL) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   723
                state->head->xflags = (int)(hold & 0xff);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   724
                state->head->os = (int)(hold >> 8);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   725
            }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   726
            if (state->flags & 0x0200) CRC2(state->check, hold);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   727
            INITBITS();
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   728
            state->mode = EXLEN;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   729
        case EXLEN:
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   730
            if (state->flags & 0x0400) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   731
                NEEDBITS(16);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   732
                state->length = (unsigned)(hold);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   733
                if (state->head != Z_NULL)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   734
                    state->head->extra_len = (unsigned)hold;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   735
                if (state->flags & 0x0200) CRC2(state->check, hold);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   736
                INITBITS();
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   737
            }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   738
            else if (state->head != Z_NULL)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   739
                state->head->extra = Z_NULL;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   740
            state->mode = EXTRA;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   741
        case EXTRA:
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   742
            if (state->flags & 0x0400) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   743
                copy = state->length;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   744
                if (copy > have) copy = have;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   745
                if (copy) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   746
                    if (state->head != Z_NULL &&
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   747
                        state->head->extra != Z_NULL) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   748
                        len = state->head->extra_len - state->length;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   749
                        zmemcpy(state->head->extra + len, next,
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   750
                                len + copy > state->head->extra_max ?
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   751
                                state->head->extra_max - len : copy);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   752
                    }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   753
                    if (state->flags & 0x0200)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   754
                        state->check = crc32(state->check, next, copy);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   755
                    have -= copy;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   756
                    next += copy;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   757
                    state->length -= copy;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   758
                }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   759
                if (state->length) goto inf_leave;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   760
            }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   761
            state->length = 0;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   762
            state->mode = NAME;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   763
        case NAME:
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   764
            if (state->flags & 0x0800) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   765
                if (have == 0) goto inf_leave;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   766
                copy = 0;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   767
                do {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   768
                    len = (unsigned)(next[copy++]);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   769
                    if (state->head != Z_NULL &&
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   770
                            state->head->name != Z_NULL &&
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   771
                            state->length < state->head->name_max)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   772
                        state->head->name[state->length++] = len;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   773
                } while (len && copy < have);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   774
                if (state->flags & 0x0200)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   775
                    state->check = crc32(state->check, next, copy);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   776
                have -= copy;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   777
                next += copy;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   778
                if (len) goto inf_leave;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   779
            }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   780
            else if (state->head != Z_NULL)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   781
                state->head->name = Z_NULL;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   782
            state->length = 0;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   783
            state->mode = COMMENT;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   784
        case COMMENT:
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   785
            if (state->flags & 0x1000) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   786
                if (have == 0) goto inf_leave;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   787
                copy = 0;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   788
                do {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   789
                    len = (unsigned)(next[copy++]);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   790
                    if (state->head != Z_NULL &&
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   791
                            state->head->comment != Z_NULL &&
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   792
                            state->length < state->head->comm_max)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   793
                        state->head->comment[state->length++] = len;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   794
                } while (len && copy < have);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   795
                if (state->flags & 0x0200)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   796
                    state->check = crc32(state->check, next, copy);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   797
                have -= copy;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   798
                next += copy;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   799
                if (len) goto inf_leave;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   800
            }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   801
            else if (state->head != Z_NULL)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   802
                state->head->comment = Z_NULL;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   803
            state->mode = HCRC;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   804
        case HCRC:
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   805
            if (state->flags & 0x0200) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   806
                NEEDBITS(16);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   807
                if (hold != (state->check & 0xffff)) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   808
                    strm->msg = (char *)"header crc mismatch";
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   809
                    state->mode = BAD;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   810
                    break;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   811
                }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   812
                INITBITS();
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   813
            }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   814
            if (state->head != Z_NULL) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   815
                state->head->hcrc = (int)((state->flags >> 9) & 1);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   816
                state->head->done = 1;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   817
            }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   818
            strm->adler = state->check = crc32(0L, Z_NULL, 0);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   819
            state->mode = TYPE;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   820
            break;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   821
#endif
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   822
        case DICTID:
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   823
            NEEDBITS(32);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   824
            strm->adler = state->check = REVERSE(hold);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   825
            INITBITS();
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   826
            state->mode = DICT;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   827
        case DICT:
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   828
            if (state->havedict == 0) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   829
                RESTORE();
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   830
                return Z_NEED_DICT;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   831
            }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   832
            strm->adler = state->check = adler32(0L, Z_NULL, 0);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   833
            state->mode = TYPE;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   834
        case TYPE:
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   835
            if (flush == Z_BLOCK || flush == Z_TREES) goto inf_leave;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   836
        case TYPEDO:
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   837
            if (state->last) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   838
                BYTEBITS();
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   839
                state->mode = CHECK;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   840
                break;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   841
            }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   842
            NEEDBITS(3);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   843
            state->last = BITS(1);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   844
            DROPBITS(1);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   845
            switch (BITS(2)) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   846
            case 0:                             /* stored block */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   847
                Tracev((stderr, "inflate:     stored block%s\n",
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   848
                        state->last ? " (last)" : ""));
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   849
                state->mode = STORED;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   850
                break;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   851
            case 1:                             /* fixed block */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   852
                fixedtables(state);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   853
                Tracev((stderr, "inflate:     fixed codes block%s\n",
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   854
                        state->last ? " (last)" : ""));
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   855
                state->mode = LEN_;             /* decode codes */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   856
                if (flush == Z_TREES) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   857
                    DROPBITS(2);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   858
                    goto inf_leave;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   859
                }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   860
                break;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   861
            case 2:                             /* dynamic block */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   862
                Tracev((stderr, "inflate:     dynamic codes block%s\n",
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   863
                        state->last ? " (last)" : ""));
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   864
                state->mode = TABLE;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   865
                break;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   866
            case 3:
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   867
                strm->msg = (char *)"invalid block type";
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   868
                state->mode = BAD;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   869
            }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   870
            DROPBITS(2);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   871
            break;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   872
        case STORED:
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   873
            BYTEBITS();                         /* go to byte boundary */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   874
            NEEDBITS(32);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   875
            if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   876
                strm->msg = (char *)"invalid stored block lengths";
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   877
                state->mode = BAD;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   878
                break;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   879
            }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   880
            state->length = (unsigned)hold & 0xffff;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   881
            Tracev((stderr, "inflate:       stored length %u\n",
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   882
                    state->length));
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   883
            INITBITS();
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   884
            state->mode = COPY_;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   885
            if (flush == Z_TREES) goto inf_leave;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   886
        case COPY_:
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   887
            state->mode = COPY;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   888
        case COPY:
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   889
            copy = state->length;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   890
            if (copy) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   891
                if (copy > have) copy = have;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   892
                if (copy > left) copy = left;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   893
                if (copy == 0) goto inf_leave;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   894
                zmemcpy(put, next, copy);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   895
                have -= copy;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   896
                next += copy;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   897
                left -= copy;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   898
                put += copy;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   899
                state->length -= copy;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   900
                break;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   901
            }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   902
            Tracev((stderr, "inflate:       stored end\n"));
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   903
            state->mode = TYPE;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   904
            break;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   905
        case TABLE:
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   906
            NEEDBITS(14);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   907
            state->nlen = BITS(5) + 257;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   908
            DROPBITS(5);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   909
            state->ndist = BITS(5) + 1;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   910
            DROPBITS(5);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   911
            state->ncode = BITS(4) + 4;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   912
            DROPBITS(4);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   913
#ifndef PKZIP_BUG_WORKAROUND
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   914
            if (state->nlen > 286 || state->ndist > 30) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   915
                strm->msg = (char *)"too many length or distance symbols";
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   916
                state->mode = BAD;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   917
                break;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   918
            }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   919
#endif
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   920
            Tracev((stderr, "inflate:       table sizes ok\n"));
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   921
            state->have = 0;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   922
            state->mode = LENLENS;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   923
        case LENLENS:
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   924
            while (state->have < state->ncode) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   925
                NEEDBITS(3);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   926
                state->lens[order[state->have++]] = (unsigned short)BITS(3);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   927
                DROPBITS(3);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   928
            }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   929
            while (state->have < 19)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   930
                state->lens[order[state->have++]] = 0;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   931
            state->next = state->codes;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   932
            state->lencode = (code const FAR *)(state->next);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   933
            state->lenbits = 7;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   934
            ret = inflate_table(CODES, state->lens, 19, &(state->next),
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   935
                                &(state->lenbits), state->work);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   936
            if (ret) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   937
                strm->msg = (char *)"invalid code lengths set";
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   938
                state->mode = BAD;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   939
                break;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   940
            }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   941
            Tracev((stderr, "inflate:       code lengths ok\n"));
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   942
            state->have = 0;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   943
            state->mode = CODELENS;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   944
        case CODELENS:
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   945
            while (state->have < state->nlen + state->ndist) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   946
                for (;;) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   947
                    here = state->lencode[BITS(state->lenbits)];
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   948
                    if ((unsigned)(here.bits) <= bits) break;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   949
                    PULLBYTE();
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   950
                }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   951
                if (here.val < 16) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   952
                    NEEDBITS(here.bits);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   953
                    DROPBITS(here.bits);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   954
                    state->lens[state->have++] = here.val;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   955
                }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   956
                else {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   957
                    if (here.val == 16) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   958
                        NEEDBITS(here.bits + 2);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   959
                        DROPBITS(here.bits);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   960
                        if (state->have == 0) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   961
                            strm->msg = (char *)"invalid bit length repeat";
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   962
                            state->mode = BAD;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   963
                            break;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   964
                        }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   965
                        len = state->lens[state->have - 1];
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   966
                        copy = 3 + BITS(2);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   967
                        DROPBITS(2);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   968
                    }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   969
                    else if (here.val == 17) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   970
                        NEEDBITS(here.bits + 3);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   971
                        DROPBITS(here.bits);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   972
                        len = 0;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   973
                        copy = 3 + BITS(3);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   974
                        DROPBITS(3);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   975
                    }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   976
                    else {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   977
                        NEEDBITS(here.bits + 7);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   978
                        DROPBITS(here.bits);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   979
                        len = 0;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   980
                        copy = 11 + BITS(7);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   981
                        DROPBITS(7);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   982
                    }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   983
                    if (state->have + copy > state->nlen + state->ndist) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   984
                        strm->msg = (char *)"invalid bit length repeat";
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   985
                        state->mode = BAD;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   986
                        break;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   987
                    }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   988
                    while (copy--)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   989
                        state->lens[state->have++] = (unsigned short)len;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   990
                }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   991
            }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   992
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   993
            /* handle error breaks in while */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   994
            if (state->mode == BAD) break;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   995
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   996
            /* check for end-of-block code (better have one) */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   997
            if (state->lens[256] == 0) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   998
                strm->msg = (char *)"invalid code -- missing end-of-block";
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   999
                state->mode = BAD;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1000
                break;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1001
            }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1002
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1003
            /* build code tables -- note: do not change the lenbits or distbits
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1004
               values here (9 and 6) without reading the comments in inftrees.h
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1005
               concerning the ENOUGH constants, which depend on those values */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1006
            state->next = state->codes;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1007
            state->lencode = (code const FAR *)(state->next);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1008
            state->lenbits = 9;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1009
            ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1010
                                &(state->lenbits), state->work);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1011
            if (ret) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1012
                strm->msg = (char *)"invalid literal/lengths set";
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1013
                state->mode = BAD;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1014
                break;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1015
            }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1016
            state->distcode = (code const FAR *)(state->next);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1017
            state->distbits = 6;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1018
            ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1019
                            &(state->next), &(state->distbits), state->work);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1020
            if (ret) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1021
                strm->msg = (char *)"invalid distances set";
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1022
                state->mode = BAD;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1023
                break;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1024
            }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1025
            Tracev((stderr, "inflate:       codes ok\n"));
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1026
            state->mode = LEN_;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1027
            if (flush == Z_TREES) goto inf_leave;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1028
        case LEN_:
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1029
            state->mode = LEN;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1030
        case LEN:
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1031
            if (have >= 6 && left >= 258) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1032
                RESTORE();
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1033
                inflate_fast(strm, out);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1034
                LOAD();
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1035
                if (state->mode == TYPE)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1036
                    state->back = -1;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1037
                break;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1038
            }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1039
            state->back = 0;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1040
            for (;;) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1041
                here = state->lencode[BITS(state->lenbits)];
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1042
                if ((unsigned)(here.bits) <= bits) break;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1043
                PULLBYTE();
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1044
            }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1045
            if (here.op && (here.op & 0xf0) == 0) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1046
                last = here;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1047
                for (;;) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1048
                    here = state->lencode[last.val +
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1049
                            (BITS(last.bits + last.op) >> last.bits)];
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1050
                    if ((unsigned)(last.bits + here.bits) <= bits) break;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1051
                    PULLBYTE();
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1052
                }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1053
                DROPBITS(last.bits);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1054
                state->back += last.bits;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1055
            }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1056
            DROPBITS(here.bits);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1057
            state->back += here.bits;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1058
            state->length = (unsigned)here.val;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1059
            if ((int)(here.op) == 0) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1060
                Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1061
                        "inflate:         literal '%c'\n" :
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1062
                        "inflate:         literal 0x%02x\n", here.val));
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1063
                state->mode = LIT;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1064
                break;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1065
            }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1066
            if (here.op & 32) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1067
                Tracevv((stderr, "inflate:         end of block\n"));
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1068
                state->back = -1;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1069
                state->mode = TYPE;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1070
                break;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1071
            }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1072
            if (here.op & 64) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1073
                strm->msg = (char *)"invalid literal/length code";
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1074
                state->mode = BAD;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1075
                break;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1076
            }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1077
            state->extra = (unsigned)(here.op) & 15;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1078
            state->mode = LENEXT;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1079
        case LENEXT:
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1080
            if (state->extra) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1081
                NEEDBITS(state->extra);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1082
                state->length += BITS(state->extra);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1083
                DROPBITS(state->extra);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1084
                state->back += state->extra;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1085
            }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1086
            Tracevv((stderr, "inflate:         length %u\n", state->length));
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1087
            state->was = state->length;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1088
            state->mode = DIST;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1089
        case DIST:
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1090
            for (;;) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1091
                here = state->distcode[BITS(state->distbits)];
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1092
                if ((unsigned)(here.bits) <= bits) break;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1093
                PULLBYTE();
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1094
            }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1095
            if ((here.op & 0xf0) == 0) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1096
                last = here;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1097
                for (;;) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1098
                    here = state->distcode[last.val +
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1099
                            (BITS(last.bits + last.op) >> last.bits)];
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1100
                    if ((unsigned)(last.bits + here.bits) <= bits) break;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1101
                    PULLBYTE();
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1102
                }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1103
                DROPBITS(last.bits);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1104
                state->back += last.bits;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1105
            }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1106
            DROPBITS(here.bits);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1107
            state->back += here.bits;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1108
            if (here.op & 64) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1109
                strm->msg = (char *)"invalid distance code";
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1110
                state->mode = BAD;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1111
                break;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1112
            }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1113
            state->offset = (unsigned)here.val;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1114
            state->extra = (unsigned)(here.op) & 15;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1115
            state->mode = DISTEXT;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1116
        case DISTEXT:
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1117
            if (state->extra) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1118
                NEEDBITS(state->extra);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1119
                state->offset += BITS(state->extra);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1120
                DROPBITS(state->extra);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1121
                state->back += state->extra;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1122
            }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1123
#ifdef INFLATE_STRICT
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1124
            if (state->offset > state->dmax) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1125
                strm->msg = (char *)"invalid distance too far back";
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1126
                state->mode = BAD;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1127
                break;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1128
            }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1129
#endif
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1130
            Tracevv((stderr, "inflate:         distance %u\n", state->offset));
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1131
            state->mode = MATCH;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1132
        case MATCH:
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1133
            if (left == 0) goto inf_leave;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1134
            copy = out - left;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1135
            if (state->offset > copy) {         /* copy from window */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1136
                copy = state->offset - copy;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1137
                if (copy > state->whave) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1138
                    if (state->sane) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1139
                        strm->msg = (char *)"invalid distance too far back";
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1140
                        state->mode = BAD;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1141
                        break;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1142
                    }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1143
#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1144
                    Trace((stderr, "inflate.c too far\n"));
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1145
                    copy -= state->whave;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1146
                    if (copy > state->length) copy = state->length;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1147
                    if (copy > left) copy = left;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1148
                    left -= copy;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1149
                    state->length -= copy;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1150
                    do {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1151
                        *put++ = 0;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1152
                    } while (--copy);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1153
                    if (state->length == 0) state->mode = LEN;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1154
                    break;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1155
#endif
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1156
                }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1157
                if (copy > state->wnext) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1158
                    copy -= state->wnext;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1159
                    from = state->window + (state->wsize - copy);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1160
                }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1161
                else
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1162
                    from = state->window + (state->wnext - copy);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1163
                if (copy > state->length) copy = state->length;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1164
            }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1165
            else {                              /* copy from output */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1166
                from = put - state->offset;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1167
                copy = state->length;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1168
            }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1169
            if (copy > left) copy = left;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1170
            left -= copy;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1171
            state->length -= copy;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1172
            do {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1173
                *put++ = *from++;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1174
            } while (--copy);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1175
            if (state->length == 0) state->mode = LEN;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1176
            break;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1177
        case LIT:
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1178
            if (left == 0) goto inf_leave;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1179
            *put++ = (unsigned char)(state->length);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1180
            left--;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1181
            state->mode = LEN;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1182
            break;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1183
        case CHECK:
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1184
            if (state->wrap) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1185
                NEEDBITS(32);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1186
                out -= left;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1187
                strm->total_out += out;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1188
                state->total += out;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1189
                if (out)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1190
                    strm->adler = state->check =
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1191
                        UPDATE(state->check, put - out, out);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1192
                out = left;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1193
                if ((
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1194
#ifdef GUNZIP
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1195
                     state->flags ? hold :
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1196
#endif
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1197
                     REVERSE(hold)) != state->check) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1198
                    strm->msg = (char *)"incorrect data check";
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1199
                    state->mode = BAD;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1200
                    break;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1201
                }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1202
                INITBITS();
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1203
                Tracev((stderr, "inflate:   check matches trailer\n"));
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1204
            }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1205
#ifdef GUNZIP
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1206
            state->mode = LENGTH;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1207
        case LENGTH:
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1208
            if (state->wrap && state->flags) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1209
                NEEDBITS(32);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1210
                if (hold != (state->total & 0xffffffffUL)) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1211
                    strm->msg = (char *)"incorrect length check";
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1212
                    state->mode = BAD;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1213
                    break;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1214
                }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1215
                INITBITS();
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1216
                Tracev((stderr, "inflate:   length matches trailer\n"));
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1217
            }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1218
#endif
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1219
            state->mode = DONE;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1220
        case DONE:
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1221
            ret = Z_STREAM_END;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1222
            goto inf_leave;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1223
        case BAD:
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1224
            ret = Z_DATA_ERROR;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1225
            goto inf_leave;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1226
        case MEM:
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1227
            return Z_MEM_ERROR;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1228
        case SYNC:
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1229
        default:
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1230
            return Z_STREAM_ERROR;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1231
        }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1232
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1233
    /*
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1234
       Return from inflate(), updating the total counts and the check value.
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1235
       If there was no progress during the inflate() call, return a buffer
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1236
       error.  Call updatewindow() to create and/or update the window state.
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1237
       Note: a memory error from inflate() is non-recoverable.
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1238
     */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1239
  inf_leave:
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1240
    RESTORE();
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1241
    if (state->wsize || (state->mode < CHECK && out != strm->avail_out))
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1242
        if (updatewindow(strm, out)) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1243
            state->mode = MEM;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1244
            return Z_MEM_ERROR;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1245
        }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1246
    in -= strm->avail_in;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1247
    out -= strm->avail_out;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1248
    strm->total_in += in;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1249
    strm->total_out += out;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1250
    state->total += out;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1251
    if (state->wrap && out)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1252
        strm->adler = state->check =
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1253
            UPDATE(state->check, strm->next_out - out, out);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1254
    strm->data_type = state->bits + (state->last ? 64 : 0) +
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1255
                      (state->mode == TYPE ? 128 : 0) +
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1256
                      (state->mode == LEN_ || state->mode == COPY_ ? 256 : 0);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1257
    if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1258
        ret = Z_BUF_ERROR;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1259
    return ret;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1260
}
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1261
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1262
int ZEXPORT inflateEnd(strm)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1263
z_streamp strm;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1264
{
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1265
    struct inflate_state FAR *state;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1266
    if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1267
        return Z_STREAM_ERROR;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1268
    state = (struct inflate_state FAR *)strm->state;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1269
    if (state->window != Z_NULL) ZFREE(strm, state->window);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1270
    ZFREE(strm, strm->state);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1271
    strm->state = Z_NULL;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1272
    Tracev((stderr, "inflate: end\n"));
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1273
    return Z_OK;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1274
}
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1275
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1276
int ZEXPORT inflateSetDictionary(strm, dictionary, dictLength)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1277
z_streamp strm;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1278
const Bytef *dictionary;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1279
uInt dictLength;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1280
{
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1281
    struct inflate_state FAR *state;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1282
    unsigned long id;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1283
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1284
    /* check state */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1285
    if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1286
    state = (struct inflate_state FAR *)strm->state;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1287
    if (state->wrap != 0 && state->mode != DICT)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1288
        return Z_STREAM_ERROR;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1289
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1290
    /* check for correct dictionary id */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1291
    if (state->mode == DICT) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1292
        id = adler32(0L, Z_NULL, 0);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1293
        id = adler32(id, dictionary, dictLength);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1294
        if (id != state->check)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1295
            return Z_DATA_ERROR;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1296
    }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1297
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1298
    /* copy dictionary to window */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1299
    if (updatewindow(strm, strm->avail_out)) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1300
        state->mode = MEM;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1301
        return Z_MEM_ERROR;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1302
    }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1303
    if (dictLength > state->wsize) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1304
        zmemcpy(state->window, dictionary + dictLength - state->wsize,
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1305
                state->wsize);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1306
        state->whave = state->wsize;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1307
    }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1308
    else {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1309
        zmemcpy(state->window + state->wsize - dictLength, dictionary,
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1310
                dictLength);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1311
        state->whave = dictLength;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1312
    }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1313
    state->havedict = 1;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1314
    Tracev((stderr, "inflate:   dictionary set\n"));
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1315
    return Z_OK;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1316
}
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1317
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1318
int ZEXPORT inflateGetHeader(strm, head)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1319
z_streamp strm;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1320
gz_headerp head;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1321
{
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1322
    struct inflate_state FAR *state;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1323
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1324
    /* check state */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1325
    if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1326
    state = (struct inflate_state FAR *)strm->state;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1327
    if ((state->wrap & 2) == 0) return Z_STREAM_ERROR;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1328
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1329
    /* save header structure */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1330
    state->head = head;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1331
    head->done = 0;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1332
    return Z_OK;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1333
}
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1334
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1335
/*
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1336
   Search buf[0..len-1] for the pattern: 0, 0, 0xff, 0xff.  Return when found
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1337
   or when out of input.  When called, *have is the number of pattern bytes
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1338
   found in order so far, in 0..3.  On return *have is updated to the new
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1339
   state.  If on return *have equals four, then the pattern was found and the
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1340
   return value is how many bytes were read including the last byte of the
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1341
   pattern.  If *have is less than four, then the pattern has not been found
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1342
   yet and the return value is len.  In the latter case, syncsearch() can be
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1343
   called again with more data and the *have state.  *have is initialized to
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1344
   zero for the first call.
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1345
 */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1346
local unsigned syncsearch(have, buf, len)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1347
unsigned FAR *have;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1348
unsigned char FAR *buf;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1349
unsigned len;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1350
{
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1351
    unsigned got;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1352
    unsigned next;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1353
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1354
    got = *have;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1355
    next = 0;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1356
    while (next < len && got < 4) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1357
        if ((int)(buf[next]) == (got < 2 ? 0 : 0xff))
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1358
            got++;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1359
        else if (buf[next])
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1360
            got = 0;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1361
        else
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1362
            got = 4 - got;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1363
        next++;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1364
    }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1365
    *have = got;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1366
    return next;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1367
}
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1368
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1369
int ZEXPORT inflateSync(strm)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1370
z_streamp strm;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1371
{
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1372
    unsigned len;               /* number of bytes to look at or looked at */
13409
fe3ab27ef1a6 7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents: 11112
diff changeset
  1373
    unsigned long in, out;      /* temporary to save total_in and total_out */
11112
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1374
    unsigned char buf[4];       /* to restore bit buffer to byte string */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1375
    struct inflate_state FAR *state;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1376
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1377
    /* check parameters */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1378
    if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1379
    state = (struct inflate_state FAR *)strm->state;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1380
    if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1381
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1382
    /* if first time, start search in bit buffer */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1383
    if (state->mode != SYNC) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1384
        state->mode = SYNC;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1385
        state->hold <<= state->bits & 7;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1386
        state->bits -= state->bits & 7;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1387
        len = 0;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1388
        while (state->bits >= 8) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1389
            buf[len++] = (unsigned char)(state->hold);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1390
            state->hold >>= 8;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1391
            state->bits -= 8;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1392
        }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1393
        state->have = 0;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1394
        syncsearch(&(state->have), buf, len);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1395
    }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1396
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1397
    /* search available input */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1398
    len = syncsearch(&(state->have), strm->next_in, strm->avail_in);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1399
    strm->avail_in -= len;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1400
    strm->next_in += len;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1401
    strm->total_in += len;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1402
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1403
    /* return no joy or set up to restart inflate() on a new block */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1404
    if (state->have != 4) return Z_DATA_ERROR;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1405
    in = strm->total_in;  out = strm->total_out;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1406
    inflateReset(strm);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1407
    strm->total_in = in;  strm->total_out = out;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1408
    state->mode = TYPE;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1409
    return Z_OK;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1410
}
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1411
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1412
/*
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1413
   Returns true if inflate is currently at the end of a block generated by
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1414
   Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1415
   implementation to provide an additional safety check. PPP uses
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1416
   Z_SYNC_FLUSH but removes the length bytes of the resulting empty stored
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1417
   block. When decompressing, PPP checks that at the end of input packet,
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1418
   inflate is waiting for these length bytes.
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1419
 */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1420
int ZEXPORT inflateSyncPoint(strm)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1421
z_streamp strm;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1422
{
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1423
    struct inflate_state FAR *state;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1424
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1425
    if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1426
    state = (struct inflate_state FAR *)strm->state;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1427
    return state->mode == STORED && state->bits == 0;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1428
}
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1429
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1430
int ZEXPORT inflateCopy(dest, source)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1431
z_streamp dest;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1432
z_streamp source;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1433
{
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1434
    struct inflate_state FAR *state;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1435
    struct inflate_state FAR *copy;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1436
    unsigned char FAR *window;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1437
    unsigned wsize;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1438
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1439
    /* check input */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1440
    if (dest == Z_NULL || source == Z_NULL || source->state == Z_NULL ||
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1441
        source->zalloc == (alloc_func)0 || source->zfree == (free_func)0)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1442
        return Z_STREAM_ERROR;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1443
    state = (struct inflate_state FAR *)source->state;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1444
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1445
    /* allocate space */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1446
    copy = (struct inflate_state FAR *)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1447
           ZALLOC(source, 1, sizeof(struct inflate_state));
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1448
    if (copy == Z_NULL) return Z_MEM_ERROR;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1449
    window = Z_NULL;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1450
    if (state->window != Z_NULL) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1451
        window = (unsigned char FAR *)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1452
                 ZALLOC(source, 1U << state->wbits, sizeof(unsigned char));
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1453
        if (window == Z_NULL) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1454
            ZFREE(source, copy);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1455
            return Z_MEM_ERROR;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1456
        }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1457
    }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1458
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1459
    /* copy state */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1460
    zmemcpy(dest, source, sizeof(z_stream));
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1461
    zmemcpy(copy, state, sizeof(struct inflate_state));
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1462
    if (state->lencode >= state->codes &&
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1463
        state->lencode <= state->codes + ENOUGH - 1) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1464
        copy->lencode = copy->codes + (state->lencode - state->codes);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1465
        copy->distcode = copy->codes + (state->distcode - state->codes);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1466
    }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1467
    copy->next = copy->codes + (state->next - state->codes);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1468
    if (window != Z_NULL) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1469
        wsize = 1U << state->wbits;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1470
        zmemcpy(window, state->window, wsize);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1471
    }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1472
    copy->window = window;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1473
    dest->state = (struct internal_state FAR *)copy;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1474
    return Z_OK;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1475
}
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1476
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1477
int ZEXPORT inflateUndermine(strm, subvert)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1478
z_streamp strm;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1479
int subvert;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1480
{
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1481
    struct inflate_state FAR *state;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1482
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1483
    if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1484
    state = (struct inflate_state FAR *)strm->state;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1485
    state->sane = !subvert;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1486
#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1487
    return Z_OK;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1488
#else
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1489
    state->sane = 1;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1490
    return Z_DATA_ERROR;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1491
#endif
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1492
}
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1493
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1494
long ZEXPORT inflateMark(strm)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1495
z_streamp strm;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1496
{
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1497
    struct inflate_state FAR *state;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1498
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1499
    if (strm == Z_NULL || strm->state == Z_NULL) return -1L << 16;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1500
    state = (struct inflate_state FAR *)strm->state;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1501
    return ((long)(state->back) << 16) +
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1502
        (state->mode == COPY ? state->length :
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1503
            (state->mode == MATCH ? state->was - state->length : 0));
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
  1504
}