1 /* 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * 4 * This code is free software; you can redistribute it and/or modify it 5 * under the terms of the GNU General Public License version 2 only, as 6 * published by the Free Software Foundation. Oracle designates this 7 * particular file as subject to the "Classpath" exception as provided 8 * by Oracle in the LICENSE file that accompanied this code. 9 * 10 * This code is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 * version 2 for more details (a copy is included in the LICENSE file that 14 * accompanied this code). 15 * 16 * You should have received a copy of the GNU General Public License version 17 * 2 along with this work; if not, write to the Free Software Foundation, 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19 * 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21 * or visit www.oracle.com if you need additional information or have any 22 * questions. 23 */ 24 25 /* gzguts.h -- zlib internal header definitions for gz* operations 26 * Copyright (C) 2004, 2005, 2010 Mark Adler 27 * For conditions of distribution and use, see copyright notice in zlib.h 28 */ 29 30 #ifdef _LARGEFILE64_SOURCE 31 # ifndef _LARGEFILE_SOURCE 32 # define _LARGEFILE_SOURCE 1 33 # endif 34 # ifdef _FILE_OFFSET_BITS 35 # undef _FILE_OFFSET_BITS 36 # endif 37 #endif 38 39 #if ((__GNUC__-0) * 10 + __GNUC_MINOR__-0 >= 33) && !defined(NO_VIZ) 40 # define ZLIB_INTERNAL __attribute__((visibility ("hidden"))) 41 #else 42 # define ZLIB_INTERNAL 43 #endif 44 45 #include <stdio.h> 46 #include "zlib.h" 47 #ifdef STDC 48 # include <string.h> 49 # include <stdlib.h> 50 # include <limits.h> 51 #endif 52 #include <fcntl.h> 53 54 #ifdef NO_DEFLATE /* for compatibility with old definition */ 55 # define NO_GZCOMPRESS 56 #endif 57 58 #ifdef _MSC_VER 59 # include <io.h> 60 # define vsnprintf _vsnprintf 61 #endif 62 63 #ifndef local 64 # define local static 65 #endif 66 /* compile with -Dlocal if your debugger can't find static symbols */ 67 68 /* gz* functions always use library allocation functions */ 69 #ifndef STDC 70 extern voidp malloc OF((uInt size)); 71 extern void free OF((voidpf ptr)); 72 #endif 73 74 /* get errno and strerror definition */ 75 #if defined UNDER_CE 76 # include <windows.h> 77 # define zstrerror() gz_strwinerror((DWORD)GetLastError()) 78 #else 79 # ifdef STDC 80 # include <errno.h> 81 # define zstrerror() strerror(errno) 82 # else 83 # define zstrerror() "stdio error (consult errno)" 84 # endif 85 #endif 86 87 /* provide prototypes for these when building zlib without LFS */ 88 #if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0 89 ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); 90 ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int)); 91 ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile)); 92 ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile)); 93 #endif 94 95 /* default i/o buffer size -- double this for output when reading */ 96 #define GZBUFSIZE 8192 97 98 /* gzip modes, also provide a little integrity check on the passed structure */ 99 #define GZ_NONE 0 100 #define GZ_READ 7247 101 #define GZ_WRITE 31153 102 #define GZ_APPEND 1 /* mode set to GZ_WRITE after the file is opened */ 103 104 /* values for gz_state how */ 105 #define LOOK 0 /* look for a gzip header */ 106 #define COPY 1 /* copy input directly */ 107 #define GZIP 2 /* decompress a gzip stream */ 108 109 /* internal gzip file state data structure */ 110 typedef struct { 111 /* used for both reading and writing */ 112 int mode; /* see gzip modes above */ 113 int fd; /* file descriptor */ 114 char *path; /* path or fd for error messages */ 115 z_off64_t pos; /* current position in uncompressed data */ 116 unsigned size; /* buffer size, zero if not allocated yet */ 117 unsigned want; /* requested buffer size, default is GZBUFSIZE */ 118 unsigned char *in; /* input buffer */ 119 unsigned char *out; /* output buffer (double-sized when reading) */ 120 unsigned char *next; /* next output data to deliver or write */ 121 /* just for reading */ 122 unsigned have; /* amount of output data unused at next */ 123 int eof; /* true if end of input file reached */ 124 z_off64_t start; /* where the gzip data started, for rewinding */ 125 z_off64_t raw; /* where the raw data started, for seeking */ 126 int how; /* 0: get header, 1: copy, 2: decompress */ 127 int direct; /* true if last read direct, false if gzip */ 128 /* just for writing */ 129 int level; /* compression level */ 130 int strategy; /* compression strategy */ 131 /* seek request */ 132 z_off64_t skip; /* amount to skip (already rewound if backwards) */ 133 int seek; /* true if seek request pending */ 134 /* error information */ 135 int err; /* error code */ 136 char *msg; /* error message */ 137 /* zlib inflate or deflate stream */ 138 z_stream strm; /* stream structure in-place (not a pointer) */ 139 } gz_state; 140 typedef gz_state FAR *gz_statep; 141 142 /* shared functions */ 143 void ZLIB_INTERNAL gz_error OF((gz_statep, int, const char *)); 144 #if defined UNDER_CE 145 char ZLIB_INTERNAL *gz_strwinerror OF((DWORD error)); 146 #endif 147 148 /* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t 149 value -- needed when comparing unsigned to z_off64_t, which is signed 150 (possible z_off64_t types off_t, off64_t, and long are all signed) */ 151 #ifdef INT_MAX 152 # define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > INT_MAX) 153 #else 154 unsigned ZLIB_INTERNAL gz_intmax OF((void)); 155 # define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax()) 156 #endif