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