Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:10

0001 /* gzguts.h -- zlib internal header definitions for gz* operations
0002  * Copyright (C) 2004-2019 Mark Adler
0003  * For conditions of distribution and use, see copyright notice in zlib.h
0004  */
0005 
0006 #ifdef _LARGEFILE64_SOURCE
0007 #  ifndef _LARGEFILE_SOURCE
0008 #    define _LARGEFILE_SOURCE 1
0009 #  endif
0010 #  ifdef _FILE_OFFSET_BITS
0011 #    undef _FILE_OFFSET_BITS
0012 #  endif
0013 #endif
0014 
0015 #ifdef HAVE_HIDDEN
0016 #  define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
0017 #else
0018 #  define ZLIB_INTERNAL
0019 #endif
0020 
0021 #include <stdio.h>
0022 #include "zlib.h"
0023 #ifdef STDC
0024 #  include <string.h>
0025 #  include <stdlib.h>
0026 #  include <limits.h>
0027 #endif
0028 
0029 #ifndef _POSIX_SOURCE
0030 #  define _POSIX_SOURCE
0031 #endif
0032 #include <fcntl.h>
0033 
0034 #ifdef _WIN32
0035 #  include <stddef.h>
0036 #endif
0037 
0038 #if defined(__TURBOC__) || defined(_MSC_VER) || defined(_WIN32)
0039 #  include <io.h>
0040 #endif
0041 
0042 #if defined(_WIN32)
0043 #  define WIDECHAR
0044 #endif
0045 
0046 #ifdef WINAPI_FAMILY
0047 #  define open _open
0048 #  define read _read
0049 #  define write _write
0050 #  define close _close
0051 #endif
0052 
0053 #ifdef NO_DEFLATE       /* for compatibility with old definition */
0054 #  define NO_GZCOMPRESS
0055 #endif
0056 
0057 #if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
0058 #  ifndef HAVE_VSNPRINTF
0059 #    define HAVE_VSNPRINTF
0060 #  endif
0061 #endif
0062 
0063 #if defined(__CYGWIN__)
0064 #  ifndef HAVE_VSNPRINTF
0065 #    define HAVE_VSNPRINTF
0066 #  endif
0067 #endif
0068 
0069 #if defined(MSDOS) && defined(__BORLANDC__) && (BORLANDC > 0x410)
0070 #  ifndef HAVE_VSNPRINTF
0071 #    define HAVE_VSNPRINTF
0072 #  endif
0073 #endif
0074 
0075 #ifndef HAVE_VSNPRINTF
0076 #  ifdef MSDOS
0077 /* vsnprintf may exist on some MS-DOS compilers (DJGPP?),
0078    but for now we just assume it doesn't. */
0079 #    define NO_vsnprintf
0080 #  endif
0081 #  ifdef __TURBOC__
0082 #    define NO_vsnprintf
0083 #  endif
0084 #  ifdef WIN32
0085 /* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */
0086 #    if !defined(vsnprintf) && !defined(NO_vsnprintf)
0087 #      if !defined(_MSC_VER) || ( defined(_MSC_VER) && _MSC_VER < 1500 )
0088 #         define vsnprintf _vsnprintf
0089 #      endif
0090 #    endif
0091 #  endif
0092 #  ifdef __SASC
0093 #    define NO_vsnprintf
0094 #  endif
0095 #  ifdef VMS
0096 #    define NO_vsnprintf
0097 #  endif
0098 #  ifdef __OS400__
0099 #    define NO_vsnprintf
0100 #  endif
0101 #  ifdef __MVS__
0102 #    define NO_vsnprintf
0103 #  endif
0104 #endif
0105 
0106 /* unlike snprintf (which is required in C99), _snprintf does not guarantee
0107    null termination of the result -- however this is only used in gzlib.c where
0108    the result is assured to fit in the space provided */
0109 #if defined(_MSC_VER) && _MSC_VER < 1900
0110 #  define snprintf _snprintf
0111 #endif
0112 
0113 #ifndef local
0114 #  define local static
0115 #endif
0116 /* since "static" is used to mean two completely different things in C, we
0117    define "local" for the non-static meaning of "static", for readability
0118    (compile with -Dlocal if your debugger can't find static symbols) */
0119 
0120 /* gz* functions always use library allocation functions */
0121 #ifndef STDC
0122   extern voidp  malloc OF((uInt size));
0123   extern void   free   OF((voidpf ptr));
0124 #endif
0125 
0126 /* get errno and strerror definition */
0127 #if defined UNDER_CE
0128 #  include <windows.h>
0129 #  define zstrerror() gz_strwinerror((DWORD)GetLastError())
0130 #else
0131 #  ifndef NO_STRERROR
0132 #    include <errno.h>
0133 #    define zstrerror() strerror(errno)
0134 #  else
0135 #    define zstrerror() "stdio error (consult errno)"
0136 #  endif
0137 #endif
0138 
0139 /* provide prototypes for these when building zlib without LFS */
0140 #if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0
0141     ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *));
0142     ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int));
0143     ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile));
0144     ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile));
0145 #endif
0146 
0147 /* default memLevel */
0148 #if MAX_MEM_LEVEL >= 8
0149 #  define DEF_MEM_LEVEL 8
0150 #else
0151 #  define DEF_MEM_LEVEL  MAX_MEM_LEVEL
0152 #endif
0153 
0154 /* default i/o buffer size -- double this for output when reading (this and
0155    twice this must be able to fit in an unsigned type) */
0156 #define GZBUFSIZE 8192
0157 
0158 /* gzip modes, also provide a little integrity check on the passed structure */
0159 #define GZ_NONE 0
0160 #define GZ_READ 7247
0161 #define GZ_WRITE 31153
0162 #define GZ_APPEND 1     /* mode set to GZ_WRITE after the file is opened */
0163 
0164 /* values for gz_state how */
0165 #define LOOK 0      /* look for a gzip header */
0166 #define COPY 1      /* copy input directly */
0167 #define GZIP 2      /* decompress a gzip stream */
0168 
0169 /* internal gzip file state data structure */
0170 typedef struct {
0171         /* exposed contents for gzgetc() macro */
0172     struct gzFile_s x;      /* "x" for exposed */
0173                             /* x.have: number of bytes available at x.next */
0174                             /* x.next: next output data to deliver or write */
0175                             /* x.pos: current position in uncompressed data */
0176         /* used for both reading and writing */
0177     int mode;               /* see gzip modes above */
0178     int fd;                 /* file descriptor */
0179     char *path;             /* path or fd for error messages */
0180     unsigned size;          /* buffer size, zero if not allocated yet */
0181     unsigned want;          /* requested buffer size, default is GZBUFSIZE */
0182     unsigned char *in;      /* input buffer (double-sized when writing) */
0183     unsigned char *out;     /* output buffer (double-sized when reading) */
0184     int direct;             /* 0 if processing gzip, 1 if transparent */
0185         /* just for reading */
0186     int how;                /* 0: get header, 1: copy, 2: decompress */
0187     z_off64_t start;        /* where the gzip data started, for rewinding */
0188     int eof;                /* true if end of input file reached */
0189     int past;               /* true if read requested past end */
0190         /* just for writing */
0191     int level;              /* compression level */
0192     int strategy;           /* compression strategy */
0193     int reset;              /* true if a reset is pending after a Z_FINISH */
0194         /* seek request */
0195     z_off64_t skip;         /* amount to skip (already rewound if backwards) */
0196     int seek;               /* true if seek request pending */
0197         /* error information */
0198     int err;                /* error code */
0199     char *msg;              /* error message */
0200         /* zlib inflate or deflate stream */
0201     z_stream strm;          /* stream structure in-place (not a pointer) */
0202 } gz_state;
0203 typedef gz_state FAR *gz_statep;
0204 
0205 /* shared functions */
0206 void ZLIB_INTERNAL gz_error OF((gz_statep, int, const char *));
0207 #if defined UNDER_CE
0208 char ZLIB_INTERNAL *gz_strwinerror OF((DWORD error));
0209 #endif
0210 
0211 /* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t
0212    value -- needed when comparing unsigned to z_off64_t, which is signed
0213    (possible z_off64_t types off_t, off64_t, and long are all signed) */
0214 #ifdef INT_MAX
0215 #  define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > INT_MAX)
0216 #else
0217 unsigned ZLIB_INTERNAL gz_intmax OF((void));
0218 #  define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax())
0219 #endif