|
Packit |
40b132 |
/* gzguts.h -- zlib internal header definitions for gz* operations
|
|
Packit |
40b132 |
* Copyright (C) 2004, 2005, 2010 Mark Adler
|
|
Packit |
40b132 |
* For conditions of distribution and use, see copyright notice in zlib.h
|
|
Packit |
40b132 |
*/
|
|
Packit |
40b132 |
|
|
Packit |
40b132 |
#ifdef _LARGEFILE64_SOURCE
|
|
Packit |
40b132 |
# ifndef _LARGEFILE_SOURCE
|
|
Packit |
40b132 |
# define _LARGEFILE_SOURCE 1
|
|
Packit |
40b132 |
# endif
|
|
Packit |
40b132 |
# ifdef _FILE_OFFSET_BITS
|
|
Packit |
40b132 |
# undef _FILE_OFFSET_BITS
|
|
Packit |
40b132 |
# endif
|
|
Packit |
40b132 |
#endif
|
|
Packit |
40b132 |
|
|
Packit |
40b132 |
#if ((__GNUC__-0) * 10 + __GNUC_MINOR__-0 >= 33) && !defined(NO_VIZ)
|
|
Packit |
40b132 |
# define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
|
|
Packit |
40b132 |
#else
|
|
Packit |
40b132 |
# define ZLIB_INTERNAL
|
|
Packit |
40b132 |
#endif
|
|
Packit |
40b132 |
|
|
Packit |
40b132 |
#include <stdio.h>
|
|
Packit |
40b132 |
#include "zlib.h"
|
|
Packit |
40b132 |
#ifdef STDC
|
|
Packit |
40b132 |
# include <string.h>
|
|
Packit |
40b132 |
# include <stdlib.h>
|
|
Packit |
40b132 |
# include <limits.h>
|
|
Packit |
40b132 |
#endif
|
|
Packit |
40b132 |
#include <fcntl.h>
|
|
Packit |
40b132 |
|
|
Packit |
40b132 |
#ifdef NO_DEFLATE /* for compatibility with old definition */
|
|
Packit |
40b132 |
# define NO_GZCOMPRESS
|
|
Packit |
40b132 |
#endif
|
|
Packit |
40b132 |
|
|
Packit |
40b132 |
#ifdef _MSC_VER
|
|
Packit |
40b132 |
# include <io.h>
|
|
Packit |
40b132 |
# define vsnprintf _vsnprintf
|
|
Packit |
40b132 |
#endif
|
|
Packit |
40b132 |
|
|
Packit |
40b132 |
#ifndef local
|
|
Packit |
40b132 |
# define local static
|
|
Packit |
40b132 |
#endif
|
|
Packit |
40b132 |
/* compile with -Dlocal if your debugger can't find static symbols */
|
|
Packit |
40b132 |
|
|
Packit |
40b132 |
/* gz* functions always use library allocation functions */
|
|
Packit |
40b132 |
#ifndef STDC
|
|
Packit |
40b132 |
extern voidp malloc OF((uInt size));
|
|
Packit |
40b132 |
extern void free OF((voidpf ptr));
|
|
Packit |
40b132 |
#endif
|
|
Packit |
40b132 |
|
|
Packit |
40b132 |
/* get errno and strerror definition */
|
|
Packit |
40b132 |
#if defined UNDER_CE
|
|
Packit |
40b132 |
# include <windows.h>
|
|
Packit |
40b132 |
# define zstrerror() gz_strwinerror((DWORD)GetLastError())
|
|
Packit |
40b132 |
#else
|
|
Packit |
40b132 |
# ifdef STDC
|
|
Packit |
40b132 |
# include <errno.h>
|
|
Packit |
40b132 |
# define zstrerror() strerror(errno)
|
|
Packit |
40b132 |
# else
|
|
Packit |
40b132 |
# define zstrerror() "stdio error (consult errno)"
|
|
Packit |
40b132 |
# endif
|
|
Packit |
40b132 |
#endif
|
|
Packit |
40b132 |
|
|
Packit |
40b132 |
/* provide prototypes for these when building zlib without LFS */
|
|
Packit |
40b132 |
#if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0
|
|
Packit |
40b132 |
ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *));
|
|
Packit |
40b132 |
ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int));
|
|
Packit |
40b132 |
ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile));
|
|
Packit |
40b132 |
ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile));
|
|
Packit |
40b132 |
#endif
|
|
Packit |
40b132 |
|
|
Packit |
40b132 |
/* default i/o buffer size -- double this for output when reading */
|
|
Packit |
40b132 |
#define GZBUFSIZE 8192
|
|
Packit |
40b132 |
|
|
Packit |
40b132 |
/* gzip modes, also provide a little integrity check on the passed structure */
|
|
Packit |
40b132 |
#define GZ_NONE 0
|
|
Packit |
40b132 |
#define GZ_READ 7247
|
|
Packit |
40b132 |
#define GZ_WRITE 31153
|
|
Packit |
40b132 |
#define GZ_APPEND 1 /* mode set to GZ_WRITE after the file is opened */
|
|
Packit |
40b132 |
|
|
Packit |
40b132 |
/* values for gz_state how */
|
|
Packit |
40b132 |
#define LOOK 0 /* look for a gzip header */
|
|
Packit |
40b132 |
#define COPY 1 /* copy input directly */
|
|
Packit |
40b132 |
#define GZIP 2 /* decompress a gzip stream */
|
|
Packit |
40b132 |
|
|
Packit |
40b132 |
/* internal gzip file state data structure */
|
|
Packit |
40b132 |
typedef struct {
|
|
Packit |
40b132 |
/* used for both reading and writing */
|
|
Packit |
40b132 |
int mode; /* see gzip modes above */
|
|
Packit |
40b132 |
int fd; /* file descriptor */
|
|
Packit |
40b132 |
char *path; /* path or fd for error messages */
|
|
Packit |
40b132 |
z_off64_t pos; /* current position in uncompressed data */
|
|
Packit |
40b132 |
unsigned size; /* buffer size, zero if not allocated yet */
|
|
Packit |
40b132 |
unsigned want; /* requested buffer size, default is GZBUFSIZE */
|
|
Packit |
40b132 |
unsigned char *in; /* input buffer */
|
|
Packit |
40b132 |
unsigned char *out; /* output buffer (double-sized when reading) */
|
|
Packit |
40b132 |
unsigned char *next; /* next output data to deliver or write */
|
|
Packit |
40b132 |
/* just for reading */
|
|
Packit |
40b132 |
unsigned have; /* amount of output data unused at next */
|
|
Packit |
40b132 |
int eof; /* true if end of input file reached */
|
|
Packit |
40b132 |
z_off64_t start; /* where the gzip data started, for rewinding */
|
|
Packit |
40b132 |
z_off64_t raw; /* where the raw data started, for seeking */
|
|
Packit |
40b132 |
int how; /* 0: get header, 1: copy, 2: decompress */
|
|
Packit |
40b132 |
int direct; /* true if last read direct, false if gzip */
|
|
Packit |
40b132 |
/* just for writing */
|
|
Packit |
40b132 |
int level; /* compression level */
|
|
Packit |
40b132 |
int strategy; /* compression strategy */
|
|
Packit |
40b132 |
/* seek request */
|
|
Packit |
40b132 |
z_off64_t skip; /* amount to skip (already rewound if backwards) */
|
|
Packit |
40b132 |
int seek; /* true if seek request pending */
|
|
Packit |
40b132 |
/* error information */
|
|
Packit |
40b132 |
int err; /* error code */
|
|
Packit |
40b132 |
char *msg; /* error message */
|
|
Packit |
40b132 |
/* zlib inflate or deflate stream */
|
|
Packit |
40b132 |
z_stream strm; /* stream structure in-place (not a pointer) */
|
|
Packit |
40b132 |
} gz_state;
|
|
Packit |
40b132 |
typedef gz_state FAR *gz_statep;
|
|
Packit |
40b132 |
|
|
Packit |
40b132 |
/* shared functions */
|
|
Packit |
40b132 |
void ZLIB_INTERNAL gz_error OF((gz_statep, int, const char *));
|
|
Packit |
40b132 |
#if defined UNDER_CE
|
|
Packit |
40b132 |
char ZLIB_INTERNAL *gz_strwinerror OF((DWORD error));
|
|
Packit |
40b132 |
#endif
|
|
Packit |
40b132 |
|
|
Packit |
40b132 |
/* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t
|
|
Packit |
40b132 |
value -- needed when comparing unsigned to z_off64_t, which is signed
|
|
Packit |
40b132 |
(possible z_off64_t types off_t, off64_t, and long are all signed) */
|
|
Packit |
40b132 |
#ifdef INT_MAX
|
|
Packit |
40b132 |
# define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > INT_MAX)
|
|
Packit |
40b132 |
#else
|
|
Packit |
40b132 |
unsigned ZLIB_INTERNAL gz_intmax OF((void));
|
|
Packit |
40b132 |
# define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax())
|
|
Packit |
40b132 |
#endif
|