xz: Merge more common code into common_setup
Reduces complexity of individual functions. Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
This commit is contained in:
1 parent
dfc4357a74
commit
b2a38b8845
1 file changed
+18
-39
@@ -143,15 +143,18 @@ static const struct option_value option_values[] = {
|
||||
};
|
||||
|
||||
static int
|
||||
common_setup(struct archive_write_filter *f)
|
||||
common_setup(struct archive *a, const char *name, int code)
|
||||
{
|
||||
struct private_data *data;
|
||||
struct archive_write *a = (struct archive_write *)f->archive;
|
||||
struct archive_write_filter *f = __archive_write_allocate_filter(a);
|
||||
|
||||
data = calloc(1, sizeof(*data));
|
||||
if (data == NULL) {
|
||||
archive_set_error(&a->archive, ENOMEM, "Out of memory");
|
||||
archive_set_error(a, ENOMEM, "Out of memory");
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
f->name = name;
|
||||
f->code = code;
|
||||
f->data = data;
|
||||
data->compression_level = LZMA_PRESET_DEFAULT;
|
||||
data->threads = 1;
|
||||
@@ -167,57 +170,33 @@ common_setup(struct archive_write_filter *f)
|
||||
* Add an xz compression filter to this write handle.
|
||||
*/
|
||||
int
|
||||
archive_write_add_filter_xz(struct archive *_a)
|
||||
archive_write_add_filter_xz(struct archive *a)
|
||||
{
|
||||
struct archive_write_filter *f;
|
||||
int r;
|
||||
|
||||
archive_check_magic(_a, ARCHIVE_WRITE_MAGIC,
|
||||
archive_check_magic(a, ARCHIVE_WRITE_MAGIC,
|
||||
ARCHIVE_STATE_NEW, "archive_write_add_filter_xz");
|
||||
f = __archive_write_allocate_filter(_a);
|
||||
r = common_setup(f);
|
||||
if (r == ARCHIVE_OK) {
|
||||
f->code = ARCHIVE_FILTER_XZ;
|
||||
f->name = "xz";
|
||||
}
|
||||
return (r);
|
||||
|
||||
return common_setup(a, "xz", ARCHIVE_FILTER_XZ);
|
||||
}
|
||||
|
||||
/* LZMA is handled identically, we just need a different compression
|
||||
* code set. (The liblzma setup looks at the code to determine
|
||||
* the one place that XZ and LZMA require different handling.) */
|
||||
int
|
||||
archive_write_add_filter_lzma(struct archive *_a)
|
||||
archive_write_add_filter_lzma(struct archive *a)
|
||||
{
|
||||
struct archive_write_filter *f;
|
||||
int r;
|
||||
|
||||
archive_check_magic(_a, ARCHIVE_WRITE_MAGIC,
|
||||
archive_check_magic(a, ARCHIVE_WRITE_MAGIC,
|
||||
ARCHIVE_STATE_NEW, "archive_write_add_filter_lzma");
|
||||
f = __archive_write_allocate_filter(_a);
|
||||
r = common_setup(f);
|
||||
if (r == ARCHIVE_OK) {
|
||||
f->code = ARCHIVE_FILTER_LZMA;
|
||||
f->name = "lzma";
|
||||
}
|
||||
return (r);
|
||||
|
||||
return common_setup(a, "lzma", ARCHIVE_FILTER_LZMA);
|
||||
}
|
||||
|
||||
int
|
||||
archive_write_add_filter_lzip(struct archive *_a)
|
||||
archive_write_add_filter_lzip(struct archive *a)
|
||||
{
|
||||
struct archive_write_filter *f;
|
||||
int r;
|
||||
|
||||
archive_check_magic(_a, ARCHIVE_WRITE_MAGIC,
|
||||
archive_check_magic(a, ARCHIVE_WRITE_MAGIC,
|
||||
ARCHIVE_STATE_NEW, "archive_write_add_filter_lzip");
|
||||
f = __archive_write_allocate_filter(_a);
|
||||
r = common_setup(f);
|
||||
if (r == ARCHIVE_OK) {
|
||||
f->code = ARCHIVE_FILTER_LZIP;
|
||||
f->name = "lzip";
|
||||
}
|
||||
return (r);
|
||||
|
||||
return common_setup(a, "lzip", ARCHIVE_FILTER_LZIP);
|
||||
}
|
||||
|
||||
static int
|
||||
|
||||
Reference in new issue
Block a user