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