Path: blob/master/src/java.base/share/native/libzip/zlib/gzguts.h
41153 views
/*1* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.2*3* This code is free software; you can redistribute it and/or modify it4* under the terms of the GNU General Public License version 2 only, as5* published by the Free Software Foundation. Oracle designates this6* particular file as subject to the "Classpath" exception as provided7* by Oracle in the LICENSE file that accompanied this code.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 2 along with this work; if not, write to the Free Software Foundation,17* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.18*19* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*/2324/* gzguts.h -- zlib internal header definitions for gz* operations25* Copyright (C) 2004, 2005, 2010, 2011, 2012, 2013, 2016 Mark Adler26* For conditions of distribution and use, see copyright notice in zlib.h27*/2829#ifdef _LARGEFILE64_SOURCE30# ifndef _LARGEFILE_SOURCE31# define _LARGEFILE_SOURCE 132# endif33# ifdef _FILE_OFFSET_BITS34# undef _FILE_OFFSET_BITS35# endif36#endif3738#ifdef HAVE_HIDDEN39# define ZLIB_INTERNAL __attribute__((visibility ("hidden")))40#else41# define ZLIB_INTERNAL42#endif4344#include <stdio.h>45#include "zlib.h"46#ifdef STDC47# include <string.h>48# include <stdlib.h>49# include <limits.h>50#endif5152#ifndef _POSIX_SOURCE53# define _POSIX_SOURCE54#endif55#include <fcntl.h>5657#ifdef _WIN3258# include <stddef.h>59#endif6061#if defined(__TURBOC__) || defined(_MSC_VER) || defined(_WIN32)62# include <io.h>63#endif6465#if defined(_WIN32) || defined(__CYGWIN__)66# define WIDECHAR67#endif6869#ifdef WINAPI_FAMILY70# define open _open71# define read _read72# define write _write73# define close _close74#endif7576#ifdef NO_DEFLATE /* for compatibility with old definition */77# define NO_GZCOMPRESS78#endif7980#if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)81# ifndef HAVE_VSNPRINTF82# define HAVE_VSNPRINTF83# endif84#endif8586#if defined(__CYGWIN__)87# ifndef HAVE_VSNPRINTF88# define HAVE_VSNPRINTF89# endif90#endif9192#if defined(MSDOS) && defined(__BORLANDC__) && (BORLANDC > 0x410)93# ifndef HAVE_VSNPRINTF94# define HAVE_VSNPRINTF95# endif96#endif9798#ifndef HAVE_VSNPRINTF99# ifdef MSDOS100/* vsnprintf may exist on some MS-DOS compilers (DJGPP?),101but for now we just assume it doesn't. */102# define NO_vsnprintf103# endif104# ifdef __TURBOC__105# define NO_vsnprintf106# endif107# ifdef WIN32108/* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */109# if !defined(vsnprintf) && !defined(NO_vsnprintf)110# if !defined(_MSC_VER) || ( defined(_MSC_VER) && _MSC_VER < 1500 )111# define vsnprintf _vsnprintf112# endif113# endif114# endif115# ifdef __SASC116# define NO_vsnprintf117# endif118# ifdef VMS119# define NO_vsnprintf120# endif121# ifdef __OS400__122# define NO_vsnprintf123# endif124# ifdef __MVS__125# define NO_vsnprintf126# endif127#endif128129/* unlike snprintf (which is required in C99), _snprintf does not guarantee130null termination of the result -- however this is only used in gzlib.c where131the result is assured to fit in the space provided */132#if defined(_MSC_VER) && _MSC_VER < 1900133# define snprintf _snprintf134#endif135136#ifndef local137# define local static138#endif139/* since "static" is used to mean two completely different things in C, we140define "local" for the non-static meaning of "static", for readability141(compile with -Dlocal if your debugger can't find static symbols) */142143/* gz* functions always use library allocation functions */144#ifndef STDC145extern voidp malloc OF((uInt size));146extern void free OF((voidpf ptr));147#endif148149/* get errno and strerror definition */150#if defined UNDER_CE151# include <windows.h>152# define zstrerror() gz_strwinerror((DWORD)GetLastError())153#else154# ifndef NO_STRERROR155# include <errno.h>156# define zstrerror() strerror(errno)157# else158# define zstrerror() "stdio error (consult errno)"159# endif160#endif161162/* provide prototypes for these when building zlib without LFS */163#if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0164ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *));165ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int));166ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile));167ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile));168#endif169170/* default memLevel */171#if MAX_MEM_LEVEL >= 8172# define DEF_MEM_LEVEL 8173#else174# define DEF_MEM_LEVEL MAX_MEM_LEVEL175#endif176177/* default i/o buffer size -- double this for output when reading (this and178twice this must be able to fit in an unsigned type) */179#define GZBUFSIZE 8192180181/* gzip modes, also provide a little integrity check on the passed structure */182#define GZ_NONE 0183#define GZ_READ 7247184#define GZ_WRITE 31153185#define GZ_APPEND 1 /* mode set to GZ_WRITE after the file is opened */186187/* values for gz_state how */188#define LOOK 0 /* look for a gzip header */189#define COPY 1 /* copy input directly */190#define GZIP 2 /* decompress a gzip stream */191192/* internal gzip file state data structure */193typedef struct {194/* exposed contents for gzgetc() macro */195struct gzFile_s x; /* "x" for exposed */196/* x.have: number of bytes available at x.next */197/* x.next: next output data to deliver or write */198/* x.pos: current position in uncompressed data */199/* used for both reading and writing */200int mode; /* see gzip modes above */201int fd; /* file descriptor */202char *path; /* path or fd for error messages */203unsigned size; /* buffer size, zero if not allocated yet */204unsigned want; /* requested buffer size, default is GZBUFSIZE */205unsigned char *in; /* input buffer (double-sized when writing) */206unsigned char *out; /* output buffer (double-sized when reading) */207int direct; /* 0 if processing gzip, 1 if transparent */208/* just for reading */209int how; /* 0: get header, 1: copy, 2: decompress */210z_off64_t start; /* where the gzip data started, for rewinding */211int eof; /* true if end of input file reached */212int past; /* true if read requested past end */213/* just for writing */214int level; /* compression level */215int strategy; /* compression strategy */216/* seek request */217z_off64_t skip; /* amount to skip (already rewound if backwards) */218int seek; /* true if seek request pending */219/* error information */220int err; /* error code */221char *msg; /* error message */222/* zlib inflate or deflate stream */223z_stream strm; /* stream structure in-place (not a pointer) */224} gz_state;225typedef gz_state FAR *gz_statep;226227/* shared functions */228void ZLIB_INTERNAL gz_error OF((gz_statep, int, const char *));229#if defined UNDER_CE230char ZLIB_INTERNAL *gz_strwinerror OF((DWORD error));231#endif232233/* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t234value -- needed when comparing unsigned to z_off64_t, which is signed235(possible z_off64_t types off_t, off64_t, and long are all signed) */236#ifdef INT_MAX237# define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > INT_MAX)238#else239unsigned ZLIB_INTERNAL gz_intmax OF((void));240# define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax())241#endif242243244