annotate src/java.base/share/native/libzip/zlib/gzguts.h @ 16744:dab92e4bd4ef

8175053: March 5 builds failed on Windows/install repo after JDK-8173207 Reviewed-by: mchung
author sherman
date Wed, 15 Feb 2017 22:50:35 -0800
parents
children
rev   line source
sherman@16744 1 /*
sherman@16744 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
sherman@16744 3 *
sherman@16744 4 * This code is free software; you can redistribute it and/or modify it
sherman@16744 5 * under the terms of the GNU General Public License version 2 only, as
sherman@16744 6 * published by the Free Software Foundation. Oracle designates this
sherman@16744 7 * particular file as subject to the "Classpath" exception as provided
sherman@16744 8 * by Oracle in the LICENSE file that accompanied this code.
sherman@16744 9 *
sherman@16744 10 * This code is distributed in the hope that it will be useful, but WITHOUT
sherman@16744 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
sherman@16744 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
sherman@16744 13 * version 2 for more details (a copy is included in the LICENSE file that
sherman@16744 14 * accompanied this code).
sherman@16744 15 *
sherman@16744 16 * You should have received a copy of the GNU General Public License version
sherman@16744 17 * 2 along with this work; if not, write to the Free Software Foundation,
sherman@16744 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
sherman@16744 19 *
sherman@16744 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
sherman@16744 21 * or visit www.oracle.com if you need additional information or have any
sherman@16744 22 * questions.
sherman@16744 23 */
sherman@16744 24
sherman@16744 25 /* gzguts.h -- zlib internal header definitions for gz* operations
sherman@16744 26 * Copyright (C) 2004, 2005, 2010, 2011, 2012, 2013, 2016 Mark Adler
sherman@16744 27 * For conditions of distribution and use, see copyright notice in zlib.h
sherman@16744 28 */
sherman@16744 29
sherman@16744 30 #ifdef _LARGEFILE64_SOURCE
sherman@16744 31 # ifndef _LARGEFILE_SOURCE
sherman@16744 32 # define _LARGEFILE_SOURCE 1
sherman@16744 33 # endif
sherman@16744 34 # ifdef _FILE_OFFSET_BITS
sherman@16744 35 # undef _FILE_OFFSET_BITS
sherman@16744 36 # endif
sherman@16744 37 #endif
sherman@16744 38
sherman@16744 39 #ifdef HAVE_HIDDEN
sherman@16744 40 # define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
sherman@16744 41 #else
sherman@16744 42 # define ZLIB_INTERNAL
sherman@16744 43 #endif
sherman@16744 44
sherman@16744 45 #include <stdio.h>
sherman@16744 46 #include "zlib.h"
sherman@16744 47 #ifdef STDC
sherman@16744 48 # include <string.h>
sherman@16744 49 # include <stdlib.h>
sherman@16744 50 # include <limits.h>
sherman@16744 51 #endif
sherman@16744 52
sherman@16744 53 #ifndef _POSIX_SOURCE
sherman@16744 54 # define _POSIX_SOURCE
sherman@16744 55 #endif
sherman@16744 56 #include <fcntl.h>
sherman@16744 57
sherman@16744 58 #ifdef _WIN32
sherman@16744 59 # include <stddef.h>
sherman@16744 60 #endif
sherman@16744 61
sherman@16744 62 #if defined(__TURBOC__) || defined(_MSC_VER) || defined(_WIN32)
sherman@16744 63 # include <io.h>
sherman@16744 64 #endif
sherman@16744 65
sherman@16744 66 #if defined(_WIN32) || defined(__CYGWIN__)
sherman@16744 67 # define WIDECHAR
sherman@16744 68 #endif
sherman@16744 69
sherman@16744 70 #ifdef WINAPI_FAMILY
sherman@16744 71 # define open _open
sherman@16744 72 # define read _read
sherman@16744 73 # define write _write
sherman@16744 74 # define close _close
sherman@16744 75 #endif
sherman@16744 76
sherman@16744 77 #ifdef NO_DEFLATE /* for compatibility with old definition */
sherman@16744 78 # define NO_GZCOMPRESS
sherman@16744 79 #endif
sherman@16744 80
sherman@16744 81 #if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
sherman@16744 82 # ifndef HAVE_VSNPRINTF
sherman@16744 83 # define HAVE_VSNPRINTF
sherman@16744 84 # endif
sherman@16744 85 #endif
sherman@16744 86
sherman@16744 87 #if defined(__CYGWIN__)
sherman@16744 88 # ifndef HAVE_VSNPRINTF
sherman@16744 89 # define HAVE_VSNPRINTF
sherman@16744 90 # endif
sherman@16744 91 #endif
sherman@16744 92
sherman@16744 93 #if defined(MSDOS) && defined(__BORLANDC__) && (BORLANDC > 0x410)
sherman@16744 94 # ifndef HAVE_VSNPRINTF
sherman@16744 95 # define HAVE_VSNPRINTF
sherman@16744 96 # endif
sherman@16744 97 #endif
sherman@16744 98
sherman@16744 99 #ifndef HAVE_VSNPRINTF
sherman@16744 100 # ifdef MSDOS
sherman@16744 101 /* vsnprintf may exist on some MS-DOS compilers (DJGPP?),
sherman@16744 102 but for now we just assume it doesn't. */
sherman@16744 103 # define NO_vsnprintf
sherman@16744 104 # endif
sherman@16744 105 # ifdef __TURBOC__
sherman@16744 106 # define NO_vsnprintf
sherman@16744 107 # endif
sherman@16744 108 # ifdef WIN32
sherman@16744 109 /* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */
sherman@16744 110 # if !defined(vsnprintf) && !defined(NO_vsnprintf)
sherman@16744 111 # if !defined(_MSC_VER) || ( defined(_MSC_VER) && _MSC_VER < 1500 )
sherman@16744 112 # define vsnprintf _vsnprintf
sherman@16744 113 # endif
sherman@16744 114 # endif
sherman@16744 115 # endif
sherman@16744 116 # ifdef __SASC
sherman@16744 117 # define NO_vsnprintf
sherman@16744 118 # endif
sherman@16744 119 # ifdef VMS
sherman@16744 120 # define NO_vsnprintf
sherman@16744 121 # endif
sherman@16744 122 # ifdef __OS400__
sherman@16744 123 # define NO_vsnprintf
sherman@16744 124 # endif
sherman@16744 125 # ifdef __MVS__
sherman@16744 126 # define NO_vsnprintf
sherman@16744 127 # endif
sherman@16744 128 #endif
sherman@16744 129
sherman@16744 130 /* unlike snprintf (which is required in C99), _snprintf does not guarantee
sherman@16744 131 null termination of the result -- however this is only used in gzlib.c where
sherman@16744 132 the result is assured to fit in the space provided */
sherman@16744 133 #if defined(_MSC_VER) && _MSC_VER < 1900
sherman@16744 134 # define snprintf _snprintf
sherman@16744 135 #endif
sherman@16744 136
sherman@16744 137 #ifndef local
sherman@16744 138 # define local static
sherman@16744 139 #endif
sherman@16744 140 /* since "static" is used to mean two completely different things in C, we
sherman@16744 141 define "local" for the non-static meaning of "static", for readability
sherman@16744 142 (compile with -Dlocal if your debugger can't find static symbols) */
sherman@16744 143
sherman@16744 144 /* gz* functions always use library allocation functions */
sherman@16744 145 #ifndef STDC
sherman@16744 146 extern voidp malloc OF((uInt size));
sherman@16744 147 extern void free OF((voidpf ptr));
sherman@16744 148 #endif
sherman@16744 149
sherman@16744 150 /* get errno and strerror definition */
sherman@16744 151 #if defined UNDER_CE
sherman@16744 152 # include <windows.h>
sherman@16744 153 # define zstrerror() gz_strwinerror((DWORD)GetLastError())
sherman@16744 154 #else
sherman@16744 155 # ifndef NO_STRERROR
sherman@16744 156 # include <errno.h>
sherman@16744 157 # define zstrerror() strerror(errno)
sherman@16744 158 # else
sherman@16744 159 # define zstrerror() "stdio error (consult errno)"
sherman@16744 160 # endif
sherman@16744 161 #endif
sherman@16744 162
sherman@16744 163 /* provide prototypes for these when building zlib without LFS */
sherman@16744 164 #if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0
sherman@16744 165 ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *));
sherman@16744 166 ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int));
sherman@16744 167 ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile));
sherman@16744 168 ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile));
sherman@16744 169 #endif
sherman@16744 170
sherman@16744 171 /* default memLevel */
sherman@16744 172 #if MAX_MEM_LEVEL >= 8
sherman@16744 173 # define DEF_MEM_LEVEL 8
sherman@16744 174 #else
sherman@16744 175 # define DEF_MEM_LEVEL MAX_MEM_LEVEL
sherman@16744 176 #endif
sherman@16744 177
sherman@16744 178 /* default i/o buffer size -- double this for output when reading (this and
sherman@16744 179 twice this must be able to fit in an unsigned type) */
sherman@16744 180 #define GZBUFSIZE 8192
sherman@16744 181
sherman@16744 182 /* gzip modes, also provide a little integrity check on the passed structure */
sherman@16744 183 #define GZ_NONE 0
sherman@16744 184 #define GZ_READ 7247
sherman@16744 185 #define GZ_WRITE 31153
sherman@16744 186 #define GZ_APPEND 1 /* mode set to GZ_WRITE after the file is opened */
sherman@16744 187
sherman@16744 188 /* values for gz_state how */
sherman@16744 189 #define LOOK 0 /* look for a gzip header */
sherman@16744 190 #define COPY 1 /* copy input directly */
sherman@16744 191 #define GZIP 2 /* decompress a gzip stream */
sherman@16744 192
sherman@16744 193 /* internal gzip file state data structure */
sherman@16744 194 typedef struct {
sherman@16744 195 /* exposed contents for gzgetc() macro */
sherman@16744 196 struct gzFile_s x; /* "x" for exposed */
sherman@16744 197 /* x.have: number of bytes available at x.next */
sherman@16744 198 /* x.next: next output data to deliver or write */
sherman@16744 199 /* x.pos: current position in uncompressed data */
sherman@16744 200 /* used for both reading and writing */
sherman@16744 201 int mode; /* see gzip modes above */
sherman@16744 202 int fd; /* file descriptor */
sherman@16744 203 char *path; /* path or fd for error messages */
sherman@16744 204 unsigned size; /* buffer size, zero if not allocated yet */
sherman@16744 205 unsigned want; /* requested buffer size, default is GZBUFSIZE */
sherman@16744 206 unsigned char *in; /* input buffer (double-sized when writing) */
sherman@16744 207 unsigned char *out; /* output buffer (double-sized when reading) */
sherman@16744 208 int direct; /* 0 if processing gzip, 1 if transparent */
sherman@16744 209 /* just for reading */
sherman@16744 210 int how; /* 0: get header, 1: copy, 2: decompress */
sherman@16744 211 z_off64_t start; /* where the gzip data started, for rewinding */
sherman@16744 212 int eof; /* true if end of input file reached */
sherman@16744 213 int past; /* true if read requested past end */
sherman@16744 214 /* just for writing */
sherman@16744 215 int level; /* compression level */
sherman@16744 216 int strategy; /* compression strategy */
sherman@16744 217 /* seek request */
sherman@16744 218 z_off64_t skip; /* amount to skip (already rewound if backwards) */
sherman@16744 219 int seek; /* true if seek request pending */
sherman@16744 220 /* error information */
sherman@16744 221 int err; /* error code */
sherman@16744 222 char *msg; /* error message */
sherman@16744 223 /* zlib inflate or deflate stream */
sherman@16744 224 z_stream strm; /* stream structure in-place (not a pointer) */
sherman@16744 225 } gz_state;
sherman@16744 226 typedef gz_state FAR *gz_statep;
sherman@16744 227
sherman@16744 228 /* shared functions */
sherman@16744 229 void ZLIB_INTERNAL gz_error OF((gz_statep, int, const char *));
sherman@16744 230 #if defined UNDER_CE
sherman@16744 231 char ZLIB_INTERNAL *gz_strwinerror OF((DWORD error));
sherman@16744 232 #endif
sherman@16744 233
sherman@16744 234 /* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t
sherman@16744 235 value -- needed when comparing unsigned to z_off64_t, which is signed
sherman@16744 236 (possible z_off64_t types off_t, off64_t, and long are all signed) */
sherman@16744 237 #ifdef INT_MAX
sherman@16744 238 # define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > INT_MAX)
sherman@16744 239 #else
sherman@16744 240 unsigned ZLIB_INTERNAL gz_intmax OF((void));
sherman@16744 241 # define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax())
sherman@16744 242 #endif