zstdlib 0.1.0-x64-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGES.md +9 -0
- data/Gemfile +3 -0
- data/README.md +96 -0
- data/Rakefile +29 -0
- data/ext/zstdlib/extconf.rb +53 -0
- data/ext/zstdlib/ruby/zlib-2.2/zlib.c +4659 -0
- data/ext/zstdlib/ruby/zlib-2.3/zlib.c +4686 -0
- data/ext/zstdlib/ruby/zlib-2.4/zlib.c +4843 -0
- data/ext/zstdlib/ruby/zlib-2.5/zlib.c +4848 -0
- data/ext/zstdlib/ruby/zlib-2.6/zlib.c +4890 -0
- data/ext/zstdlib/zlib-1.2.11/adler32.c +186 -0
- data/ext/zstdlib/zlib-1.2.11/compress.c +86 -0
- data/ext/zstdlib/zlib-1.2.11/crc32.c +442 -0
- data/ext/zstdlib/zlib-1.2.11/crc32.h +441 -0
- data/ext/zstdlib/zlib-1.2.11/deflate.c +2163 -0
- data/ext/zstdlib/zlib-1.2.11/deflate.h +349 -0
- data/ext/zstdlib/zlib-1.2.11/gzclose.c +25 -0
- data/ext/zstdlib/zlib-1.2.11/gzguts.h +218 -0
- data/ext/zstdlib/zlib-1.2.11/gzlib.c +637 -0
- data/ext/zstdlib/zlib-1.2.11/gzread.c +654 -0
- data/ext/zstdlib/zlib-1.2.11/gzwrite.c +665 -0
- data/ext/zstdlib/zlib-1.2.11/infback.c +640 -0
- data/ext/zstdlib/zlib-1.2.11/inffast.c +323 -0
- data/ext/zstdlib/zlib-1.2.11/inffast.h +11 -0
- data/ext/zstdlib/zlib-1.2.11/inffixed.h +94 -0
- data/ext/zstdlib/zlib-1.2.11/inflate.c +1561 -0
- data/ext/zstdlib/zlib-1.2.11/inflate.h +125 -0
- data/ext/zstdlib/zlib-1.2.11/inftrees.c +304 -0
- data/ext/zstdlib/zlib-1.2.11/inftrees.h +62 -0
- data/ext/zstdlib/zlib-1.2.11/trees.c +1203 -0
- data/ext/zstdlib/zlib-1.2.11/trees.h +128 -0
- data/ext/zstdlib/zlib-1.2.11/uncompr.c +93 -0
- data/ext/zstdlib/zlib-1.2.11/zconf.h +534 -0
- data/ext/zstdlib/zlib-1.2.11/zlib.h +1912 -0
- data/ext/zstdlib/zlib-1.2.11/zutil.c +325 -0
- data/ext/zstdlib/zlib-1.2.11/zutil.h +271 -0
- data/ext/zstdlib/zlib.mk +14 -0
- data/ext/zstdlib/zlibwrapper.mk +14 -0
- data/ext/zstdlib/zlibwrapper/zlibwrapper.c +14 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/bitstream.h +455 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/compiler.h +140 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/cpu.h +215 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/debug.c +44 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/debug.h +134 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/entropy_common.c +236 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/error_private.c +54 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/error_private.h +76 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/fse.h +708 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/fse_decompress.c +309 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/huf.h +358 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/mem.h +380 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/pool.c +340 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/pool.h +84 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/threading.c +75 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/threading.h +123 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/xxhash.c +876 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/xxhash.h +305 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/zstd_common.c +83 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/zstd_errors.h +93 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/zstd_internal.h +266 -0
- data/ext/zstdlib/zstd-1.3.8/lib/compress/fse_compress.c +721 -0
- data/ext/zstdlib/zstd-1.3.8/lib/compress/hist.c +203 -0
- data/ext/zstdlib/zstd-1.3.8/lib/compress/hist.h +95 -0
- data/ext/zstdlib/zstd-1.3.8/lib/compress/huf_compress.c +798 -0
- data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_compress.c +4290 -0
- data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_compress_internal.h +860 -0
- data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_double_fast.c +499 -0
- data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_double_fast.h +38 -0
- data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_fast.c +391 -0
- data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_fast.h +37 -0
- data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_lazy.c +1106 -0
- data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_lazy.h +67 -0
- data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_ldm.c +597 -0
- data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_ldm.h +105 -0
- data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_opt.c +1217 -0
- data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_opt.h +56 -0
- data/ext/zstdlib/zstd-1.3.8/lib/compress/zstdmt_compress.c +2107 -0
- data/ext/zstdlib/zstd-1.3.8/lib/compress/zstdmt_compress.h +174 -0
- data/ext/zstdlib/zstd-1.3.8/lib/decompress/huf_decompress.c +1232 -0
- data/ext/zstdlib/zstd-1.3.8/lib/decompress/zstd_ddict.c +240 -0
- data/ext/zstdlib/zstd-1.3.8/lib/decompress/zstd_ddict.h +44 -0
- data/ext/zstdlib/zstd-1.3.8/lib/decompress/zstd_decompress.c +1672 -0
- data/ext/zstdlib/zstd-1.3.8/lib/decompress/zstd_decompress_block.c +1307 -0
- data/ext/zstdlib/zstd-1.3.8/lib/decompress/zstd_decompress_block.h +59 -0
- data/ext/zstdlib/zstd-1.3.8/lib/decompress/zstd_decompress_internal.h +168 -0
- data/ext/zstdlib/zstd-1.3.8/lib/zstd.h +1766 -0
- data/ext/zstdlib/zstd-1.3.8/zlibWrapper/gzclose.c +28 -0
- data/ext/zstdlib/zstd-1.3.8/zlibWrapper/gzcompatibility.h +68 -0
- data/ext/zstdlib/zstd-1.3.8/zlibWrapper/gzguts.h +227 -0
- data/ext/zstdlib/zstd-1.3.8/zlibWrapper/gzlib.c +640 -0
- data/ext/zstdlib/zstd-1.3.8/zlibWrapper/gzread.c +670 -0
- data/ext/zstdlib/zstd-1.3.8/zlibWrapper/gzwrite.c +671 -0
- data/ext/zstdlib/zstd-1.3.8/zlibWrapper/zstd_zlibwrapper.c +1105 -0
- data/ext/zstdlib/zstd-1.3.8/zlibWrapper/zstd_zlibwrapper.h +88 -0
- data/ext/zstdlib/zstd.mk +14 -0
- data/lib/2.2/zstdlib.so +0 -0
- data/lib/2.3/zstdlib.so +0 -0
- data/lib/2.4/zstdlib.so +0 -0
- data/lib/2.5/zstdlib.so +0 -0
- data/lib/2.6/zstdlib.so +0 -0
- data/lib/zstdlib.rb +6 -0
- data/test/zstdlib_test.rb +21 -0
- metadata +205 -0
@@ -0,0 +1,28 @@
|
|
1
|
+
/* gzclose.c contains minimal changes required to be compiled with zlibWrapper:
|
2
|
+
* - gz_statep was converted to union to work with -Wstrict-aliasing=1 */
|
3
|
+
|
4
|
+
/* gzclose.c -- zlib gzclose() function
|
5
|
+
* Copyright (C) 2004, 2010 Mark Adler
|
6
|
+
* For conditions of distribution and use, see http://www.zlib.net/zlib_license.html
|
7
|
+
*/
|
8
|
+
|
9
|
+
#include "gzguts.h"
|
10
|
+
|
11
|
+
/* gzclose() is in a separate file so that it is linked in only if it is used.
|
12
|
+
That way the other gzclose functions can be used instead to avoid linking in
|
13
|
+
unneeded compression or decompression routines. */
|
14
|
+
int ZEXPORT gzclose(file)
|
15
|
+
gzFile file;
|
16
|
+
{
|
17
|
+
#ifndef NO_GZCOMPRESS
|
18
|
+
gz_statep state;
|
19
|
+
|
20
|
+
if (file == NULL)
|
21
|
+
return Z_STREAM_ERROR;
|
22
|
+
state = (gz_statep)file;
|
23
|
+
|
24
|
+
return state.state->mode == GZ_READ ? gzclose_r(file) : gzclose_w(file);
|
25
|
+
#else
|
26
|
+
return gzclose_r(file);
|
27
|
+
#endif
|
28
|
+
}
|
@@ -0,0 +1,68 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2016-present, Przemyslaw Skibinski, Yann Collet, Facebook, Inc.
|
3
|
+
* All rights reserved.
|
4
|
+
*
|
5
|
+
* This source code is licensed under both the BSD-style license (found in the
|
6
|
+
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
7
|
+
* in the COPYING file in the root directory of this source tree).
|
8
|
+
* You may select, at your option, one of the above-listed licenses.
|
9
|
+
*/
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
#if ZLIB_VERNUM <= 0x1240
|
14
|
+
ZEXTERN int ZEXPORT gzclose_r OF((gzFile file));
|
15
|
+
ZEXTERN int ZEXPORT gzclose_w OF((gzFile file));
|
16
|
+
ZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned size));
|
17
|
+
ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile file));
|
18
|
+
|
19
|
+
#if !defined(_WIN32) && defined(Z_LARGE64)
|
20
|
+
# define z_off64_t off64_t
|
21
|
+
#else
|
22
|
+
# if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO)
|
23
|
+
# define z_off64_t __int64
|
24
|
+
# else
|
25
|
+
# define z_off64_t z_off_t
|
26
|
+
# endif
|
27
|
+
#endif
|
28
|
+
#endif
|
29
|
+
|
30
|
+
|
31
|
+
#if ZLIB_VERNUM <= 0x1250
|
32
|
+
struct gzFile_s {
|
33
|
+
unsigned have;
|
34
|
+
unsigned char *next;
|
35
|
+
z_off64_t pos;
|
36
|
+
};
|
37
|
+
#endif
|
38
|
+
|
39
|
+
|
40
|
+
#if ZLIB_VERNUM <= 0x1270
|
41
|
+
#if defined(_WIN32) && !defined(Z_SOLO)
|
42
|
+
# include <stddef.h> /* for wchar_t */
|
43
|
+
ZEXTERN gzFile ZEXPORT gzopen_w OF((const wchar_t *path,
|
44
|
+
const char *mode));
|
45
|
+
#endif
|
46
|
+
#endif
|
47
|
+
|
48
|
+
|
49
|
+
#if ZLIB_VERNUM < 0x12B0
|
50
|
+
#ifdef Z_SOLO
|
51
|
+
typedef unsigned long z_size_t;
|
52
|
+
#else
|
53
|
+
# define z_longlong long long
|
54
|
+
# if defined(NO_SIZE_T)
|
55
|
+
typedef unsigned NO_SIZE_T z_size_t;
|
56
|
+
# elif defined(STDC)
|
57
|
+
# include <stddef.h>
|
58
|
+
typedef size_t z_size_t;
|
59
|
+
# else
|
60
|
+
typedef unsigned long z_size_t;
|
61
|
+
# endif
|
62
|
+
# undef z_longlong
|
63
|
+
#endif
|
64
|
+
ZEXTERN z_size_t ZEXPORT gzfread OF((voidp buf, z_size_t size, z_size_t nitems,
|
65
|
+
gzFile file));
|
66
|
+
ZEXTERN z_size_t ZEXPORT gzfwrite OF((voidpc buf, z_size_t size,
|
67
|
+
z_size_t nitems, gzFile file));
|
68
|
+
#endif
|
@@ -0,0 +1,227 @@
|
|
1
|
+
/* gzguts.h contains minimal changes required to be compiled with zlibWrapper:
|
2
|
+
* - #include "zlib.h" was changed to #include "zstd_zlibwrapper.h"
|
3
|
+
* - gz_statep was converted to union to work with -Wstrict-aliasing=1 */
|
4
|
+
|
5
|
+
/* gzguts.h -- zlib internal header definitions for gz* operations
|
6
|
+
* Copyright (C) 2004, 2005, 2010, 2011, 2012, 2013, 2016 Mark Adler
|
7
|
+
* For conditions of distribution and use, see http://www.zlib.net/zlib_license.html
|
8
|
+
*/
|
9
|
+
|
10
|
+
#ifdef _LARGEFILE64_SOURCE
|
11
|
+
# ifndef _LARGEFILE_SOURCE
|
12
|
+
# define _LARGEFILE_SOURCE 1
|
13
|
+
# endif
|
14
|
+
# ifdef _FILE_OFFSET_BITS
|
15
|
+
# undef _FILE_OFFSET_BITS
|
16
|
+
# endif
|
17
|
+
#endif
|
18
|
+
|
19
|
+
#ifdef HAVE_HIDDEN
|
20
|
+
# define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
|
21
|
+
#else
|
22
|
+
# define ZLIB_INTERNAL
|
23
|
+
#endif
|
24
|
+
|
25
|
+
#include <stdio.h>
|
26
|
+
#include "zstd_zlibwrapper.h"
|
27
|
+
#include "gzcompatibility.h"
|
28
|
+
#ifdef STDC
|
29
|
+
# include <string.h>
|
30
|
+
# include <stdlib.h>
|
31
|
+
# include <limits.h>
|
32
|
+
#endif
|
33
|
+
|
34
|
+
#ifndef _POSIX_SOURCE
|
35
|
+
# define _POSIX_SOURCE
|
36
|
+
#endif
|
37
|
+
#include <fcntl.h>
|
38
|
+
|
39
|
+
#ifdef _WIN32
|
40
|
+
# include <stddef.h>
|
41
|
+
#endif
|
42
|
+
|
43
|
+
#if defined(__TURBOC__) || defined(_MSC_VER) || defined(_WIN32)
|
44
|
+
# include <io.h>
|
45
|
+
#endif
|
46
|
+
|
47
|
+
#if defined(_WIN32)
|
48
|
+
# define WIDECHAR
|
49
|
+
#endif
|
50
|
+
|
51
|
+
#ifdef WINAPI_FAMILY
|
52
|
+
# define open _open
|
53
|
+
# define read _read
|
54
|
+
# define write _write
|
55
|
+
# define close _close
|
56
|
+
#endif
|
57
|
+
|
58
|
+
#ifdef NO_DEFLATE /* for compatibility with old definition */
|
59
|
+
# define NO_GZCOMPRESS
|
60
|
+
#endif
|
61
|
+
|
62
|
+
#if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
|
63
|
+
# ifndef HAVE_VSNPRINTF
|
64
|
+
# define HAVE_VSNPRINTF
|
65
|
+
# endif
|
66
|
+
#endif
|
67
|
+
|
68
|
+
#if defined(__CYGWIN__)
|
69
|
+
# ifndef HAVE_VSNPRINTF
|
70
|
+
# define HAVE_VSNPRINTF
|
71
|
+
# endif
|
72
|
+
#endif
|
73
|
+
|
74
|
+
#if defined(MSDOS) && defined(__BORLANDC__) && (BORLANDC > 0x410)
|
75
|
+
# ifndef HAVE_VSNPRINTF
|
76
|
+
# define HAVE_VSNPRINTF
|
77
|
+
# endif
|
78
|
+
#endif
|
79
|
+
|
80
|
+
#ifndef HAVE_VSNPRINTF
|
81
|
+
# ifdef MSDOS
|
82
|
+
/* vsnprintf may exist on some MS-DOS compilers (DJGPP?),
|
83
|
+
but for now we just assume it doesn't. */
|
84
|
+
# define NO_vsnprintf
|
85
|
+
# endif
|
86
|
+
# ifdef __TURBOC__
|
87
|
+
# define NO_vsnprintf
|
88
|
+
# endif
|
89
|
+
# ifdef WIN32
|
90
|
+
/* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */
|
91
|
+
# if !defined(vsnprintf) && !defined(NO_vsnprintf)
|
92
|
+
# if !defined(_MSC_VER) || ( defined(_MSC_VER) && _MSC_VER < 1500 )
|
93
|
+
# define vsnprintf _vsnprintf
|
94
|
+
# endif
|
95
|
+
# endif
|
96
|
+
# endif
|
97
|
+
# ifdef __SASC
|
98
|
+
# define NO_vsnprintf
|
99
|
+
# endif
|
100
|
+
# ifdef VMS
|
101
|
+
# define NO_vsnprintf
|
102
|
+
# endif
|
103
|
+
# ifdef __OS400__
|
104
|
+
# define NO_vsnprintf
|
105
|
+
# endif
|
106
|
+
# ifdef __MVS__
|
107
|
+
# define NO_vsnprintf
|
108
|
+
# endif
|
109
|
+
#endif
|
110
|
+
|
111
|
+
/* unlike snprintf (which is required in C99), _snprintf does not guarantee
|
112
|
+
null termination of the result -- however this is only used in gzlib.c where
|
113
|
+
the result is assured to fit in the space provided */
|
114
|
+
#if defined(_MSC_VER) && _MSC_VER < 1900
|
115
|
+
# define snprintf _snprintf
|
116
|
+
#endif
|
117
|
+
|
118
|
+
#ifndef local
|
119
|
+
# define local static
|
120
|
+
#endif
|
121
|
+
/* since "static" is used to mean two completely different things in C, we
|
122
|
+
define "local" for the non-static meaning of "static", for readability
|
123
|
+
(compile with -Dlocal if your debugger can't find static symbols) */
|
124
|
+
|
125
|
+
/* gz* functions always use library allocation functions */
|
126
|
+
#ifndef STDC
|
127
|
+
extern voidp malloc OF((uInt size));
|
128
|
+
extern void free OF((voidpf ptr));
|
129
|
+
#endif
|
130
|
+
|
131
|
+
/* get errno and strerror definition */
|
132
|
+
#if defined UNDER_CE
|
133
|
+
# include <windows.h>
|
134
|
+
# define zstrerror() gz_strwinerror((DWORD)GetLastError())
|
135
|
+
#else
|
136
|
+
# ifndef NO_STRERROR
|
137
|
+
# include <errno.h>
|
138
|
+
# define zstrerror() strerror(errno)
|
139
|
+
# else
|
140
|
+
# define zstrerror() "stdio error (consult errno)"
|
141
|
+
# endif
|
142
|
+
#endif
|
143
|
+
|
144
|
+
/* provide prototypes for these when building zlib without LFS */
|
145
|
+
#if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0
|
146
|
+
ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *));
|
147
|
+
ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int));
|
148
|
+
ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile));
|
149
|
+
ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile));
|
150
|
+
#endif
|
151
|
+
|
152
|
+
/* default memLevel */
|
153
|
+
#if MAX_MEM_LEVEL >= 8
|
154
|
+
# define DEF_MEM_LEVEL 8
|
155
|
+
#else
|
156
|
+
# define DEF_MEM_LEVEL MAX_MEM_LEVEL
|
157
|
+
#endif
|
158
|
+
|
159
|
+
/* default i/o buffer size -- double this for output when reading (this and
|
160
|
+
twice this must be able to fit in an unsigned type) */
|
161
|
+
#define GZBUFSIZE 8192
|
162
|
+
|
163
|
+
/* gzip modes, also provide a little integrity check on the passed structure */
|
164
|
+
#define GZ_NONE 0
|
165
|
+
#define GZ_READ 7247
|
166
|
+
#define GZ_WRITE 31153
|
167
|
+
#define GZ_APPEND 1 /* mode set to GZ_WRITE after the file is opened */
|
168
|
+
|
169
|
+
/* values for gz_state how */
|
170
|
+
#define LOOK 0 /* look for a gzip header */
|
171
|
+
#define COPY 1 /* copy input directly */
|
172
|
+
#define GZIP 2 /* decompress a gzip stream */
|
173
|
+
|
174
|
+
/* internal gzip file state data structure */
|
175
|
+
typedef struct {
|
176
|
+
/* exposed contents for gzgetc() macro */
|
177
|
+
struct gzFile_s x; /* "x" for exposed */
|
178
|
+
/* x.have: number of bytes available at x.next */
|
179
|
+
/* x.next: next output data to deliver or write */
|
180
|
+
/* x.pos: current position in uncompressed data */
|
181
|
+
/* used for both reading and writing */
|
182
|
+
int mode; /* see gzip modes above */
|
183
|
+
int fd; /* file descriptor */
|
184
|
+
char *path; /* path or fd for error messages */
|
185
|
+
unsigned size; /* buffer size, zero if not allocated yet */
|
186
|
+
unsigned want; /* requested buffer size, default is GZBUFSIZE */
|
187
|
+
unsigned char *in; /* input buffer (double-sized when writing) */
|
188
|
+
unsigned char *out; /* output buffer (double-sized when reading) */
|
189
|
+
int direct; /* 0 if processing gzip, 1 if transparent */
|
190
|
+
/* just for reading */
|
191
|
+
int how; /* 0: get header, 1: copy, 2: decompress */
|
192
|
+
z_off64_t start; /* where the gzip data started, for rewinding */
|
193
|
+
int eof; /* true if end of input file reached */
|
194
|
+
int past; /* true if read requested past end */
|
195
|
+
/* just for writing */
|
196
|
+
int level; /* compression level */
|
197
|
+
int strategy; /* compression strategy */
|
198
|
+
/* seek request */
|
199
|
+
z_off64_t skip; /* amount to skip (already rewound if backwards) */
|
200
|
+
int seek; /* true if seek request pending */
|
201
|
+
/* error information */
|
202
|
+
int err; /* error code */
|
203
|
+
char *msg; /* error message */
|
204
|
+
/* zlib inflate or deflate stream */
|
205
|
+
z_stream strm; /* stream structure in-place (not a pointer) */
|
206
|
+
} gz_state;
|
207
|
+
|
208
|
+
typedef union {
|
209
|
+
gz_state FAR *state;
|
210
|
+
gzFile file;
|
211
|
+
} gz_statep;
|
212
|
+
|
213
|
+
/* shared functions */
|
214
|
+
void ZLIB_INTERNAL gz_error OF((gz_statep, int, const char *));
|
215
|
+
#if defined UNDER_CE
|
216
|
+
char ZLIB_INTERNAL *gz_strwinerror OF((DWORD error));
|
217
|
+
#endif
|
218
|
+
|
219
|
+
/* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t
|
220
|
+
value -- needed when comparing unsigned to z_off64_t, which is signed
|
221
|
+
(possible z_off64_t types off_t, off64_t, and long are all signed) */
|
222
|
+
#ifdef INT_MAX
|
223
|
+
# define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > INT_MAX)
|
224
|
+
#else
|
225
|
+
unsigned ZLIB_INTERNAL gz_intmax OF((void));
|
226
|
+
# define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax())
|
227
|
+
#endif
|
@@ -0,0 +1,640 @@
|
|
1
|
+
/* gzlib.c contains minimal changes required to be compiled with zlibWrapper:
|
2
|
+
* - gz_statep was converted to union to work with -Wstrict-aliasing=1 */
|
3
|
+
|
4
|
+
/* gzlib.c -- zlib functions common to reading and writing gzip files
|
5
|
+
* Copyright (C) 2004-2017 Mark Adler
|
6
|
+
* For conditions of distribution and use, see http://www.zlib.net/zlib_license.html
|
7
|
+
*/
|
8
|
+
|
9
|
+
#include "gzguts.h"
|
10
|
+
|
11
|
+
#if defined(_WIN32) && !defined(__BORLANDC__) && !defined(__MINGW32__)
|
12
|
+
# define LSEEK _lseeki64
|
13
|
+
#else
|
14
|
+
#if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0
|
15
|
+
# define LSEEK lseek64
|
16
|
+
#else
|
17
|
+
# define LSEEK lseek
|
18
|
+
#endif
|
19
|
+
#endif
|
20
|
+
|
21
|
+
/* Local functions */
|
22
|
+
local void gz_reset OF((gz_statep));
|
23
|
+
local gzFile gz_open OF((const void *, int, const char *));
|
24
|
+
|
25
|
+
#if defined UNDER_CE
|
26
|
+
|
27
|
+
/* Map the Windows error number in ERROR to a locale-dependent error message
|
28
|
+
string and return a pointer to it. Typically, the values for ERROR come
|
29
|
+
from GetLastError.
|
30
|
+
|
31
|
+
The string pointed to shall not be modified by the application, but may be
|
32
|
+
overwritten by a subsequent call to gz_strwinerror
|
33
|
+
|
34
|
+
The gz_strwinerror function does not change the current setting of
|
35
|
+
GetLastError. */
|
36
|
+
char ZLIB_INTERNAL *gz_strwinerror (error)
|
37
|
+
DWORD error;
|
38
|
+
{
|
39
|
+
static char buf[1024];
|
40
|
+
|
41
|
+
wchar_t *msgbuf;
|
42
|
+
DWORD lasterr = GetLastError();
|
43
|
+
DWORD chars = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM
|
44
|
+
| FORMAT_MESSAGE_ALLOCATE_BUFFER,
|
45
|
+
NULL,
|
46
|
+
error,
|
47
|
+
0, /* Default language */
|
48
|
+
(LPVOID)&msgbuf,
|
49
|
+
0,
|
50
|
+
NULL);
|
51
|
+
if (chars != 0) {
|
52
|
+
/* If there is an \r\n appended, zap it. */
|
53
|
+
if (chars >= 2
|
54
|
+
&& msgbuf[chars - 2] == '\r' && msgbuf[chars - 1] == '\n') {
|
55
|
+
chars -= 2;
|
56
|
+
msgbuf[chars] = 0;
|
57
|
+
}
|
58
|
+
|
59
|
+
if (chars > sizeof (buf) - 1) {
|
60
|
+
chars = sizeof (buf) - 1;
|
61
|
+
msgbuf[chars] = 0;
|
62
|
+
}
|
63
|
+
|
64
|
+
wcstombs(buf, msgbuf, chars + 1);
|
65
|
+
LocalFree(msgbuf);
|
66
|
+
}
|
67
|
+
else {
|
68
|
+
sprintf(buf, "unknown win32 error (%ld)", error);
|
69
|
+
}
|
70
|
+
|
71
|
+
SetLastError(lasterr);
|
72
|
+
return buf;
|
73
|
+
}
|
74
|
+
|
75
|
+
#endif /* UNDER_CE */
|
76
|
+
|
77
|
+
/* Reset gzip file state */
|
78
|
+
local void gz_reset(state)
|
79
|
+
gz_statep state;
|
80
|
+
{
|
81
|
+
state.state->x.have = 0; /* no output data available */
|
82
|
+
if (state.state->mode == GZ_READ) { /* for reading ... */
|
83
|
+
state.state->eof = 0; /* not at end of file */
|
84
|
+
state.state->past = 0; /* have not read past end yet */
|
85
|
+
state.state->how = LOOK; /* look for gzip header */
|
86
|
+
}
|
87
|
+
state.state->seek = 0; /* no seek request pending */
|
88
|
+
gz_error(state, Z_OK, NULL); /* clear error */
|
89
|
+
state.state->x.pos = 0; /* no uncompressed data yet */
|
90
|
+
state.state->strm.avail_in = 0; /* no input data yet */
|
91
|
+
}
|
92
|
+
|
93
|
+
/* Open a gzip file either by name or file descriptor. */
|
94
|
+
local gzFile gz_open(path, fd, mode)
|
95
|
+
const void *path;
|
96
|
+
int fd;
|
97
|
+
const char *mode;
|
98
|
+
{
|
99
|
+
gz_statep state;
|
100
|
+
z_size_t len;
|
101
|
+
int oflag;
|
102
|
+
#ifdef O_CLOEXEC
|
103
|
+
int cloexec = 0;
|
104
|
+
#endif
|
105
|
+
#ifdef O_EXCL
|
106
|
+
int exclusive = 0;
|
107
|
+
#endif
|
108
|
+
|
109
|
+
/* check input */
|
110
|
+
if (path == NULL)
|
111
|
+
return NULL;
|
112
|
+
|
113
|
+
/* allocate gzFile structure to return */
|
114
|
+
state.state = (gz_state*)malloc(sizeof(gz_state));
|
115
|
+
if (state.state == NULL)
|
116
|
+
return NULL;
|
117
|
+
state.state->size = 0; /* no buffers allocated yet */
|
118
|
+
state.state->want = GZBUFSIZE; /* requested buffer size */
|
119
|
+
state.state->msg = NULL; /* no error message yet */
|
120
|
+
|
121
|
+
/* interpret mode */
|
122
|
+
state.state->mode = GZ_NONE;
|
123
|
+
state.state->level = Z_DEFAULT_COMPRESSION;
|
124
|
+
state.state->strategy = Z_DEFAULT_STRATEGY;
|
125
|
+
state.state->direct = 0;
|
126
|
+
while (*mode) {
|
127
|
+
if (*mode >= '0' && *mode <= '9')
|
128
|
+
state.state->level = *mode - '0';
|
129
|
+
else
|
130
|
+
switch (*mode) {
|
131
|
+
case 'r':
|
132
|
+
state.state->mode = GZ_READ;
|
133
|
+
break;
|
134
|
+
#ifndef NO_GZCOMPRESS
|
135
|
+
case 'w':
|
136
|
+
state.state->mode = GZ_WRITE;
|
137
|
+
break;
|
138
|
+
case 'a':
|
139
|
+
state.state->mode = GZ_APPEND;
|
140
|
+
break;
|
141
|
+
#endif
|
142
|
+
case '+': /* can't read and write at the same time */
|
143
|
+
free(state.state);
|
144
|
+
return NULL;
|
145
|
+
case 'b': /* ignore -- will request binary anyway */
|
146
|
+
break;
|
147
|
+
#ifdef O_CLOEXEC
|
148
|
+
case 'e':
|
149
|
+
cloexec = 1;
|
150
|
+
break;
|
151
|
+
#endif
|
152
|
+
#ifdef O_EXCL
|
153
|
+
case 'x':
|
154
|
+
exclusive = 1;
|
155
|
+
break;
|
156
|
+
#endif
|
157
|
+
case 'f':
|
158
|
+
state.state->strategy = Z_FILTERED;
|
159
|
+
break;
|
160
|
+
case 'h':
|
161
|
+
state.state->strategy = Z_HUFFMAN_ONLY;
|
162
|
+
break;
|
163
|
+
case 'R':
|
164
|
+
state.state->strategy = Z_RLE;
|
165
|
+
break;
|
166
|
+
case 'F':
|
167
|
+
state.state->strategy = Z_FIXED;
|
168
|
+
break;
|
169
|
+
case 'T':
|
170
|
+
state.state->direct = 1;
|
171
|
+
break;
|
172
|
+
default: /* could consider as an error, but just ignore */
|
173
|
+
;
|
174
|
+
}
|
175
|
+
mode++;
|
176
|
+
}
|
177
|
+
|
178
|
+
/* must provide an "r", "w", or "a" */
|
179
|
+
if (state.state->mode == GZ_NONE) {
|
180
|
+
free(state.state);
|
181
|
+
return NULL;
|
182
|
+
}
|
183
|
+
|
184
|
+
/* can't force transparent read */
|
185
|
+
if (state.state->mode == GZ_READ) {
|
186
|
+
if (state.state->direct) {
|
187
|
+
free(state.state);
|
188
|
+
return NULL;
|
189
|
+
}
|
190
|
+
state.state->direct = 1; /* for empty file */
|
191
|
+
}
|
192
|
+
|
193
|
+
/* save the path name for error messages */
|
194
|
+
#ifdef WIDECHAR
|
195
|
+
if (fd == -2) {
|
196
|
+
len = wcstombs(NULL, path, 0);
|
197
|
+
if (len == (z_size_t)-1)
|
198
|
+
len = 0;
|
199
|
+
}
|
200
|
+
else
|
201
|
+
#endif
|
202
|
+
len = strlen((const char *)path);
|
203
|
+
state.state->path = (char *)malloc(len + 1);
|
204
|
+
if (state.state->path == NULL) {
|
205
|
+
free(state.state);
|
206
|
+
return NULL;
|
207
|
+
}
|
208
|
+
#ifdef WIDECHAR
|
209
|
+
if (fd == -2)
|
210
|
+
if (len)
|
211
|
+
wcstombs(state.state->path, path, len + 1);
|
212
|
+
else
|
213
|
+
*(state.state->path) = 0;
|
214
|
+
else
|
215
|
+
#endif
|
216
|
+
#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
|
217
|
+
(void)snprintf(state.state->path, len + 1, "%s", (const char *)path);
|
218
|
+
#else
|
219
|
+
strcpy(state.state->path, path);
|
220
|
+
#endif
|
221
|
+
|
222
|
+
/* compute the flags for open() */
|
223
|
+
oflag =
|
224
|
+
#ifdef O_LARGEFILE
|
225
|
+
O_LARGEFILE |
|
226
|
+
#endif
|
227
|
+
#ifdef O_BINARY
|
228
|
+
O_BINARY |
|
229
|
+
#endif
|
230
|
+
#ifdef O_CLOEXEC
|
231
|
+
(cloexec ? O_CLOEXEC : 0) |
|
232
|
+
#endif
|
233
|
+
(state.state->mode == GZ_READ ?
|
234
|
+
O_RDONLY :
|
235
|
+
(O_WRONLY | O_CREAT |
|
236
|
+
#ifdef O_EXCL
|
237
|
+
(exclusive ? O_EXCL : 0) |
|
238
|
+
#endif
|
239
|
+
(state.state->mode == GZ_WRITE ?
|
240
|
+
O_TRUNC :
|
241
|
+
O_APPEND)));
|
242
|
+
|
243
|
+
/* open the file with the appropriate flags (or just use fd) */
|
244
|
+
state.state->fd = fd > -1 ? fd : (
|
245
|
+
#ifdef WIDECHAR
|
246
|
+
fd == -2 ? _wopen(path, oflag, 0666) :
|
247
|
+
#endif
|
248
|
+
open((const char *)path, oflag, 0666));
|
249
|
+
if (state.state->fd == -1) {
|
250
|
+
free(state.state->path);
|
251
|
+
free(state.state);
|
252
|
+
return NULL;
|
253
|
+
}
|
254
|
+
if (state.state->mode == GZ_APPEND) {
|
255
|
+
LSEEK(state.state->fd, 0, SEEK_END); /* so gzoffset() is correct */
|
256
|
+
state.state->mode = GZ_WRITE; /* simplify later checks */
|
257
|
+
}
|
258
|
+
|
259
|
+
/* save the current position for rewinding (only if reading) */
|
260
|
+
if (state.state->mode == GZ_READ) {
|
261
|
+
state.state->start = LSEEK(state.state->fd, 0, SEEK_CUR);
|
262
|
+
if (state.state->start == -1) state.state->start = 0;
|
263
|
+
}
|
264
|
+
|
265
|
+
/* initialize stream */
|
266
|
+
gz_reset(state);
|
267
|
+
|
268
|
+
/* return stream */
|
269
|
+
return state.file;
|
270
|
+
}
|
271
|
+
|
272
|
+
/* -- see zlib.h -- */
|
273
|
+
gzFile ZEXPORT gzopen(path, mode)
|
274
|
+
const char *path;
|
275
|
+
const char *mode;
|
276
|
+
{
|
277
|
+
return gz_open(path, -1, mode);
|
278
|
+
}
|
279
|
+
|
280
|
+
/* -- see zlib.h -- */
|
281
|
+
gzFile ZEXPORT gzopen64(path, mode)
|
282
|
+
const char *path;
|
283
|
+
const char *mode;
|
284
|
+
{
|
285
|
+
return gz_open(path, -1, mode);
|
286
|
+
}
|
287
|
+
|
288
|
+
/* -- see zlib.h -- */
|
289
|
+
gzFile ZEXPORT gzdopen(fd, mode)
|
290
|
+
int fd;
|
291
|
+
const char *mode;
|
292
|
+
{
|
293
|
+
char *path; /* identifier for error messages */
|
294
|
+
gzFile gz;
|
295
|
+
|
296
|
+
if (fd == -1 || (path = (char *)malloc(7 + 3 * sizeof(int))) == NULL)
|
297
|
+
return NULL;
|
298
|
+
#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
|
299
|
+
(void)snprintf(path, 7 + 3 * sizeof(int), "<fd:%d>", fd);
|
300
|
+
#else
|
301
|
+
sprintf(path, "<fd:%d>", fd); /* for debugging */
|
302
|
+
#endif
|
303
|
+
gz = gz_open(path, fd, mode);
|
304
|
+
free(path);
|
305
|
+
return gz;
|
306
|
+
}
|
307
|
+
|
308
|
+
/* -- see zlib.h -- */
|
309
|
+
#ifdef WIDECHAR
|
310
|
+
gzFile ZEXPORT gzopen_w(path, mode)
|
311
|
+
const wchar_t *path;
|
312
|
+
const char *mode;
|
313
|
+
{
|
314
|
+
return gz_open(path, -2, mode);
|
315
|
+
}
|
316
|
+
#endif
|
317
|
+
|
318
|
+
/* -- see zlib.h -- */
|
319
|
+
int ZEXPORT gzbuffer(file, size)
|
320
|
+
gzFile file;
|
321
|
+
unsigned size;
|
322
|
+
{
|
323
|
+
gz_statep state;
|
324
|
+
|
325
|
+
/* get internal structure and check integrity */
|
326
|
+
if (file == NULL)
|
327
|
+
return -1;
|
328
|
+
state = (gz_statep)file;
|
329
|
+
if (state.state->mode != GZ_READ && state.state->mode != GZ_WRITE)
|
330
|
+
return -1;
|
331
|
+
|
332
|
+
/* make sure we haven't already allocated memory */
|
333
|
+
if (state.state->size != 0)
|
334
|
+
return -1;
|
335
|
+
|
336
|
+
/* check and set requested size */
|
337
|
+
if ((size << 1) < size)
|
338
|
+
return -1; /* need to be able to double it */
|
339
|
+
if (size < 2)
|
340
|
+
size = 2; /* need two bytes to check magic header */
|
341
|
+
state.state->want = size;
|
342
|
+
return 0;
|
343
|
+
}
|
344
|
+
|
345
|
+
/* -- see zlib.h -- */
|
346
|
+
int ZEXPORT gzrewind(file)
|
347
|
+
gzFile file;
|
348
|
+
{
|
349
|
+
gz_statep state;
|
350
|
+
|
351
|
+
/* get internal structure */
|
352
|
+
if (file == NULL)
|
353
|
+
return -1;
|
354
|
+
state = (gz_statep)file;
|
355
|
+
|
356
|
+
/* check that we're reading and that there's no error */
|
357
|
+
if (state.state->mode != GZ_READ ||
|
358
|
+
(state.state->err != Z_OK && state.state->err != Z_BUF_ERROR))
|
359
|
+
return -1;
|
360
|
+
|
361
|
+
/* back up and start over */
|
362
|
+
if (LSEEK(state.state->fd, state.state->start, SEEK_SET) == -1)
|
363
|
+
return -1;
|
364
|
+
gz_reset(state);
|
365
|
+
return 0;
|
366
|
+
}
|
367
|
+
|
368
|
+
/* -- see zlib.h -- */
|
369
|
+
z_off64_t ZEXPORT gzseek64(file, offset, whence)
|
370
|
+
gzFile file;
|
371
|
+
z_off64_t offset;
|
372
|
+
int whence;
|
373
|
+
{
|
374
|
+
unsigned n;
|
375
|
+
z_off64_t ret;
|
376
|
+
gz_statep state;
|
377
|
+
|
378
|
+
/* get internal structure and check integrity */
|
379
|
+
if (file == NULL)
|
380
|
+
return -1;
|
381
|
+
state = (gz_statep)file;
|
382
|
+
if (state.state->mode != GZ_READ && state.state->mode != GZ_WRITE)
|
383
|
+
return -1;
|
384
|
+
|
385
|
+
/* check that there's no error */
|
386
|
+
if (state.state->err != Z_OK && state.state->err != Z_BUF_ERROR)
|
387
|
+
return -1;
|
388
|
+
|
389
|
+
/* can only seek from start or relative to current position */
|
390
|
+
if (whence != SEEK_SET && whence != SEEK_CUR)
|
391
|
+
return -1;
|
392
|
+
|
393
|
+
/* normalize offset to a SEEK_CUR specification */
|
394
|
+
if (whence == SEEK_SET)
|
395
|
+
offset -= state.state->x.pos;
|
396
|
+
else if (state.state->seek)
|
397
|
+
offset += state.state->skip;
|
398
|
+
state.state->seek = 0;
|
399
|
+
|
400
|
+
/* if within raw area while reading, just go there */
|
401
|
+
if (state.state->mode == GZ_READ && state.state->how == COPY &&
|
402
|
+
state.state->x.pos + offset >= 0) {
|
403
|
+
ret = LSEEK(state.state->fd, offset - state.state->x.have, SEEK_CUR);
|
404
|
+
if (ret == -1)
|
405
|
+
return -1;
|
406
|
+
state.state->x.have = 0;
|
407
|
+
state.state->eof = 0;
|
408
|
+
state.state->past = 0;
|
409
|
+
state.state->seek = 0;
|
410
|
+
gz_error(state, Z_OK, NULL);
|
411
|
+
state.state->strm.avail_in = 0;
|
412
|
+
state.state->x.pos += offset;
|
413
|
+
return state.state->x.pos;
|
414
|
+
}
|
415
|
+
|
416
|
+
/* calculate skip amount, rewinding if needed for back seek when reading */
|
417
|
+
if (offset < 0) {
|
418
|
+
if (state.state->mode != GZ_READ) /* writing -- can't go backwards */
|
419
|
+
return -1;
|
420
|
+
offset += state.state->x.pos;
|
421
|
+
if (offset < 0) /* before start of file! */
|
422
|
+
return -1;
|
423
|
+
if (gzrewind(file) == -1) /* rewind, then skip to offset */
|
424
|
+
return -1;
|
425
|
+
}
|
426
|
+
|
427
|
+
/* if reading, skip what's in output buffer (one less gzgetc() check) */
|
428
|
+
if (state.state->mode == GZ_READ) {
|
429
|
+
n = GT_OFF(state.state->x.have) || (z_off64_t)state.state->x.have > offset ?
|
430
|
+
(unsigned)offset : state.state->x.have;
|
431
|
+
state.state->x.have -= n;
|
432
|
+
state.state->x.next += n;
|
433
|
+
state.state->x.pos += n;
|
434
|
+
offset -= n;
|
435
|
+
}
|
436
|
+
|
437
|
+
/* request skip (if not zero) */
|
438
|
+
if (offset) {
|
439
|
+
state.state->seek = 1;
|
440
|
+
state.state->skip = offset;
|
441
|
+
}
|
442
|
+
return state.state->x.pos + offset;
|
443
|
+
}
|
444
|
+
|
445
|
+
/* -- see zlib.h -- */
|
446
|
+
z_off_t ZEXPORT gzseek(file, offset, whence)
|
447
|
+
gzFile file;
|
448
|
+
z_off_t offset;
|
449
|
+
int whence;
|
450
|
+
{
|
451
|
+
z_off64_t ret;
|
452
|
+
|
453
|
+
ret = gzseek64(file, (z_off64_t)offset, whence);
|
454
|
+
return ret == (z_off_t)ret ? (z_off_t)ret : -1;
|
455
|
+
}
|
456
|
+
|
457
|
+
/* -- see zlib.h -- */
|
458
|
+
z_off64_t ZEXPORT gztell64(file)
|
459
|
+
gzFile file;
|
460
|
+
{
|
461
|
+
gz_statep state;
|
462
|
+
|
463
|
+
/* get internal structure and check integrity */
|
464
|
+
if (file == NULL)
|
465
|
+
return -1;
|
466
|
+
state = (gz_statep)file;
|
467
|
+
if (state.state->mode != GZ_READ && state.state->mode != GZ_WRITE)
|
468
|
+
return -1;
|
469
|
+
|
470
|
+
/* return position */
|
471
|
+
return state.state->x.pos + (state.state->seek ? state.state->skip : 0);
|
472
|
+
}
|
473
|
+
|
474
|
+
/* -- see zlib.h -- */
|
475
|
+
z_off_t ZEXPORT gztell(file)
|
476
|
+
gzFile file;
|
477
|
+
{
|
478
|
+
z_off64_t ret;
|
479
|
+
|
480
|
+
ret = gztell64(file);
|
481
|
+
return ret == (z_off_t)ret ? (z_off_t)ret : -1;
|
482
|
+
}
|
483
|
+
|
484
|
+
/* -- see zlib.h -- */
|
485
|
+
z_off64_t ZEXPORT gzoffset64(file)
|
486
|
+
gzFile file;
|
487
|
+
{
|
488
|
+
z_off64_t offset;
|
489
|
+
gz_statep state;
|
490
|
+
|
491
|
+
/* get internal structure and check integrity */
|
492
|
+
if (file == NULL)
|
493
|
+
return -1;
|
494
|
+
state = (gz_statep)file;
|
495
|
+
if (state.state->mode != GZ_READ && state.state->mode != GZ_WRITE)
|
496
|
+
return -1;
|
497
|
+
|
498
|
+
/* compute and return effective offset in file */
|
499
|
+
offset = LSEEK(state.state->fd, 0, SEEK_CUR);
|
500
|
+
if (offset == -1)
|
501
|
+
return -1;
|
502
|
+
if (state.state->mode == GZ_READ) /* reading */
|
503
|
+
offset -= state.state->strm.avail_in; /* don't count buffered input */
|
504
|
+
return offset;
|
505
|
+
}
|
506
|
+
|
507
|
+
/* -- see zlib.h -- */
|
508
|
+
z_off_t ZEXPORT gzoffset(file)
|
509
|
+
gzFile file;
|
510
|
+
{
|
511
|
+
z_off64_t ret;
|
512
|
+
|
513
|
+
ret = gzoffset64(file);
|
514
|
+
return ret == (z_off_t)ret ? (z_off_t)ret : -1;
|
515
|
+
}
|
516
|
+
|
517
|
+
/* -- see zlib.h -- */
|
518
|
+
int ZEXPORT gzeof(file)
|
519
|
+
gzFile file;
|
520
|
+
{
|
521
|
+
gz_statep state;
|
522
|
+
|
523
|
+
/* get internal structure and check integrity */
|
524
|
+
if (file == NULL)
|
525
|
+
return 0;
|
526
|
+
state = (gz_statep)file;
|
527
|
+
if (state.state->mode != GZ_READ && state.state->mode != GZ_WRITE)
|
528
|
+
return 0;
|
529
|
+
|
530
|
+
/* return end-of-file state */
|
531
|
+
return state.state->mode == GZ_READ ? state.state->past : 0;
|
532
|
+
}
|
533
|
+
|
534
|
+
/* -- see zlib.h -- */
|
535
|
+
const char * ZEXPORT gzerror(file, errnum)
|
536
|
+
gzFile file;
|
537
|
+
int *errnum;
|
538
|
+
{
|
539
|
+
gz_statep state;
|
540
|
+
|
541
|
+
/* get internal structure and check integrity */
|
542
|
+
if (file == NULL)
|
543
|
+
return NULL;
|
544
|
+
state = (gz_statep)file;
|
545
|
+
if (state.state->mode != GZ_READ && state.state->mode != GZ_WRITE)
|
546
|
+
return NULL;
|
547
|
+
|
548
|
+
/* return error information */
|
549
|
+
if (errnum != NULL)
|
550
|
+
*errnum = state.state->err;
|
551
|
+
return state.state->err == Z_MEM_ERROR ? "out of memory" :
|
552
|
+
(state.state->msg == NULL ? "" : state.state->msg);
|
553
|
+
}
|
554
|
+
|
555
|
+
/* -- see zlib.h -- */
|
556
|
+
void ZEXPORT gzclearerr(file)
|
557
|
+
gzFile file;
|
558
|
+
{
|
559
|
+
gz_statep state;
|
560
|
+
|
561
|
+
/* get internal structure and check integrity */
|
562
|
+
if (file == NULL)
|
563
|
+
return;
|
564
|
+
state = (gz_statep)file;
|
565
|
+
if (state.state->mode != GZ_READ && state.state->mode != GZ_WRITE)
|
566
|
+
return;
|
567
|
+
|
568
|
+
/* clear error and end-of-file */
|
569
|
+
if (state.state->mode == GZ_READ) {
|
570
|
+
state.state->eof = 0;
|
571
|
+
state.state->past = 0;
|
572
|
+
}
|
573
|
+
gz_error(state, Z_OK, NULL);
|
574
|
+
}
|
575
|
+
|
576
|
+
/* Create an error message in allocated memory and set state.state->err and
|
577
|
+
state.state->msg accordingly. Free any previous error message already there. Do
|
578
|
+
not try to free or allocate space if the error is Z_MEM_ERROR (out of
|
579
|
+
memory). Simply save the error message as a static string. If there is an
|
580
|
+
allocation failure constructing the error message, then convert the error to
|
581
|
+
out of memory. */
|
582
|
+
void ZLIB_INTERNAL gz_error(state, err, msg)
|
583
|
+
gz_statep state;
|
584
|
+
int err;
|
585
|
+
const char *msg;
|
586
|
+
{
|
587
|
+
/* free previously allocated message and clear */
|
588
|
+
if (state.state->msg != NULL) {
|
589
|
+
if (state.state->err != Z_MEM_ERROR)
|
590
|
+
free(state.state->msg);
|
591
|
+
state.state->msg = NULL;
|
592
|
+
}
|
593
|
+
|
594
|
+
/* if fatal, set state.state->x.have to 0 so that the gzgetc() macro fails */
|
595
|
+
if (err != Z_OK && err != Z_BUF_ERROR)
|
596
|
+
state.state->x.have = 0;
|
597
|
+
|
598
|
+
/* set error code, and if no message, then done */
|
599
|
+
state.state->err = err;
|
600
|
+
if (msg == NULL)
|
601
|
+
return;
|
602
|
+
|
603
|
+
/* for an out of memory error, return literal string when requested */
|
604
|
+
if (err == Z_MEM_ERROR)
|
605
|
+
return;
|
606
|
+
|
607
|
+
/* construct error message with path */
|
608
|
+
if ((state.state->msg = (char *)malloc(strlen(state.state->path) + strlen(msg) + 3)) ==
|
609
|
+
NULL) {
|
610
|
+
state.state->err = Z_MEM_ERROR;
|
611
|
+
return;
|
612
|
+
}
|
613
|
+
#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
|
614
|
+
(void)snprintf(state.state->msg, strlen(state.state->path) + strlen(msg) + 3,
|
615
|
+
"%s%s%s", state.state->path, ": ", msg);
|
616
|
+
#else
|
617
|
+
strcpy(state.state->msg, state.state->path);
|
618
|
+
strcat(state.state->msg, ": ");
|
619
|
+
strcat(state.state->msg, msg);
|
620
|
+
#endif
|
621
|
+
}
|
622
|
+
|
623
|
+
#ifndef INT_MAX
|
624
|
+
/* portably return maximum value for an int (when limits.h presumed not
|
625
|
+
available) -- we need to do this to cover cases where 2's complement not
|
626
|
+
used, since C standard permits 1's complement and sign-bit representations,
|
627
|
+
otherwise we could just use ((unsigned)-1) >> 1 */
|
628
|
+
unsigned ZLIB_INTERNAL gz_intmax()
|
629
|
+
{
|
630
|
+
unsigned p, q;
|
631
|
+
|
632
|
+
p = 1;
|
633
|
+
do {
|
634
|
+
q = p;
|
635
|
+
p <<= 1;
|
636
|
+
p++;
|
637
|
+
} while (p > q);
|
638
|
+
return q >> 1;
|
639
|
+
}
|
640
|
+
#endif
|