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