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