jdk/src/java.base/share/native/libzip/zlib/gzread.c
author sherman
Wed, 15 Feb 2017 22:50:35 -0800
changeset 43810 a8fca792a14b
permissions -rw-r--r--
8175053: March 5 builds failed on Windows/install repo after JDK-8173207 Reviewed-by: mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
43810
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
     1
/*
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
     2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
     3
 *
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
     4
 * This code is free software; you can redistribute it and/or modify it
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
     5
 * under the terms of the GNU General Public License version 2 only, as
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
     6
 * published by the Free Software Foundation.  Oracle designates this
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
     7
 * particular file as subject to the "Classpath" exception as provided
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
     8
 * by Oracle in the LICENSE file that accompanied this code.
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
     9
 *
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    14
 * accompanied this code).
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    15
 *
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    19
 *
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    22
 * questions.
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    23
 */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    24
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    25
/* gzread.c -- zlib functions for reading gzip files
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    26
 * Copyright (C) 2004, 2005, 2010, 2011, 2012, 2013, 2016 Mark Adler
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    27
 * For conditions of distribution and use, see copyright notice in zlib.h
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    28
 */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    29
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    30
#include "gzguts.h"
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    31
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    32
/* Local functions */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    33
local int gz_load OF((gz_statep, unsigned char *, unsigned, unsigned *));
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    34
local int gz_avail OF((gz_statep));
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    35
local int gz_look OF((gz_statep));
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    36
local int gz_decomp OF((gz_statep));
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    37
local int gz_fetch OF((gz_statep));
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    38
local int gz_skip OF((gz_statep, z_off64_t));
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    39
local z_size_t gz_read OF((gz_statep, voidp, z_size_t));
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    40
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    41
/* Use read() to load a buffer -- return -1 on error, otherwise 0.  Read from
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    42
   state->fd, and update state->eof, state->err, and state->msg as appropriate.
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    43
   This function needs to loop on read(), since read() is not guaranteed to
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    44
   read the number of bytes requested, depending on the type of descriptor. */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    45
local int gz_load(state, buf, len, have)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    46
    gz_statep state;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    47
    unsigned char *buf;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    48
    unsigned len;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    49
    unsigned *have;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    50
{
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    51
    int ret;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    52
    unsigned get, max = ((unsigned)-1 >> 2) + 1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    53
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    54
    *have = 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    55
    do {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    56
        get = len - *have;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    57
        if (get > max)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    58
            get = max;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    59
        ret = read(state->fd, buf + *have, get);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    60
        if (ret <= 0)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    61
            break;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    62
        *have += (unsigned)ret;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    63
    } while (*have < len);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    64
    if (ret < 0) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    65
        gz_error(state, Z_ERRNO, zstrerror());
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    66
        return -1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    67
    }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    68
    if (ret == 0)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    69
        state->eof = 1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    70
    return 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    71
}
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    72
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    73
/* Load up input buffer and set eof flag if last data loaded -- return -1 on
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    74
   error, 0 otherwise.  Note that the eof flag is set when the end of the input
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    75
   file is reached, even though there may be unused data in the buffer.  Once
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    76
   that data has been used, no more attempts will be made to read the file.
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    77
   If strm->avail_in != 0, then the current data is moved to the beginning of
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    78
   the input buffer, and then the remainder of the buffer is loaded with the
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    79
   available data from the input file. */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    80
local int gz_avail(state)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    81
    gz_statep state;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    82
{
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    83
    unsigned got;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    84
    z_streamp strm = &(state->strm);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    85
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    86
    if (state->err != Z_OK && state->err != Z_BUF_ERROR)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    87
        return -1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    88
    if (state->eof == 0) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    89
        if (strm->avail_in) {       /* copy what's there to the start */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    90
            unsigned char *p = state->in;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    91
            unsigned const char *q = strm->next_in;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    92
            unsigned n = strm->avail_in;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    93
            do {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    94
                *p++ = *q++;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    95
            } while (--n);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    96
        }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    97
        if (gz_load(state, state->in + strm->avail_in,
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    98
                    state->size - strm->avail_in, &got) == -1)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    99
            return -1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   100
        strm->avail_in += got;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   101
        strm->next_in = state->in;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   102
    }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   103
    return 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   104
}
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   105
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   106
/* Look for gzip header, set up for inflate or copy.  state->x.have must be 0.
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   107
   If this is the first time in, allocate required memory.  state->how will be
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   108
   left unchanged if there is no more input data available, will be set to COPY
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   109
   if there is no gzip header and direct copying will be performed, or it will
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   110
   be set to GZIP for decompression.  If direct copying, then leftover input
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   111
   data from the input buffer will be copied to the output buffer.  In that
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   112
   case, all further file reads will be directly to either the output buffer or
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   113
   a user buffer.  If decompressing, the inflate state will be initialized.
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   114
   gz_look() will return 0 on success or -1 on failure. */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   115
local int gz_look(state)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   116
    gz_statep state;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   117
{
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   118
    z_streamp strm = &(state->strm);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   119
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   120
    /* allocate read buffers and inflate memory */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   121
    if (state->size == 0) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   122
        /* allocate buffers */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   123
        state->in = (unsigned char *)malloc(state->want);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   124
        state->out = (unsigned char *)malloc(state->want << 1);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   125
        if (state->in == NULL || state->out == NULL) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   126
            free(state->out);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   127
            free(state->in);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   128
            gz_error(state, Z_MEM_ERROR, "out of memory");
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   129
            return -1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   130
        }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   131
        state->size = state->want;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   132
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   133
        /* allocate inflate memory */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   134
        state->strm.zalloc = Z_NULL;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   135
        state->strm.zfree = Z_NULL;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   136
        state->strm.opaque = Z_NULL;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   137
        state->strm.avail_in = 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   138
        state->strm.next_in = Z_NULL;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   139
        if (inflateInit2(&(state->strm), 15 + 16) != Z_OK) {    /* gunzip */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   140
            free(state->out);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   141
            free(state->in);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   142
            state->size = 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   143
            gz_error(state, Z_MEM_ERROR, "out of memory");
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   144
            return -1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   145
        }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   146
    }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   147
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   148
    /* get at least the magic bytes in the input buffer */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   149
    if (strm->avail_in < 2) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   150
        if (gz_avail(state) == -1)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   151
            return -1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   152
        if (strm->avail_in == 0)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   153
            return 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   154
    }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   155
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   156
    /* look for gzip magic bytes -- if there, do gzip decoding (note: there is
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   157
       a logical dilemma here when considering the case of a partially written
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   158
       gzip file, to wit, if a single 31 byte is written, then we cannot tell
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   159
       whether this is a single-byte file, or just a partially written gzip
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   160
       file -- for here we assume that if a gzip file is being written, then
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   161
       the header will be written in a single operation, so that reading a
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   162
       single byte is sufficient indication that it is not a gzip file) */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   163
    if (strm->avail_in > 1 &&
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   164
            strm->next_in[0] == 31 && strm->next_in[1] == 139) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   165
        inflateReset(strm);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   166
        state->how = GZIP;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   167
        state->direct = 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   168
        return 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   169
    }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   170
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   171
    /* no gzip header -- if we were decoding gzip before, then this is trailing
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   172
       garbage.  Ignore the trailing garbage and finish. */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   173
    if (state->direct == 0) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   174
        strm->avail_in = 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   175
        state->eof = 1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   176
        state->x.have = 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   177
        return 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   178
    }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   179
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   180
    /* doing raw i/o, copy any leftover input to output -- this assumes that
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   181
       the output buffer is larger than the input buffer, which also assures
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   182
       space for gzungetc() */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   183
    state->x.next = state->out;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   184
    if (strm->avail_in) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   185
        memcpy(state->x.next, strm->next_in, strm->avail_in);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   186
        state->x.have = strm->avail_in;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   187
        strm->avail_in = 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   188
    }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   189
    state->how = COPY;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   190
    state->direct = 1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   191
    return 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   192
}
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   193
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   194
/* Decompress from input to the provided next_out and avail_out in the state.
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   195
   On return, state->x.have and state->x.next point to the just decompressed
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   196
   data.  If the gzip stream completes, state->how is reset to LOOK to look for
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   197
   the next gzip stream or raw data, once state->x.have is depleted.  Returns 0
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   198
   on success, -1 on failure. */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   199
local int gz_decomp(state)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   200
    gz_statep state;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   201
{
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   202
    int ret = Z_OK;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   203
    unsigned had;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   204
    z_streamp strm = &(state->strm);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   205
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   206
    /* fill output buffer up to end of deflate stream */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   207
    had = strm->avail_out;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   208
    do {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   209
        /* get more input for inflate() */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   210
        if (strm->avail_in == 0 && gz_avail(state) == -1)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   211
            return -1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   212
        if (strm->avail_in == 0) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   213
            gz_error(state, Z_BUF_ERROR, "unexpected end of file");
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   214
            break;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   215
        }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   216
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   217
        /* decompress and handle errors */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   218
        ret = inflate(strm, Z_NO_FLUSH);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   219
        if (ret == Z_STREAM_ERROR || ret == Z_NEED_DICT) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   220
            gz_error(state, Z_STREAM_ERROR,
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   221
                     "internal error: inflate stream corrupt");
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   222
            return -1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   223
        }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   224
        if (ret == Z_MEM_ERROR) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   225
            gz_error(state, Z_MEM_ERROR, "out of memory");
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   226
            return -1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   227
        }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   228
        if (ret == Z_DATA_ERROR) {              /* deflate stream invalid */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   229
            gz_error(state, Z_DATA_ERROR,
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   230
                     strm->msg == NULL ? "compressed data error" : strm->msg);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   231
            return -1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   232
        }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   233
    } while (strm->avail_out && ret != Z_STREAM_END);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   234
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   235
    /* update available output */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   236
    state->x.have = had - strm->avail_out;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   237
    state->x.next = strm->next_out - state->x.have;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   238
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   239
    /* if the gzip stream completed successfully, look for another */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   240
    if (ret == Z_STREAM_END)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   241
        state->how = LOOK;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   242
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   243
    /* good decompression */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   244
    return 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   245
}
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   246
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   247
/* Fetch data and put it in the output buffer.  Assumes state->x.have is 0.
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   248
   Data is either copied from the input file or decompressed from the input
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   249
   file depending on state->how.  If state->how is LOOK, then a gzip header is
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   250
   looked for to determine whether to copy or decompress.  Returns -1 on error,
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   251
   otherwise 0.  gz_fetch() will leave state->how as COPY or GZIP unless the
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   252
   end of the input file has been reached and all data has been processed.  */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   253
local int gz_fetch(state)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   254
    gz_statep state;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   255
{
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   256
    z_streamp strm = &(state->strm);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   257
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   258
    do {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   259
        switch(state->how) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   260
        case LOOK:      /* -> LOOK, COPY (only if never GZIP), or GZIP */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   261
            if (gz_look(state) == -1)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   262
                return -1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   263
            if (state->how == LOOK)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   264
                return 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   265
            break;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   266
        case COPY:      /* -> COPY */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   267
            if (gz_load(state, state->out, state->size << 1, &(state->x.have))
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   268
                    == -1)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   269
                return -1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   270
            state->x.next = state->out;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   271
            return 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   272
        case GZIP:      /* -> GZIP or LOOK (if end of gzip stream) */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   273
            strm->avail_out = state->size << 1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   274
            strm->next_out = state->out;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   275
            if (gz_decomp(state) == -1)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   276
                return -1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   277
        }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   278
    } while (state->x.have == 0 && (!state->eof || strm->avail_in));
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   279
    return 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   280
}
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   281
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   282
/* Skip len uncompressed bytes of output.  Return -1 on error, 0 on success. */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   283
local int gz_skip(state, len)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   284
    gz_statep state;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   285
    z_off64_t len;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   286
{
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   287
    unsigned n;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   288
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   289
    /* skip over len bytes or reach end-of-file, whichever comes first */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   290
    while (len)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   291
        /* skip over whatever is in output buffer */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   292
        if (state->x.have) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   293
            n = GT_OFF(state->x.have) || (z_off64_t)state->x.have > len ?
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   294
                (unsigned)len : state->x.have;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   295
            state->x.have -= n;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   296
            state->x.next += n;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   297
            state->x.pos += n;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   298
            len -= n;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   299
        }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   300
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   301
        /* output buffer empty -- return if we're at the end of the input */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   302
        else if (state->eof && state->strm.avail_in == 0)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   303
            break;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   304
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   305
        /* need more data to skip -- load up output buffer */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   306
        else {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   307
            /* get more output, looking for header if required */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   308
            if (gz_fetch(state) == -1)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   309
                return -1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   310
        }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   311
    return 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   312
}
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   313
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   314
/* Read len bytes into buf from file, or less than len up to the end of the
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   315
   input.  Return the number of bytes read.  If zero is returned, either the
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   316
   end of file was reached, or there was an error.  state->err must be
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   317
   consulted in that case to determine which. */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   318
local z_size_t gz_read(state, buf, len)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   319
    gz_statep state;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   320
    voidp buf;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   321
    z_size_t len;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   322
{
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   323
    z_size_t got;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   324
    unsigned n;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   325
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   326
    /* if len is zero, avoid unnecessary operations */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   327
    if (len == 0)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   328
        return 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   329
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   330
    /* process a skip request */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   331
    if (state->seek) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   332
        state->seek = 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   333
        if (gz_skip(state, state->skip) == -1)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   334
            return 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   335
    }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   336
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   337
    /* get len bytes to buf, or less than len if at the end */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   338
    got = 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   339
    do {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   340
        /* set n to the maximum amount of len that fits in an unsigned int */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   341
        n = -1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   342
        if (n > len)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   343
            n = (unsigned)len;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   344
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   345
        /* first just try copying data from the output buffer */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   346
        if (state->x.have) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   347
            if (state->x.have < n)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   348
                n = state->x.have;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   349
            memcpy(buf, state->x.next, n);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   350
            state->x.next += n;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   351
            state->x.have -= n;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   352
        }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   353
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   354
        /* output buffer empty -- return if we're at the end of the input */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   355
        else if (state->eof && state->strm.avail_in == 0) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   356
            state->past = 1;        /* tried to read past end */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   357
            break;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   358
        }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   359
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   360
        /* need output data -- for small len or new stream load up our output
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   361
           buffer */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   362
        else if (state->how == LOOK || n < (state->size << 1)) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   363
            /* get more output, looking for header if required */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   364
            if (gz_fetch(state) == -1)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   365
                return 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   366
            continue;       /* no progress yet -- go back to copy above */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   367
            /* the copy above assures that we will leave with space in the
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   368
               output buffer, allowing at least one gzungetc() to succeed */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   369
        }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   370
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   371
        /* large len -- read directly into user buffer */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   372
        else if (state->how == COPY) {      /* read directly */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   373
            if (gz_load(state, (unsigned char *)buf, n, &n) == -1)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   374
                return 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   375
        }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   376
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   377
        /* large len -- decompress directly into user buffer */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   378
        else {  /* state->how == GZIP */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   379
            state->strm.avail_out = n;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   380
            state->strm.next_out = (unsigned char *)buf;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   381
            if (gz_decomp(state) == -1)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   382
                return 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   383
            n = state->x.have;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   384
            state->x.have = 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   385
        }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   386
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   387
        /* update progress */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   388
        len -= n;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   389
        buf = (char *)buf + n;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   390
        got += n;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   391
        state->x.pos += n;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   392
    } while (len);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   393
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   394
    /* return number of bytes read into user buffer */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   395
    return got;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   396
}
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   397
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   398
/* -- see zlib.h -- */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   399
int ZEXPORT gzread(file, buf, len)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   400
    gzFile file;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   401
    voidp buf;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   402
    unsigned len;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   403
{
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   404
    gz_statep state;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   405
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   406
    /* get internal structure */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   407
    if (file == NULL)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   408
        return -1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   409
    state = (gz_statep)file;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   410
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   411
    /* check that we're reading and that there's no (serious) error */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   412
    if (state->mode != GZ_READ ||
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   413
            (state->err != Z_OK && state->err != Z_BUF_ERROR))
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   414
        return -1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   415
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   416
    /* since an int is returned, make sure len fits in one, otherwise return
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   417
       with an error (this avoids a flaw in the interface) */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   418
    if ((int)len < 0) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   419
        gz_error(state, Z_STREAM_ERROR, "request does not fit in an int");
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   420
        return -1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   421
    }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   422
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   423
    /* read len or fewer bytes to buf */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   424
    len = (unsigned)gz_read(state, buf, len);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   425
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   426
    /* check for an error */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   427
    if (len == 0 && state->err != Z_OK && state->err != Z_BUF_ERROR)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   428
        return -1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   429
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   430
    /* return the number of bytes read (this is assured to fit in an int) */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   431
    return (int)len;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   432
}
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   433
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   434
/* -- see zlib.h -- */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   435
z_size_t ZEXPORT gzfread(buf, size, nitems, file)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   436
    voidp buf;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   437
    z_size_t size;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   438
    z_size_t nitems;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   439
    gzFile file;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   440
{
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   441
    z_size_t len;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   442
    gz_statep state;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   443
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   444
    /* get internal structure */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   445
    if (file == NULL)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   446
        return 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   447
    state = (gz_statep)file;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   448
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   449
    /* check that we're reading and that there's no (serious) error */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   450
    if (state->mode != GZ_READ ||
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   451
            (state->err != Z_OK && state->err != Z_BUF_ERROR))
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   452
        return 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   453
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   454
    /* compute bytes to read -- error on overflow */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   455
    len = nitems * size;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   456
    if (size && len / size != nitems) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   457
        gz_error(state, Z_STREAM_ERROR, "request does not fit in a size_t");
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   458
        return 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   459
    }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   460
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   461
    /* read len or fewer bytes to buf, return the number of full items read */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   462
    return len ? gz_read(state, buf, len) / size : 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   463
}
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   464
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   465
/* -- see zlib.h -- */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   466
#ifdef Z_PREFIX_SET
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   467
#  undef z_gzgetc
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   468
#else
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   469
#  undef gzgetc
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   470
#endif
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   471
int ZEXPORT gzgetc(file)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   472
    gzFile file;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   473
{
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   474
    int ret;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   475
    unsigned char buf[1];
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   476
    gz_statep state;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   477
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   478
    /* get internal structure */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   479
    if (file == NULL)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   480
        return -1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   481
    state = (gz_statep)file;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   482
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   483
    /* check that we're reading and that there's no (serious) error */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   484
    if (state->mode != GZ_READ ||
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   485
        (state->err != Z_OK && state->err != Z_BUF_ERROR))
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   486
        return -1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   487
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   488
    /* try output buffer (no need to check for skip request) */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   489
    if (state->x.have) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   490
        state->x.have--;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   491
        state->x.pos++;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   492
        return *(state->x.next)++;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   493
    }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   494
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   495
    /* nothing there -- try gz_read() */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   496
    ret = (int)gz_read(state, buf, 1);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   497
    return ret < 1 ? -1 : buf[0];
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   498
}
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   499
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   500
int ZEXPORT gzgetc_(file)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   501
gzFile file;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   502
{
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   503
    return gzgetc(file);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   504
}
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   505
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   506
/* -- see zlib.h -- */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   507
int ZEXPORT gzungetc(c, file)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   508
    int c;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   509
    gzFile file;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   510
{
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   511
    gz_statep state;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   512
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   513
    /* get internal structure */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   514
    if (file == NULL)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   515
        return -1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   516
    state = (gz_statep)file;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   517
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   518
    /* check that we're reading and that there's no (serious) error */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   519
    if (state->mode != GZ_READ ||
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   520
        (state->err != Z_OK && state->err != Z_BUF_ERROR))
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   521
        return -1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   522
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   523
    /* process a skip request */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   524
    if (state->seek) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   525
        state->seek = 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   526
        if (gz_skip(state, state->skip) == -1)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   527
            return -1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   528
    }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   529
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   530
    /* can't push EOF */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   531
    if (c < 0)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   532
        return -1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   533
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   534
    /* if output buffer empty, put byte at end (allows more pushing) */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   535
    if (state->x.have == 0) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   536
        state->x.have = 1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   537
        state->x.next = state->out + (state->size << 1) - 1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   538
        state->x.next[0] = (unsigned char)c;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   539
        state->x.pos--;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   540
        state->past = 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   541
        return c;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   542
    }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   543
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   544
    /* if no room, give up (must have already done a gzungetc()) */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   545
    if (state->x.have == (state->size << 1)) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   546
        gz_error(state, Z_DATA_ERROR, "out of room to push characters");
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   547
        return -1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   548
    }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   549
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   550
    /* slide output data if needed and insert byte before existing data */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   551
    if (state->x.next == state->out) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   552
        unsigned char *src = state->out + state->x.have;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   553
        unsigned char *dest = state->out + (state->size << 1);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   554
        while (src > state->out)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   555
            *--dest = *--src;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   556
        state->x.next = dest;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   557
    }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   558
    state->x.have++;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   559
    state->x.next--;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   560
    state->x.next[0] = (unsigned char)c;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   561
    state->x.pos--;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   562
    state->past = 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   563
    return c;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   564
}
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   565
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   566
/* -- see zlib.h -- */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   567
char * ZEXPORT gzgets(file, buf, len)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   568
    gzFile file;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   569
    char *buf;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   570
    int len;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   571
{
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   572
    unsigned left, n;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   573
    char *str;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   574
    unsigned char *eol;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   575
    gz_statep state;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   576
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   577
    /* check parameters and get internal structure */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   578
    if (file == NULL || buf == NULL || len < 1)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   579
        return NULL;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   580
    state = (gz_statep)file;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   581
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   582
    /* check that we're reading and that there's no (serious) error */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   583
    if (state->mode != GZ_READ ||
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   584
        (state->err != Z_OK && state->err != Z_BUF_ERROR))
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   585
        return NULL;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   586
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   587
    /* process a skip request */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   588
    if (state->seek) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   589
        state->seek = 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   590
        if (gz_skip(state, state->skip) == -1)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   591
            return NULL;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   592
    }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   593
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   594
    /* copy output bytes up to new line or len - 1, whichever comes first --
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   595
       append a terminating zero to the string (we don't check for a zero in
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   596
       the contents, let the user worry about that) */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   597
    str = buf;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   598
    left = (unsigned)len - 1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   599
    if (left) do {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   600
        /* assure that something is in the output buffer */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   601
        if (state->x.have == 0 && gz_fetch(state) == -1)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   602
            return NULL;                /* error */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   603
        if (state->x.have == 0) {       /* end of file */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   604
            state->past = 1;            /* read past end */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   605
            break;                      /* return what we have */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   606
        }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   607
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   608
        /* look for end-of-line in current output buffer */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   609
        n = state->x.have > left ? left : state->x.have;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   610
        eol = (unsigned char *)memchr(state->x.next, '\n', n);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   611
        if (eol != NULL)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   612
            n = (unsigned)(eol - state->x.next) + 1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   613
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   614
        /* copy through end-of-line, or remainder if not found */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   615
        memcpy(buf, state->x.next, n);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   616
        state->x.have -= n;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   617
        state->x.next += n;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   618
        state->x.pos += n;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   619
        left -= n;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   620
        buf += n;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   621
    } while (left && eol == NULL);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   622
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   623
    /* return terminated string, or if nothing, end of file */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   624
    if (buf == str)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   625
        return NULL;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   626
    buf[0] = 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   627
    return str;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   628
}
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   629
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   630
/* -- see zlib.h -- */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   631
int ZEXPORT gzdirect(file)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   632
    gzFile file;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   633
{
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   634
    gz_statep state;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   635
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   636
    /* get internal structure */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   637
    if (file == NULL)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   638
        return 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   639
    state = (gz_statep)file;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   640
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   641
    /* if the state is not known, but we can find out, then do so (this is
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   642
       mainly for right after a gzopen() or gzdopen()) */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   643
    if (state->mode == GZ_READ && state->how == LOOK && state->x.have == 0)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   644
        (void)gz_look(state);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   645
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   646
    /* return 1 if transparent, 0 if processing a gzip stream */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   647
    return state->direct;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   648
}
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   649
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   650
/* -- see zlib.h -- */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   651
int ZEXPORT gzclose_r(file)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   652
    gzFile file;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   653
{
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   654
    int ret, err;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   655
    gz_statep state;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   656
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   657
    /* get internal structure */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   658
    if (file == NULL)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   659
        return Z_STREAM_ERROR;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   660
    state = (gz_statep)file;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   661
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   662
    /* check that we're reading */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   663
    if (state->mode != GZ_READ)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   664
        return Z_STREAM_ERROR;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   665
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   666
    /* free memory and close file */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   667
    if (state->size) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   668
        inflateEnd(&(state->strm));
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   669
        free(state->out);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   670
        free(state->in);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   671
    }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   672
    err = state->err == Z_BUF_ERROR ? Z_BUF_ERROR : Z_OK;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   673
    gz_error(state, Z_OK, NULL);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   674
    free(state->path);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   675
    ret = close(state->fd);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   676
    free(state);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   677
    return ret ? Z_ERRNO : err;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   678
}