Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* gzguts.h -- zlib internal header definitions for gz* operations |
michael@0 | 2 | * Copyright (C) 2004, 2005, 2010, 2011, 2012, 2013 Mark Adler |
michael@0 | 3 | * For conditions of distribution and use, see copyright notice in zlib.h |
michael@0 | 4 | */ |
michael@0 | 5 | |
michael@0 | 6 | #ifdef _LARGEFILE64_SOURCE |
michael@0 | 7 | # ifndef _LARGEFILE_SOURCE |
michael@0 | 8 | # define _LARGEFILE_SOURCE 1 |
michael@0 | 9 | # endif |
michael@0 | 10 | # ifdef _FILE_OFFSET_BITS |
michael@0 | 11 | # undef _FILE_OFFSET_BITS |
michael@0 | 12 | # endif |
michael@0 | 13 | #endif |
michael@0 | 14 | |
michael@0 | 15 | #ifdef HAVE_HIDDEN |
michael@0 | 16 | # define ZLIB_INTERNAL __attribute__((visibility ("hidden"))) |
michael@0 | 17 | #else |
michael@0 | 18 | # define ZLIB_INTERNAL |
michael@0 | 19 | #endif |
michael@0 | 20 | |
michael@0 | 21 | #include <stdio.h> |
michael@0 | 22 | #include "zlib.h" |
michael@0 | 23 | #ifdef STDC |
michael@0 | 24 | # include <string.h> |
michael@0 | 25 | # include <stdlib.h> |
michael@0 | 26 | # include <limits.h> |
michael@0 | 27 | #endif |
michael@0 | 28 | #include <fcntl.h> |
michael@0 | 29 | |
michael@0 | 30 | #ifdef _WIN32 |
michael@0 | 31 | # include <stddef.h> |
michael@0 | 32 | #endif |
michael@0 | 33 | |
michael@0 | 34 | #if defined(__TURBOC__) || defined(_MSC_VER) || defined(_WIN32) |
michael@0 | 35 | # include <io.h> |
michael@0 | 36 | #endif |
michael@0 | 37 | |
michael@0 | 38 | #ifdef WINAPI_FAMILY |
michael@0 | 39 | # define open _open |
michael@0 | 40 | # define read _read |
michael@0 | 41 | # define write _write |
michael@0 | 42 | # define close _close |
michael@0 | 43 | #endif |
michael@0 | 44 | |
michael@0 | 45 | #ifdef NO_DEFLATE /* for compatibility with old definition */ |
michael@0 | 46 | # define NO_GZCOMPRESS |
michael@0 | 47 | #endif |
michael@0 | 48 | |
michael@0 | 49 | #if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550) |
michael@0 | 50 | # ifndef HAVE_VSNPRINTF |
michael@0 | 51 | # define HAVE_VSNPRINTF |
michael@0 | 52 | # endif |
michael@0 | 53 | #endif |
michael@0 | 54 | |
michael@0 | 55 | #if defined(__CYGWIN__) |
michael@0 | 56 | # ifndef HAVE_VSNPRINTF |
michael@0 | 57 | # define HAVE_VSNPRINTF |
michael@0 | 58 | # endif |
michael@0 | 59 | #endif |
michael@0 | 60 | |
michael@0 | 61 | #if defined(MSDOS) && defined(__BORLANDC__) && (BORLANDC > 0x410) |
michael@0 | 62 | # ifndef HAVE_VSNPRINTF |
michael@0 | 63 | # define HAVE_VSNPRINTF |
michael@0 | 64 | # endif |
michael@0 | 65 | #endif |
michael@0 | 66 | |
michael@0 | 67 | #ifndef HAVE_VSNPRINTF |
michael@0 | 68 | # ifdef MSDOS |
michael@0 | 69 | /* vsnprintf may exist on some MS-DOS compilers (DJGPP?), |
michael@0 | 70 | but for now we just assume it doesn't. */ |
michael@0 | 71 | # define NO_vsnprintf |
michael@0 | 72 | # endif |
michael@0 | 73 | # ifdef __TURBOC__ |
michael@0 | 74 | # define NO_vsnprintf |
michael@0 | 75 | # endif |
michael@0 | 76 | # ifdef WIN32 |
michael@0 | 77 | /* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */ |
michael@0 | 78 | # if !defined(vsnprintf) && !defined(NO_vsnprintf) |
michael@0 | 79 | # if !defined(_MSC_VER) || ( defined(_MSC_VER) && _MSC_VER < 1500 ) |
michael@0 | 80 | # define vsnprintf _vsnprintf |
michael@0 | 81 | # endif |
michael@0 | 82 | # endif |
michael@0 | 83 | # endif |
michael@0 | 84 | # ifdef __SASC |
michael@0 | 85 | # define NO_vsnprintf |
michael@0 | 86 | # endif |
michael@0 | 87 | # ifdef VMS |
michael@0 | 88 | # define NO_vsnprintf |
michael@0 | 89 | # endif |
michael@0 | 90 | # ifdef __OS400__ |
michael@0 | 91 | # define NO_vsnprintf |
michael@0 | 92 | # endif |
michael@0 | 93 | # ifdef __MVS__ |
michael@0 | 94 | # define NO_vsnprintf |
michael@0 | 95 | # endif |
michael@0 | 96 | #endif |
michael@0 | 97 | |
michael@0 | 98 | /* unlike snprintf (which is required in C99, yet still not supported by |
michael@0 | 99 | Microsoft more than a decade later!), _snprintf does not guarantee null |
michael@0 | 100 | termination of the result -- however this is only used in gzlib.c where |
michael@0 | 101 | the result is assured to fit in the space provided */ |
michael@0 | 102 | #ifdef _MSC_VER |
michael@0 | 103 | # define snprintf _snprintf |
michael@0 | 104 | #endif |
michael@0 | 105 | |
michael@0 | 106 | #ifndef local |
michael@0 | 107 | # define local static |
michael@0 | 108 | #endif |
michael@0 | 109 | /* compile with -Dlocal if your debugger can't find static symbols */ |
michael@0 | 110 | |
michael@0 | 111 | /* gz* functions always use library allocation functions */ |
michael@0 | 112 | #ifndef STDC |
michael@0 | 113 | extern voidp malloc OF((uInt size)); |
michael@0 | 114 | extern void free OF((voidpf ptr)); |
michael@0 | 115 | #endif |
michael@0 | 116 | |
michael@0 | 117 | /* get errno and strerror definition */ |
michael@0 | 118 | #if defined UNDER_CE |
michael@0 | 119 | # include <windows.h> |
michael@0 | 120 | # define zstrerror() gz_strwinerror((DWORD)GetLastError()) |
michael@0 | 121 | #else |
michael@0 | 122 | # ifndef NO_STRERROR |
michael@0 | 123 | # include <errno.h> |
michael@0 | 124 | # define zstrerror() strerror(errno) |
michael@0 | 125 | # else |
michael@0 | 126 | # define zstrerror() "stdio error (consult errno)" |
michael@0 | 127 | # endif |
michael@0 | 128 | #endif |
michael@0 | 129 | |
michael@0 | 130 | /* provide prototypes for these when building zlib without LFS */ |
michael@0 | 131 | #if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0 |
michael@0 | 132 | ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); |
michael@0 | 133 | ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int)); |
michael@0 | 134 | ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile)); |
michael@0 | 135 | ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile)); |
michael@0 | 136 | #endif |
michael@0 | 137 | |
michael@0 | 138 | /* default memLevel */ |
michael@0 | 139 | #if MAX_MEM_LEVEL >= 8 |
michael@0 | 140 | # define DEF_MEM_LEVEL 8 |
michael@0 | 141 | #else |
michael@0 | 142 | # define DEF_MEM_LEVEL MAX_MEM_LEVEL |
michael@0 | 143 | #endif |
michael@0 | 144 | |
michael@0 | 145 | /* default i/o buffer size -- double this for output when reading (this and |
michael@0 | 146 | twice this must be able to fit in an unsigned type) */ |
michael@0 | 147 | #define GZBUFSIZE 8192 |
michael@0 | 148 | |
michael@0 | 149 | /* gzip modes, also provide a little integrity check on the passed structure */ |
michael@0 | 150 | #define GZ_NONE 0 |
michael@0 | 151 | #define GZ_READ 7247 |
michael@0 | 152 | #define GZ_WRITE 31153 |
michael@0 | 153 | #define GZ_APPEND 1 /* mode set to GZ_WRITE after the file is opened */ |
michael@0 | 154 | |
michael@0 | 155 | /* values for gz_state how */ |
michael@0 | 156 | #define LOOK 0 /* look for a gzip header */ |
michael@0 | 157 | #define COPY 1 /* copy input directly */ |
michael@0 | 158 | #define GZIP 2 /* decompress a gzip stream */ |
michael@0 | 159 | |
michael@0 | 160 | /* internal gzip file state data structure */ |
michael@0 | 161 | typedef struct { |
michael@0 | 162 | /* exposed contents for gzgetc() macro */ |
michael@0 | 163 | struct gzFile_s x; /* "x" for exposed */ |
michael@0 | 164 | /* x.have: number of bytes available at x.next */ |
michael@0 | 165 | /* x.next: next output data to deliver or write */ |
michael@0 | 166 | /* x.pos: current position in uncompressed data */ |
michael@0 | 167 | /* used for both reading and writing */ |
michael@0 | 168 | int mode; /* see gzip modes above */ |
michael@0 | 169 | int fd; /* file descriptor */ |
michael@0 | 170 | char *path; /* path or fd for error messages */ |
michael@0 | 171 | unsigned size; /* buffer size, zero if not allocated yet */ |
michael@0 | 172 | unsigned want; /* requested buffer size, default is GZBUFSIZE */ |
michael@0 | 173 | unsigned char *in; /* input buffer */ |
michael@0 | 174 | unsigned char *out; /* output buffer (double-sized when reading) */ |
michael@0 | 175 | int direct; /* 0 if processing gzip, 1 if transparent */ |
michael@0 | 176 | /* just for reading */ |
michael@0 | 177 | int how; /* 0: get header, 1: copy, 2: decompress */ |
michael@0 | 178 | z_off64_t start; /* where the gzip data started, for rewinding */ |
michael@0 | 179 | int eof; /* true if end of input file reached */ |
michael@0 | 180 | int past; /* true if read requested past end */ |
michael@0 | 181 | /* just for writing */ |
michael@0 | 182 | int level; /* compression level */ |
michael@0 | 183 | int strategy; /* compression strategy */ |
michael@0 | 184 | /* seek request */ |
michael@0 | 185 | z_off64_t skip; /* amount to skip (already rewound if backwards) */ |
michael@0 | 186 | int seek; /* true if seek request pending */ |
michael@0 | 187 | /* error information */ |
michael@0 | 188 | int err; /* error code */ |
michael@0 | 189 | char *msg; /* error message */ |
michael@0 | 190 | /* zlib inflate or deflate stream */ |
michael@0 | 191 | z_stream strm; /* stream structure in-place (not a pointer) */ |
michael@0 | 192 | } gz_state; |
michael@0 | 193 | typedef gz_state FAR *gz_statep; |
michael@0 | 194 | |
michael@0 | 195 | /* shared functions */ |
michael@0 | 196 | void ZLIB_INTERNAL gz_error OF((gz_statep, int, const char *)); |
michael@0 | 197 | #if defined UNDER_CE |
michael@0 | 198 | char ZLIB_INTERNAL *gz_strwinerror OF((DWORD error)); |
michael@0 | 199 | #endif |
michael@0 | 200 | |
michael@0 | 201 | /* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t |
michael@0 | 202 | value -- needed when comparing unsigned to z_off64_t, which is signed |
michael@0 | 203 | (possible z_off64_t types off_t, off64_t, and long are all signed) */ |
michael@0 | 204 | #ifdef INT_MAX |
michael@0 | 205 | # define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > INT_MAX) |
michael@0 | 206 | #else |
michael@0 | 207 | unsigned ZLIB_INTERNAL gz_intmax OF((void)); |
michael@0 | 208 | # define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax()) |
michael@0 | 209 | #endif |