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,126 @@
|
|
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_write_open_memory.c,v 1.3 2007/01/09 08:05:56 kientzle Exp $");
|
28
|
+
|
29
|
+
#include <errno.h>
|
30
|
+
#include <stdlib.h>
|
31
|
+
#include <string.h>
|
32
|
+
|
33
|
+
#include "archive.h"
|
34
|
+
|
35
|
+
/*
|
36
|
+
* This is a little tricky. I used to allow the
|
37
|
+
* compression handling layer to fork the compressor,
|
38
|
+
* which means this write function gets invoked in
|
39
|
+
* a separate process. That would, of course, make it impossible
|
40
|
+
* to actually use the data stored into memory here.
|
41
|
+
* Fortunately, none of the compressors fork today and
|
42
|
+
* I'm reluctant to use that route in the future but, if
|
43
|
+
* forking compressors ever do reappear, this will have
|
44
|
+
* to get a lot more complicated.
|
45
|
+
*/
|
46
|
+
|
47
|
+
struct write_memory_data {
|
48
|
+
size_t used;
|
49
|
+
size_t size;
|
50
|
+
size_t * client_size;
|
51
|
+
unsigned char * buff;
|
52
|
+
};
|
53
|
+
|
54
|
+
static int memory_write_close(struct archive *, void *);
|
55
|
+
static int memory_write_open(struct archive *, void *);
|
56
|
+
static ssize_t memory_write(struct archive *, void *, const void *buff, size_t);
|
57
|
+
|
58
|
+
/*
|
59
|
+
* Client provides a pointer to a block of memory to receive
|
60
|
+
* the data. The 'size' param both tells us the size of the
|
61
|
+
* client buffer and lets us tell the client the final size.
|
62
|
+
*/
|
63
|
+
int
|
64
|
+
archive_write_open_memory(struct archive *a, void *buff, size_t buffSize, size_t *used)
|
65
|
+
{
|
66
|
+
struct write_memory_data *mine;
|
67
|
+
|
68
|
+
mine = (struct write_memory_data *)malloc(sizeof(*mine));
|
69
|
+
if (mine == NULL) {
|
70
|
+
archive_set_error(a, ENOMEM, "No memory");
|
71
|
+
return (ARCHIVE_FATAL);
|
72
|
+
}
|
73
|
+
memset(mine, 0, sizeof(*mine));
|
74
|
+
mine->buff = buff;
|
75
|
+
mine->size = buffSize;
|
76
|
+
mine->client_size = used;
|
77
|
+
return (archive_write_open(a, mine,
|
78
|
+
memory_write_open, memory_write, memory_write_close));
|
79
|
+
}
|
80
|
+
|
81
|
+
static int
|
82
|
+
memory_write_open(struct archive *a, void *client_data)
|
83
|
+
{
|
84
|
+
struct write_memory_data *mine;
|
85
|
+
mine = client_data;
|
86
|
+
mine->used = 0;
|
87
|
+
if (mine->client_size != NULL)
|
88
|
+
*mine->client_size = mine->used;
|
89
|
+
/* Disable padding if it hasn't been set explicitly. */
|
90
|
+
if (-1 == archive_write_get_bytes_in_last_block(a))
|
91
|
+
archive_write_set_bytes_in_last_block(a, 1);
|
92
|
+
return (ARCHIVE_OK);
|
93
|
+
}
|
94
|
+
|
95
|
+
/*
|
96
|
+
* Copy the data into the client buffer.
|
97
|
+
* Note that we update mine->client_size on every write.
|
98
|
+
* In particular, this means the client can follow exactly
|
99
|
+
* how much has been written into their buffer at any time.
|
100
|
+
*/
|
101
|
+
static ssize_t
|
102
|
+
memory_write(struct archive *a, void *client_data, const void *buff, size_t length)
|
103
|
+
{
|
104
|
+
struct write_memory_data *mine;
|
105
|
+
mine = client_data;
|
106
|
+
|
107
|
+
if (mine->used + length > mine->size) {
|
108
|
+
archive_set_error(a, ENOMEM, "Buffer exhausted");
|
109
|
+
return (ARCHIVE_FATAL);
|
110
|
+
}
|
111
|
+
memcpy(mine->buff + mine->used, buff, length);
|
112
|
+
mine->used += length;
|
113
|
+
if (mine->client_size != NULL)
|
114
|
+
*mine->client_size = mine->used;
|
115
|
+
return (length);
|
116
|
+
}
|
117
|
+
|
118
|
+
static int
|
119
|
+
memory_write_close(struct archive *a, void *client_data)
|
120
|
+
{
|
121
|
+
struct write_memory_data *mine;
|
122
|
+
(void)a; /* UNUSED */
|
123
|
+
mine = client_data;
|
124
|
+
free(mine);
|
125
|
+
return (ARCHIVE_OK);
|
126
|
+
}
|
@@ -0,0 +1,122 @@
|
|
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
|
+
* $FreeBSD: head/lib/libarchive/archive_write_private.h 201155 2009-12-29 05:20:12Z kientzle $
|
26
|
+
*/
|
27
|
+
|
28
|
+
#ifndef __LIBARCHIVE_BUILD
|
29
|
+
#error This header is only to be used internally to libarchive.
|
30
|
+
#endif
|
31
|
+
|
32
|
+
#ifndef ARCHIVE_WRITE_PRIVATE_H_INCLUDED
|
33
|
+
#define ARCHIVE_WRITE_PRIVATE_H_INCLUDED
|
34
|
+
|
35
|
+
#include "archive.h"
|
36
|
+
#include "archive_string.h"
|
37
|
+
#include "archive_private.h"
|
38
|
+
|
39
|
+
struct archive_write {
|
40
|
+
struct archive archive;
|
41
|
+
|
42
|
+
/* Dev/ino of the archive being written. */
|
43
|
+
dev_t skip_file_dev;
|
44
|
+
int64_t skip_file_ino;
|
45
|
+
|
46
|
+
/* Utility: Pointer to a block of nulls. */
|
47
|
+
const unsigned char *nulls;
|
48
|
+
size_t null_length;
|
49
|
+
|
50
|
+
/* Callbacks to open/read/write/close archive stream. */
|
51
|
+
archive_open_callback *client_opener;
|
52
|
+
archive_write_callback *client_writer;
|
53
|
+
archive_close_callback *client_closer;
|
54
|
+
void *client_data;
|
55
|
+
|
56
|
+
/*
|
57
|
+
* Blocking information. Note that bytes_in_last_block is
|
58
|
+
* misleadingly named; I should find a better name. These
|
59
|
+
* control the final output from all compressors, including
|
60
|
+
* compression_none.
|
61
|
+
*/
|
62
|
+
int bytes_per_block;
|
63
|
+
int bytes_in_last_block;
|
64
|
+
|
65
|
+
/*
|
66
|
+
* These control whether data within a gzip/bzip2 compressed
|
67
|
+
* stream gets padded or not. If pad_uncompressed is set,
|
68
|
+
* the data will be padded to a full block before being
|
69
|
+
* compressed. The pad_uncompressed_byte determines the value
|
70
|
+
* that will be used for padding. Note that these have no
|
71
|
+
* effect on compression "none."
|
72
|
+
*/
|
73
|
+
int pad_uncompressed;
|
74
|
+
int pad_uncompressed_byte; /* TODO: Support this. */
|
75
|
+
|
76
|
+
/*
|
77
|
+
* On write, the client just invokes an archive_write_set function
|
78
|
+
* which sets up the data here directly.
|
79
|
+
*/
|
80
|
+
struct {
|
81
|
+
void *data;
|
82
|
+
void *config;
|
83
|
+
int (*init)(struct archive_write *);
|
84
|
+
int (*options)(struct archive_write *,
|
85
|
+
const char *key, const char *value);
|
86
|
+
int (*finish)(struct archive_write *);
|
87
|
+
int (*write)(struct archive_write *, const void *, size_t);
|
88
|
+
} compressor;
|
89
|
+
|
90
|
+
/*
|
91
|
+
* Pointers to format-specific functions for writing. They're
|
92
|
+
* initialized by archive_write_set_format_XXX() calls.
|
93
|
+
*/
|
94
|
+
void *format_data;
|
95
|
+
const char *format_name;
|
96
|
+
int (*format_init)(struct archive_write *);
|
97
|
+
int (*format_options)(struct archive_write *,
|
98
|
+
const char *key, const char *value);
|
99
|
+
int (*format_finish)(struct archive_write *);
|
100
|
+
int (*format_destroy)(struct archive_write *);
|
101
|
+
int (*format_finish_entry)(struct archive_write *);
|
102
|
+
int (*format_write_header)(struct archive_write *,
|
103
|
+
struct archive_entry *);
|
104
|
+
ssize_t (*format_write_data)(struct archive_write *,
|
105
|
+
const void *buff, size_t);
|
106
|
+
};
|
107
|
+
|
108
|
+
/*
|
109
|
+
* Utility function to format a USTAR header into a buffer. If
|
110
|
+
* "strict" is set, this tries to create the absolutely most portable
|
111
|
+
* version of a ustar header. If "strict" is set to 0, then it will
|
112
|
+
* relax certain requirements.
|
113
|
+
*
|
114
|
+
* Generally, format-specific declarations don't belong in this
|
115
|
+
* header; this is a rare example of a function that is shared by
|
116
|
+
* two very similar formats (ustar and pax).
|
117
|
+
*/
|
118
|
+
int
|
119
|
+
__archive_write_format_header_ustar(struct archive_write *, char buff[512],
|
120
|
+
struct archive_entry *, int tartype, int strict);
|
121
|
+
|
122
|
+
#endif
|
@@ -0,0 +1,408 @@
|
|
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
|
+
|
28
|
+
__FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_compression_bzip2.c 201091 2009-12-28 02:22:41Z kientzle $");
|
29
|
+
|
30
|
+
#ifdef HAVE_ERRNO_H
|
31
|
+
#include <errno.h>
|
32
|
+
#endif
|
33
|
+
#include <stdio.h>
|
34
|
+
#ifdef HAVE_STDLIB_H
|
35
|
+
#include <stdlib.h>
|
36
|
+
#endif
|
37
|
+
#ifdef HAVE_STRING_H
|
38
|
+
#include <string.h>
|
39
|
+
#endif
|
40
|
+
#ifdef HAVE_BZLIB_H
|
41
|
+
#include <bzlib.h>
|
42
|
+
#endif
|
43
|
+
|
44
|
+
#include "archive.h"
|
45
|
+
#include "archive_private.h"
|
46
|
+
#include "archive_write_private.h"
|
47
|
+
|
48
|
+
#if !defined(HAVE_BZLIB_H) || !defined(BZ_CONFIG_ERROR)
|
49
|
+
int
|
50
|
+
archive_write_set_compression_bzip2(struct archive *a)
|
51
|
+
{
|
52
|
+
archive_set_error(a, ARCHIVE_ERRNO_MISC,
|
53
|
+
"bzip2 compression not supported on this platform");
|
54
|
+
return (ARCHIVE_FATAL);
|
55
|
+
}
|
56
|
+
#else
|
57
|
+
/* Don't compile this if we don't have bzlib. */
|
58
|
+
|
59
|
+
struct private_data {
|
60
|
+
bz_stream stream;
|
61
|
+
int64_t total_in;
|
62
|
+
char *compressed;
|
63
|
+
size_t compressed_buffer_size;
|
64
|
+
};
|
65
|
+
|
66
|
+
struct private_config {
|
67
|
+
int compression_level;
|
68
|
+
};
|
69
|
+
|
70
|
+
/*
|
71
|
+
* Yuck. bzlib.h is not const-correct, so I need this one bit
|
72
|
+
* of ugly hackery to convert a const * pointer to a non-const pointer.
|
73
|
+
*/
|
74
|
+
#define SET_NEXT_IN(st,src) \
|
75
|
+
(st)->stream.next_in = (char *)(uintptr_t)(const void *)(src)
|
76
|
+
|
77
|
+
static int archive_compressor_bzip2_finish(struct archive_write *);
|
78
|
+
static int archive_compressor_bzip2_init(struct archive_write *);
|
79
|
+
static int archive_compressor_bzip2_options(struct archive_write *,
|
80
|
+
const char *, const char *);
|
81
|
+
static int archive_compressor_bzip2_write(struct archive_write *,
|
82
|
+
const void *, size_t);
|
83
|
+
static int drive_compressor(struct archive_write *, struct private_data *,
|
84
|
+
int finishing);
|
85
|
+
|
86
|
+
/*
|
87
|
+
* Allocate, initialize and return an archive object.
|
88
|
+
*/
|
89
|
+
int
|
90
|
+
archive_write_set_compression_bzip2(struct archive *_a)
|
91
|
+
{
|
92
|
+
struct archive_write *a = (struct archive_write *)_a;
|
93
|
+
struct private_config *config;
|
94
|
+
__archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC,
|
95
|
+
ARCHIVE_STATE_NEW, "archive_write_set_compression_bzip2");
|
96
|
+
config = malloc(sizeof(*config));
|
97
|
+
if (config == NULL) {
|
98
|
+
archive_set_error(&a->archive, ENOMEM, "Out of memory");
|
99
|
+
return (ARCHIVE_FATAL);
|
100
|
+
}
|
101
|
+
a->compressor.config = config;
|
102
|
+
a->compressor.finish = archive_compressor_bzip2_finish;
|
103
|
+
config->compression_level = 9; /* default */
|
104
|
+
a->compressor.init = &archive_compressor_bzip2_init;
|
105
|
+
a->compressor.options = &archive_compressor_bzip2_options;
|
106
|
+
a->archive.compression_code = ARCHIVE_COMPRESSION_BZIP2;
|
107
|
+
a->archive.compression_name = "bzip2";
|
108
|
+
return (ARCHIVE_OK);
|
109
|
+
}
|
110
|
+
|
111
|
+
/*
|
112
|
+
* Setup callback.
|
113
|
+
*/
|
114
|
+
static int
|
115
|
+
archive_compressor_bzip2_init(struct archive_write *a)
|
116
|
+
{
|
117
|
+
int ret;
|
118
|
+
struct private_data *state;
|
119
|
+
struct private_config *config;
|
120
|
+
|
121
|
+
config = (struct private_config *)a->compressor.config;
|
122
|
+
if (a->client_opener != NULL) {
|
123
|
+
ret = (a->client_opener)(&a->archive, a->client_data);
|
124
|
+
if (ret != 0)
|
125
|
+
return (ret);
|
126
|
+
}
|
127
|
+
|
128
|
+
state = (struct private_data *)malloc(sizeof(*state));
|
129
|
+
if (state == NULL) {
|
130
|
+
archive_set_error(&a->archive, ENOMEM,
|
131
|
+
"Can't allocate data for compression");
|
132
|
+
return (ARCHIVE_FATAL);
|
133
|
+
}
|
134
|
+
memset(state, 0, sizeof(*state));
|
135
|
+
|
136
|
+
state->compressed_buffer_size = a->bytes_per_block;
|
137
|
+
state->compressed = (char *)malloc(state->compressed_buffer_size);
|
138
|
+
|
139
|
+
if (state->compressed == NULL) {
|
140
|
+
archive_set_error(&a->archive, ENOMEM,
|
141
|
+
"Can't allocate data for compression buffer");
|
142
|
+
free(state);
|
143
|
+
return (ARCHIVE_FATAL);
|
144
|
+
}
|
145
|
+
|
146
|
+
state->stream.next_out = state->compressed;
|
147
|
+
state->stream.avail_out = state->compressed_buffer_size;
|
148
|
+
a->compressor.write = archive_compressor_bzip2_write;
|
149
|
+
|
150
|
+
/* Initialize compression library */
|
151
|
+
ret = BZ2_bzCompressInit(&(state->stream),
|
152
|
+
config->compression_level, 0, 30);
|
153
|
+
if (ret == BZ_OK) {
|
154
|
+
a->compressor.data = state;
|
155
|
+
return (ARCHIVE_OK);
|
156
|
+
}
|
157
|
+
|
158
|
+
/* Library setup failed: clean up. */
|
159
|
+
archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
|
160
|
+
"Internal error initializing compression library");
|
161
|
+
free(state->compressed);
|
162
|
+
free(state);
|
163
|
+
|
164
|
+
/* Override the error message if we know what really went wrong. */
|
165
|
+
switch (ret) {
|
166
|
+
case BZ_PARAM_ERROR:
|
167
|
+
archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
|
168
|
+
"Internal error initializing compression library: "
|
169
|
+
"invalid setup parameter");
|
170
|
+
break;
|
171
|
+
case BZ_MEM_ERROR:
|
172
|
+
archive_set_error(&a->archive, ENOMEM,
|
173
|
+
"Internal error initializing compression library: "
|
174
|
+
"out of memory");
|
175
|
+
break;
|
176
|
+
case BZ_CONFIG_ERROR:
|
177
|
+
archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
|
178
|
+
"Internal error initializing compression library: "
|
179
|
+
"mis-compiled library");
|
180
|
+
break;
|
181
|
+
}
|
182
|
+
|
183
|
+
return (ARCHIVE_FATAL);
|
184
|
+
|
185
|
+
}
|
186
|
+
|
187
|
+
/*
|
188
|
+
* Set write options.
|
189
|
+
*/
|
190
|
+
static int
|
191
|
+
archive_compressor_bzip2_options(struct archive_write *a, const char *key,
|
192
|
+
const char *value)
|
193
|
+
{
|
194
|
+
struct private_config *config;
|
195
|
+
|
196
|
+
config = (struct private_config *)a->compressor.config;
|
197
|
+
if (strcmp(key, "compression-level") == 0) {
|
198
|
+
if (value == NULL || !(value[0] >= '0' && value[0] <= '9') ||
|
199
|
+
value[1] != '\0')
|
200
|
+
return (ARCHIVE_WARN);
|
201
|
+
config->compression_level = value[0] - '0';
|
202
|
+
/* Make '0' be a synonym for '1'. */
|
203
|
+
/* This way, bzip2 compressor supports the same 0..9
|
204
|
+
* range of levels as gzip. */
|
205
|
+
if (config->compression_level < 1)
|
206
|
+
config->compression_level = 1;
|
207
|
+
return (ARCHIVE_OK);
|
208
|
+
}
|
209
|
+
|
210
|
+
return (ARCHIVE_WARN);
|
211
|
+
}
|
212
|
+
|
213
|
+
/*
|
214
|
+
* Write data to the compressed stream.
|
215
|
+
*
|
216
|
+
* Returns ARCHIVE_OK if all data written, error otherwise.
|
217
|
+
*/
|
218
|
+
static int
|
219
|
+
archive_compressor_bzip2_write(struct archive_write *a, const void *buff,
|
220
|
+
size_t length)
|
221
|
+
{
|
222
|
+
struct private_data *state;
|
223
|
+
|
224
|
+
state = (struct private_data *)a->compressor.data;
|
225
|
+
if (a->client_writer == NULL) {
|
226
|
+
archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER,
|
227
|
+
"No write callback is registered? "
|
228
|
+
"This is probably an internal programming error.");
|
229
|
+
return (ARCHIVE_FATAL);
|
230
|
+
}
|
231
|
+
|
232
|
+
/* Update statistics */
|
233
|
+
state->total_in += length;
|
234
|
+
|
235
|
+
/* Compress input data to output buffer */
|
236
|
+
SET_NEXT_IN(state, buff);
|
237
|
+
state->stream.avail_in = length;
|
238
|
+
if (drive_compressor(a, state, 0))
|
239
|
+
return (ARCHIVE_FATAL);
|
240
|
+
a->archive.file_position += length;
|
241
|
+
return (ARCHIVE_OK);
|
242
|
+
}
|
243
|
+
|
244
|
+
|
245
|
+
/*
|
246
|
+
* Finish the compression.
|
247
|
+
*/
|
248
|
+
static int
|
249
|
+
archive_compressor_bzip2_finish(struct archive_write *a)
|
250
|
+
{
|
251
|
+
ssize_t block_length;
|
252
|
+
int ret;
|
253
|
+
struct private_data *state;
|
254
|
+
ssize_t target_block_length;
|
255
|
+
ssize_t bytes_written;
|
256
|
+
unsigned tocopy;
|
257
|
+
|
258
|
+
ret = ARCHIVE_OK;
|
259
|
+
state = (struct private_data *)a->compressor.data;
|
260
|
+
if (state != NULL) {
|
261
|
+
if (a->client_writer == NULL) {
|
262
|
+
archive_set_error(&a->archive,
|
263
|
+
ARCHIVE_ERRNO_PROGRAMMER,
|
264
|
+
"No write callback is registered?\n"
|
265
|
+
"This is probably an internal programming error.");
|
266
|
+
ret = ARCHIVE_FATAL;
|
267
|
+
goto cleanup;
|
268
|
+
}
|
269
|
+
|
270
|
+
/* By default, always pad the uncompressed data. */
|
271
|
+
if (a->pad_uncompressed) {
|
272
|
+
tocopy = a->bytes_per_block -
|
273
|
+
(state->total_in % a->bytes_per_block);
|
274
|
+
while (tocopy > 0 && tocopy < (unsigned)a->bytes_per_block) {
|
275
|
+
SET_NEXT_IN(state, a->nulls);
|
276
|
+
state->stream.avail_in = tocopy < a->null_length ?
|
277
|
+
tocopy : a->null_length;
|
278
|
+
state->total_in += state->stream.avail_in;
|
279
|
+
tocopy -= state->stream.avail_in;
|
280
|
+
ret = drive_compressor(a, state, 0);
|
281
|
+
if (ret != ARCHIVE_OK)
|
282
|
+
goto cleanup;
|
283
|
+
}
|
284
|
+
}
|
285
|
+
|
286
|
+
/* Finish compression cycle. */
|
287
|
+
if ((ret = drive_compressor(a, state, 1)))
|
288
|
+
goto cleanup;
|
289
|
+
|
290
|
+
/* Optionally, pad the final compressed block. */
|
291
|
+
block_length = state->stream.next_out - state->compressed;
|
292
|
+
|
293
|
+
/* Tricky calculation to determine size of last block. */
|
294
|
+
if (a->bytes_in_last_block <= 0)
|
295
|
+
/* Default or Zero: pad to full block */
|
296
|
+
target_block_length = a->bytes_per_block;
|
297
|
+
else
|
298
|
+
/* Round length to next multiple of bytes_in_last_block. */
|
299
|
+
target_block_length = a->bytes_in_last_block *
|
300
|
+
( (block_length + a->bytes_in_last_block - 1) /
|
301
|
+
a->bytes_in_last_block);
|
302
|
+
if (target_block_length > a->bytes_per_block)
|
303
|
+
target_block_length = a->bytes_per_block;
|
304
|
+
if (block_length < target_block_length) {
|
305
|
+
memset(state->stream.next_out, 0,
|
306
|
+
target_block_length - block_length);
|
307
|
+
block_length = target_block_length;
|
308
|
+
}
|
309
|
+
|
310
|
+
/* Write the last block */
|
311
|
+
bytes_written = (a->client_writer)(&a->archive, a->client_data,
|
312
|
+
state->compressed, block_length);
|
313
|
+
|
314
|
+
/* TODO: Handle short write of final block. */
|
315
|
+
if (bytes_written <= 0)
|
316
|
+
ret = ARCHIVE_FATAL;
|
317
|
+
else {
|
318
|
+
a->archive.raw_position += ret;
|
319
|
+
ret = ARCHIVE_OK;
|
320
|
+
}
|
321
|
+
|
322
|
+
/* Cleanup: shut down compressor, release memory, etc. */
|
323
|
+
cleanup:
|
324
|
+
switch (BZ2_bzCompressEnd(&(state->stream))) {
|
325
|
+
case BZ_OK:
|
326
|
+
break;
|
327
|
+
default:
|
328
|
+
archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER,
|
329
|
+
"Failed to clean up compressor");
|
330
|
+
ret = ARCHIVE_FATAL;
|
331
|
+
}
|
332
|
+
|
333
|
+
free(state->compressed);
|
334
|
+
free(state);
|
335
|
+
}
|
336
|
+
/* Free configuration data even if we were never fully initialized. */
|
337
|
+
free(a->compressor.config);
|
338
|
+
a->compressor.config = NULL;
|
339
|
+
return (ret);
|
340
|
+
}
|
341
|
+
|
342
|
+
/*
|
343
|
+
* Utility function to push input data through compressor, writing
|
344
|
+
* full output blocks as necessary.
|
345
|
+
*
|
346
|
+
* Note that this handles both the regular write case (finishing ==
|
347
|
+
* false) and the end-of-archive case (finishing == true).
|
348
|
+
*/
|
349
|
+
static int
|
350
|
+
drive_compressor(struct archive_write *a, struct private_data *state, int finishing)
|
351
|
+
{
|
352
|
+
ssize_t bytes_written;
|
353
|
+
int ret;
|
354
|
+
|
355
|
+
for (;;) {
|
356
|
+
if (state->stream.avail_out == 0) {
|
357
|
+
bytes_written = (a->client_writer)(&a->archive,
|
358
|
+
a->client_data, state->compressed,
|
359
|
+
state->compressed_buffer_size);
|
360
|
+
if (bytes_written <= 0) {
|
361
|
+
/* TODO: Handle this write failure */
|
362
|
+
return (ARCHIVE_FATAL);
|
363
|
+
} else if ((size_t)bytes_written < state->compressed_buffer_size) {
|
364
|
+
/* Short write: Move remainder to
|
365
|
+
* front and keep filling */
|
366
|
+
memmove(state->compressed,
|
367
|
+
state->compressed + bytes_written,
|
368
|
+
state->compressed_buffer_size - bytes_written);
|
369
|
+
}
|
370
|
+
|
371
|
+
a->archive.raw_position += bytes_written;
|
372
|
+
state->stream.next_out = state->compressed +
|
373
|
+
state->compressed_buffer_size - bytes_written;
|
374
|
+
state->stream.avail_out = bytes_written;
|
375
|
+
}
|
376
|
+
|
377
|
+
/* If there's nothing to do, we're done. */
|
378
|
+
if (!finishing && state->stream.avail_in == 0)
|
379
|
+
return (ARCHIVE_OK);
|
380
|
+
|
381
|
+
ret = BZ2_bzCompress(&(state->stream),
|
382
|
+
finishing ? BZ_FINISH : BZ_RUN);
|
383
|
+
|
384
|
+
switch (ret) {
|
385
|
+
case BZ_RUN_OK:
|
386
|
+
/* In non-finishing case, did compressor
|
387
|
+
* consume everything? */
|
388
|
+
if (!finishing && state->stream.avail_in == 0)
|
389
|
+
return (ARCHIVE_OK);
|
390
|
+
break;
|
391
|
+
case BZ_FINISH_OK: /* Finishing: There's more work to do */
|
392
|
+
break;
|
393
|
+
case BZ_STREAM_END: /* Finishing: all done */
|
394
|
+
/* Only occurs in finishing case */
|
395
|
+
return (ARCHIVE_OK);
|
396
|
+
default:
|
397
|
+
/* Any other return value indicates an error */
|
398
|
+
archive_set_error(&a->archive,
|
399
|
+
ARCHIVE_ERRNO_PROGRAMMER,
|
400
|
+
"Bzip2 compression failed;"
|
401
|
+
" BZ2_bzCompress() returned %d",
|
402
|
+
ret);
|
403
|
+
return (ARCHIVE_FATAL);
|
404
|
+
}
|
405
|
+
}
|
406
|
+
}
|
407
|
+
|
408
|
+
#endif /* HAVE_BZLIB_H && BZ_CONFIG_ERROR */
|