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,165 @@
|
|
1
|
+
/*-
|
2
|
+
* Copyright (c) 2003-2007 Tim Kientzle
|
3
|
+
* All rights reserved.
|
4
|
+
*
|
5
|
+
* Redistribution and use in source and binary forms, with or without
|
6
|
+
* modification, are permitted provided that the following conditions
|
7
|
+
* are met:
|
8
|
+
* 1. Redistributions of source code must retain the above copyright
|
9
|
+
* notice, this list of conditions and the following disclaimer.
|
10
|
+
* 2. Redistributions in binary form must reproduce the above copyright
|
11
|
+
* notice, this list of conditions and the following disclaimer in the
|
12
|
+
* documentation and/or other materials provided with the distribution.
|
13
|
+
*
|
14
|
+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
|
15
|
+
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
16
|
+
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
17
|
+
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
|
18
|
+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
19
|
+
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
20
|
+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
21
|
+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
22
|
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
23
|
+
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
24
|
+
*/
|
25
|
+
|
26
|
+
#include "archive_platform.h"
|
27
|
+
__FBSDID("$FreeBSD: head/lib/libarchive/archive_read_open_file.c 201093 2009-12-28 02:28:44Z kientzle $");
|
28
|
+
|
29
|
+
#ifdef HAVE_SYS_STAT_H
|
30
|
+
#include <sys/stat.h>
|
31
|
+
#endif
|
32
|
+
#ifdef HAVE_ERRNO_H
|
33
|
+
#include <errno.h>
|
34
|
+
#endif
|
35
|
+
#ifdef HAVE_FCNTL_H
|
36
|
+
#include <fcntl.h>
|
37
|
+
#endif
|
38
|
+
#ifdef HAVE_IO_H
|
39
|
+
#include <io.h>
|
40
|
+
#endif
|
41
|
+
#ifdef HAVE_STDLIB_H
|
42
|
+
#include <stdlib.h>
|
43
|
+
#endif
|
44
|
+
#ifdef HAVE_STRING_H
|
45
|
+
#include <string.h>
|
46
|
+
#endif
|
47
|
+
#ifdef HAVE_UNISTD_H
|
48
|
+
#include <unistd.h>
|
49
|
+
#endif
|
50
|
+
|
51
|
+
#include "archive.h"
|
52
|
+
|
53
|
+
struct read_FILE_data {
|
54
|
+
FILE *f;
|
55
|
+
size_t block_size;
|
56
|
+
void *buffer;
|
57
|
+
char can_skip;
|
58
|
+
};
|
59
|
+
|
60
|
+
static int file_close(struct archive *, void *);
|
61
|
+
static ssize_t file_read(struct archive *, void *, const void **buff);
|
62
|
+
#if ARCHIVE_API_VERSION < 2
|
63
|
+
static ssize_t file_skip(struct archive *, void *, size_t request);
|
64
|
+
#else
|
65
|
+
static off_t file_skip(struct archive *, void *, off_t request);
|
66
|
+
#endif
|
67
|
+
|
68
|
+
int
|
69
|
+
archive_read_open_FILE(struct archive *a, FILE *f)
|
70
|
+
{
|
71
|
+
struct stat st;
|
72
|
+
struct read_FILE_data *mine;
|
73
|
+
size_t block_size = 128 * 1024;
|
74
|
+
void *b;
|
75
|
+
|
76
|
+
archive_clear_error(a);
|
77
|
+
mine = (struct read_FILE_data *)malloc(sizeof(*mine));
|
78
|
+
b = malloc(block_size);
|
79
|
+
if (mine == NULL || b == NULL) {
|
80
|
+
archive_set_error(a, ENOMEM, "No memory");
|
81
|
+
free(mine);
|
82
|
+
free(b);
|
83
|
+
return (ARCHIVE_FATAL);
|
84
|
+
}
|
85
|
+
mine->block_size = block_size;
|
86
|
+
mine->buffer = b;
|
87
|
+
mine->f = f;
|
88
|
+
/*
|
89
|
+
* If we can't fstat() the file, it may just be that it's not
|
90
|
+
* a file. (FILE * objects can wrap many kinds of I/O
|
91
|
+
* streams, some of which don't support fileno()).)
|
92
|
+
*/
|
93
|
+
if (fstat(fileno(mine->f), &st) == 0 && S_ISREG(st.st_mode)) {
|
94
|
+
archive_read_extract_set_skip_file(a, st.st_dev, st.st_ino);
|
95
|
+
/* Enable the seek optimization only for regular files. */
|
96
|
+
mine->can_skip = 1;
|
97
|
+
} else
|
98
|
+
mine->can_skip = 0;
|
99
|
+
|
100
|
+
#if defined(__CYGWIN__) || defined(_WIN32)
|
101
|
+
setmode(fileno(mine->f), O_BINARY);
|
102
|
+
#endif
|
103
|
+
|
104
|
+
return (archive_read_open2(a, mine, NULL, file_read,
|
105
|
+
file_skip, file_close));
|
106
|
+
}
|
107
|
+
|
108
|
+
static ssize_t
|
109
|
+
file_read(struct archive *a, void *client_data, const void **buff)
|
110
|
+
{
|
111
|
+
struct read_FILE_data *mine = (struct read_FILE_data *)client_data;
|
112
|
+
ssize_t bytes_read;
|
113
|
+
|
114
|
+
*buff = mine->buffer;
|
115
|
+
bytes_read = fread(mine->buffer, 1, mine->block_size, mine->f);
|
116
|
+
if (bytes_read < 0) {
|
117
|
+
archive_set_error(a, errno, "Error reading file");
|
118
|
+
}
|
119
|
+
return (bytes_read);
|
120
|
+
}
|
121
|
+
|
122
|
+
#if ARCHIVE_API_VERSION < 2
|
123
|
+
static ssize_t
|
124
|
+
file_skip(struct archive *a, void *client_data, size_t request)
|
125
|
+
#else
|
126
|
+
static off_t
|
127
|
+
file_skip(struct archive *a, void *client_data, off_t request)
|
128
|
+
#endif
|
129
|
+
{
|
130
|
+
struct read_FILE_data *mine = (struct read_FILE_data *)client_data;
|
131
|
+
|
132
|
+
(void)a; /* UNUSED */
|
133
|
+
|
134
|
+
/*
|
135
|
+
* If we can't skip, return 0 as the amount we did step and
|
136
|
+
* the caller will work around by reading and discarding.
|
137
|
+
*/
|
138
|
+
if (!mine->can_skip)
|
139
|
+
return (0);
|
140
|
+
if (request == 0)
|
141
|
+
return (0);
|
142
|
+
|
143
|
+
#if HAVE_FSEEKO
|
144
|
+
if (fseeko(mine->f, request, SEEK_CUR) != 0)
|
145
|
+
#else
|
146
|
+
if (fseek(mine->f, request, SEEK_CUR) != 0)
|
147
|
+
#endif
|
148
|
+
{
|
149
|
+
mine->can_skip = 0;
|
150
|
+
return (0);
|
151
|
+
}
|
152
|
+
return (request);
|
153
|
+
}
|
154
|
+
|
155
|
+
static int
|
156
|
+
file_close(struct archive *a, void *client_data)
|
157
|
+
{
|
158
|
+
struct read_FILE_data *mine = (struct read_FILE_data *)client_data;
|
159
|
+
|
160
|
+
(void)a; /* UNUSED */
|
161
|
+
if (mine->buffer != NULL)
|
162
|
+
free(mine->buffer);
|
163
|
+
free(mine);
|
164
|
+
return (ARCHIVE_OK);
|
165
|
+
}
|
@@ -0,0 +1,272 @@
|
|
1
|
+
/*-
|
2
|
+
* Copyright (c) 2003-2007 Tim Kientzle
|
3
|
+
* All rights reserved.
|
4
|
+
*
|
5
|
+
* Redistribution and use in source and binary forms, with or without
|
6
|
+
* modification, are permitted provided that the following conditions
|
7
|
+
* are met:
|
8
|
+
* 1. Redistributions of source code must retain the above copyright
|
9
|
+
* notice, this list of conditions and the following disclaimer.
|
10
|
+
* 2. Redistributions in binary form must reproduce the above copyright
|
11
|
+
* notice, this list of conditions and the following disclaimer in the
|
12
|
+
* documentation and/or other materials provided with the distribution.
|
13
|
+
*
|
14
|
+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
|
15
|
+
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
16
|
+
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
17
|
+
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
|
18
|
+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
19
|
+
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
20
|
+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
21
|
+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
22
|
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
23
|
+
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
24
|
+
*/
|
25
|
+
|
26
|
+
#include "archive_platform.h"
|
27
|
+
__FBSDID("$FreeBSD: head/lib/libarchive/archive_read_open_filename.c 201093 2009-12-28 02:28:44Z kientzle $");
|
28
|
+
|
29
|
+
#ifdef HAVE_SYS_STAT_H
|
30
|
+
#include <sys/stat.h>
|
31
|
+
#endif
|
32
|
+
#ifdef HAVE_ERRNO_H
|
33
|
+
#include <errno.h>
|
34
|
+
#endif
|
35
|
+
#ifdef HAVE_FCNTL_H
|
36
|
+
#include <fcntl.h>
|
37
|
+
#endif
|
38
|
+
#ifdef HAVE_IO_H
|
39
|
+
#include <io.h>
|
40
|
+
#endif
|
41
|
+
#ifdef HAVE_STDLIB_H
|
42
|
+
#include <stdlib.h>
|
43
|
+
#endif
|
44
|
+
#ifdef HAVE_STRING_H
|
45
|
+
#include <string.h>
|
46
|
+
#endif
|
47
|
+
#ifdef HAVE_UNISTD_H
|
48
|
+
#include <unistd.h>
|
49
|
+
#endif
|
50
|
+
|
51
|
+
#include "archive.h"
|
52
|
+
|
53
|
+
#ifndef O_BINARY
|
54
|
+
#define O_BINARY 0
|
55
|
+
#endif
|
56
|
+
|
57
|
+
struct read_file_data {
|
58
|
+
int fd;
|
59
|
+
size_t block_size;
|
60
|
+
void *buffer;
|
61
|
+
mode_t st_mode; /* Mode bits for opened file. */
|
62
|
+
char can_skip; /* This file supports skipping. */
|
63
|
+
char filename[1]; /* Must be last! */
|
64
|
+
};
|
65
|
+
|
66
|
+
static int file_close(struct archive *, void *);
|
67
|
+
static ssize_t file_read(struct archive *, void *, const void **buff);
|
68
|
+
#if ARCHIVE_API_VERSION < 2
|
69
|
+
static ssize_t file_skip(struct archive *, void *, size_t request);
|
70
|
+
#else
|
71
|
+
static off_t file_skip(struct archive *, void *, off_t request);
|
72
|
+
#endif
|
73
|
+
|
74
|
+
int
|
75
|
+
archive_read_open_file(struct archive *a, const char *filename,
|
76
|
+
size_t block_size)
|
77
|
+
{
|
78
|
+
return (archive_read_open_filename(a, filename, block_size));
|
79
|
+
}
|
80
|
+
|
81
|
+
int
|
82
|
+
archive_read_open_filename(struct archive *a, const char *filename,
|
83
|
+
size_t block_size)
|
84
|
+
{
|
85
|
+
struct stat st;
|
86
|
+
struct read_file_data *mine;
|
87
|
+
void *b;
|
88
|
+
int fd;
|
89
|
+
|
90
|
+
archive_clear_error(a);
|
91
|
+
if (filename == NULL || filename[0] == '\0') {
|
92
|
+
/* We used to invoke archive_read_open_fd(a,0,block_size)
|
93
|
+
* here, but that doesn't (and shouldn't) handle the
|
94
|
+
* end-of-file flush when reading stdout from a pipe.
|
95
|
+
* Basically, read_open_fd() is intended for folks who
|
96
|
+
* are willing to handle such details themselves. This
|
97
|
+
* API is intended to be a little smarter for folks who
|
98
|
+
* want easy handling of the common case.
|
99
|
+
*/
|
100
|
+
filename = ""; /* Normalize NULL to "" */
|
101
|
+
fd = 0;
|
102
|
+
#if defined(__CYGWIN__) || defined(_WIN32)
|
103
|
+
setmode(0, O_BINARY);
|
104
|
+
#endif
|
105
|
+
} else {
|
106
|
+
fd = open(filename, O_RDONLY | O_BINARY);
|
107
|
+
if (fd < 0) {
|
108
|
+
archive_set_error(a, errno,
|
109
|
+
"Failed to open '%s'", filename);
|
110
|
+
return (ARCHIVE_FATAL);
|
111
|
+
}
|
112
|
+
}
|
113
|
+
if (fstat(fd, &st) != 0) {
|
114
|
+
archive_set_error(a, errno, "Can't stat '%s'", filename);
|
115
|
+
return (ARCHIVE_FATAL);
|
116
|
+
}
|
117
|
+
|
118
|
+
mine = (struct read_file_data *)calloc(1,
|
119
|
+
sizeof(*mine) + strlen(filename));
|
120
|
+
b = malloc(block_size);
|
121
|
+
if (mine == NULL || b == NULL) {
|
122
|
+
archive_set_error(a, ENOMEM, "No memory");
|
123
|
+
free(mine);
|
124
|
+
free(b);
|
125
|
+
return (ARCHIVE_FATAL);
|
126
|
+
}
|
127
|
+
strcpy(mine->filename, filename);
|
128
|
+
mine->block_size = block_size;
|
129
|
+
mine->buffer = b;
|
130
|
+
mine->fd = fd;
|
131
|
+
/* Remember mode so close can decide whether to flush. */
|
132
|
+
mine->st_mode = st.st_mode;
|
133
|
+
/* If we're reading a file from disk, ensure that we don't
|
134
|
+
overwrite it with an extracted file. */
|
135
|
+
if (S_ISREG(st.st_mode)) {
|
136
|
+
archive_read_extract_set_skip_file(a, st.st_dev, st.st_ino);
|
137
|
+
/*
|
138
|
+
* Enabling skip here is a performance optimization
|
139
|
+
* for anything that supports lseek(). On FreeBSD
|
140
|
+
* (and probably many other systems), only regular
|
141
|
+
* files and raw disk devices support lseek() (on
|
142
|
+
* other input types, lseek() returns success but
|
143
|
+
* doesn't actually change the file pointer, which
|
144
|
+
* just completely screws up the position-tracking
|
145
|
+
* logic). In addition, I've yet to find a portable
|
146
|
+
* way to determine if a device is a raw disk device.
|
147
|
+
* So I don't see a way to do much better than to only
|
148
|
+
* enable this optimization for regular files.
|
149
|
+
*/
|
150
|
+
mine->can_skip = 1;
|
151
|
+
}
|
152
|
+
return (archive_read_open2(a, mine,
|
153
|
+
NULL, file_read, file_skip, file_close));
|
154
|
+
}
|
155
|
+
|
156
|
+
static ssize_t
|
157
|
+
file_read(struct archive *a, void *client_data, const void **buff)
|
158
|
+
{
|
159
|
+
struct read_file_data *mine = (struct read_file_data *)client_data;
|
160
|
+
ssize_t bytes_read;
|
161
|
+
|
162
|
+
*buff = mine->buffer;
|
163
|
+
for (;;) {
|
164
|
+
bytes_read = read(mine->fd, mine->buffer, mine->block_size);
|
165
|
+
if (bytes_read < 0) {
|
166
|
+
if (errno == EINTR)
|
167
|
+
continue;
|
168
|
+
else if (mine->filename[0] == '\0')
|
169
|
+
archive_set_error(a, errno, "Error reading stdin");
|
170
|
+
else
|
171
|
+
archive_set_error(a, errno, "Error reading '%s'",
|
172
|
+
mine->filename);
|
173
|
+
}
|
174
|
+
return (bytes_read);
|
175
|
+
}
|
176
|
+
}
|
177
|
+
|
178
|
+
#if ARCHIVE_API_VERSION < 2
|
179
|
+
static ssize_t
|
180
|
+
file_skip(struct archive *a, void *client_data, size_t request)
|
181
|
+
#else
|
182
|
+
static off_t
|
183
|
+
file_skip(struct archive *a, void *client_data, off_t request)
|
184
|
+
#endif
|
185
|
+
{
|
186
|
+
struct read_file_data *mine = (struct read_file_data *)client_data;
|
187
|
+
off_t old_offset, new_offset;
|
188
|
+
|
189
|
+
if (!mine->can_skip) /* We can't skip, so ... */
|
190
|
+
return (0); /* ... skip zero bytes. */
|
191
|
+
|
192
|
+
/* Reduce request to the next smallest multiple of block_size */
|
193
|
+
request = (request / mine->block_size) * mine->block_size;
|
194
|
+
if (request == 0)
|
195
|
+
return (0);
|
196
|
+
|
197
|
+
/*
|
198
|
+
* Hurray for lazy evaluation: if the first lseek fails, the second
|
199
|
+
* one will not be executed.
|
200
|
+
*/
|
201
|
+
if (((old_offset = lseek(mine->fd, 0, SEEK_CUR)) < 0) ||
|
202
|
+
((new_offset = lseek(mine->fd, request, SEEK_CUR)) < 0))
|
203
|
+
{
|
204
|
+
/* If skip failed once, it will probably fail again. */
|
205
|
+
mine->can_skip = 0;
|
206
|
+
|
207
|
+
if (errno == ESPIPE)
|
208
|
+
{
|
209
|
+
/*
|
210
|
+
* Failure to lseek() can be caused by the file
|
211
|
+
* descriptor pointing to a pipe, socket or FIFO.
|
212
|
+
* Return 0 here, so the compression layer will use
|
213
|
+
* read()s instead to advance the file descriptor.
|
214
|
+
* It's slower of course, but works as well.
|
215
|
+
*/
|
216
|
+
return (0);
|
217
|
+
}
|
218
|
+
/*
|
219
|
+
* There's been an error other than ESPIPE. This is most
|
220
|
+
* likely caused by a programmer error (too large request)
|
221
|
+
* or a corrupted archive file.
|
222
|
+
*/
|
223
|
+
if (mine->filename[0] == '\0')
|
224
|
+
/*
|
225
|
+
* Should never get here, since lseek() on stdin ought
|
226
|
+
* to return an ESPIPE error.
|
227
|
+
*/
|
228
|
+
archive_set_error(a, errno, "Error seeking in stdin");
|
229
|
+
else
|
230
|
+
archive_set_error(a, errno, "Error seeking in '%s'",
|
231
|
+
mine->filename);
|
232
|
+
return (-1);
|
233
|
+
}
|
234
|
+
return (new_offset - old_offset);
|
235
|
+
}
|
236
|
+
|
237
|
+
static int
|
238
|
+
file_close(struct archive *a, void *client_data)
|
239
|
+
{
|
240
|
+
struct read_file_data *mine = (struct read_file_data *)client_data;
|
241
|
+
|
242
|
+
(void)a; /* UNUSED */
|
243
|
+
|
244
|
+
/* Only flush and close if open succeeded. */
|
245
|
+
if (mine->fd >= 0) {
|
246
|
+
/*
|
247
|
+
* Sometimes, we should flush the input before closing.
|
248
|
+
* Regular files: faster to just close without flush.
|
249
|
+
* Devices: must not flush (user might need to
|
250
|
+
* read the "next" item on a non-rewind device).
|
251
|
+
* Pipes and sockets: must flush (otherwise, the
|
252
|
+
* program feeding the pipe or socket may complain).
|
253
|
+
* Here, I flush everything except for regular files and
|
254
|
+
* device nodes.
|
255
|
+
*/
|
256
|
+
if (!S_ISREG(mine->st_mode)
|
257
|
+
&& !S_ISCHR(mine->st_mode)
|
258
|
+
&& !S_ISBLK(mine->st_mode)) {
|
259
|
+
ssize_t bytesRead;
|
260
|
+
do {
|
261
|
+
bytesRead = read(mine->fd, mine->buffer,
|
262
|
+
mine->block_size);
|
263
|
+
} while (bytesRead > 0);
|
264
|
+
}
|
265
|
+
/* If a named file was opened, then it needs to be closed. */
|
266
|
+
if (mine->filename[0] != '\0')
|
267
|
+
close(mine->fd);
|
268
|
+
}
|
269
|
+
free(mine->buffer);
|
270
|
+
free(mine);
|
271
|
+
return (ARCHIVE_OK);
|
272
|
+
}
|
@@ -0,0 +1,156 @@
|
|
1
|
+
/*-
|
2
|
+
* Copyright (c) 2003-2007 Tim Kientzle
|
3
|
+
* All rights reserved.
|
4
|
+
*
|
5
|
+
* Redistribution and use in source and binary forms, with or without
|
6
|
+
* modification, are permitted provided that the following conditions
|
7
|
+
* are met:
|
8
|
+
* 1. Redistributions of source code must retain the above copyright
|
9
|
+
* notice, this list of conditions and the following disclaimer.
|
10
|
+
* 2. Redistributions in binary form must reproduce the above copyright
|
11
|
+
* notice, this list of conditions and the following disclaimer in the
|
12
|
+
* documentation and/or other materials provided with the distribution.
|
13
|
+
*
|
14
|
+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
|
15
|
+
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
16
|
+
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
17
|
+
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
|
18
|
+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
19
|
+
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
20
|
+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
21
|
+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
22
|
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
23
|
+
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
24
|
+
*/
|
25
|
+
|
26
|
+
#include "archive_platform.h"
|
27
|
+
__FBSDID("$FreeBSD: src/lib/libarchive/archive_read_open_memory.c,v 1.6 2007/07/06 15:51:59 kientzle Exp $");
|
28
|
+
|
29
|
+
#include <errno.h>
|
30
|
+
#include <stdlib.h>
|
31
|
+
#include <string.h>
|
32
|
+
|
33
|
+
#include "archive.h"
|
34
|
+
|
35
|
+
/*
|
36
|
+
* Glue to read an archive from a block of memory.
|
37
|
+
*
|
38
|
+
* This is mostly a huge help in building test harnesses;
|
39
|
+
* test programs can build archives in memory and read them
|
40
|
+
* back again without having to mess with files on disk.
|
41
|
+
*/
|
42
|
+
|
43
|
+
struct read_memory_data {
|
44
|
+
unsigned char *buffer;
|
45
|
+
unsigned char *end;
|
46
|
+
ssize_t read_size;
|
47
|
+
};
|
48
|
+
|
49
|
+
static int memory_read_close(struct archive *, void *);
|
50
|
+
static int memory_read_open(struct archive *, void *);
|
51
|
+
#if ARCHIVE_API_VERSION < 2
|
52
|
+
static ssize_t memory_read_skip(struct archive *, void *, size_t request);
|
53
|
+
#else
|
54
|
+
static off_t memory_read_skip(struct archive *, void *, off_t request);
|
55
|
+
#endif
|
56
|
+
static ssize_t memory_read(struct archive *, void *, const void **buff);
|
57
|
+
|
58
|
+
int
|
59
|
+
archive_read_open_memory(struct archive *a, void *buff, size_t size)
|
60
|
+
{
|
61
|
+
return archive_read_open_memory2(a, buff, size, size);
|
62
|
+
}
|
63
|
+
|
64
|
+
/*
|
65
|
+
* Don't use _open_memory2() in production code; the archive_read_open_memory()
|
66
|
+
* version is the one you really want. This is just here so that
|
67
|
+
* test harnesses can exercise block operations inside the library.
|
68
|
+
*/
|
69
|
+
int
|
70
|
+
archive_read_open_memory2(struct archive *a, void *buff,
|
71
|
+
size_t size, size_t read_size)
|
72
|
+
{
|
73
|
+
struct read_memory_data *mine;
|
74
|
+
|
75
|
+
mine = (struct read_memory_data *)malloc(sizeof(*mine));
|
76
|
+
if (mine == NULL) {
|
77
|
+
archive_set_error(a, ENOMEM, "No memory");
|
78
|
+
return (ARCHIVE_FATAL);
|
79
|
+
}
|
80
|
+
memset(mine, 0, sizeof(*mine));
|
81
|
+
mine->buffer = (unsigned char *)buff;
|
82
|
+
mine->end = mine->buffer + size;
|
83
|
+
mine->read_size = read_size;
|
84
|
+
return (archive_read_open2(a, mine, memory_read_open,
|
85
|
+
memory_read, memory_read_skip, memory_read_close));
|
86
|
+
}
|
87
|
+
|
88
|
+
/*
|
89
|
+
* There's nothing to open.
|
90
|
+
*/
|
91
|
+
static int
|
92
|
+
memory_read_open(struct archive *a, void *client_data)
|
93
|
+
{
|
94
|
+
(void)a; /* UNUSED */
|
95
|
+
(void)client_data; /* UNUSED */
|
96
|
+
return (ARCHIVE_OK);
|
97
|
+
}
|
98
|
+
|
99
|
+
/*
|
100
|
+
* This is scary simple: Just advance a pointer. Limiting
|
101
|
+
* to read_size is not technically necessary, but it exercises
|
102
|
+
* more of the internal logic when used with a small block size
|
103
|
+
* in a test harness. Production use should not specify a block
|
104
|
+
* size; then this is much faster.
|
105
|
+
*/
|
106
|
+
static ssize_t
|
107
|
+
memory_read(struct archive *a, void *client_data, const void **buff)
|
108
|
+
{
|
109
|
+
struct read_memory_data *mine = (struct read_memory_data *)client_data;
|
110
|
+
ssize_t size;
|
111
|
+
|
112
|
+
(void)a; /* UNUSED */
|
113
|
+
*buff = mine->buffer;
|
114
|
+
size = mine->end - mine->buffer;
|
115
|
+
if (size > mine->read_size)
|
116
|
+
size = mine->read_size;
|
117
|
+
mine->buffer += size;
|
118
|
+
return (size);
|
119
|
+
}
|
120
|
+
|
121
|
+
/*
|
122
|
+
* Advancing is just as simple. Again, this is doing more than
|
123
|
+
* necessary in order to better exercise internal code when used
|
124
|
+
* as a test harness.
|
125
|
+
*/
|
126
|
+
#if ARCHIVE_API_VERSION < 2
|
127
|
+
static ssize_t
|
128
|
+
memory_read_skip(struct archive *a, void *client_data, size_t skip)
|
129
|
+
#else
|
130
|
+
static off_t
|
131
|
+
memory_read_skip(struct archive *a, void *client_data, off_t skip)
|
132
|
+
#endif
|
133
|
+
{
|
134
|
+
struct read_memory_data *mine = (struct read_memory_data *)client_data;
|
135
|
+
|
136
|
+
(void)a; /* UNUSED */
|
137
|
+
if ((off_t)skip > (off_t)(mine->end - mine->buffer))
|
138
|
+
skip = mine->end - mine->buffer;
|
139
|
+
/* Round down to block size. */
|
140
|
+
skip /= mine->read_size;
|
141
|
+
skip *= mine->read_size;
|
142
|
+
mine->buffer += skip;
|
143
|
+
return (skip);
|
144
|
+
}
|
145
|
+
|
146
|
+
/*
|
147
|
+
* Close is just cleaning up our one small bit of data.
|
148
|
+
*/
|
149
|
+
static int
|
150
|
+
memory_read_close(struct archive *a, void *client_data)
|
151
|
+
{
|
152
|
+
struct read_memory_data *mine = (struct read_memory_data *)client_data;
|
153
|
+
(void)a; /* UNUSED */
|
154
|
+
free(mine);
|
155
|
+
return (ARCHIVE_OK);
|
156
|
+
}
|