gzguts.h 4.5 KB
Newer Older
M
Mark Adler 已提交
1 2 3 4 5
/* gzguts.h -- zlib internal header definitions for gz* operations
 * Copyright (C) 2004, 2005, 2010 Mark Adler
 * For conditions of distribution and use, see copyright notice in zlib.h
 */

M
Mark Adler 已提交
6
#if _LARGEFILE64_SOURCE
M
Mark Adler 已提交
7
#  ifndef _LARGEFILE_SOURCE
M
Mark Adler 已提交
8
#    define _LARGEFILE_SOURCE 1
M
Mark Adler 已提交
9 10 11 12 13 14 15 16 17 18
#  endif
#  ifdef _FILE_OFFSET_BITS
#    undef _FILE_OFFSET_BITS
#  endif
#endif

#define ZLIB_INTERNAL

#include <stdio.h>
#include "zlib.h"
M
Mark Adler 已提交
19 20 21
#ifdef STDC
#  include <string.h>
#  include <stdlib.h>
M
Mark Adler 已提交
22
#  include <limits.h>
M
Mark Adler 已提交
23 24
#endif
#include <fcntl.h>
M
Mark Adler 已提交
25 26 27 28 29

#ifdef NO_DEFLATE       /* for compatibility with old definition */
#  define NO_GZCOMPRESS
#endif

M
Mark Adler 已提交
30
#ifdef _MSC_VER
M
Mark Adler 已提交
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
#  include <io.h>
#  define vsnprintf _vsnprintf
#endif

#ifndef local
#  define local static
#endif
/* compile with -Dlocal if your debugger can't find static symbols */

/* gz* functions always use library allocation functions */
#ifndef STDC
  extern voidp  malloc OF((uInt size));
  extern void   free   OF((voidpf ptr));
#endif

/* get errno and strerror definition */
M
Mark Adler 已提交
47
#if defined UNDER_CE
M
Mark Adler 已提交
48 49
#  include <windows.h>
#  define zstrerror() gz_strwinerror((DWORD)GetLastError())
M
Mark Adler 已提交
50 51 52 53 54 55 56 57 58
#else
#  ifdef STDC
#    include <errno.h>
#    define zstrerror() strerror(errno)
#  else
#    define zstrerror() "stdio error (consult errno)"
#  endif
#endif

M
Mark Adler 已提交
59
#if _LARGEFILE64_SOURCE
M
Mark Adler 已提交
60 61 62 63 64
#  define z_off64_t off64_t
#else
#  define z_off64_t z_off_t
#endif

M
Mark Adler 已提交
65 66 67 68 69 70 71 72
/* provide prototypes for these when building zlib without LFS */
#if _LARGEFILE64_SOURCE+0 != 1 || _LFS64_LARGEFILE+0 != 1
    ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *));
    ZEXTERN z_off_t ZEXPORT gzseek64 OF((gzFile, off_t, int));
    ZEXTERN z_off_t ZEXPORT gztell64 OF((gzFile));
    ZEXTERN z_off_t ZEXPORT gzoffset64 OF((gzFile));
#endif

M
Mark Adler 已提交
73 74 75 76 77 78 79 80 81
/* default i/o buffer size -- double this for output when reading */
#define GZBUFSIZE 8192

/* gzip modes, also provide a little integrity check on the passed structure */
#define GZ_NONE 0
#define GZ_READ 7247
#define GZ_WRITE 31153
#define GZ_APPEND 1     /* mode set to GZ_WRITE after the file is opened */

M
Mark Adler 已提交
82 83 84 85 86
/* values for gz_state how */
#define LOOK 0      /* look for a gzip header */
#define COPY 1      /* copy input directly */
#define GZIP 2      /* decompress a gzip stream */

M
Mark Adler 已提交
87 88 89 90 91 92 93 94 95 96 97 98 99
/* internal gzip file state data structure */
typedef struct {
        /* used for both reading and writing */
    int mode;               /* see gzip modes above */
    int fd;                 /* file descriptor */
    char *path;             /* path or fd for error messages */
    z_off64_t pos;          /* current position in uncompressed data */
    unsigned size;          /* buffer size, zero if not allocated yet */
    unsigned want;          /* requested buffer size, default is GZBUFSIZE */
    unsigned char *in;      /* input buffer */
    unsigned char *out;     /* output buffer (double-sized when reading) */
    unsigned char *next;    /* next output data to deliver or write */
        /* just for reading */
M
Mark Adler 已提交
100 101
    unsigned have;          /* amount of output data unused at next */
    int eof;                /* true if end of input file reached */
M
Mark Adler 已提交
102 103
    z_off64_t start;        /* where the gzip data started, for rewinding */
    z_off64_t raw;          /* where the raw data started, for seeking */
M
Mark Adler 已提交
104 105
    int how;                /* 0: get header, 1: copy, 2: decompress */
    int direct;             /* true if last read direct, false if gzip */
M
Mark Adler 已提交
106 107 108 109 110
        /* just for writing */
    int level;              /* compression level */
    int strategy;           /* compression strategy */
        /* seek request */
    z_off64_t skip;         /* amount to skip (already rewound if backwards) */
M
Mark Adler 已提交
111
    int seek;               /* true if seek request pending */
M
Mark Adler 已提交
112 113 114 115 116 117 118 119 120
        /* error information */
    int err;                /* error code */
    char *msg;              /* error message */
        /* zlib inflate or deflate stream */
    z_stream strm;          /* stream structure in-place (not a pointer) */
} gz_state;
typedef gz_state FAR *gz_statep;

/* shared functions */
M
Mark Adler 已提交
121
ZEXTERN void ZEXPORT gz_error OF((gz_statep, int, const char *));
M
Mark Adler 已提交
122
#if defined UNDER_CE
M
Mark Adler 已提交
123 124
ZEXTERN char ZEXPORT *gz_strwinerror OF((DWORD error));
#endif
M
Mark Adler 已提交
125 126 127 128 129 130 131 132 133 134

/* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t
   value -- needed when comparing unsigned to z_off64_t, which is signed
   (possible z_off64_t types off_t, off64_t, and long are all signed) */
#ifdef INT_MAX
#  define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > INT_MAX)
#else
ZEXTERN unsigned ZEXPORT gz_intmax OF((void));
#  define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax())
#endif