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