annotate zlib/gzguts.h @ 158:494b0b89df80 default tip

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