Chris@4: /* gzguts.h -- zlib internal header definitions for gz* operations Chris@4: * Copyright (C) 2004, 2005, 2010, 2011, 2012 Mark Adler Chris@4: * For conditions of distribution and use, see copyright notice in zlib.h Chris@4: */ Chris@4: Chris@4: #ifdef _LARGEFILE64_SOURCE Chris@4: # ifndef _LARGEFILE_SOURCE Chris@4: # define _LARGEFILE_SOURCE 1 Chris@4: # endif Chris@4: # ifdef _FILE_OFFSET_BITS Chris@4: # undef _FILE_OFFSET_BITS Chris@4: # endif Chris@4: #endif Chris@4: Chris@4: #ifdef HAVE_HIDDEN Chris@4: # define ZLIB_INTERNAL __attribute__((visibility ("hidden"))) Chris@4: #else Chris@4: # define ZLIB_INTERNAL Chris@4: #endif Chris@4: Chris@4: #include Chris@4: #include "zlib.h" Chris@4: #ifdef STDC Chris@4: # include Chris@4: # include Chris@4: # include Chris@4: #endif Chris@4: #include Chris@4: Chris@4: #ifdef _WIN32 Chris@4: # include Chris@4: #endif Chris@4: Chris@4: #if defined(__TURBOC__) || defined(_MSC_VER) || defined(_WIN32) Chris@4: # include Chris@4: #endif Chris@4: Chris@4: #ifdef NO_DEFLATE /* for compatibility with old definition */ Chris@4: # define NO_GZCOMPRESS Chris@4: #endif Chris@4: Chris@4: #if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550) Chris@4: # ifndef HAVE_VSNPRINTF Chris@4: # define HAVE_VSNPRINTF Chris@4: # endif Chris@4: #endif Chris@4: Chris@4: #if defined(__CYGWIN__) Chris@4: # ifndef HAVE_VSNPRINTF Chris@4: # define HAVE_VSNPRINTF Chris@4: # endif Chris@4: #endif Chris@4: Chris@4: #if defined(MSDOS) && defined(__BORLANDC__) && (BORLANDC > 0x410) Chris@4: # ifndef HAVE_VSNPRINTF Chris@4: # define HAVE_VSNPRINTF Chris@4: # endif Chris@4: #endif Chris@4: Chris@4: #ifndef HAVE_VSNPRINTF Chris@4: # ifdef MSDOS Chris@4: /* vsnprintf may exist on some MS-DOS compilers (DJGPP?), Chris@4: but for now we just assume it doesn't. */ Chris@4: # define NO_vsnprintf Chris@4: # endif Chris@4: # ifdef __TURBOC__ Chris@4: # define NO_vsnprintf Chris@4: # endif Chris@4: # ifdef WIN32 Chris@4: /* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */ Chris@4: # if !defined(vsnprintf) && !defined(NO_vsnprintf) Chris@4: # if !defined(_MSC_VER) || ( defined(_MSC_VER) && _MSC_VER < 1500 ) Chris@4: # define vsnprintf _vsnprintf Chris@4: # endif Chris@4: # endif Chris@4: # endif Chris@4: # ifdef __SASC Chris@4: # define NO_vsnprintf Chris@4: # endif Chris@4: # ifdef VMS Chris@4: # define NO_vsnprintf Chris@4: # endif Chris@4: # ifdef __OS400__ Chris@4: # define NO_vsnprintf Chris@4: # endif Chris@4: # ifdef __MVS__ Chris@4: # define NO_vsnprintf Chris@4: # endif Chris@4: #endif Chris@4: Chris@4: #ifndef local Chris@4: # define local static Chris@4: #endif Chris@4: /* compile with -Dlocal if your debugger can't find static symbols */ Chris@4: Chris@4: /* gz* functions always use library allocation functions */ Chris@4: #ifndef STDC Chris@4: extern voidp malloc OF((uInt size)); Chris@4: extern void free OF((voidpf ptr)); Chris@4: #endif Chris@4: Chris@4: /* get errno and strerror definition */ Chris@4: #if defined UNDER_CE Chris@4: # include Chris@4: # define zstrerror() gz_strwinerror((DWORD)GetLastError()) Chris@4: #else Chris@4: # ifndef NO_STRERROR Chris@4: # include Chris@4: # define zstrerror() strerror(errno) Chris@4: # else Chris@4: # define zstrerror() "stdio error (consult errno)" Chris@4: # endif Chris@4: #endif Chris@4: Chris@4: /* provide prototypes for these when building zlib without LFS */ Chris@4: #if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0 Chris@4: ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); Chris@4: ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int)); Chris@4: ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile)); Chris@4: ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile)); Chris@4: #endif Chris@4: Chris@4: /* default memLevel */ Chris@4: #if MAX_MEM_LEVEL >= 8 Chris@4: # define DEF_MEM_LEVEL 8 Chris@4: #else Chris@4: # define DEF_MEM_LEVEL MAX_MEM_LEVEL Chris@4: #endif Chris@4: Chris@4: /* default i/o buffer size -- double this for output when reading */ Chris@4: #define GZBUFSIZE 8192 Chris@4: Chris@4: /* gzip modes, also provide a little integrity check on the passed structure */ Chris@4: #define GZ_NONE 0 Chris@4: #define GZ_READ 7247 Chris@4: #define GZ_WRITE 31153 Chris@4: #define GZ_APPEND 1 /* mode set to GZ_WRITE after the file is opened */ Chris@4: Chris@4: /* values for gz_state how */ Chris@4: #define LOOK 0 /* look for a gzip header */ Chris@4: #define COPY 1 /* copy input directly */ Chris@4: #define GZIP 2 /* decompress a gzip stream */ Chris@4: Chris@4: /* internal gzip file state data structure */ Chris@4: typedef struct { Chris@4: /* exposed contents for gzgetc() macro */ Chris@4: struct gzFile_s x; /* "x" for exposed */ Chris@4: /* x.have: number of bytes available at x.next */ Chris@4: /* x.next: next output data to deliver or write */ Chris@4: /* x.pos: current position in uncompressed data */ Chris@4: /* used for both reading and writing */ Chris@4: int mode; /* see gzip modes above */ Chris@4: int fd; /* file descriptor */ Chris@4: char *path; /* path or fd for error messages */ Chris@4: unsigned size; /* buffer size, zero if not allocated yet */ Chris@4: unsigned want; /* requested buffer size, default is GZBUFSIZE */ Chris@4: unsigned char *in; /* input buffer */ Chris@4: unsigned char *out; /* output buffer (double-sized when reading) */ Chris@4: int direct; /* 0 if processing gzip, 1 if transparent */ Chris@4: /* just for reading */ Chris@4: int how; /* 0: get header, 1: copy, 2: decompress */ Chris@4: z_off64_t start; /* where the gzip data started, for rewinding */ Chris@4: int eof; /* true if end of input file reached */ Chris@4: int past; /* true if read requested past end */ Chris@4: /* just for writing */ Chris@4: int level; /* compression level */ Chris@4: int strategy; /* compression strategy */ Chris@4: /* seek request */ Chris@4: z_off64_t skip; /* amount to skip (already rewound if backwards) */ Chris@4: int seek; /* true if seek request pending */ Chris@4: /* error information */ Chris@4: int err; /* error code */ Chris@4: char *msg; /* error message */ Chris@4: /* zlib inflate or deflate stream */ Chris@4: z_stream strm; /* stream structure in-place (not a pointer) */ Chris@4: } gz_state; Chris@4: typedef gz_state FAR *gz_statep; Chris@4: Chris@4: /* shared functions */ Chris@4: void ZLIB_INTERNAL gz_error OF((gz_statep, int, const char *)); Chris@4: #if defined UNDER_CE Chris@4: char ZLIB_INTERNAL *gz_strwinerror OF((DWORD error)); Chris@4: #endif Chris@4: Chris@4: /* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t Chris@4: value -- needed when comparing unsigned to z_off64_t, which is signed Chris@4: (possible z_off64_t types off_t, off64_t, and long are all signed) */ Chris@4: #ifdef INT_MAX Chris@4: # define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > INT_MAX) Chris@4: #else Chris@4: unsigned ZLIB_INTERNAL gz_intmax OF((void)); Chris@4: # define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax()) Chris@4: #endif