jdk/src/java.base/share/native/libzip/zlib/gzwrite.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
/* gzwrite.c -- zlib functions for writing gzip files
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    26
 * Copyright (C) 2004-2017 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_init OF((gz_statep));
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    34
local int gz_comp OF((gz_statep, int));
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    35
local int gz_zero OF((gz_statep, z_off64_t));
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    36
local z_size_t gz_write OF((gz_statep, voidpc, z_size_t));
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    37
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    38
/* Initialize state for writing a gzip file.  Mark initialization by setting
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    39
   state->size to non-zero.  Return -1 on a memory allocation failure, or 0 on
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    40
   success. */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    41
local int gz_init(state)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    42
    gz_statep state;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    43
{
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    44
    int ret;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    45
    z_streamp strm = &(state->strm);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    46
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    47
    /* allocate input buffer (double size for gzprintf) */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    48
    state->in = (unsigned char *)malloc(state->want << 1);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    49
    if (state->in == NULL) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    50
        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
    51
        return -1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    52
    }
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
    /* only need output buffer and deflate state if compressing */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    55
    if (!state->direct) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    56
        /* allocate output buffer */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    57
        state->out = (unsigned char *)malloc(state->want);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    58
        if (state->out == NULL) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    59
            free(state->in);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    60
            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
    61
            return -1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    62
        }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    63
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    64
        /* allocate deflate memory, set up for gzip compression */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    65
        strm->zalloc = Z_NULL;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    66
        strm->zfree = Z_NULL;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    67
        strm->opaque = Z_NULL;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    68
        ret = deflateInit2(strm, state->level, Z_DEFLATED,
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    69
                           MAX_WBITS + 16, DEF_MEM_LEVEL, state->strategy);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    70
        if (ret != Z_OK) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    71
            free(state->out);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    72
            free(state->in);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    73
            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
    74
            return -1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    75
        }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    76
        strm->next_in = NULL;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    77
    }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    78
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    79
    /* mark state as initialized */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    80
    state->size = state->want;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    81
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    82
    /* initialize write buffer if compressing */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    83
    if (!state->direct) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    84
        strm->avail_out = state->size;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    85
        strm->next_out = state->out;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    86
        state->x.next = strm->next_out;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    87
    }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    88
    return 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    89
}
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    90
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    91
/* Compress whatever is at avail_in and next_in and write to the output file.
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    92
   Return -1 if there is an error writing to the output file or if gz_init()
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    93
   fails to allocate memory, otherwise 0.  flush is assumed to be a valid
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    94
   deflate() flush value.  If flush is Z_FINISH, then the deflate() state is
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    95
   reset to start a new gzip stream.  If gz->direct is true, then simply write
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    96
   to the output file without compressing, and ignore flush. */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    97
local int gz_comp(state, flush)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    98
    gz_statep state;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    99
    int flush;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   100
{
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   101
    int ret, writ;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   102
    unsigned have, put, max = ((unsigned)-1 >> 2) + 1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   103
    z_streamp strm = &(state->strm);
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
    /* allocate memory if this is the first time through */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   106
    if (state->size == 0 && gz_init(state) == -1)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   107
        return -1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   108
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   109
    /* write directly if requested */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   110
    if (state->direct) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   111
        while (strm->avail_in) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   112
            put = strm->avail_in > max ? max : strm->avail_in;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   113
            writ = write(state->fd, strm->next_in, put);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   114
            if (writ < 0) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   115
                gz_error(state, Z_ERRNO, zstrerror());
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   116
                return -1;
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
            strm->avail_in -= (unsigned)writ;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   119
            strm->next_in += writ;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   120
        }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   121
        return 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   122
    }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   123
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   124
    /* run deflate() on provided input until it produces no more output */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   125
    ret = Z_OK;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   126
    do {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   127
        /* write out current buffer contents if full, or if flushing, but if
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   128
           doing Z_FINISH then don't write until we get to Z_STREAM_END */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   129
        if (strm->avail_out == 0 || (flush != Z_NO_FLUSH &&
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   130
            (flush != Z_FINISH || ret == Z_STREAM_END))) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   131
            while (strm->next_out > state->x.next) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   132
                put = strm->next_out - state->x.next > (int)max ? max :
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   133
                      (unsigned)(strm->next_out - state->x.next);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   134
                writ = write(state->fd, state->x.next, put);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   135
                if (writ < 0) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   136
                    gz_error(state, Z_ERRNO, zstrerror());
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   137
                    return -1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   138
                }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   139
                state->x.next += writ;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   140
            }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   141
            if (strm->avail_out == 0) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   142
                strm->avail_out = state->size;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   143
                strm->next_out = state->out;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   144
                state->x.next = state->out;
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
        /* compress */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   149
        have = strm->avail_out;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   150
        ret = deflate(strm, flush);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   151
        if (ret == Z_STREAM_ERROR) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   152
            gz_error(state, Z_STREAM_ERROR,
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   153
                      "internal error: deflate stream corrupt");
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   154
            return -1;
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
        have -= strm->avail_out;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   157
    } while (have);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   158
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   159
    /* if that completed a deflate stream, allow another to start */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   160
    if (flush == Z_FINISH)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   161
        deflateReset(strm);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   162
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   163
    /* all done, no errors */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   164
    return 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   165
}
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   166
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   167
/* Compress len zeros to output.  Return -1 on a write error or memory
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   168
   allocation failure by gz_comp(), or 0 on success. */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   169
local int gz_zero(state, len)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   170
    gz_statep state;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   171
    z_off64_t len;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   172
{
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   173
    int first;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   174
    unsigned n;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   175
    z_streamp strm = &(state->strm);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   176
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   177
    /* consume whatever's left in the input buffer */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   178
    if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   179
        return -1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   180
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   181
    /* compress len zeros (len guaranteed > 0) */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   182
    first = 1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   183
    while (len) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   184
        n = GT_OFF(state->size) || (z_off64_t)state->size > len ?
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   185
            (unsigned)len : state->size;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   186
        if (first) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   187
            memset(state->in, 0, n);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   188
            first = 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   189
        }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   190
        strm->avail_in = n;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   191
        strm->next_in = state->in;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   192
        state->x.pos += n;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   193
        if (gz_comp(state, Z_NO_FLUSH) == -1)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   194
            return -1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   195
        len -= n;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   196
    }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   197
    return 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   198
}
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   199
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   200
/* Write len bytes from buf to file.  Return the number of bytes written.  If
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   201
   the returned value is less than len, then there was an error. */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   202
local z_size_t gz_write(state, buf, len)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   203
    gz_statep state;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   204
    voidpc buf;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   205
    z_size_t len;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   206
{
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   207
    z_size_t put = len;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   208
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   209
    /* if len is zero, avoid unnecessary operations */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   210
    if (len == 0)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   211
        return 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   212
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   213
    /* allocate memory if this is the first time through */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   214
    if (state->size == 0 && gz_init(state) == -1)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   215
        return 0;
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
    /* check for seek request */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   218
    if (state->seek) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   219
        state->seek = 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   220
        if (gz_zero(state, state->skip) == -1)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   221
            return 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   222
    }
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
    /* for small len, copy to input buffer, otherwise compress directly */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   225
    if (len < state->size) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   226
        /* copy to input buffer, compress when full */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   227
        do {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   228
            unsigned have, copy;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   229
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   230
            if (state->strm.avail_in == 0)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   231
                state->strm.next_in = state->in;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   232
            have = (unsigned)((state->strm.next_in + state->strm.avail_in) -
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   233
                              state->in);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   234
            copy = state->size - have;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   235
            if (copy > len)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   236
                copy = (unsigned)len;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   237
            memcpy(state->in + have, buf, copy);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   238
            state->strm.avail_in += copy;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   239
            state->x.pos += copy;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   240
            buf = (const char *)buf + copy;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   241
            len -= copy;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   242
            if (len && gz_comp(state, Z_NO_FLUSH) == -1)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   243
                return 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   244
        } while (len);
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
    else {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   247
        /* consume whatever's left in the input buffer */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   248
        if (state->strm.avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   249
            return 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   250
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   251
        /* directly compress user buffer to file */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   252
        state->strm.next_in = (z_const Bytef *)buf;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   253
        do {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   254
            unsigned n = (unsigned)-1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   255
            if (n > len)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   256
                n = (unsigned)len;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   257
            state->strm.avail_in = n;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   258
            state->x.pos += n;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   259
            if (gz_comp(state, Z_NO_FLUSH) == -1)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   260
                return 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   261
            len -= n;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   262
        } while (len);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   263
    }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   264
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   265
    /* input was all buffered or compressed */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   266
    return put;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   267
}
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   268
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   269
/* -- see zlib.h -- */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   270
int ZEXPORT gzwrite(file, buf, len)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   271
    gzFile file;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   272
    voidpc buf;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   273
    unsigned len;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   274
{
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   275
    gz_statep state;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   276
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   277
    /* get internal structure */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   278
    if (file == NULL)
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
    state = (gz_statep)file;
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
    /* check that we're writing and that there's no error */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   283
    if (state->mode != GZ_WRITE || state->err != Z_OK)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   284
        return 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   285
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   286
    /* 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
   287
       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
   288
    if ((int)len < 0) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   289
        gz_error(state, Z_DATA_ERROR, "requested length does not fit in int");
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   290
        return 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   291
    }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   292
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   293
    /* write len bytes from buf (the return value will fit in an int) */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   294
    return (int)gz_write(state, buf, len);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   295
}
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   296
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   297
/* -- see zlib.h -- */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   298
z_size_t ZEXPORT gzfwrite(buf, size, nitems, file)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   299
    voidpc buf;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   300
    z_size_t size;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   301
    z_size_t nitems;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   302
    gzFile file;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   303
{
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   304
    z_size_t len;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   305
    gz_statep state;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   306
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   307
    /* get internal structure */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   308
    if (file == NULL)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   309
        return 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   310
    state = (gz_statep)file;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   311
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   312
    /* check that we're writing and that there's no error */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   313
    if (state->mode != GZ_WRITE || state->err != Z_OK)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   314
        return 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   315
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   316
    /* compute bytes to read -- error on overflow */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   317
    len = nitems * size;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   318
    if (size && len / size != nitems) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   319
        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
   320
        return 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   321
    }
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
    /* write len bytes to buf, return the number of full items written */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   324
    return len ? gz_write(state, buf, len) / size : 0;
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
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   327
/* -- see zlib.h -- */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   328
int ZEXPORT gzputc(file, c)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   329
    gzFile file;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   330
    int c;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   331
{
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   332
    unsigned have;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   333
    unsigned char buf[1];
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   334
    gz_statep state;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   335
    z_streamp strm;
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 internal structure */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   338
    if (file == NULL)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   339
        return -1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   340
    state = (gz_statep)file;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   341
    strm = &(state->strm);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   342
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   343
    /* check that we're writing and that there's no error */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   344
    if (state->mode != GZ_WRITE || state->err != Z_OK)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   345
        return -1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   346
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   347
    /* check for seek request */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   348
    if (state->seek) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   349
        state->seek = 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   350
        if (gz_zero(state, state->skip) == -1)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   351
            return -1;
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
    /* try writing to input buffer for speed (state->size == 0 if buffer not
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   355
       initialized) */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   356
    if (state->size) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   357
        if (strm->avail_in == 0)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   358
            strm->next_in = state->in;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   359
        have = (unsigned)((strm->next_in + strm->avail_in) - state->in);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   360
        if (have < state->size) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   361
            state->in[have] = (unsigned char)c;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   362
            strm->avail_in++;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   363
            state->x.pos++;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   364
            return c & 0xff;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   365
        }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   366
    }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   367
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   368
    /* no room in buffer or not initialized, use gz_write() */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   369
    buf[0] = (unsigned char)c;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   370
    if (gz_write(state, buf, 1) != 1)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   371
        return -1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   372
    return c & 0xff;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   373
}
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   374
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   375
/* -- see zlib.h -- */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   376
int ZEXPORT gzputs(file, str)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   377
    gzFile file;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   378
    const char *str;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   379
{
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   380
    int ret;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   381
    z_size_t len;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   382
    gz_statep state;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   383
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   384
    /* get internal structure */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   385
    if (file == NULL)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   386
        return -1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   387
    state = (gz_statep)file;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   388
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   389
    /* check that we're writing and that there's no error */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   390
    if (state->mode != GZ_WRITE || state->err != Z_OK)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   391
        return -1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   392
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   393
    /* write string */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   394
    len = strlen(str);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   395
    ret = (int)gz_write(state, str, len);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   396
    return ret == 0 && len != 0 ? -1 : ret;
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
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   399
#if defined(STDC) || defined(Z_HAVE_STDARG_H)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   400
#include <stdarg.h>
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   401
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   402
/* -- see zlib.h -- */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   403
int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   404
{
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   405
    int len;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   406
    unsigned left;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   407
    char *next;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   408
    gz_statep state;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   409
    z_streamp strm;
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
    /* get internal structure */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   412
    if (file == NULL)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   413
        return Z_STREAM_ERROR;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   414
    state = (gz_statep)file;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   415
    strm = &(state->strm);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   416
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   417
    /* check that we're writing and that there's no error */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   418
    if (state->mode != GZ_WRITE || state->err != Z_OK)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   419
        return Z_STREAM_ERROR;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   420
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   421
    /* make sure we have some buffer space */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   422
    if (state->size == 0 && gz_init(state) == -1)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   423
        return state->err;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   424
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   425
    /* check for seek request */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   426
    if (state->seek) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   427
        state->seek = 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   428
        if (gz_zero(state, state->skip) == -1)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   429
            return state->err;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   430
    }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   431
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   432
    /* do the printf() into the input buffer, put length in len -- the input
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   433
       buffer is double-sized just for this function, so there is guaranteed to
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   434
       be state->size bytes available after the current contents */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   435
    if (strm->avail_in == 0)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   436
        strm->next_in = state->in;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   437
    next = (char *)(state->in + (strm->next_in - state->in) + strm->avail_in);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   438
    next[state->size - 1] = 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   439
#ifdef NO_vsnprintf
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   440
#  ifdef HAS_vsprintf_void
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   441
    (void)vsprintf(next, format, va);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   442
    for (len = 0; len < state->size; len++)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   443
        if (next[len] == 0) break;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   444
#  else
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   445
    len = vsprintf(next, format, va);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   446
#  endif
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   447
#else
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   448
#  ifdef HAS_vsnprintf_void
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   449
    (void)vsnprintf(next, state->size, format, va);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   450
    len = strlen(next);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   451
#  else
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   452
    len = vsnprintf(next, state->size, format, va);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   453
#  endif
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   454
#endif
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   455
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   456
    /* check that printf() results fit in buffer */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   457
    if (len == 0 || (unsigned)len >= state->size || next[state->size - 1] != 0)
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
    /* update buffer and position, compress first half if past that */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   461
    strm->avail_in += (unsigned)len;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   462
    state->x.pos += len;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   463
    if (strm->avail_in >= state->size) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   464
        left = strm->avail_in - state->size;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   465
        strm->avail_in = state->size;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   466
        if (gz_comp(state, Z_NO_FLUSH) == -1)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   467
            return state->err;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   468
        memcpy(state->in, state->in + state->size, left);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   469
        strm->next_in = state->in;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   470
        strm->avail_in = left;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   471
    }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   472
    return len;
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
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   475
int ZEXPORTVA gzprintf(gzFile file, const char *format, ...)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   476
{
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   477
    va_list va;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   478
    int ret;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   479
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   480
    va_start(va, format);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   481
    ret = gzvprintf(file, format, va);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   482
    va_end(va);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   483
    return ret;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   484
}
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   485
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   486
#else /* !STDC && !Z_HAVE_STDARG_H */
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
/* -- see zlib.h -- */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   489
int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   490
                       a11, a12, a13, a14, a15, a16, a17, a18, a19, a20)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   491
    gzFile file;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   492
    const char *format;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   493
    int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   494
        a11, a12, a13, a14, a15, a16, a17, a18, a19, a20;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   495
{
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   496
    unsigned len, left;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   497
    char *next;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   498
    gz_statep state;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   499
    z_streamp strm;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   500
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   501
    /* get internal structure */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   502
    if (file == NULL)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   503
        return Z_STREAM_ERROR;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   504
    state = (gz_statep)file;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   505
    strm = &(state->strm);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   506
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   507
    /* check that can really pass pointer in ints */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   508
    if (sizeof(int) != sizeof(void *))
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   509
        return Z_STREAM_ERROR;
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
    /* check that we're writing and that there's no error */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   512
    if (state->mode != GZ_WRITE || state->err != Z_OK)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   513
        return Z_STREAM_ERROR;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   514
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   515
    /* make sure we have some buffer space */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   516
    if (state->size == 0 && gz_init(state) == -1)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   517
        return state->error;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   518
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   519
    /* check for seek request */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   520
    if (state->seek) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   521
        state->seek = 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   522
        if (gz_zero(state, state->skip) == -1)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   523
            return state->error;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   524
    }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   525
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   526
    /* do the printf() into the input buffer, put length in len -- the input
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   527
       buffer is double-sized just for this function, so there is guaranteed to
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   528
       be state->size bytes available after the current contents */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   529
    if (strm->avail_in == 0)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   530
        strm->next_in = state->in;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   531
    next = (char *)(strm->next_in + strm->avail_in);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   532
    next[state->size - 1] = 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   533
#ifdef NO_snprintf
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   534
#  ifdef HAS_sprintf_void
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   535
    sprintf(next, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12,
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   536
            a13, a14, a15, a16, a17, a18, a19, a20);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   537
    for (len = 0; len < size; len++)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   538
        if (next[len] == 0)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   539
            break;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   540
#  else
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   541
    len = sprintf(next, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11,
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   542
                  a12, a13, a14, a15, a16, a17, a18, a19, a20);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   543
#  endif
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   544
#else
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   545
#  ifdef HAS_snprintf_void
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   546
    snprintf(next, state->size, format, a1, a2, a3, a4, a5, a6, a7, a8, a9,
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   547
             a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   548
    len = strlen(next);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   549
#  else
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   550
    len = snprintf(next, state->size, format, a1, a2, a3, a4, a5, a6, a7, a8,
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   551
                   a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   552
#  endif
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   553
#endif
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   554
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   555
    /* check that printf() results fit in buffer */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   556
    if (len == 0 || len >= state->size || next[state->size - 1] != 0)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   557
        return 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   558
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   559
    /* update buffer and position, compress first half if past that */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   560
    strm->avail_in += len;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   561
    state->x.pos += len;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   562
    if (strm->avail_in >= state->size) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   563
        left = strm->avail_in - state->size;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   564
        strm->avail_in = state->size;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   565
        if (gz_comp(state, Z_NO_FLUSH) == -1)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   566
            return state->err;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   567
        memcpy(state->in, state->in + state->size, left);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   568
        strm->next_in = state->in;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   569
        strm->avail_in = left;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   570
    }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   571
    return (int)len;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   572
}
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   573
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   574
#endif
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   575
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   576
/* -- see zlib.h -- */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   577
int ZEXPORT gzflush(file, flush)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   578
    gzFile file;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   579
    int flush;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   580
{
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   581
    gz_statep state;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   582
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   583
    /* get internal structure */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   584
    if (file == NULL)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   585
        return Z_STREAM_ERROR;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   586
    state = (gz_statep)file;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   587
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   588
    /* check that we're writing and that there's no error */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   589
    if (state->mode != GZ_WRITE || state->err != Z_OK)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   590
        return Z_STREAM_ERROR;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   591
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   592
    /* check flush parameter */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   593
    if (flush < 0 || flush > Z_FINISH)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   594
        return Z_STREAM_ERROR;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   595
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   596
    /* check for seek request */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   597
    if (state->seek) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   598
        state->seek = 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   599
        if (gz_zero(state, state->skip) == -1)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   600
            return state->err;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   601
    }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   602
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   603
    /* compress remaining data with requested flush */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   604
    (void)gz_comp(state, flush);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   605
    return state->err;
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
/* -- see zlib.h -- */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   609
int ZEXPORT gzsetparams(file, level, strategy)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   610
    gzFile file;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   611
    int level;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   612
    int strategy;
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
    gz_statep state;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   615
    z_streamp strm;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   616
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   617
    /* get internal structure */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   618
    if (file == NULL)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   619
        return Z_STREAM_ERROR;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   620
    state = (gz_statep)file;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   621
    strm = &(state->strm);
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
    /* check that we're writing and that there's no error */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   624
    if (state->mode != GZ_WRITE || state->err != Z_OK)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   625
        return Z_STREAM_ERROR;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   626
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   627
    /* if no change is requested, then do nothing */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   628
    if (level == state->level && strategy == state->strategy)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   629
        return Z_OK;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   630
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   631
    /* check for seek request */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   632
    if (state->seek) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   633
        state->seek = 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   634
        if (gz_zero(state, state->skip) == -1)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   635
            return state->err;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   636
    }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   637
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   638
    /* change compression parameters for subsequent input */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   639
    if (state->size) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   640
        /* flush previous input with previous parameters before changing */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   641
        if (strm->avail_in && gz_comp(state, Z_BLOCK) == -1)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   642
            return state->err;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   643
        deflateParams(strm, level, strategy);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   644
    }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   645
    state->level = level;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   646
    state->strategy = strategy;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   647
    return Z_OK;
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_w(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 = Z_OK;
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 writing */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   663
    if (state->mode != GZ_WRITE)
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
    /* check for seek request */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   667
    if (state->seek) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   668
        state->seek = 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   669
        if (gz_zero(state, state->skip) == -1)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   670
            ret = state->err;
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
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   673
    /* flush, free memory, and close file */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   674
    if (gz_comp(state, Z_FINISH) == -1)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   675
        ret = state->err;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   676
    if (state->size) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   677
        if (!state->direct) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   678
            (void)deflateEnd(&(state->strm));
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   679
            free(state->out);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   680
        }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   681
        free(state->in);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   682
    }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   683
    gz_error(state, Z_OK, NULL);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   684
    free(state->path);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   685
    if (close(state->fd) == -1)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   686
        ret = Z_ERRNO;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   687
    free(state);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   688
    return ret;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   689
}