/* gzguts.h -- zlib internal header definitions for gz* operations1* Copyright (C) 2004-2024 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# undef _FILE_OFFSET_BITS10# undef _TIME_BITS11#endif1213#ifdef HAVE_HIDDEN14# define ZLIB_INTERNAL __attribute__((visibility ("hidden")))15#else16# define ZLIB_INTERNAL17#endif1819#include <stdio.h>20#include "zlib.h"21#ifdef STDC22# include <string.h>23# include <stdlib.h>24# include <limits.h>25#endif2627#ifndef _POSIX_SOURCE28# define _POSIX_SOURCE29#endif30#include <fcntl.h>3132#ifdef _WIN3233# include <stddef.h>34#endif3536#if defined(__TURBOC__) || defined(_MSC_VER) || defined(_WIN32)37# include <io.h>38#endif3940#if defined(_WIN32)41# define WIDECHAR42#endif4344#ifdef WINAPI_FAMILY45# define open _open46# define read _read47# define write _write48# define close _close49#endif5051#ifdef NO_DEFLATE /* for compatibility with old definition */52# define NO_GZCOMPRESS53#endif5455#if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)56# ifndef HAVE_VSNPRINTF57# define HAVE_VSNPRINTF58# endif59#endif6061#if defined(__CYGWIN__)62# ifndef HAVE_VSNPRINTF63# define HAVE_VSNPRINTF64# endif65#endif6667#if defined(MSDOS) && defined(__BORLANDC__) && (BORLANDC > 0x410)68# ifndef HAVE_VSNPRINTF69# define HAVE_VSNPRINTF70# endif71#endif7273#ifndef HAVE_VSNPRINTF74# ifdef MSDOS75/* vsnprintf may exist on some MS-DOS compilers (DJGPP?),76but for now we just assume it doesn't. */77# define NO_vsnprintf78# endif79# ifdef __TURBOC__80# define NO_vsnprintf81# endif82# ifdef WIN3283/* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */84# if !defined(vsnprintf) && !defined(NO_vsnprintf)85# if !defined(_MSC_VER) || ( defined(_MSC_VER) && _MSC_VER < 1500 )86# define vsnprintf _vsnprintf87# endif88# endif89# endif90# ifdef __SASC91# define NO_vsnprintf92# endif93# ifdef VMS94# define NO_vsnprintf95# endif96# ifdef __OS400__97# define NO_vsnprintf98# endif99# ifdef __MVS__100# define NO_vsnprintf101# endif102#endif103104/* unlike snprintf (which is required in C99), _snprintf does not guarantee105null termination of the result -- however this is only used in gzlib.c where106the result is assured to fit in the space provided */107#if defined(_MSC_VER) && _MSC_VER < 1900108# define snprintf _snprintf109#endif110111#ifndef local112# define local static113#endif114/* since "static" is used to mean two completely different things in C, we115define "local" for the non-static meaning of "static", for readability116(compile with -Dlocal if your debugger can't find static symbols) */117118/* gz* functions always use library allocation functions */119#ifndef STDC120extern voidp malloc(uInt size);121extern void free(voidpf ptr);122#endif123124/* get errno and strerror definition */125#if defined UNDER_CE126# include <windows.h>127# define zstrerror() gz_strwinerror((DWORD)GetLastError())128#else129# ifndef NO_STRERROR130# include <errno.h>131# define zstrerror() strerror(errno)132# else133# define zstrerror() "stdio error (consult errno)"134# endif135#endif136137/* provide prototypes for these when building zlib without LFS */138#if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0139ZEXTERN gzFile ZEXPORT gzopen64(const char *, const char *);140ZEXTERN z_off64_t ZEXPORT gzseek64(gzFile, z_off64_t, int);141ZEXTERN z_off64_t ZEXPORT gztell64(gzFile);142ZEXTERN z_off64_t ZEXPORT gzoffset64(gzFile);143#endif144145/* default memLevel */146#if MAX_MEM_LEVEL >= 8147# define DEF_MEM_LEVEL 8148#else149# define DEF_MEM_LEVEL MAX_MEM_LEVEL150#endif151152/* default i/o buffer size -- double this for output when reading (this and153twice this must be able to fit in an unsigned type) */154#define GZBUFSIZE 8192155156/* gzip modes, also provide a little integrity check on the passed structure */157#define GZ_NONE 0158#define GZ_READ 7247159#define GZ_WRITE 31153160#define GZ_APPEND 1 /* mode set to GZ_WRITE after the file is opened */161162/* values for gz_state how */163#define LOOK 0 /* look for a gzip header */164#define COPY 1 /* copy input directly */165#define GZIP 2 /* decompress a gzip stream */166167/* internal gzip file state data structure */168typedef struct {169/* exposed contents for gzgetc() macro */170struct gzFile_s x; /* "x" for exposed */171/* x.have: number of bytes available at x.next */172/* x.next: next output data to deliver or write */173/* x.pos: current position in uncompressed data */174/* used for both reading and writing */175int mode; /* see gzip modes above */176int fd; /* file descriptor */177char *path; /* path or fd for error messages */178unsigned size; /* buffer size, zero if not allocated yet */179unsigned want; /* requested buffer size, default is GZBUFSIZE */180unsigned char *in; /* input buffer (double-sized when writing) */181unsigned char *out; /* output buffer (double-sized when reading) */182int direct; /* 0 if processing gzip, 1 if transparent */183/* just for reading */184int how; /* 0: get header, 1: copy, 2: decompress */185z_off64_t start; /* where the gzip data started, for rewinding */186int eof; /* true if end of input file reached */187int past; /* true if read requested past end */188/* just for writing */189int level; /* compression level */190int strategy; /* compression strategy */191int reset; /* true if a reset is pending after a Z_FINISH */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(gz_statep, int, const char *);205#if defined UNDER_CE206char ZLIB_INTERNAL *gz_strwinerror(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) */212unsigned ZLIB_INTERNAL gz_intmax(void);213#define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax())214215216