MySQL 8.0.29
Source Code Documentation
azlib.h
Go to the documentation of this file.
1/*
2 This libary has been modified for use by the MySQL Archive Engine.
3 -Brian Aker
4
5 This file was modified by Oracle on 02-08-2016.
6 Modifications Copyright (c) 2016, 2021, Oracle and/or its affiliates.
7*/
8
9/* zlib.h -- interface of the 'zlib' general purpose compression library
10 version 1.2.3, July 18th, 2005
11
12 Copyright (C) 1995-2005 Jean-loup Gailly and Mark Adler
13
14 This software is provided 'as-is', without any express or implied
15 warranty. In no event will the authors be held liable for any damages
16 arising from the use of this software.
17
18 Permission is granted to anyone to use this software for any purpose,
19 including commercial applications, and to alter it and redistribute it
20 freely, subject to the following restrictions:
21
22 1. The origin of this software must not be misrepresented; you must not
23 claim that you wrote the original software. If you use this software
24 in a product, an acknowledgment in the product documentation would be
25 appreciated but is not required.
26 2. Altered source versions must be plainly marked as such, and must not be
27 misrepresented as being the original software.
28 3. This notice may not be removed or altered from any source distribution.
29
30 Jean-loup Gailly Mark Adler
31 jloup@gzip.org madler@alumni.caltech.edu
32
33
34 The data format used by the zlib library is described by RFCs (Request for
35 Comments) 1950 to 1952 in the files http://www.ietf.org/rfc/rfc1950.txt
36 (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
37*/
38
39#include <zlib.h>
40#include "my_dir.h"
41#include "my_io.h"
42
43#ifdef __cplusplus
44extern "C" {
45#endif
46/* Start of MySQL Specific Information */
47
48/*
49 ulonglong + ulonglong + ulonglong + ulonglong + uchar
50*/
51#define AZMETA_BUFFER_SIZE \
52 sizeof(unsigned long long) + sizeof(unsigned long long) + \
53 sizeof(unsigned long long) + sizeof(unsigned long long) + \
54 sizeof(unsigned int) + sizeof(unsigned int) + sizeof(unsigned int) + \
55 sizeof(unsigned int) + sizeof(unsigned char)
56
57#define AZHEADER_SIZE 29
58
59#define AZ_MAGIC_POS 0
60#define AZ_VERSION_POS 1
61#define AZ_MINOR_VERSION_POS 2
62#define AZ_BLOCK_POS 3
63#define AZ_STRATEGY_POS 4
64#define AZ_FRM_POS 5
65#define AZ_FRM_LENGTH_POS 9
66#define AZ_META_POS 13
67#define AZ_META_LENGTH_POS 17
68#define AZ_START_POS 21
69#define AZ_ROW_POS 29
70#define AZ_FLUSH_POS 37
71#define AZ_CHECK_POS 45
72#define AZ_AUTOINCREMENT_POS 53
73#define AZ_LONGEST_POS 61
74#define AZ_SHORTEST_POS 65
75#define AZ_COMMENT_POS 69
76#define AZ_COMMENT_LENGTH_POS 73
77#define AZ_DIRTY_POS 77
78
79/*
80 Flags for state
81*/
82#define AZ_STATE_CLEAN 0
83#define AZ_STATE_DIRTY 1
84#define AZ_STATE_SAVED 2
85#define AZ_STATE_CRASHED 3
86
87/*
88 The 'zlib' compression library provides in-memory compression and
89 decompression functions, including integrity checks of the uncompressed
90 data. This version of the library supports only one compression method
91 (deflation) but other algorithms will be added later and will have the same
92 stream interface.
93
94 Compression can be done in a single step if the buffers are large
95 enough (for example if an input file is mmap'ed), or can be done by
96 repeated calls of the compression function. In the latter case, the
97 application must provide more input and/or consume the output
98 (providing more output space) before each call.
99
100 The compressed data format used by default by the in-memory functions is
101 the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped
102 around a deflate stream, which is itself documented in RFC 1951.
103
104 The library also supports reading and writing files in gzip (.gz) format
105 with an interface similar to that of stdio using the functions that start
106 with "gz". The gzip format is different from the zlib format. gzip is a
107 gzip wrapper, documented in RFC 1952, wrapped around a deflate stream.
108
109 This library can optionally read and write gzip streams in memory as well.
110
111 The zlib format was designed to be compact and fast for use in memory
112 and on communications channels. The gzip format was designed for single-
113 file compression on file systems, has a larger header than zlib to maintain
114 directory information, and uses a different, slower check method than zlib.
115
116 The library does not install any signal handler. The decoder checks
117 the consistency of the compressed data, so the library should never
118 crash even in case of corrupted input.
119*/
120
121/*
122 The application must update next_in and avail_in when avail_in has
123 dropped to zero. It must update next_out and avail_out when avail_out
124 has dropped to zero. The application must initialize zalloc, zfree and
125 opaque before calling the init function. All other fields are set by the
126 compression library and must not be updated by the application.
127
128 The opaque value provided by the application will be passed as the first
129 parameter for calls of zalloc and zfree. This can be useful for custom
130 memory management. The compression library attaches no meaning to the
131 opaque value.
132
133 zalloc must return Z_NULL if there is not enough memory for the object.
134 If zlib is used in a multi-threaded application, zalloc and zfree must be
135 thread safe.
136
137 On 16-bit systems, the functions zalloc and zfree must be able to allocate
138 exactly 65536 bytes, but will not be required to allocate more than this
139 if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS,
140 pointers returned by zalloc for objects of exactly 65536 bytes *must*
141 have their offset normalized to zero. The default allocation function
142 provided by this library ensures this (see zutil.c). To reduce memory
143 requirements and avoid any allocation of 64K objects, at the expense of
144 compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h).
145
146 The fields total_in and total_out can be used for statistics or
147 progress reports. After compression, total_in holds the total size of
148 the uncompressed data and may be saved for use in the decompressor
149 (particularly if the decompressor wants to decompress everything in
150 a single step).
151*/
152
153/* constants */
154
155#define Z_NO_FLUSH 0
156#define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
157#define Z_SYNC_FLUSH 2
158#define Z_FULL_FLUSH 3
159#define Z_FINISH 4
160#define Z_BLOCK 5
161/* Allowed flush values; see deflate() and inflate() below for details */
162
163#define Z_OK 0
164#define Z_STREAM_END 1
165#define Z_NEED_DICT 2
166#define Z_ERRNO (-1)
167#define Z_STREAM_ERROR (-2)
168#define Z_DATA_ERROR (-3)
169#define Z_MEM_ERROR (-4)
170#define Z_BUF_ERROR (-5)
171#define Z_VERSION_ERROR (-6)
172/* Return codes for the compression/decompression functions. Negative
173 * values are errors, positive values are used for special but normal events.
174 */
175
176#define Z_NO_COMPRESSION 0
177#define Z_BEST_SPEED 1
178#define Z_BEST_COMPRESSION 9
179#define Z_DEFAULT_COMPRESSION (-1)
180/* compression levels */
181
182#define Z_FILTERED 1
183#define Z_HUFFMAN_ONLY 2
184#define Z_RLE 3
185#define Z_FIXED 4
186#define Z_DEFAULT_STRATEGY 0
187/* compression strategy; see deflateInit2() below for details */
188
189#define Z_BINARY 0
190#define Z_TEXT 1
191#define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */
192#define Z_UNKNOWN 2
193/* Possible values of the data_type field (though see inflate()) */
194
195#define Z_DEFLATED 8
196/* The deflate compression method (the only one supported in this version) */
197
198#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
199#define AZ_BUFSIZE_READ 32768
200#define AZ_BUFSIZE_WRITE 16384
201
202typedef struct azio_stream {
203 z_stream stream;
204 int z_err; /* error code for last stream operation */
205 int z_eof; /* set if end of input file */
206 File file; /* .gz file */
207 Byte inbuf[AZ_BUFSIZE_READ]; /* input buffer */
208 Byte outbuf[AZ_BUFSIZE_WRITE]; /* output buffer */
209 uLong crc; /* crc32 of uncompressed data */
210 char *msg; /* error message */
211 int transparent; /* 1 if input file is not a .gz file */
212 char mode; /* 'w' or 'r' */
213 my_off_t start; /* start of compressed data in file (header skipped) */
214 my_off_t in; /* bytes into deflate or inflate */
215 my_off_t out; /* bytes out of deflate or inflate */
216 int back; /* one character push-back */
217 int last; /* true if push-back is last character */
218 unsigned char version; /* Version */
219 unsigned char minor_version; /* Version */
220 unsigned int block_size; /* Block Size */
221 unsigned long long check_point; /* Last position we checked */
222 unsigned long long forced_flushes; /* Forced Flushes */
223 unsigned long long rows; /* rows */
224 unsigned long long auto_increment; /* auto increment field */
225 unsigned int longest_row; /* Longest row */
226 unsigned int shortest_row; /* Shortest row */
227 unsigned char dirty; /* State of file */
228 unsigned int frm_start_pos; /* Position for start of FRM */
229 unsigned int frm_length; /* Position for start of FRM */
230 unsigned int comment_start_pos; /* Position for start of comment */
231 unsigned int comment_length; /* Position for start of comment */
233
234/* basic functions */
235
236extern int azopen(azio_stream *s, const char *path, int Flags);
237/*
238 Opens a gzip (.gz) file for reading or writing. The mode parameter
239 is as in fopen ("rb" or "wb") but can also include a compression level
240 ("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for
241 Huffman only compression as in "wb1h", or 'R' for run-length encoding
242 as in "wb1R". (See the description of deflateInit2 for more information
243 about the strategy parameter.)
244
245 azopen can be used to read a file which is not in gzip format; in this
246 case gzread will directly read from the file without decompression.
247
248 azopen returns NULL if the file could not be opened or if there was
249 insufficient memory to allocate the (de)compression state; errno
250 can be checked to distinguish the two cases (if errno is zero, the
251 zlib error is Z_MEM_ERROR). */
252
253int azdopen(azio_stream *s, File fd, int Flags);
254/*
255 azdopen() associates a azio_stream with the file descriptor fd. File
256 descriptors are obtained from calls like open, dup, creat, pipe or
257 fileno (in the file has been previously opened with fopen).
258 The mode parameter is as in azopen.
259 The next call of gzclose on the returned azio_stream will also close the
260 file descriptor fd, just like fclose(fdopen(fd), mode) closes the file
261 descriptor fd. If you want to keep fd open, use azdopen(dup(fd), mode).
262 azdopen returns NULL if there was insufficient memory to allocate
263 the (de)compression state.
264*/
265
266extern size_t azread(azio_stream *s, voidp buf, size_t len, int *error);
267/*
268 Reads the given number of uncompressed bytes from the compressed file.
269 If the input file was not in gzip format, gzread copies the given number
270 of bytes into the buffer.
271 gzread returns the number of uncompressed bytes actually read (0 for
272 end of file, -1 for error). */
273
274extern unsigned int azwrite(azio_stream *s, const voidp buf, unsigned int len);
275/*
276 Writes the given number of uncompressed bytes into the compressed file.
277 azwrite returns the number of uncompressed bytes actually written
278 (0 in case of error).
279*/
280
281extern int azflush(azio_stream *file, int flush);
282/*
283 Flushes all pending output into the compressed file. The parameter
284 flush is as in the deflate() function. The return value is the zlib
285 error number (see function gzerror below). gzflush returns Z_OK if
286 the flush parameter is Z_FINISH and all output could be flushed.
287 gzflush should be called only when strictly necessary because it can
288 degrade compression.
289*/
290
291extern my_off_t azseek(azio_stream *file, my_off_t offset, int whence);
292/*
293 Sets the starting position for the next gzread or gzwrite on the
294 given compressed file. The offset represents a number of bytes in the
295 uncompressed data stream. The whence parameter is defined as in lseek(2);
296 the value SEEK_END is not supported.
297 If the file is opened for reading, this function is emulated but can be
298 extremely slow. If the file is opened for writing, only forward seeks are
299 supported; gzseek then compresses a sequence of zeroes up to the new
300 starting position.
301
302 gzseek returns the resulting offset location as measured in bytes from
303 the beginning of the uncompressed stream, or -1 in case of error, in
304 particular if the file is opened for writing and the new starting position
305 would be before the current position.
306*/
307
308extern int azrewind(azio_stream *file);
309/*
310 Rewinds the given file. This function is supported only for reading.
311
312 gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET)
313*/
314
316/*
317 Returns the starting position for the next gzread or gzwrite on the
318 given compressed file. This position represents a number of bytes in the
319 uncompressed data stream.
320
321 gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR)
322*/
323
324extern int azclose(azio_stream *file);
325/*
326 Flushes all pending output if necessary, closes the compressed file
327 and deallocates all the (de)compression state. The return value is the zlib
328 error number (see function gzerror below).
329*/
330
331extern int azwrite_frm(azio_stream *s, char *blob, size_t length);
332extern int azread_frm(azio_stream *s, char *blob);
333extern int azwrite_comment(azio_stream *s, char *blob, size_t length);
334extern int azread_comment(azio_stream *s, char *blob);
335
336#ifdef __cplusplus
337}
338#endif
struct azio_stream azio_stream
#define AZ_BUFSIZE_WRITE
Definition: azlib.h:200
int azflush(azio_stream *file, int flush)
Definition: azio.cc:593
size_t azread(azio_stream *s, voidp buf, size_t len, int *error)
Definition: azio.cc:394
int azread_comment(azio_stream *s, char *blob)
Definition: azio.cc:818
int azwrite_frm(azio_stream *s, char *blob, size_t length)
Definition: azio.cc:772
#define AZ_BUFSIZE_READ
Definition: azlib.h:199
int azrewind(azio_stream *file)
Definition: azio.cc:616
int azwrite_comment(azio_stream *s, char *blob, size_t length)
Definition: azio.cc:800
my_off_t aztell(azio_stream *file)
Definition: azio.cc:712
int azclose(azio_stream *file)
Definition: azio.cc:750
int azread_frm(azio_stream *s, char *blob)
Definition: azio.cc:790
my_off_t azseek(azio_stream *file, my_off_t offset, int whence)
Definition: azio.cc:640
unsigned int azwrite(azio_stream *s, const voidp buf, unsigned int len)
Definition: azio.cc:507
int azopen(azio_stream *s, const char *path, int Flags)
Definition: azio.cc:206
int azdopen(azio_stream *s, File fd, int Flags)
Definition: azio.cc:214
static const char * whence(const Item_field *cached_field)
Get the name of the cached field of an Item_cache_json instance.
Definition: item.cc:9731
ulonglong my_off_t
Definition: my_inttypes.h:71
Common #defines and includes for file and socket I/O.
int File
Definition: my_io_bits.h:50
Log error(cerr, "ERROR")
static char * path
Definition: mysqldump.cc:130
Definition: buf0block_hint.cc:29
constexpr value_type blob
Definition: classic_protocol_constants.h:267
Definition: os0file.h:85
bool length(const dd::Spatial_reference_system *srs, const Geometry *g1, double *length, bool *null) noexcept
Computes the length of linestrings and multilinestrings.
Definition: length.cc:75
static mysql_service_status_t flush(reference_caching_cache cache) noexcept
Definition: component.cc:121
Definition: azlib.h:202
int z_err
Definition: azlib.h:204
unsigned char dirty
Definition: azlib.h:227
Byte inbuf[AZ_BUFSIZE_READ]
Definition: azlib.h:207
unsigned int comment_start_pos
Definition: azlib.h:230
unsigned int frm_length
Definition: azlib.h:229
int back
Definition: azlib.h:216
my_off_t start
Definition: azlib.h:213
unsigned long long rows
Definition: azlib.h:223
unsigned int block_size
Definition: azlib.h:220
unsigned int comment_length
Definition: azlib.h:231
unsigned int longest_row
Definition: azlib.h:225
my_off_t in
Definition: azlib.h:214
unsigned long long forced_flushes
Definition: azlib.h:222
char mode
Definition: azlib.h:212
unsigned int frm_start_pos
Definition: azlib.h:228
my_off_t out
Definition: azlib.h:215
char * msg
Definition: azlib.h:210
unsigned char version
Definition: azlib.h:218
z_stream stream
Definition: azlib.h:203
int transparent
Definition: azlib.h:211
int last
Definition: azlib.h:217
unsigned int shortest_row
Definition: azlib.h:226
File file
Definition: azlib.h:206
uLong crc
Definition: azlib.h:209
int z_eof
Definition: azlib.h:205
unsigned long long auto_increment
Definition: azlib.h:224
unsigned long long check_point
Definition: azlib.h:221
unsigned char minor_version
Definition: azlib.h:219
Byte outbuf[AZ_BUFSIZE_WRITE]
Definition: azlib.h:208