jdk/src/java.base/share/native/libzip/zlib/gzlib.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
/* gzlib.c -- zlib functions common to reading and 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
#if defined(_WIN32) && !defined(__BORLANDC__) && !defined(__MINGW32__)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    33
#  define LSEEK _lseeki64
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    34
#else
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    35
#if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    36
#  define LSEEK lseek64
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    37
#else
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    38
#  define LSEEK lseek
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    39
#endif
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    40
#endif
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    41
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    42
/* Local functions */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    43
local void gz_reset OF((gz_statep));
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    44
local gzFile gz_open OF((const void *, int, const char *));
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    45
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    46
#if defined UNDER_CE
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    47
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    48
/* Map the Windows error number in ERROR to a locale-dependent error message
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    49
   string and return a pointer to it.  Typically, the values for ERROR come
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    50
   from GetLastError.
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    51
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    52
   The string pointed to shall not be modified by the application, but may be
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    53
   overwritten by a subsequent call to gz_strwinerror
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    54
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    55
   The gz_strwinerror function does not change the current setting of
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    56
   GetLastError. */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    57
char ZLIB_INTERNAL *gz_strwinerror (error)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    58
     DWORD error;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    59
{
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    60
    static char buf[1024];
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    61
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    62
    wchar_t *msgbuf;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    63
    DWORD lasterr = GetLastError();
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    64
    DWORD chars = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    65
        | FORMAT_MESSAGE_ALLOCATE_BUFFER,
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    66
        NULL,
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    67
        error,
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    68
        0, /* Default language */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    69
        (LPVOID)&msgbuf,
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    70
        0,
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    71
        NULL);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    72
    if (chars != 0) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    73
        /* If there is an \r\n appended, zap it.  */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    74
        if (chars >= 2
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    75
            && msgbuf[chars - 2] == '\r' && msgbuf[chars - 1] == '\n') {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    76
            chars -= 2;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    77
            msgbuf[chars] = 0;
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
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    80
        if (chars > sizeof (buf) - 1) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    81
            chars = sizeof (buf) - 1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    82
            msgbuf[chars] = 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    83
        }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    84
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    85
        wcstombs(buf, msgbuf, chars + 1);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    86
        LocalFree(msgbuf);
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
    else {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    89
        sprintf(buf, "unknown win32 error (%ld)", error);
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
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    92
    SetLastError(lasterr);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    93
    return buf;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    94
}
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    95
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    96
#endif /* UNDER_CE */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    97
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    98
/* Reset gzip file state */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
    99
local void gz_reset(state)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   100
    gz_statep state;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   101
{
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   102
    state->x.have = 0;              /* no output data available */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   103
    if (state->mode == GZ_READ) {   /* for reading ... */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   104
        state->eof = 0;             /* not at end of file */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   105
        state->past = 0;            /* have not read past end yet */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   106
        state->how = LOOK;          /* look for gzip header */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   107
    }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   108
    state->seek = 0;                /* no seek request pending */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   109
    gz_error(state, Z_OK, NULL);    /* clear error */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   110
    state->x.pos = 0;               /* no uncompressed data yet */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   111
    state->strm.avail_in = 0;       /* no input data yet */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   112
}
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   113
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   114
/* Open a gzip file either by name or file descriptor. */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   115
local gzFile gz_open(path, fd, mode)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   116
    const void *path;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   117
    int fd;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   118
    const char *mode;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   119
{
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   120
    gz_statep state;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   121
    z_size_t len;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   122
    int oflag;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   123
#ifdef O_CLOEXEC
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   124
    int cloexec = 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   125
#endif
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   126
#ifdef O_EXCL
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   127
    int exclusive = 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   128
#endif
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   129
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   130
    /* check input */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   131
    if (path == NULL)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   132
        return NULL;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   133
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   134
    /* allocate gzFile structure to return */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   135
    state = (gz_statep)malloc(sizeof(gz_state));
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   136
    if (state == NULL)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   137
        return NULL;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   138
    state->size = 0;            /* no buffers allocated yet */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   139
    state->want = GZBUFSIZE;    /* requested buffer size */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   140
    state->msg = NULL;          /* no error message yet */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   141
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   142
    /* interpret mode */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   143
    state->mode = GZ_NONE;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   144
    state->level = Z_DEFAULT_COMPRESSION;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   145
    state->strategy = Z_DEFAULT_STRATEGY;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   146
    state->direct = 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   147
    while (*mode) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   148
        if (*mode >= '0' && *mode <= '9')
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   149
            state->level = *mode - '0';
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   150
        else
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   151
            switch (*mode) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   152
            case 'r':
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   153
                state->mode = GZ_READ;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   154
                break;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   155
#ifndef NO_GZCOMPRESS
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   156
            case 'w':
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   157
                state->mode = GZ_WRITE;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   158
                break;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   159
            case 'a':
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   160
                state->mode = GZ_APPEND;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   161
                break;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   162
#endif
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   163
            case '+':       /* can't read and write at the same time */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   164
                free(state);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   165
                return NULL;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   166
            case 'b':       /* ignore -- will request binary anyway */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   167
                break;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   168
#ifdef O_CLOEXEC
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   169
            case 'e':
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   170
                cloexec = 1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   171
                break;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   172
#endif
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   173
#ifdef O_EXCL
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   174
            case 'x':
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   175
                exclusive = 1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   176
                break;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   177
#endif
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   178
            case 'f':
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   179
                state->strategy = Z_FILTERED;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   180
                break;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   181
            case 'h':
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   182
                state->strategy = Z_HUFFMAN_ONLY;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   183
                break;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   184
            case 'R':
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   185
                state->strategy = Z_RLE;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   186
                break;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   187
            case 'F':
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   188
                state->strategy = Z_FIXED;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   189
                break;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   190
            case 'T':
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   191
                state->direct = 1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   192
                break;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   193
            default:        /* could consider as an error, but just ignore */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   194
                ;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   195
            }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   196
        mode++;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   197
    }
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
    /* must provide an "r", "w", or "a" */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   200
    if (state->mode == GZ_NONE) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   201
        free(state);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   202
        return NULL;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   203
    }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   204
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   205
    /* can't force transparent read */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   206
    if (state->mode == GZ_READ) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   207
        if (state->direct) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   208
            free(state);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   209
            return NULL;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   210
        }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   211
        state->direct = 1;      /* for empty file */
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
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   214
    /* save the path name for error messages */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   215
#ifdef WIDECHAR
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   216
    if (fd == -2) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   217
        len = wcstombs(NULL, path, 0);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   218
        if (len == (z_size_t)-1)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   219
            len = 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   220
    }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   221
    else
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   222
#endif
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   223
        len = strlen((const char *)path);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   224
    state->path = (char *)malloc(len + 1);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   225
    if (state->path == NULL) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   226
        free(state);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   227
        return NULL;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   228
    }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   229
#ifdef WIDECHAR
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   230
    if (fd == -2)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   231
        if (len)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   232
            wcstombs(state->path, path, len + 1);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   233
        else
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   234
            *(state->path) = 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   235
    else
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   236
#endif
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   237
#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   238
        (void)snprintf(state->path, len + 1, "%s", (const char *)path);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   239
#else
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   240
        strcpy(state->path, path);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   241
#endif
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   242
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   243
    /* compute the flags for open() */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   244
    oflag =
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   245
#ifdef O_LARGEFILE
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   246
        O_LARGEFILE |
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   247
#endif
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   248
#ifdef O_BINARY
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   249
        O_BINARY |
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   250
#endif
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   251
#ifdef O_CLOEXEC
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   252
        (cloexec ? O_CLOEXEC : 0) |
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   253
#endif
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   254
        (state->mode == GZ_READ ?
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   255
         O_RDONLY :
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   256
         (O_WRONLY | O_CREAT |
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   257
#ifdef O_EXCL
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   258
          (exclusive ? O_EXCL : 0) |
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   259
#endif
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   260
          (state->mode == GZ_WRITE ?
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   261
           O_TRUNC :
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   262
           O_APPEND)));
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
    /* open the file with the appropriate flags (or just use fd) */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   265
    state->fd = fd > -1 ? fd : (
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   266
#ifdef WIDECHAR
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   267
        fd == -2 ? _wopen(path, oflag, 0666) :
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   268
#endif
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   269
        open((const char *)path, oflag, 0666));
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   270
    if (state->fd == -1) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   271
        free(state->path);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   272
        free(state);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   273
        return NULL;
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
    if (state->mode == GZ_APPEND) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   276
        LSEEK(state->fd, 0, SEEK_END);  /* so gzoffset() is correct */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   277
        state->mode = GZ_WRITE;         /* simplify later checks */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   278
    }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   279
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   280
    /* save the current position for rewinding (only if reading) */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   281
    if (state->mode == GZ_READ) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   282
        state->start = LSEEK(state->fd, 0, SEEK_CUR);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   283
        if (state->start == -1) state->start = 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   284
    }
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
    /* initialize stream */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   287
    gz_reset(state);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   288
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   289
    /* return stream */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   290
    return (gzFile)state;
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
/* -- see zlib.h -- */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   294
gzFile ZEXPORT gzopen(path, mode)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   295
    const char *path;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   296
    const char *mode;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   297
{
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   298
    return gz_open(path, -1, mode);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   299
}
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   300
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   301
/* -- see zlib.h -- */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   302
gzFile ZEXPORT gzopen64(path, mode)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   303
    const char *path;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   304
    const char *mode;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   305
{
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   306
    return gz_open(path, -1, mode);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   307
}
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   308
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   309
/* -- see zlib.h -- */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   310
gzFile ZEXPORT gzdopen(fd, mode)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   311
    int fd;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   312
    const char *mode;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   313
{
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   314
    char *path;         /* identifier for error messages */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   315
    gzFile gz;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   316
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   317
    if (fd == -1 || (path = (char *)malloc(7 + 3 * sizeof(int))) == NULL)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   318
        return NULL;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   319
#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   320
    (void)snprintf(path, 7 + 3 * sizeof(int), "<fd:%d>", fd);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   321
#else
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   322
    sprintf(path, "<fd:%d>", fd);   /* for debugging */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   323
#endif
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   324
    gz = gz_open(path, fd, mode);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   325
    free(path);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   326
    return gz;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   327
}
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   328
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   329
/* -- see zlib.h -- */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   330
#ifdef WIDECHAR
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   331
gzFile ZEXPORT gzopen_w(path, mode)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   332
    const wchar_t *path;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   333
    const char *mode;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   334
{
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   335
    return gz_open(path, -2, mode);
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
#endif
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   338
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   339
/* -- see zlib.h -- */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   340
int ZEXPORT gzbuffer(file, size)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   341
    gzFile file;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   342
    unsigned size;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   343
{
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   344
    gz_statep state;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   345
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   346
    /* get internal structure and check integrity */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   347
    if (file == NULL)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   348
        return -1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   349
    state = (gz_statep)file;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   350
    if (state->mode != GZ_READ && state->mode != GZ_WRITE)
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
    /* make sure we haven't already allocated memory */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   354
    if (state->size != 0)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   355
        return -1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   356
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   357
    /* check and set requested size */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   358
    if ((size << 1) < size)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   359
        return -1;              /* need to be able to double it */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   360
    if (size < 2)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   361
        size = 2;               /* need two bytes to check magic header */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   362
    state->want = size;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   363
    return 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   364
}
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
/* -- see zlib.h -- */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   367
int ZEXPORT gzrewind(file)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   368
    gzFile file;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   369
{
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   370
    gz_statep state;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   371
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   372
    /* get internal structure */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   373
    if (file == NULL)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   374
        return -1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   375
    state = (gz_statep)file;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   376
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   377
    /* check that we're reading and that there's no error */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   378
    if (state->mode != GZ_READ ||
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   379
            (state->err != Z_OK && state->err != Z_BUF_ERROR))
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   380
        return -1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   381
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   382
    /* back up and start over */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   383
    if (LSEEK(state->fd, state->start, SEEK_SET) == -1)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   384
        return -1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   385
    gz_reset(state);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   386
    return 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   387
}
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
/* -- see zlib.h -- */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   390
z_off64_t ZEXPORT gzseek64(file, offset, whence)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   391
    gzFile file;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   392
    z_off64_t offset;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   393
    int whence;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   394
{
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   395
    unsigned n;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   396
    z_off64_t ret;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   397
    gz_statep state;
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
    /* get internal structure and check integrity */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   400
    if (file == NULL)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   401
        return -1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   402
    state = (gz_statep)file;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   403
    if (state->mode != GZ_READ && state->mode != GZ_WRITE)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   404
        return -1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   405
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   406
    /* check that there's no error */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   407
    if (state->err != Z_OK && state->err != Z_BUF_ERROR)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   408
        return -1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   409
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   410
    /* can only seek from start or relative to current position */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   411
    if (whence != SEEK_SET && whence != SEEK_CUR)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   412
        return -1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   413
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   414
    /* normalize offset to a SEEK_CUR specification */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   415
    if (whence == SEEK_SET)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   416
        offset -= state->x.pos;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   417
    else if (state->seek)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   418
        offset += state->skip;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   419
    state->seek = 0;
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
    /* if within raw area while reading, just go there */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   422
    if (state->mode == GZ_READ && state->how == COPY &&
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   423
            state->x.pos + offset >= 0) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   424
        ret = LSEEK(state->fd, offset - state->x.have, SEEK_CUR);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   425
        if (ret == -1)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   426
            return -1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   427
        state->x.have = 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   428
        state->eof = 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   429
        state->past = 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   430
        state->seek = 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   431
        gz_error(state, Z_OK, NULL);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   432
        state->strm.avail_in = 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   433
        state->x.pos += offset;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   434
        return state->x.pos;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   435
    }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   436
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   437
    /* calculate skip amount, rewinding if needed for back seek when reading */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   438
    if (offset < 0) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   439
        if (state->mode != GZ_READ)         /* writing -- can't go backwards */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   440
            return -1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   441
        offset += state->x.pos;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   442
        if (offset < 0)                     /* before start of file! */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   443
            return -1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   444
        if (gzrewind(file) == -1)           /* rewind, then skip to offset */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   445
            return -1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   446
    }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   447
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   448
    /* if reading, skip what's in output buffer (one less gzgetc() check) */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   449
    if (state->mode == GZ_READ) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   450
        n = GT_OFF(state->x.have) || (z_off64_t)state->x.have > offset ?
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   451
            (unsigned)offset : state->x.have;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   452
        state->x.have -= n;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   453
        state->x.next += n;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   454
        state->x.pos += n;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   455
        offset -= n;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   456
    }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   457
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   458
    /* request skip (if not zero) */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   459
    if (offset) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   460
        state->seek = 1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   461
        state->skip = offset;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   462
    }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   463
    return state->x.pos + offset;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   464
}
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   465
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   466
/* -- see zlib.h -- */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   467
z_off_t ZEXPORT gzseek(file, offset, whence)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   468
    gzFile file;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   469
    z_off_t offset;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   470
    int whence;
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
    z_off64_t ret;
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
    ret = gzseek64(file, (z_off64_t)offset, whence);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   475
    return ret == (z_off_t)ret ? (z_off_t)ret : -1;
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
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   478
/* -- see zlib.h -- */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   479
z_off64_t ZEXPORT gztell64(file)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   480
    gzFile file;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   481
{
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   482
    gz_statep state;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   483
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   484
    /* get internal structure and check integrity */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   485
    if (file == NULL)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   486
        return -1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   487
    state = (gz_statep)file;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   488
    if (state->mode != GZ_READ && state->mode != GZ_WRITE)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   489
        return -1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   490
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   491
    /* return position */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   492
    return state->x.pos + (state->seek ? state->skip : 0);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   493
}
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   494
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   495
/* -- see zlib.h -- */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   496
z_off_t ZEXPORT gztell(file)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   497
    gzFile file;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   498
{
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   499
    z_off64_t ret;
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
    ret = gztell64(file);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   502
    return ret == (z_off_t)ret ? (z_off_t)ret : -1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   503
}
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   504
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   505
/* -- see zlib.h -- */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   506
z_off64_t ZEXPORT gzoffset64(file)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   507
    gzFile file;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   508
{
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   509
    z_off64_t offset;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   510
    gz_statep state;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   511
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   512
    /* get internal structure and check integrity */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   513
    if (file == NULL)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   514
        return -1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   515
    state = (gz_statep)file;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   516
    if (state->mode != GZ_READ && state->mode != GZ_WRITE)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   517
        return -1;
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
    /* compute and return effective offset in file */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   520
    offset = LSEEK(state->fd, 0, SEEK_CUR);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   521
    if (offset == -1)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   522
        return -1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   523
    if (state->mode == GZ_READ)             /* reading */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   524
        offset -= state->strm.avail_in;     /* don't count buffered input */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   525
    return offset;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   526
}
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   527
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   528
/* -- see zlib.h -- */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   529
z_off_t ZEXPORT gzoffset(file)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   530
    gzFile file;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   531
{
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   532
    z_off64_t ret;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   533
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   534
    ret = gzoffset64(file);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   535
    return ret == (z_off_t)ret ? (z_off_t)ret : -1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   536
}
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   537
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   538
/* -- see zlib.h -- */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   539
int ZEXPORT gzeof(file)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   540
    gzFile file;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   541
{
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   542
    gz_statep state;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   543
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   544
    /* get internal structure and check integrity */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   545
    if (file == NULL)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   546
        return 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   547
    state = (gz_statep)file;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   548
    if (state->mode != GZ_READ && state->mode != GZ_WRITE)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   549
        return 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   550
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   551
    /* return end-of-file state */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   552
    return state->mode == GZ_READ ? state->past : 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   553
}
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
/* -- see zlib.h -- */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   556
const char * ZEXPORT gzerror(file, errnum)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   557
    gzFile file;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   558
    int *errnum;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   559
{
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   560
    gz_statep state;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   561
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   562
    /* get internal structure and check integrity */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   563
    if (file == NULL)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   564
        return NULL;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   565
    state = (gz_statep)file;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   566
    if (state->mode != GZ_READ && state->mode != GZ_WRITE)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   567
        return NULL;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   568
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   569
    /* return error information */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   570
    if (errnum != NULL)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   571
        *errnum = state->err;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   572
    return state->err == Z_MEM_ERROR ? "out of memory" :
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   573
                                       (state->msg == NULL ? "" : state->msg);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   574
}
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
void ZEXPORT gzclearerr(file)
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
{
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   580
    gz_statep state;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   581
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   582
    /* get internal structure and check integrity */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   583
    if (file == NULL)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   584
        return;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   585
    state = (gz_statep)file;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   586
    if (state->mode != GZ_READ && state->mode != GZ_WRITE)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   587
        return;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   588
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   589
    /* clear error and end-of-file */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   590
    if (state->mode == GZ_READ) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   591
        state->eof = 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   592
        state->past = 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   593
    }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   594
    gz_error(state, Z_OK, NULL);
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
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   597
/* Create an error message in allocated memory and set state->err and
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   598
   state->msg accordingly.  Free any previous error message already there.  Do
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   599
   not try to free or allocate space if the error is Z_MEM_ERROR (out of
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   600
   memory).  Simply save the error message as a static string.  If there is an
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   601
   allocation failure constructing the error message, then convert the error to
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   602
   out of memory. */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   603
void ZLIB_INTERNAL gz_error(state, err, msg)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   604
    gz_statep state;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   605
    int err;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   606
    const char *msg;
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
    /* free previously allocated message and clear */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   609
    if (state->msg != NULL) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   610
        if (state->err != Z_MEM_ERROR)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   611
            free(state->msg);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   612
        state->msg = NULL;
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
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   615
    /* if fatal, set state->x.have to 0 so that the gzgetc() macro fails */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   616
    if (err != Z_OK && err != Z_BUF_ERROR)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   617
        state->x.have = 0;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   618
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   619
    /* set error code, and if no message, then done */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   620
    state->err = err;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   621
    if (msg == NULL)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   622
        return;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   623
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   624
    /* for an out of memory error, return literal string when requested */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   625
    if (err == Z_MEM_ERROR)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   626
        return;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   627
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   628
    /* construct error message with path */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   629
    if ((state->msg = (char *)malloc(strlen(state->path) + strlen(msg) + 3)) ==
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   630
            NULL) {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   631
        state->err = Z_MEM_ERROR;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   632
        return;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   633
    }
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   634
#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   635
    (void)snprintf(state->msg, strlen(state->path) + strlen(msg) + 3,
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   636
                   "%s%s%s", state->path, ": ", msg);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   637
#else
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   638
    strcpy(state->msg, state->path);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   639
    strcat(state->msg, ": ");
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   640
    strcat(state->msg, msg);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   641
#endif
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   642
}
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   643
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   644
#ifndef INT_MAX
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   645
/* portably return maximum value for an int (when limits.h presumed not
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   646
   available) -- we need to do this to cover cases where 2's complement not
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   647
   used, since C standard permits 1's complement and sign-bit representations,
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   648
   otherwise we could just use ((unsigned)-1) >> 1 */
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   649
unsigned ZLIB_INTERNAL gz_intmax()
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   650
{
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   651
    unsigned p, q;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   652
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   653
    p = 1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   654
    do {
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   655
        q = p;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   656
        p <<= 1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   657
        p++;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   658
    } while (p > q);
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   659
    return q >> 1;
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   660
}
a8fca792a14b 8175053: March 5 builds failed on Windows/install repo after JDK-8173207
sherman
parents:
diff changeset
   661
#endif