jdk/src/share/native/java/util/zip/zlib-1.1.3/uncompr.c
changeset 3713 3f49733cf145
parent 3637 84b603d2b088
parent 3712 8851d55adef0
child 3714 6a4eb8f53f91
child 4197 f6266efbfc05
equal deleted inserted replaced
3637:84b603d2b088 3713:3f49733cf145
     1 /*
       
     2  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     3  *
       
     4  * This code is free software; you can redistribute it and/or modify it
       
     5  * under the terms of the GNU General Public License version 2 only, as
       
     6  * published by the Free Software Foundation.  Sun designates this
       
     7  * particular file as subject to the "Classpath" exception as provided
       
     8  * by Sun in the LICENSE file that accompanied this code.
       
     9  *
       
    10  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    13  * version 2 for more details (a copy is included in the LICENSE file that
       
    14  * accompanied this code).
       
    15  *
       
    16  * You should have received a copy of the GNU General Public License version
       
    17  * 2 along with this work; if not, write to the Free Software Foundation,
       
    18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    19  *
       
    20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
       
    21  * CA 95054 USA or visit www.sun.com if you need additional information or
       
    22  * have any questions.
       
    23  */
       
    24 
       
    25 /*
       
    26  * This file is available under and governed by the GNU General Public
       
    27  * License version 2 only, as published by the Free Software Foundation.
       
    28  * However, the following notice accompanied the original version of this
       
    29  * file and, per its terms, should not be removed:
       
    30  *
       
    31  * uncompr.c -- decompress a memory buffer
       
    32  * Copyright (C) 1995-1998 Jean-loup Gailly.
       
    33  * For conditions of distribution and use, see copyright notice in zlib.h
       
    34  */
       
    35 
       
    36 #include "zlib.h"
       
    37 
       
    38 /* ===========================================================================
       
    39      Decompresses the source buffer into the destination buffer.  sourceLen is
       
    40    the byte length of the source buffer. Upon entry, destLen is the total
       
    41    size of the destination buffer, which must be large enough to hold the
       
    42    entire uncompressed data. (The size of the uncompressed data must have
       
    43    been saved previously by the compressor and transmitted to the decompressor
       
    44    by some mechanism outside the scope of this compression library.)
       
    45    Upon exit, destLen is the actual size of the compressed buffer.
       
    46      This function can be used to decompress a whole file at once if the
       
    47    input file is mmap'ed.
       
    48 
       
    49      uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
       
    50    enough memory, Z_BUF_ERROR if there was not enough room in the output
       
    51    buffer, or Z_DATA_ERROR if the input data was corrupted.
       
    52 */
       
    53 int ZEXPORT uncompress (dest, destLen, source, sourceLen)
       
    54     Bytef *dest;
       
    55     uLongf *destLen;
       
    56     const Bytef *source;
       
    57     uLong sourceLen;
       
    58 {
       
    59     z_stream stream;
       
    60     int err;
       
    61 
       
    62     stream.next_in = (Bytef*)source;
       
    63     stream.avail_in = (uInt)sourceLen;
       
    64     /* Check for source > 64K on 16-bit machine: */
       
    65     if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
       
    66 
       
    67     stream.next_out = dest;
       
    68     stream.avail_out = (uInt)*destLen;
       
    69     if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
       
    70 
       
    71     stream.zalloc = (alloc_func)0;
       
    72     stream.zfree = (free_func)0;
       
    73 
       
    74     err = inflateInit(&stream);
       
    75     if (err != Z_OK) return err;
       
    76 
       
    77     err = inflate(&stream, Z_FINISH);
       
    78     if (err != Z_STREAM_END) {
       
    79         inflateEnd(&stream);
       
    80         return err == Z_OK ? Z_BUF_ERROR : err;
       
    81     }
       
    82     *destLen = stream.total_out;
       
    83 
       
    84     err = inflateEnd(&stream);
       
    85     return err;
       
    86 }