libarchive-static 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ext/Makefile +6 -0
- data/ext/extconf.rb +61 -0
- data/ext/libarchive-0.1.1/COPYING.libarchive +60 -0
- data/ext/libarchive-0.1.1/LICENSE.libbzip2 +42 -0
- data/ext/libarchive-0.1.1/README.txt +143 -0
- data/ext/libarchive-0.1.1/ext/Makefile.in +0 -0
- data/ext/libarchive-0.1.1/ext/archive_read_support_compression.c +31 -0
- data/ext/libarchive-0.1.1/ext/archive_read_support_compression.h +6 -0
- data/ext/libarchive-0.1.1/ext/archive_read_support_format.c +32 -0
- data/ext/libarchive-0.1.1/ext/archive_read_support_format.h +6 -0
- data/ext/libarchive-0.1.1/ext/archive_write_open_rb_str.c +29 -0
- data/ext/libarchive-0.1.1/ext/archive_write_open_rb_str.h +6 -0
- data/ext/libarchive-0.1.1/ext/archive_write_set_compression.c +32 -0
- data/ext/libarchive-0.1.1/ext/archive_write_set_compression.h +6 -0
- data/ext/libarchive-0.1.1/ext/config.h.in +22 -0
- data/ext/libarchive-0.1.1/ext/configure +3904 -0
- data/ext/libarchive-0.1.1/ext/configure.in +11 -0
- data/ext/libarchive-0.1.1/ext/depend +19 -0
- data/ext/libarchive-0.1.1/ext/extconf.rb +6 -0
- data/ext/libarchive-0.1.1/ext/install-sh +250 -0
- data/ext/libarchive-0.1.1/ext/libarchive.c +89 -0
- data/ext/libarchive-0.1.1/ext/libarchive_archive.c +84 -0
- data/ext/libarchive-0.1.1/ext/libarchive_entry.c +1015 -0
- data/ext/libarchive-0.1.1/ext/libarchive_internal.h +155 -0
- data/ext/libarchive-0.1.1/ext/libarchive_reader.c +328 -0
- data/ext/libarchive-0.1.1/ext/libarchive_win32.h +52 -0
- data/ext/libarchive-0.1.1/ext/libarchive_writer.c +246 -0
- data/ext/libarchive-0.1.1/libarchive.c +1762 -0
- data/ext/libarchive-2.8.4/Makefile.in +7076 -0
- data/ext/libarchive-2.8.4/build/autoconf/check_stdcall_func.m4 +51 -0
- data/ext/libarchive-2.8.4/build/autoconf/compile +143 -0
- data/ext/libarchive-2.8.4/build/autoconf/config.guess +1502 -0
- data/ext/libarchive-2.8.4/build/autoconf/config.sub +1708 -0
- data/ext/libarchive-2.8.4/build/autoconf/depcomp +630 -0
- data/ext/libarchive-2.8.4/build/autoconf/install-sh +291 -0
- data/ext/libarchive-2.8.4/build/autoconf/la_uid_t.m4 +20 -0
- data/ext/libarchive-2.8.4/build/autoconf/ltmain.sh +8406 -0
- data/ext/libarchive-2.8.4/build/autoconf/missing +376 -0
- data/ext/libarchive-2.8.4/build/pkgconfig/libarchive.pc.in +10 -0
- data/ext/libarchive-2.8.4/config.h.in +772 -0
- data/ext/libarchive-2.8.4/configure +17916 -0
- data/ext/libarchive-2.8.4/libarchive/archive.h +741 -0
- data/ext/libarchive-2.8.4/libarchive/archive_check_magic.c +134 -0
- data/ext/libarchive-2.8.4/libarchive/archive_crc32.h +66 -0
- data/ext/libarchive-2.8.4/libarchive/archive_endian.h +162 -0
- data/ext/libarchive-2.8.4/libarchive/archive_entry.c +2202 -0
- data/ext/libarchive-2.8.4/libarchive/archive_entry.h +524 -0
- data/ext/libarchive-2.8.4/libarchive/archive_entry_copy_bhfi.c +74 -0
- data/ext/libarchive-2.8.4/libarchive/archive_entry_copy_stat.c +77 -0
- data/ext/libarchive-2.8.4/libarchive/archive_entry_link_resolver.c +405 -0
- data/ext/libarchive-2.8.4/libarchive/archive_entry_private.h +184 -0
- data/ext/libarchive-2.8.4/libarchive/archive_entry_stat.c +118 -0
- data/ext/libarchive-2.8.4/libarchive/archive_entry_strmode.c +87 -0
- data/ext/libarchive-2.8.4/libarchive/archive_entry_xattr.c +158 -0
- data/ext/libarchive-2.8.4/libarchive/archive_hash.h +281 -0
- data/ext/libarchive-2.8.4/libarchive/archive_platform.h +165 -0
- data/ext/libarchive-2.8.4/libarchive/archive_private.h +124 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read.c +1249 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_data_into_fd.c +93 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_disk.c +198 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_disk_entry_from_file.c +570 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_disk_private.h +62 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_disk_set_standard_lookup.c +303 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_extract.c +182 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_open_fd.c +190 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_open_file.c +165 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_open_filename.c +272 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_open_memory.c +156 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_private.h +199 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_compression_all.c +60 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_compression_bzip2.c +353 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_compression_compress.c +444 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_compression_gzip.c +465 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_compression_none.c +40 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_compression_program.c +459 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_compression_rpm.c +287 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_compression_uu.c +627 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_compression_xz.c +708 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_all.c +43 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_ar.c +584 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_cpio.c +777 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_empty.c +93 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_iso9660.c +2830 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_mtree.c +1304 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_raw.c +185 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_tar.c +2418 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_xar.c +3151 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_zip.c +903 -0
- data/ext/libarchive-2.8.4/libarchive/archive_string.c +453 -0
- data/ext/libarchive-2.8.4/libarchive/archive_string.h +148 -0
- data/ext/libarchive-2.8.4/libarchive/archive_string_sprintf.c +164 -0
- data/ext/libarchive-2.8.4/libarchive/archive_util.c +391 -0
- data/ext/libarchive-2.8.4/libarchive/archive_virtual.c +94 -0
- data/ext/libarchive-2.8.4/libarchive/archive_windows.c +1236 -0
- data/ext/libarchive-2.8.4/libarchive/archive_windows.h +347 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write.c +466 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_disk.c +2628 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_disk_private.h +38 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_disk_set_standard_lookup.c +262 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_open_fd.c +141 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_open_file.c +105 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_open_filename.c +162 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_open_memory.c +126 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_private.h +122 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_compression_bzip2.c +408 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_compression_compress.c +492 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_compression_gzip.c +477 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_compression_none.c +257 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_compression_program.c +347 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_compression_xz.c +438 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_format.c +72 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_ar.c +550 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_by_name.c +76 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_cpio.c +344 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_cpio_newc.c +295 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_mtree.c +1050 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_pax.c +1386 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_shar.c +626 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_ustar.c +587 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_zip.c +667 -0
- data/ext/libarchive-2.8.4/libarchive/config_freebsd.h +154 -0
- data/ext/libarchive-2.8.4/libarchive/filter_fork.c +161 -0
- data/ext/libarchive-2.8.4/libarchive/filter_fork.h +41 -0
- data/ext/libarchive-2.8.4/libarchive/filter_fork_windows.c +113 -0
- data/ext/libarchive-static-makefile +80 -0
- data/ext/libarchive-static-wrapper-makefile +22 -0
- data/ext/zlib-1.2.5/Makefile.in +257 -0
- data/ext/zlib-1.2.5/adler32.c +169 -0
- data/ext/zlib-1.2.5/compress.c +80 -0
- data/ext/zlib-1.2.5/configure +596 -0
- data/ext/zlib-1.2.5/crc32.c +442 -0
- data/ext/zlib-1.2.5/crc32.h +441 -0
- data/ext/zlib-1.2.5/deflate.c +1834 -0
- data/ext/zlib-1.2.5/deflate.h +342 -0
- data/ext/zlib-1.2.5/example.c +565 -0
- data/ext/zlib-1.2.5/gzclose.c +25 -0
- data/ext/zlib-1.2.5/gzguts.h +132 -0
- data/ext/zlib-1.2.5/gzlib.c +537 -0
- data/ext/zlib-1.2.5/gzread.c +653 -0
- data/ext/zlib-1.2.5/gzwrite.c +531 -0
- data/ext/zlib-1.2.5/infback.c +632 -0
- data/ext/zlib-1.2.5/inffast.c +340 -0
- data/ext/zlib-1.2.5/inffast.h +11 -0
- data/ext/zlib-1.2.5/inffixed.h +94 -0
- data/ext/zlib-1.2.5/inflate.c +1480 -0
- data/ext/zlib-1.2.5/inflate.h +122 -0
- data/ext/zlib-1.2.5/inftrees.c +330 -0
- data/ext/zlib-1.2.5/inftrees.h +62 -0
- data/ext/zlib-1.2.5/minigzip.c +440 -0
- data/ext/zlib-1.2.5/trees.c +1244 -0
- data/ext/zlib-1.2.5/trees.h +128 -0
- data/ext/zlib-1.2.5/uncompr.c +59 -0
- data/ext/zlib-1.2.5/zconf.h +428 -0
- data/ext/zlib-1.2.5/zlib.h +1613 -0
- data/ext/zlib-1.2.5/zutil.c +318 -0
- data/ext/zlib-1.2.5/zutil.h +274 -0
- metadata +211 -0
@@ -0,0 +1,132 @@
|
|
1
|
+
/* gzguts.h -- zlib internal header definitions for gz* operations
|
2
|
+
* Copyright (C) 2004, 2005, 2010 Mark Adler
|
3
|
+
* For conditions of distribution and use, see copyright notice in zlib.h
|
4
|
+
*/
|
5
|
+
|
6
|
+
#ifdef _LARGEFILE64_SOURCE
|
7
|
+
# ifndef _LARGEFILE_SOURCE
|
8
|
+
# define _LARGEFILE_SOURCE 1
|
9
|
+
# endif
|
10
|
+
# ifdef _FILE_OFFSET_BITS
|
11
|
+
# undef _FILE_OFFSET_BITS
|
12
|
+
# endif
|
13
|
+
#endif
|
14
|
+
|
15
|
+
#if ((__GNUC__-0) * 10 + __GNUC_MINOR__-0 >= 33) && !defined(NO_VIZ)
|
16
|
+
# define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
|
17
|
+
#else
|
18
|
+
# define ZLIB_INTERNAL
|
19
|
+
#endif
|
20
|
+
|
21
|
+
#include <stdio.h>
|
22
|
+
#include "zlib.h"
|
23
|
+
#ifdef STDC
|
24
|
+
# include <string.h>
|
25
|
+
# include <stdlib.h>
|
26
|
+
# include <limits.h>
|
27
|
+
#endif
|
28
|
+
#include <fcntl.h>
|
29
|
+
|
30
|
+
#ifdef NO_DEFLATE /* for compatibility with old definition */
|
31
|
+
# define NO_GZCOMPRESS
|
32
|
+
#endif
|
33
|
+
|
34
|
+
#ifdef _MSC_VER
|
35
|
+
# include <io.h>
|
36
|
+
# define vsnprintf _vsnprintf
|
37
|
+
#endif
|
38
|
+
|
39
|
+
#ifndef local
|
40
|
+
# define local static
|
41
|
+
#endif
|
42
|
+
/* compile with -Dlocal if your debugger can't find static symbols */
|
43
|
+
|
44
|
+
/* gz* functions always use library allocation functions */
|
45
|
+
#ifndef STDC
|
46
|
+
extern voidp malloc OF((uInt size));
|
47
|
+
extern void free OF((voidpf ptr));
|
48
|
+
#endif
|
49
|
+
|
50
|
+
/* get errno and strerror definition */
|
51
|
+
#if defined UNDER_CE
|
52
|
+
# include <windows.h>
|
53
|
+
# define zstrerror() gz_strwinerror((DWORD)GetLastError())
|
54
|
+
#else
|
55
|
+
# ifdef STDC
|
56
|
+
# include <errno.h>
|
57
|
+
# define zstrerror() strerror(errno)
|
58
|
+
# else
|
59
|
+
# define zstrerror() "stdio error (consult errno)"
|
60
|
+
# endif
|
61
|
+
#endif
|
62
|
+
|
63
|
+
/* provide prototypes for these when building zlib without LFS */
|
64
|
+
#if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0
|
65
|
+
ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *));
|
66
|
+
ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int));
|
67
|
+
ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile));
|
68
|
+
ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile));
|
69
|
+
#endif
|
70
|
+
|
71
|
+
/* default i/o buffer size -- double this for output when reading */
|
72
|
+
#define GZBUFSIZE 8192
|
73
|
+
|
74
|
+
/* gzip modes, also provide a little integrity check on the passed structure */
|
75
|
+
#define GZ_NONE 0
|
76
|
+
#define GZ_READ 7247
|
77
|
+
#define GZ_WRITE 31153
|
78
|
+
#define GZ_APPEND 1 /* mode set to GZ_WRITE after the file is opened */
|
79
|
+
|
80
|
+
/* values for gz_state how */
|
81
|
+
#define LOOK 0 /* look for a gzip header */
|
82
|
+
#define COPY 1 /* copy input directly */
|
83
|
+
#define GZIP 2 /* decompress a gzip stream */
|
84
|
+
|
85
|
+
/* internal gzip file state data structure */
|
86
|
+
typedef struct {
|
87
|
+
/* used for both reading and writing */
|
88
|
+
int mode; /* see gzip modes above */
|
89
|
+
int fd; /* file descriptor */
|
90
|
+
char *path; /* path or fd for error messages */
|
91
|
+
z_off64_t pos; /* current position in uncompressed data */
|
92
|
+
unsigned size; /* buffer size, zero if not allocated yet */
|
93
|
+
unsigned want; /* requested buffer size, default is GZBUFSIZE */
|
94
|
+
unsigned char *in; /* input buffer */
|
95
|
+
unsigned char *out; /* output buffer (double-sized when reading) */
|
96
|
+
unsigned char *next; /* next output data to deliver or write */
|
97
|
+
/* just for reading */
|
98
|
+
unsigned have; /* amount of output data unused at next */
|
99
|
+
int eof; /* true if end of input file reached */
|
100
|
+
z_off64_t start; /* where the gzip data started, for rewinding */
|
101
|
+
z_off64_t raw; /* where the raw data started, for seeking */
|
102
|
+
int how; /* 0: get header, 1: copy, 2: decompress */
|
103
|
+
int direct; /* true if last read direct, false if gzip */
|
104
|
+
/* just for writing */
|
105
|
+
int level; /* compression level */
|
106
|
+
int strategy; /* compression strategy */
|
107
|
+
/* seek request */
|
108
|
+
z_off64_t skip; /* amount to skip (already rewound if backwards) */
|
109
|
+
int seek; /* true if seek request pending */
|
110
|
+
/* error information */
|
111
|
+
int err; /* error code */
|
112
|
+
char *msg; /* error message */
|
113
|
+
/* zlib inflate or deflate stream */
|
114
|
+
z_stream strm; /* stream structure in-place (not a pointer) */
|
115
|
+
} gz_state;
|
116
|
+
typedef gz_state FAR *gz_statep;
|
117
|
+
|
118
|
+
/* shared functions */
|
119
|
+
void ZLIB_INTERNAL gz_error OF((gz_statep, int, const char *));
|
120
|
+
#if defined UNDER_CE
|
121
|
+
char ZLIB_INTERNAL *gz_strwinerror OF((DWORD error));
|
122
|
+
#endif
|
123
|
+
|
124
|
+
/* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t
|
125
|
+
value -- needed when comparing unsigned to z_off64_t, which is signed
|
126
|
+
(possible z_off64_t types off_t, off64_t, and long are all signed) */
|
127
|
+
#ifdef INT_MAX
|
128
|
+
# define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > INT_MAX)
|
129
|
+
#else
|
130
|
+
unsigned ZLIB_INTERNAL gz_intmax OF((void));
|
131
|
+
# define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax())
|
132
|
+
#endif
|
@@ -0,0 +1,537 @@
|
|
1
|
+
/* gzlib.c -- zlib functions common to reading and writing gzip files
|
2
|
+
* Copyright (C) 2004, 2010 Mark Adler
|
3
|
+
* For conditions of distribution and use, see copyright notice in zlib.h
|
4
|
+
*/
|
5
|
+
|
6
|
+
#include "gzguts.h"
|
7
|
+
|
8
|
+
#if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0
|
9
|
+
# define LSEEK lseek64
|
10
|
+
#else
|
11
|
+
# define LSEEK lseek
|
12
|
+
#endif
|
13
|
+
|
14
|
+
/* Local functions */
|
15
|
+
local void gz_reset OF((gz_statep));
|
16
|
+
local gzFile gz_open OF((const char *, int, const char *));
|
17
|
+
|
18
|
+
#if defined UNDER_CE
|
19
|
+
|
20
|
+
/* Map the Windows error number in ERROR to a locale-dependent error message
|
21
|
+
string and return a pointer to it. Typically, the values for ERROR come
|
22
|
+
from GetLastError.
|
23
|
+
|
24
|
+
The string pointed to shall not be modified by the application, but may be
|
25
|
+
overwritten by a subsequent call to gz_strwinerror
|
26
|
+
|
27
|
+
The gz_strwinerror function does not change the current setting of
|
28
|
+
GetLastError. */
|
29
|
+
char ZLIB_INTERNAL *gz_strwinerror (error)
|
30
|
+
DWORD error;
|
31
|
+
{
|
32
|
+
static char buf[1024];
|
33
|
+
|
34
|
+
wchar_t *msgbuf;
|
35
|
+
DWORD lasterr = GetLastError();
|
36
|
+
DWORD chars = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM
|
37
|
+
| FORMAT_MESSAGE_ALLOCATE_BUFFER,
|
38
|
+
NULL,
|
39
|
+
error,
|
40
|
+
0, /* Default language */
|
41
|
+
(LPVOID)&msgbuf,
|
42
|
+
0,
|
43
|
+
NULL);
|
44
|
+
if (chars != 0) {
|
45
|
+
/* If there is an \r\n appended, zap it. */
|
46
|
+
if (chars >= 2
|
47
|
+
&& msgbuf[chars - 2] == '\r' && msgbuf[chars - 1] == '\n') {
|
48
|
+
chars -= 2;
|
49
|
+
msgbuf[chars] = 0;
|
50
|
+
}
|
51
|
+
|
52
|
+
if (chars > sizeof (buf) - 1) {
|
53
|
+
chars = sizeof (buf) - 1;
|
54
|
+
msgbuf[chars] = 0;
|
55
|
+
}
|
56
|
+
|
57
|
+
wcstombs(buf, msgbuf, chars + 1);
|
58
|
+
LocalFree(msgbuf);
|
59
|
+
}
|
60
|
+
else {
|
61
|
+
sprintf(buf, "unknown win32 error (%ld)", error);
|
62
|
+
}
|
63
|
+
|
64
|
+
SetLastError(lasterr);
|
65
|
+
return buf;
|
66
|
+
}
|
67
|
+
|
68
|
+
#endif /* UNDER_CE */
|
69
|
+
|
70
|
+
/* Reset gzip file state */
|
71
|
+
local void gz_reset(state)
|
72
|
+
gz_statep state;
|
73
|
+
{
|
74
|
+
if (state->mode == GZ_READ) { /* for reading ... */
|
75
|
+
state->have = 0; /* no output data available */
|
76
|
+
state->eof = 0; /* not at end of file */
|
77
|
+
state->how = LOOK; /* look for gzip header */
|
78
|
+
state->direct = 1; /* default for empty file */
|
79
|
+
}
|
80
|
+
state->seek = 0; /* no seek request pending */
|
81
|
+
gz_error(state, Z_OK, NULL); /* clear error */
|
82
|
+
state->pos = 0; /* no uncompressed data yet */
|
83
|
+
state->strm.avail_in = 0; /* no input data yet */
|
84
|
+
}
|
85
|
+
|
86
|
+
/* Open a gzip file either by name or file descriptor. */
|
87
|
+
local gzFile gz_open(path, fd, mode)
|
88
|
+
const char *path;
|
89
|
+
int fd;
|
90
|
+
const char *mode;
|
91
|
+
{
|
92
|
+
gz_statep state;
|
93
|
+
|
94
|
+
/* allocate gzFile structure to return */
|
95
|
+
state = malloc(sizeof(gz_state));
|
96
|
+
if (state == NULL)
|
97
|
+
return NULL;
|
98
|
+
state->size = 0; /* no buffers allocated yet */
|
99
|
+
state->want = GZBUFSIZE; /* requested buffer size */
|
100
|
+
state->msg = NULL; /* no error message yet */
|
101
|
+
|
102
|
+
/* interpret mode */
|
103
|
+
state->mode = GZ_NONE;
|
104
|
+
state->level = Z_DEFAULT_COMPRESSION;
|
105
|
+
state->strategy = Z_DEFAULT_STRATEGY;
|
106
|
+
while (*mode) {
|
107
|
+
if (*mode >= '0' && *mode <= '9')
|
108
|
+
state->level = *mode - '0';
|
109
|
+
else
|
110
|
+
switch (*mode) {
|
111
|
+
case 'r':
|
112
|
+
state->mode = GZ_READ;
|
113
|
+
break;
|
114
|
+
#ifndef NO_GZCOMPRESS
|
115
|
+
case 'w':
|
116
|
+
state->mode = GZ_WRITE;
|
117
|
+
break;
|
118
|
+
case 'a':
|
119
|
+
state->mode = GZ_APPEND;
|
120
|
+
break;
|
121
|
+
#endif
|
122
|
+
case '+': /* can't read and write at the same time */
|
123
|
+
free(state);
|
124
|
+
return NULL;
|
125
|
+
case 'b': /* ignore -- will request binary anyway */
|
126
|
+
break;
|
127
|
+
case 'f':
|
128
|
+
state->strategy = Z_FILTERED;
|
129
|
+
break;
|
130
|
+
case 'h':
|
131
|
+
state->strategy = Z_HUFFMAN_ONLY;
|
132
|
+
break;
|
133
|
+
case 'R':
|
134
|
+
state->strategy = Z_RLE;
|
135
|
+
break;
|
136
|
+
case 'F':
|
137
|
+
state->strategy = Z_FIXED;
|
138
|
+
default: /* could consider as an error, but just ignore */
|
139
|
+
;
|
140
|
+
}
|
141
|
+
mode++;
|
142
|
+
}
|
143
|
+
|
144
|
+
/* must provide an "r", "w", or "a" */
|
145
|
+
if (state->mode == GZ_NONE) {
|
146
|
+
free(state);
|
147
|
+
return NULL;
|
148
|
+
}
|
149
|
+
|
150
|
+
/* save the path name for error messages */
|
151
|
+
state->path = malloc(strlen(path) + 1);
|
152
|
+
if (state->path == NULL) {
|
153
|
+
free(state);
|
154
|
+
return NULL;
|
155
|
+
}
|
156
|
+
strcpy(state->path, path);
|
157
|
+
|
158
|
+
/* open the file with the appropriate mode (or just use fd) */
|
159
|
+
state->fd = fd != -1 ? fd :
|
160
|
+
open(path,
|
161
|
+
#ifdef O_LARGEFILE
|
162
|
+
O_LARGEFILE |
|
163
|
+
#endif
|
164
|
+
#ifdef O_BINARY
|
165
|
+
O_BINARY |
|
166
|
+
#endif
|
167
|
+
(state->mode == GZ_READ ?
|
168
|
+
O_RDONLY :
|
169
|
+
(O_WRONLY | O_CREAT | (
|
170
|
+
state->mode == GZ_WRITE ?
|
171
|
+
O_TRUNC :
|
172
|
+
O_APPEND))),
|
173
|
+
0666);
|
174
|
+
if (state->fd == -1) {
|
175
|
+
free(state->path);
|
176
|
+
free(state);
|
177
|
+
return NULL;
|
178
|
+
}
|
179
|
+
if (state->mode == GZ_APPEND)
|
180
|
+
state->mode = GZ_WRITE; /* simplify later checks */
|
181
|
+
|
182
|
+
/* save the current position for rewinding (only if reading) */
|
183
|
+
if (state->mode == GZ_READ) {
|
184
|
+
state->start = LSEEK(state->fd, 0, SEEK_CUR);
|
185
|
+
if (state->start == -1) state->start = 0;
|
186
|
+
}
|
187
|
+
|
188
|
+
/* initialize stream */
|
189
|
+
gz_reset(state);
|
190
|
+
|
191
|
+
/* return stream */
|
192
|
+
return (gzFile)state;
|
193
|
+
}
|
194
|
+
|
195
|
+
/* -- see zlib.h -- */
|
196
|
+
gzFile ZEXPORT gzopen(path, mode)
|
197
|
+
const char *path;
|
198
|
+
const char *mode;
|
199
|
+
{
|
200
|
+
return gz_open(path, -1, mode);
|
201
|
+
}
|
202
|
+
|
203
|
+
/* -- see zlib.h -- */
|
204
|
+
gzFile ZEXPORT gzopen64(path, mode)
|
205
|
+
const char *path;
|
206
|
+
const char *mode;
|
207
|
+
{
|
208
|
+
return gz_open(path, -1, mode);
|
209
|
+
}
|
210
|
+
|
211
|
+
/* -- see zlib.h -- */
|
212
|
+
gzFile ZEXPORT gzdopen(fd, mode)
|
213
|
+
int fd;
|
214
|
+
const char *mode;
|
215
|
+
{
|
216
|
+
char *path; /* identifier for error messages */
|
217
|
+
gzFile gz;
|
218
|
+
|
219
|
+
if (fd == -1 || (path = malloc(7 + 3 * sizeof(int))) == NULL)
|
220
|
+
return NULL;
|
221
|
+
sprintf(path, "<fd:%d>", fd); /* for debugging */
|
222
|
+
gz = gz_open(path, fd, mode);
|
223
|
+
free(path);
|
224
|
+
return gz;
|
225
|
+
}
|
226
|
+
|
227
|
+
/* -- see zlib.h -- */
|
228
|
+
int ZEXPORT gzbuffer(file, size)
|
229
|
+
gzFile file;
|
230
|
+
unsigned size;
|
231
|
+
{
|
232
|
+
gz_statep state;
|
233
|
+
|
234
|
+
/* get internal structure and check integrity */
|
235
|
+
if (file == NULL)
|
236
|
+
return -1;
|
237
|
+
state = (gz_statep)file;
|
238
|
+
if (state->mode != GZ_READ && state->mode != GZ_WRITE)
|
239
|
+
return -1;
|
240
|
+
|
241
|
+
/* make sure we haven't already allocated memory */
|
242
|
+
if (state->size != 0)
|
243
|
+
return -1;
|
244
|
+
|
245
|
+
/* check and set requested size */
|
246
|
+
if (size == 0)
|
247
|
+
return -1;
|
248
|
+
state->want = size;
|
249
|
+
return 0;
|
250
|
+
}
|
251
|
+
|
252
|
+
/* -- see zlib.h -- */
|
253
|
+
int ZEXPORT gzrewind(file)
|
254
|
+
gzFile file;
|
255
|
+
{
|
256
|
+
gz_statep state;
|
257
|
+
|
258
|
+
/* get internal structure */
|
259
|
+
if (file == NULL)
|
260
|
+
return -1;
|
261
|
+
state = (gz_statep)file;
|
262
|
+
|
263
|
+
/* check that we're reading and that there's no error */
|
264
|
+
if (state->mode != GZ_READ || state->err != Z_OK)
|
265
|
+
return -1;
|
266
|
+
|
267
|
+
/* back up and start over */
|
268
|
+
if (LSEEK(state->fd, state->start, SEEK_SET) == -1)
|
269
|
+
return -1;
|
270
|
+
gz_reset(state);
|
271
|
+
return 0;
|
272
|
+
}
|
273
|
+
|
274
|
+
/* -- see zlib.h -- */
|
275
|
+
z_off64_t ZEXPORT gzseek64(file, offset, whence)
|
276
|
+
gzFile file;
|
277
|
+
z_off64_t offset;
|
278
|
+
int whence;
|
279
|
+
{
|
280
|
+
unsigned n;
|
281
|
+
z_off64_t ret;
|
282
|
+
gz_statep state;
|
283
|
+
|
284
|
+
/* get internal structure and check integrity */
|
285
|
+
if (file == NULL)
|
286
|
+
return -1;
|
287
|
+
state = (gz_statep)file;
|
288
|
+
if (state->mode != GZ_READ && state->mode != GZ_WRITE)
|
289
|
+
return -1;
|
290
|
+
|
291
|
+
/* check that there's no error */
|
292
|
+
if (state->err != Z_OK)
|
293
|
+
return -1;
|
294
|
+
|
295
|
+
/* can only seek from start or relative to current position */
|
296
|
+
if (whence != SEEK_SET && whence != SEEK_CUR)
|
297
|
+
return -1;
|
298
|
+
|
299
|
+
/* normalize offset to a SEEK_CUR specification */
|
300
|
+
if (whence == SEEK_SET)
|
301
|
+
offset -= state->pos;
|
302
|
+
else if (state->seek)
|
303
|
+
offset += state->skip;
|
304
|
+
state->seek = 0;
|
305
|
+
|
306
|
+
/* if within raw area while reading, just go there */
|
307
|
+
if (state->mode == GZ_READ && state->how == COPY &&
|
308
|
+
state->pos + offset >= state->raw) {
|
309
|
+
ret = LSEEK(state->fd, offset - state->have, SEEK_CUR);
|
310
|
+
if (ret == -1)
|
311
|
+
return -1;
|
312
|
+
state->have = 0;
|
313
|
+
state->eof = 0;
|
314
|
+
state->seek = 0;
|
315
|
+
gz_error(state, Z_OK, NULL);
|
316
|
+
state->strm.avail_in = 0;
|
317
|
+
state->pos += offset;
|
318
|
+
return state->pos;
|
319
|
+
}
|
320
|
+
|
321
|
+
/* calculate skip amount, rewinding if needed for back seek when reading */
|
322
|
+
if (offset < 0) {
|
323
|
+
if (state->mode != GZ_READ) /* writing -- can't go backwards */
|
324
|
+
return -1;
|
325
|
+
offset += state->pos;
|
326
|
+
if (offset < 0) /* before start of file! */
|
327
|
+
return -1;
|
328
|
+
if (gzrewind(file) == -1) /* rewind, then skip to offset */
|
329
|
+
return -1;
|
330
|
+
}
|
331
|
+
|
332
|
+
/* if reading, skip what's in output buffer (one less gzgetc() check) */
|
333
|
+
if (state->mode == GZ_READ) {
|
334
|
+
n = GT_OFF(state->have) || (z_off64_t)state->have > offset ?
|
335
|
+
(unsigned)offset : state->have;
|
336
|
+
state->have -= n;
|
337
|
+
state->next += n;
|
338
|
+
state->pos += n;
|
339
|
+
offset -= n;
|
340
|
+
}
|
341
|
+
|
342
|
+
/* request skip (if not zero) */
|
343
|
+
if (offset) {
|
344
|
+
state->seek = 1;
|
345
|
+
state->skip = offset;
|
346
|
+
}
|
347
|
+
return state->pos + offset;
|
348
|
+
}
|
349
|
+
|
350
|
+
/* -- see zlib.h -- */
|
351
|
+
z_off_t ZEXPORT gzseek(file, offset, whence)
|
352
|
+
gzFile file;
|
353
|
+
z_off_t offset;
|
354
|
+
int whence;
|
355
|
+
{
|
356
|
+
z_off64_t ret;
|
357
|
+
|
358
|
+
ret = gzseek64(file, (z_off64_t)offset, whence);
|
359
|
+
return ret == (z_off_t)ret ? (z_off_t)ret : -1;
|
360
|
+
}
|
361
|
+
|
362
|
+
/* -- see zlib.h -- */
|
363
|
+
z_off64_t ZEXPORT gztell64(file)
|
364
|
+
gzFile file;
|
365
|
+
{
|
366
|
+
gz_statep state;
|
367
|
+
|
368
|
+
/* get internal structure and check integrity */
|
369
|
+
if (file == NULL)
|
370
|
+
return -1;
|
371
|
+
state = (gz_statep)file;
|
372
|
+
if (state->mode != GZ_READ && state->mode != GZ_WRITE)
|
373
|
+
return -1;
|
374
|
+
|
375
|
+
/* return position */
|
376
|
+
return state->pos + (state->seek ? state->skip : 0);
|
377
|
+
}
|
378
|
+
|
379
|
+
/* -- see zlib.h -- */
|
380
|
+
z_off_t ZEXPORT gztell(file)
|
381
|
+
gzFile file;
|
382
|
+
{
|
383
|
+
z_off64_t ret;
|
384
|
+
|
385
|
+
ret = gztell64(file);
|
386
|
+
return ret == (z_off_t)ret ? (z_off_t)ret : -1;
|
387
|
+
}
|
388
|
+
|
389
|
+
/* -- see zlib.h -- */
|
390
|
+
z_off64_t ZEXPORT gzoffset64(file)
|
391
|
+
gzFile file;
|
392
|
+
{
|
393
|
+
z_off64_t offset;
|
394
|
+
gz_statep state;
|
395
|
+
|
396
|
+
/* get internal structure and check integrity */
|
397
|
+
if (file == NULL)
|
398
|
+
return -1;
|
399
|
+
state = (gz_statep)file;
|
400
|
+
if (state->mode != GZ_READ && state->mode != GZ_WRITE)
|
401
|
+
return -1;
|
402
|
+
|
403
|
+
/* compute and return effective offset in file */
|
404
|
+
offset = LSEEK(state->fd, 0, SEEK_CUR);
|
405
|
+
if (offset == -1)
|
406
|
+
return -1;
|
407
|
+
if (state->mode == GZ_READ) /* reading */
|
408
|
+
offset -= state->strm.avail_in; /* don't count buffered input */
|
409
|
+
return offset;
|
410
|
+
}
|
411
|
+
|
412
|
+
/* -- see zlib.h -- */
|
413
|
+
z_off_t ZEXPORT gzoffset(file)
|
414
|
+
gzFile file;
|
415
|
+
{
|
416
|
+
z_off64_t ret;
|
417
|
+
|
418
|
+
ret = gzoffset64(file);
|
419
|
+
return ret == (z_off_t)ret ? (z_off_t)ret : -1;
|
420
|
+
}
|
421
|
+
|
422
|
+
/* -- see zlib.h -- */
|
423
|
+
int ZEXPORT gzeof(file)
|
424
|
+
gzFile file;
|
425
|
+
{
|
426
|
+
gz_statep state;
|
427
|
+
|
428
|
+
/* get internal structure and check integrity */
|
429
|
+
if (file == NULL)
|
430
|
+
return 0;
|
431
|
+
state = (gz_statep)file;
|
432
|
+
if (state->mode != GZ_READ && state->mode != GZ_WRITE)
|
433
|
+
return 0;
|
434
|
+
|
435
|
+
/* return end-of-file state */
|
436
|
+
return state->mode == GZ_READ ?
|
437
|
+
(state->eof && state->strm.avail_in == 0 && state->have == 0) : 0;
|
438
|
+
}
|
439
|
+
|
440
|
+
/* -- see zlib.h -- */
|
441
|
+
const char * ZEXPORT gzerror(file, errnum)
|
442
|
+
gzFile file;
|
443
|
+
int *errnum;
|
444
|
+
{
|
445
|
+
gz_statep state;
|
446
|
+
|
447
|
+
/* get internal structure and check integrity */
|
448
|
+
if (file == NULL)
|
449
|
+
return NULL;
|
450
|
+
state = (gz_statep)file;
|
451
|
+
if (state->mode != GZ_READ && state->mode != GZ_WRITE)
|
452
|
+
return NULL;
|
453
|
+
|
454
|
+
/* return error information */
|
455
|
+
if (errnum != NULL)
|
456
|
+
*errnum = state->err;
|
457
|
+
return state->msg == NULL ? "" : state->msg;
|
458
|
+
}
|
459
|
+
|
460
|
+
/* -- see zlib.h -- */
|
461
|
+
void ZEXPORT gzclearerr(file)
|
462
|
+
gzFile file;
|
463
|
+
{
|
464
|
+
gz_statep state;
|
465
|
+
|
466
|
+
/* get internal structure and check integrity */
|
467
|
+
if (file == NULL)
|
468
|
+
return;
|
469
|
+
state = (gz_statep)file;
|
470
|
+
if (state->mode != GZ_READ && state->mode != GZ_WRITE)
|
471
|
+
return;
|
472
|
+
|
473
|
+
/* clear error and end-of-file */
|
474
|
+
if (state->mode == GZ_READ)
|
475
|
+
state->eof = 0;
|
476
|
+
gz_error(state, Z_OK, NULL);
|
477
|
+
}
|
478
|
+
|
479
|
+
/* Create an error message in allocated memory and set state->err and
|
480
|
+
state->msg accordingly. Free any previous error message already there. Do
|
481
|
+
not try to free or allocate space if the error is Z_MEM_ERROR (out of
|
482
|
+
memory). Simply save the error message as a static string. If there is an
|
483
|
+
allocation failure constructing the error message, then convert the error to
|
484
|
+
out of memory. */
|
485
|
+
void ZLIB_INTERNAL gz_error(state, err, msg)
|
486
|
+
gz_statep state;
|
487
|
+
int err;
|
488
|
+
const char *msg;
|
489
|
+
{
|
490
|
+
/* free previously allocated message and clear */
|
491
|
+
if (state->msg != NULL) {
|
492
|
+
if (state->err != Z_MEM_ERROR)
|
493
|
+
free(state->msg);
|
494
|
+
state->msg = NULL;
|
495
|
+
}
|
496
|
+
|
497
|
+
/* set error code, and if no message, then done */
|
498
|
+
state->err = err;
|
499
|
+
if (msg == NULL)
|
500
|
+
return;
|
501
|
+
|
502
|
+
/* for an out of memory error, save as static string */
|
503
|
+
if (err == Z_MEM_ERROR) {
|
504
|
+
state->msg = (char *)msg;
|
505
|
+
return;
|
506
|
+
}
|
507
|
+
|
508
|
+
/* construct error message with path */
|
509
|
+
if ((state->msg = malloc(strlen(state->path) + strlen(msg) + 3)) == NULL) {
|
510
|
+
state->err = Z_MEM_ERROR;
|
511
|
+
state->msg = (char *)"out of memory";
|
512
|
+
return;
|
513
|
+
}
|
514
|
+
strcpy(state->msg, state->path);
|
515
|
+
strcat(state->msg, ": ");
|
516
|
+
strcat(state->msg, msg);
|
517
|
+
return;
|
518
|
+
}
|
519
|
+
|
520
|
+
#ifndef INT_MAX
|
521
|
+
/* portably return maximum value for an int (when limits.h presumed not
|
522
|
+
available) -- we need to do this to cover cases where 2's complement not
|
523
|
+
used, since C standard permits 1's complement and sign-bit representations,
|
524
|
+
otherwise we could just use ((unsigned)-1) >> 1 */
|
525
|
+
unsigned ZLIB_INTERNAL gz_intmax()
|
526
|
+
{
|
527
|
+
unsigned p, q;
|
528
|
+
|
529
|
+
p = 1;
|
530
|
+
do {
|
531
|
+
q = p;
|
532
|
+
p <<= 1;
|
533
|
+
p++;
|
534
|
+
} while (p > q);
|
535
|
+
return q >> 1;
|
536
|
+
}
|
537
|
+
#endif
|