2011-09-10 10:26:49 +04:00
|
|
|
/* gzguts.h -- zlib internal header definitions for gz* operations
|
2024-01-22 21:14:31 +03:00
|
|
|
* Copyright (C) 2004-2024 Mark Adler
|
2011-09-10 10:26:49 +04:00
|
|
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
|
|
|
*/
|
|
|
|
|
2011-09-10 10:34:38 +04:00
|
|
|
#ifdef _LARGEFILE64_SOURCE
|
2011-09-10 10:26:49 +04:00
|
|
|
# ifndef _LARGEFILE_SOURCE
|
2011-09-10 10:34:22 +04:00
|
|
|
# define _LARGEFILE_SOURCE 1
|
2011-09-10 10:26:49 +04:00
|
|
|
# endif
|
2023-07-30 08:13:09 +03:00
|
|
|
# undef _FILE_OFFSET_BITS
|
|
|
|
# undef _TIME_BITS
|
2011-09-10 10:26:49 +04:00
|
|
|
#endif
|
|
|
|
|
2012-03-03 12:20:00 +04:00
|
|
|
#ifdef HAVE_HIDDEN
|
2011-09-10 10:34:55 +04:00
|
|
|
# define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
|
|
|
|
#else
|
|
|
|
# define ZLIB_INTERNAL
|
|
|
|
#endif
|
2011-09-10 10:26:49 +04:00
|
|
|
|
2024-02-09 04:35:23 +03:00
|
|
|
#if defined(_WIN32) && !defined(_CRT_SECURE_NO_WARNINGS)
|
|
|
|
# define _CRT_SECURE_NO_WARNINGS
|
|
|
|
#endif
|
|
|
|
|
2011-09-10 10:26:49 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include "zlib.h"
|
2011-09-10 10:26:58 +04:00
|
|
|
#ifdef STDC
|
|
|
|
# include <string.h>
|
|
|
|
# include <stdlib.h>
|
2011-09-10 10:27:17 +04:00
|
|
|
# include <limits.h>
|
2011-09-10 10:26:58 +04:00
|
|
|
#endif
|
2015-07-29 09:32:35 +03:00
|
|
|
|
2024-02-06 08:00:21 +03:00
|
|
|
#ifndef _POSIX_C_SOURCE
|
|
|
|
# define _POSIX_C_SOURCE 200112L
|
2015-07-29 09:32:35 +03:00
|
|
|
#endif
|
2011-09-10 10:26:58 +04:00
|
|
|
#include <fcntl.h>
|
2011-09-10 10:26:49 +04:00
|
|
|
|
2012-03-18 08:42:30 +04:00
|
|
|
#ifdef _WIN32
|
|
|
|
# include <stddef.h>
|
|
|
|
#endif
|
|
|
|
|
2012-03-17 07:53:09 +04:00
|
|
|
#if defined(__TURBOC__) || defined(_MSC_VER) || defined(_WIN32)
|
2011-11-22 06:38:37 +04:00
|
|
|
# include <io.h>
|
2024-02-09 19:27:07 +03:00
|
|
|
# include <share.h>
|
2024-02-09 04:35:23 +03:00
|
|
|
# include <sys/stat.h>
|
2011-11-22 06:38:37 +04:00
|
|
|
#endif
|
|
|
|
|
2024-02-09 04:35:23 +03:00
|
|
|
#if defined(_WIN32) && !defined(WIDECHAR)
|
2015-08-02 03:38:56 +03:00
|
|
|
# define WIDECHAR
|
|
|
|
#endif
|
|
|
|
|
2024-02-09 04:35:23 +03:00
|
|
|
#if defined(_WIN32) || defined(WINAPI_FAMILY)
|
2013-02-24 08:27:13 +04:00
|
|
|
# define open _open
|
|
|
|
# define read _read
|
|
|
|
# define write _write
|
|
|
|
# define close _close
|
|
|
|
#endif
|
|
|
|
|
2011-09-10 10:26:49 +04:00
|
|
|
#ifdef NO_DEFLATE /* for compatibility with old definition */
|
|
|
|
# define NO_GZCOMPRESS
|
|
|
|
#endif
|
|
|
|
|
2011-10-02 22:15:00 +04:00
|
|
|
#if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
|
|
|
|
# ifndef HAVE_VSNPRINTF
|
|
|
|
# define HAVE_VSNPRINTF
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__CYGWIN__)
|
|
|
|
# ifndef HAVE_VSNPRINTF
|
|
|
|
# define HAVE_VSNPRINTF
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2011-11-19 11:14:14 +04:00
|
|
|
#if defined(MSDOS) && defined(__BORLANDC__) && (BORLANDC > 0x410)
|
|
|
|
# ifndef HAVE_VSNPRINTF
|
|
|
|
# define HAVE_VSNPRINTF
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2011-10-02 22:15:00 +04:00
|
|
|
#ifndef HAVE_VSNPRINTF
|
2024-02-07 02:59:25 +03:00
|
|
|
# if !defined(NO_vsnprintf) && \
|
|
|
|
(defined(MSDOS) || defined(__TURBOC__) || defined(__SASC) || \
|
|
|
|
defined(VMS) || defined(__OS400) || defined(__MVS__))
|
2011-10-02 22:15:00 +04:00
|
|
|
/* vsnprintf may exist on some MS-DOS compilers (DJGPP?),
|
2013-03-25 03:56:05 +04:00
|
|
|
but for now we just assume it doesn't. */
|
2011-10-02 22:15:00 +04:00
|
|
|
# define NO_vsnprintf
|
|
|
|
# endif
|
|
|
|
# ifdef WIN32
|
|
|
|
/* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */
|
2024-02-07 02:59:25 +03:00
|
|
|
# if !defined(_MSC_VER) || ( defined(_MSC_VER) && _MSC_VER < 1500 )
|
|
|
|
# ifndef vsnprintf
|
|
|
|
# define vsnprintf _vsnprintf
|
2011-10-02 22:15:00 +04:00
|
|
|
# endif
|
|
|
|
# endif
|
2024-02-07 02:59:25 +03:00
|
|
|
# elif !defined(__STDC_VERSION__) || __STDC_VERSION__-0 < 199901L
|
|
|
|
/* Otherwise if C89/90, assume no C99 snprintf() or vsnprintf() */
|
|
|
|
# ifndef NO_snprintf
|
|
|
|
# define NO_snprintf
|
|
|
|
# endif
|
|
|
|
# ifndef NO_vsnprintf
|
|
|
|
# define NO_vsnprintf
|
|
|
|
# endif
|
2011-10-02 22:15:00 +04:00
|
|
|
# endif
|
2011-09-10 10:26:49 +04:00
|
|
|
#endif
|
|
|
|
|
2016-12-31 04:13:31 +03:00
|
|
|
/* unlike snprintf (which is required in C99), _snprintf does not guarantee
|
|
|
|
null termination of the result -- however this is only used in gzlib.c where
|
2012-06-03 23:45:55 +04:00
|
|
|
the result is assured to fit in the space provided */
|
2016-12-31 04:13:31 +03:00
|
|
|
#if defined(_MSC_VER) && _MSC_VER < 1900
|
2012-06-03 23:45:55 +04:00
|
|
|
# define snprintf _snprintf
|
|
|
|
#endif
|
|
|
|
|
2011-09-10 10:26:49 +04:00
|
|
|
#ifndef local
|
|
|
|
# define local static
|
|
|
|
#endif
|
2016-10-26 20:25:10 +03:00
|
|
|
/* since "static" is used to mean two completely different things in C, we
|
|
|
|
define "local" for the non-static meaning of "static", for readability
|
|
|
|
(compile with -Dlocal if your debugger can't find static symbols) */
|
2011-09-10 10:26:49 +04:00
|
|
|
|
|
|
|
/* gz* functions always use library allocation functions */
|
|
|
|
#ifndef STDC
|
2023-04-14 11:42:03 +03:00
|
|
|
extern voidp malloc(uInt size);
|
|
|
|
extern void free(voidpf ptr);
|
2011-09-10 10:26:49 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* get errno and strerror definition */
|
2011-09-10 10:34:22 +04:00
|
|
|
#if defined UNDER_CE
|
2011-09-10 10:26:58 +04:00
|
|
|
# include <windows.h>
|
|
|
|
# define zstrerror() gz_strwinerror((DWORD)GetLastError())
|
2011-09-10 10:26:49 +04:00
|
|
|
#else
|
2012-02-19 01:55:09 +04:00
|
|
|
# ifndef NO_STRERROR
|
2011-09-10 10:26:49 +04:00
|
|
|
# include <errno.h>
|
|
|
|
# define zstrerror() strerror(errno)
|
|
|
|
# else
|
|
|
|
# define zstrerror() "stdio error (consult errno)"
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2011-09-10 10:34:30 +04:00
|
|
|
/* provide prototypes for these when building zlib without LFS */
|
2011-09-10 10:34:38 +04:00
|
|
|
#if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0
|
2023-04-14 11:42:03 +03:00
|
|
|
ZEXTERN gzFile ZEXPORT gzopen64(const char *, const char *);
|
|
|
|
ZEXTERN z_off64_t ZEXPORT gzseek64(gzFile, z_off64_t, int);
|
|
|
|
ZEXTERN z_off64_t ZEXPORT gztell64(gzFile);
|
|
|
|
ZEXTERN z_off64_t ZEXPORT gzoffset64(gzFile);
|
2011-09-10 10:34:30 +04:00
|
|
|
#endif
|
|
|
|
|
2011-12-08 22:16:31 +04:00
|
|
|
/* default memLevel */
|
|
|
|
#if MAX_MEM_LEVEL >= 8
|
|
|
|
# define DEF_MEM_LEVEL 8
|
|
|
|
#else
|
|
|
|
# define DEF_MEM_LEVEL MAX_MEM_LEVEL
|
|
|
|
#endif
|
|
|
|
|
2013-04-14 05:04:06 +04:00
|
|
|
/* default i/o buffer size -- double this for output when reading (this and
|
|
|
|
twice this must be able to fit in an unsigned type) */
|
2011-09-10 10:26:49 +04:00
|
|
|
#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 */
|
|
|
|
|
2011-09-10 10:27:08 +04:00
|
|
|
/* 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 */
|
|
|
|
|
2011-09-10 10:26:49 +04:00
|
|
|
/* internal gzip file state data structure */
|
|
|
|
typedef struct {
|
2011-09-27 09:50:28 +04:00
|
|
|
/* exposed contents for gzgetc() macro */
|
|
|
|
struct gzFile_s x; /* "x" for exposed */
|
|
|
|
/* x.have: number of bytes available at x.next */
|
|
|
|
/* x.next: next output data to deliver or write */
|
|
|
|
/* x.pos: current position in uncompressed data */
|
2011-09-10 10:26:49 +04:00
|
|
|
/* used for both reading and writing */
|
|
|
|
int mode; /* see gzip modes above */
|
|
|
|
int fd; /* file descriptor */
|
|
|
|
char *path; /* path or fd for error messages */
|
|
|
|
unsigned size; /* buffer size, zero if not allocated yet */
|
|
|
|
unsigned want; /* requested buffer size, default is GZBUFSIZE */
|
2015-07-06 04:14:53 +03:00
|
|
|
unsigned char *in; /* input buffer (double-sized when writing) */
|
2011-09-10 10:26:49 +04:00
|
|
|
unsigned char *out; /* output buffer (double-sized when reading) */
|
2011-10-03 00:24:43 +04:00
|
|
|
int direct; /* 0 if processing gzip, 1 if transparent */
|
2011-09-10 10:26:49 +04:00
|
|
|
/* just for reading */
|
2011-09-10 10:27:08 +04:00
|
|
|
int how; /* 0: get header, 1: copy, 2: decompress */
|
2011-10-13 10:24:31 +04:00
|
|
|
z_off64_t start; /* where the gzip data started, for rewinding */
|
|
|
|
int eof; /* true if end of input file reached */
|
|
|
|
int past; /* true if read requested past end */
|
2011-09-10 10:26:49 +04:00
|
|
|
/* just for writing */
|
|
|
|
int level; /* compression level */
|
|
|
|
int strategy; /* compression strategy */
|
2019-04-14 03:05:16 +03:00
|
|
|
int reset; /* true if a reset is pending after a Z_FINISH */
|
2011-09-10 10:26:49 +04:00
|
|
|
/* seek request */
|
|
|
|
z_off64_t skip; /* amount to skip (already rewound if backwards) */
|
2011-09-10 10:27:08 +04:00
|
|
|
int seek; /* true if seek request pending */
|
2011-09-10 10:26:49 +04:00
|
|
|
/* 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 */
|
2023-04-14 11:42:03 +03:00
|
|
|
void ZLIB_INTERNAL gz_error(gz_statep, int, const char *);
|
2011-09-10 10:34:22 +04:00
|
|
|
#if defined UNDER_CE
|
2023-04-14 11:42:03 +03:00
|
|
|
char ZLIB_INTERNAL *gz_strwinerror(DWORD error);
|
2011-09-10 10:26:58 +04:00
|
|
|
#endif
|
2011-09-10 10:27:17 +04:00
|
|
|
|
|
|
|
/* 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) */
|
2023-04-14 11:42:03 +03:00
|
|
|
unsigned ZLIB_INTERNAL gz_intmax(void);
|
2023-10-09 16:04:51 +03:00
|
|
|
#define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax())
|