/* gzguts.h -- zlib internal header definitions for gz* operations1* Copyright (C) 2004, 2005, 2010, 2011, 2012, 2013, 2016 Mark Adler2* For conditions of distribution and use, see copyright notice in zlib.h3*/45#ifdef _LARGEFILE64_SOURCE6# ifndef _LARGEFILE_SOURCE7# define _LARGEFILE_SOURCE 18# endif9# ifdef _FILE_OFFSET_BITS10# undef _FILE_OFFSET_BITS11# endif12#endif1314#ifdef HAVE_HIDDEN15# define ZLIB_INTERNAL __attribute__((visibility ("hidden")))16#else17# define ZLIB_INTERNAL18#endif1920#include <stdio.h>21#include "zlib.h"22#ifdef STDC23# include <string.h>24# include <stdlib.h>25# include <limits.h>26#endif2728#ifndef _POSIX_SOURCE29# define _POSIX_SOURCE30#endif31#include <fcntl.h>3233#ifdef _WIN3234# include <stddef.h>35#endif3637#if defined(__TURBOC__) || defined(_MSC_VER) || defined(_WIN32)38# include <io.h>39#endif4041#if defined(_WIN32) || defined(__CYGWIN__)42# define WIDECHAR43#endif4445#ifdef WINAPI_FAMILY46# define open _open47# define read _read48# define write _write49# define close _close50#endif5152#ifdef NO_DEFLATE /* for compatibility with old definition */53# define NO_GZCOMPRESS54#endif5556#if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)57# ifndef HAVE_VSNPRINTF58# define HAVE_VSNPRINTF59# endif60#endif6162#if defined(__CYGWIN__)63# ifndef HAVE_VSNPRINTF64# define HAVE_VSNPRINTF65# endif66#endif6768#if defined(MSDOS) && defined(__BORLANDC__) && (BORLANDC > 0x410)69# ifndef HAVE_VSNPRINTF70# define HAVE_VSNPRINTF71# endif72#endif7374#ifndef HAVE_VSNPRINTF75# ifdef MSDOS76/* vsnprintf may exist on some MS-DOS compilers (DJGPP?),77but for now we just assume it doesn't. */78# define NO_vsnprintf79# endif80# ifdef __TURBOC__81# define NO_vsnprintf82# endif83# ifdef WIN3284/* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */85# if !defined(vsnprintf) && !defined(NO_vsnprintf)86# if !defined(_MSC_VER) || ( defined(_MSC_VER) && _MSC_VER < 1500 )87# define vsnprintf _vsnprintf88# endif89# endif90# endif91# ifdef __SASC92# define NO_vsnprintf93# endif94# ifdef VMS95# define NO_vsnprintf96# endif97# ifdef __OS400__98# define NO_vsnprintf99# endif100# ifdef __MVS__101# define NO_vsnprintf102# endif103#endif104105/* unlike snprintf (which is required in C99), _snprintf does not guarantee106null termination of the result -- however this is only used in gzlib.c where107the result is assured to fit in the space provided */108#if defined(_MSC_VER) && _MSC_VER < 1900109# define snprintf _snprintf110#endif111112#ifndef local113# define local static114#endif115/* since "static" is used to mean two completely different things in C, we116define "local" for the non-static meaning of "static", for readability117(compile with -Dlocal if your debugger can't find static symbols) */118119/* gz* functions always use library allocation functions */120#ifndef STDC121extern voidp malloc OF((uInt size));122extern void free OF((voidpf ptr));123#endif124125/* get errno and strerror definition */126#if defined UNDER_CE127# include <windows.h>128# define zstrerror() gz_strwinerror((DWORD)GetLastError())129#else130# ifndef NO_STRERROR131# include <errno.h>132# define zstrerror() strerror(errno)133# else134# define zstrerror() "stdio error (consult errno)"135# endif136#endif137138/* provide prototypes for these when building zlib without LFS */139#if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0140ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *));141ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int));142ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile));143ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile));144#endif145146/* default memLevel */147#if MAX_MEM_LEVEL >= 8148# define DEF_MEM_LEVEL 8149#else150# define DEF_MEM_LEVEL MAX_MEM_LEVEL151#endif152153/* default i/o buffer size -- double this for output when reading (this and154twice this must be able to fit in an unsigned type) */155#define GZBUFSIZE 8192156157/* gzip modes, also provide a little integrity check on the passed structure */158#define GZ_NONE 0159#define GZ_READ 7247160#define GZ_WRITE 31153161#define GZ_APPEND 1 /* mode set to GZ_WRITE after the file is opened */162163/* values for gz_state how */164#define LOOK 0 /* look for a gzip header */165#define COPY 1 /* copy input directly */166#define GZIP 2 /* decompress a gzip stream */167168/* internal gzip file state data structure */169typedef struct {170/* exposed contents for gzgetc() macro */171struct gzFile_s x; /* "x" for exposed */172/* x.have: number of bytes available at x.next */173/* x.next: next output data to deliver or write */174/* x.pos: current position in uncompressed data */175/* used for both reading and writing */176int mode; /* see gzip modes above */177int fd; /* file descriptor */178char *path; /* path or fd for error messages */179unsigned size; /* buffer size, zero if not allocated yet */180unsigned want; /* requested buffer size, default is GZBUFSIZE */181unsigned char *in; /* input buffer (double-sized when writing) */182unsigned char *out; /* output buffer (double-sized when reading) */183int direct; /* 0 if processing gzip, 1 if transparent */184/* just for reading */185int how; /* 0: get header, 1: copy, 2: decompress */186z_off64_t start; /* where the gzip data started, for rewinding */187int eof; /* true if end of input file reached */188int past; /* true if read requested past end */189/* just for writing */190int level; /* compression level */191int strategy; /* compression strategy */192/* seek request */193z_off64_t skip; /* amount to skip (already rewound if backwards) */194int seek; /* true if seek request pending */195/* error information */196int err; /* error code */197char *msg; /* error message */198/* zlib inflate or deflate stream */199z_stream strm; /* stream structure in-place (not a pointer) */200} gz_state;201typedef gz_state FAR *gz_statep;202203/* shared functions */204void ZLIB_INTERNAL gz_error OF((gz_statep, int, const char *));205#if defined UNDER_CE206char ZLIB_INTERNAL *gz_strwinerror OF((DWORD error));207#endif208209/* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t210value -- needed when comparing unsigned to z_off64_t, which is signed211(possible z_off64_t types off_t, off64_t, and long are all signed) */212#ifdef INT_MAX213# define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > INT_MAX)214#else215unsigned ZLIB_INTERNAL gz_intmax OF((void));216# define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax())217#endif218219220