2004-02-09 23:22:54 +00:00
|
|
|
/*-
|
2007-01-09 08:05:56 +00:00
|
|
|
* Copyright (c) 2003-2007 Tim Kientzle
|
2004-02-09 23:22:54 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
2007-01-09 08:05:56 +00:00
|
|
|
* notice, this list of conditions and the following disclaimer.
|
2004-02-09 23:22:54 +00:00
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2004-03-09 19:50:41 +00:00
|
|
|
#include "archive_platform.h"
|
2004-07-30 04:14:47 +00:00
|
|
|
|
2004-02-09 23:22:54 +00:00
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2006-11-10 06:39:46 +00:00
|
|
|
#ifdef HAVE_ERRNO_H
|
2004-02-09 23:22:54 +00:00
|
|
|
#include <errno.h>
|
2006-11-10 06:39:46 +00:00
|
|
|
#endif
|
2004-11-05 05:26:30 +00:00
|
|
|
#include <stdio.h>
|
2006-11-10 06:39:46 +00:00
|
|
|
#ifdef HAVE_STDLIB_H
|
2004-02-09 23:22:54 +00:00
|
|
|
#include <stdlib.h>
|
2006-11-10 06:39:46 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRING_H
|
2004-02-09 23:22:54 +00:00
|
|
|
#include <string.h>
|
2006-11-10 06:39:46 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_BZLIB_H
|
2004-02-09 23:22:54 +00:00
|
|
|
#include <bzlib.h>
|
2006-11-10 06:39:46 +00:00
|
|
|
#endif
|
2004-02-09 23:22:54 +00:00
|
|
|
|
|
|
|
#include "archive.h"
|
|
|
|
#include "archive_private.h"
|
2007-03-03 07:37:37 +00:00
|
|
|
#include "archive_write_private.h"
|
2004-02-09 23:22:54 +00:00
|
|
|
|
2009-03-03 17:07:27 +00:00
|
|
|
#ifndef HAVE_BZLIB_H
|
|
|
|
int
|
2009-04-17 00:42:45 +00:00
|
|
|
archive_write_set_compression_bzip2(struct archive *a)
|
2009-03-03 17:07:27 +00:00
|
|
|
{
|
2009-04-17 00:42:45 +00:00
|
|
|
archive_set_error(a, ARCHIVE_ERRNO_MISC,
|
|
|
|
"bzip2 compression not supported on this platform");
|
2009-03-03 17:07:27 +00:00
|
|
|
return (ARCHIVE_FATAL);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
/* Don't compile this if we don't have bzlib. */
|
|
|
|
|
2004-02-09 23:22:54 +00:00
|
|
|
struct private_data {
|
|
|
|
bz_stream stream;
|
|
|
|
int64_t total_in;
|
|
|
|
char *compressed;
|
|
|
|
size_t compressed_buffer_size;
|
|
|
|
};
|
|
|
|
|
2009-04-17 00:42:45 +00:00
|
|
|
struct private_config {
|
|
|
|
int compression_level;
|
|
|
|
};
|
2004-02-09 23:22:54 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Yuck. bzlib.h is not const-correct, so I need this one bit
|
|
|
|
* of ugly hackery to convert a const * pointer to a non-const pointer.
|
|
|
|
*/
|
|
|
|
#define SET_NEXT_IN(st,src) \
|
2006-11-10 06:39:46 +00:00
|
|
|
(st)->stream.next_in = (char *)(uintptr_t)(const void *)(src)
|
2004-02-09 23:22:54 +00:00
|
|
|
|
2007-03-03 07:37:37 +00:00
|
|
|
static int archive_compressor_bzip2_finish(struct archive_write *);
|
|
|
|
static int archive_compressor_bzip2_init(struct archive_write *);
|
2009-04-17 00:42:45 +00:00
|
|
|
static int archive_compressor_bzip2_options(struct archive_write *,
|
|
|
|
const char *, const char *);
|
2007-03-03 07:37:37 +00:00
|
|
|
static int archive_compressor_bzip2_write(struct archive_write *,
|
|
|
|
const void *, size_t);
|
|
|
|
static int drive_compressor(struct archive_write *, struct private_data *,
|
2004-02-09 23:22:54 +00:00
|
|
|
int finishing);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate, initialize and return an archive object.
|
|
|
|
*/
|
|
|
|
int
|
2007-03-03 07:37:37 +00:00
|
|
|
archive_write_set_compression_bzip2(struct archive *_a)
|
2004-02-09 23:22:54 +00:00
|
|
|
{
|
2007-03-03 07:37:37 +00:00
|
|
|
struct archive_write *a = (struct archive_write *)_a;
|
2009-04-17 00:42:45 +00:00
|
|
|
struct private_config *config;
|
2007-03-03 07:37:37 +00:00
|
|
|
__archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC,
|
|
|
|
ARCHIVE_STATE_NEW, "archive_write_set_compression_bzip2");
|
2009-04-17 00:42:45 +00:00
|
|
|
config = malloc(sizeof(*config));
|
|
|
|
if (config == NULL) {
|
|
|
|
archive_set_error(&a->archive, ENOMEM, "Out of memory");
|
|
|
|
return (ARCHIVE_FATAL);
|
|
|
|
}
|
|
|
|
a->compressor.config = config;
|
|
|
|
a->compressor.finish = archive_compressor_bzip2_finish;
|
|
|
|
config->compression_level = 9; /* default */
|
2007-05-29 01:00:21 +00:00
|
|
|
a->compressor.init = &archive_compressor_bzip2_init;
|
2009-04-17 00:42:45 +00:00
|
|
|
a->compressor.options = &archive_compressor_bzip2_options;
|
|
|
|
a->archive.compression_code = ARCHIVE_COMPRESSION_BZIP2;
|
|
|
|
a->archive.compression_name = "bzip2";
|
2004-02-09 23:22:54 +00:00
|
|
|
return (ARCHIVE_OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Setup callback.
|
|
|
|
*/
|
|
|
|
static int
|
2007-03-03 07:37:37 +00:00
|
|
|
archive_compressor_bzip2_init(struct archive_write *a)
|
2004-02-09 23:22:54 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct private_data *state;
|
2009-04-17 00:42:45 +00:00
|
|
|
struct private_config *config;
|
2004-02-09 23:22:54 +00:00
|
|
|
|
2009-04-17 00:42:45 +00:00
|
|
|
config = (struct private_config *)a->compressor.config;
|
2004-02-09 23:22:54 +00:00
|
|
|
if (a->client_opener != NULL) {
|
2007-03-03 07:37:37 +00:00
|
|
|
ret = (a->client_opener)(&a->archive, a->client_data);
|
2004-02-09 23:22:54 +00:00
|
|
|
if (ret != 0)
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
2006-11-10 06:39:46 +00:00
|
|
|
state = (struct private_data *)malloc(sizeof(*state));
|
2004-02-09 23:22:54 +00:00
|
|
|
if (state == NULL) {
|
2007-03-03 07:37:37 +00:00
|
|
|
archive_set_error(&a->archive, ENOMEM,
|
2004-02-09 23:22:54 +00:00
|
|
|
"Can't allocate data for compression");
|
|
|
|
return (ARCHIVE_FATAL);
|
|
|
|
}
|
|
|
|
memset(state, 0, sizeof(*state));
|
|
|
|
|
|
|
|
state->compressed_buffer_size = a->bytes_per_block;
|
2006-11-10 06:39:46 +00:00
|
|
|
state->compressed = (char *)malloc(state->compressed_buffer_size);
|
2004-02-09 23:22:54 +00:00
|
|
|
|
|
|
|
if (state->compressed == NULL) {
|
2007-03-03 07:37:37 +00:00
|
|
|
archive_set_error(&a->archive, ENOMEM,
|
2004-02-09 23:22:54 +00:00
|
|
|
"Can't allocate data for compression buffer");
|
|
|
|
free(state);
|
|
|
|
return (ARCHIVE_FATAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
state->stream.next_out = state->compressed;
|
|
|
|
state->stream.avail_out = state->compressed_buffer_size;
|
2007-05-29 01:00:21 +00:00
|
|
|
a->compressor.write = archive_compressor_bzip2_write;
|
2004-02-09 23:22:54 +00:00
|
|
|
|
|
|
|
/* Initialize compression library */
|
2009-04-17 00:42:45 +00:00
|
|
|
ret = BZ2_bzCompressInit(&(state->stream),
|
|
|
|
config->compression_level, 0, 30);
|
2004-02-09 23:22:54 +00:00
|
|
|
if (ret == BZ_OK) {
|
2007-05-29 01:00:21 +00:00
|
|
|
a->compressor.data = state;
|
2004-02-09 23:22:54 +00:00
|
|
|
return (ARCHIVE_OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Library setup failed: clean up. */
|
2007-03-03 07:37:37 +00:00
|
|
|
archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
|
2004-02-09 23:22:54 +00:00
|
|
|
"Internal error initializing compression library");
|
|
|
|
free(state->compressed);
|
|
|
|
free(state);
|
|
|
|
|
|
|
|
/* Override the error message if we know what really went wrong. */
|
|
|
|
switch (ret) {
|
|
|
|
case BZ_PARAM_ERROR:
|
2007-03-03 07:37:37 +00:00
|
|
|
archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
|
2004-02-09 23:22:54 +00:00
|
|
|
"Internal error initializing compression library: "
|
|
|
|
"invalid setup parameter");
|
|
|
|
break;
|
|
|
|
case BZ_MEM_ERROR:
|
2007-03-03 07:37:37 +00:00
|
|
|
archive_set_error(&a->archive, ENOMEM,
|
2004-02-09 23:22:54 +00:00
|
|
|
"Internal error initializing compression library: "
|
|
|
|
"out of memory");
|
|
|
|
break;
|
|
|
|
case BZ_CONFIG_ERROR:
|
2007-03-03 07:37:37 +00:00
|
|
|
archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
|
2004-02-09 23:22:54 +00:00
|
|
|
"Internal error initializing compression library: "
|
|
|
|
"mis-compiled library");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (ARCHIVE_FATAL);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-04-17 00:42:45 +00:00
|
|
|
/*
|
|
|
|
* Set write options.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
archive_compressor_bzip2_options(struct archive_write *a, const char *key,
|
|
|
|
const char *value)
|
|
|
|
{
|
|
|
|
struct private_config *config;
|
|
|
|
|
|
|
|
config = (struct private_config *)a->compressor.config;
|
|
|
|
if (strcmp(key, "compression-level") == 0) {
|
|
|
|
if (value == NULL || !(value[0] >= '0' && value[0] <= '9') ||
|
|
|
|
value[1] != '\0')
|
|
|
|
return (ARCHIVE_WARN);
|
|
|
|
config->compression_level = value[0] - '0';
|
|
|
|
/* Make '0' be a synonym for '1'. */
|
|
|
|
/* This way, bzip2 compressor supports the same 0..9
|
|
|
|
* range of levels as gzip. */
|
|
|
|
if (config->compression_level < 1)
|
|
|
|
config->compression_level = 1;
|
|
|
|
return (ARCHIVE_OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (ARCHIVE_WARN);
|
|
|
|
}
|
|
|
|
|
2004-02-09 23:22:54 +00:00
|
|
|
/*
|
|
|
|
* Write data to the compressed stream.
|
2004-11-05 05:26:30 +00:00
|
|
|
*
|
|
|
|
* Returns ARCHIVE_OK if all data written, error otherwise.
|
2004-02-09 23:22:54 +00:00
|
|
|
*/
|
2004-11-05 05:26:30 +00:00
|
|
|
static int
|
2007-03-03 07:37:37 +00:00
|
|
|
archive_compressor_bzip2_write(struct archive_write *a, const void *buff,
|
2004-02-09 23:22:54 +00:00
|
|
|
size_t length)
|
|
|
|
{
|
|
|
|
struct private_data *state;
|
|
|
|
|
2007-05-29 01:00:21 +00:00
|
|
|
state = (struct private_data *)a->compressor.data;
|
2004-11-05 05:26:30 +00:00
|
|
|
if (a->client_writer == NULL) {
|
2007-03-03 07:37:37 +00:00
|
|
|
archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER,
|
2004-02-09 23:22:54 +00:00
|
|
|
"No write callback is registered? "
|
|
|
|
"This is probably an internal programming error.");
|
|
|
|
return (ARCHIVE_FATAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update statistics */
|
|
|
|
state->total_in += length;
|
|
|
|
|
|
|
|
/* Compress input data to output buffer */
|
|
|
|
SET_NEXT_IN(state, buff);
|
|
|
|
state->stream.avail_in = length;
|
|
|
|
if (drive_compressor(a, state, 0))
|
2004-11-05 05:26:30 +00:00
|
|
|
return (ARCHIVE_FATAL);
|
2007-03-03 07:37:37 +00:00
|
|
|
a->archive.file_position += length;
|
2004-11-05 05:26:30 +00:00
|
|
|
return (ARCHIVE_OK);
|
2004-02-09 23:22:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Finish the compression.
|
|
|
|
*/
|
|
|
|
static int
|
2007-03-03 07:37:37 +00:00
|
|
|
archive_compressor_bzip2_finish(struct archive_write *a)
|
2004-02-09 23:22:54 +00:00
|
|
|
{
|
|
|
|
ssize_t block_length;
|
|
|
|
int ret;
|
|
|
|
struct private_data *state;
|
|
|
|
ssize_t target_block_length;
|
2004-11-05 05:26:30 +00:00
|
|
|
ssize_t bytes_written;
|
2004-02-09 23:22:54 +00:00
|
|
|
unsigned tocopy;
|
|
|
|
|
|
|
|
ret = ARCHIVE_OK;
|
2009-04-17 00:42:45 +00:00
|
|
|
state = (struct private_data *)a->compressor.data;
|
|
|
|
if (state != NULL) {
|
|
|
|
if (a->client_writer == NULL) {
|
|
|
|
archive_set_error(&a->archive,
|
|
|
|
ARCHIVE_ERRNO_PROGRAMMER,
|
|
|
|
"No write callback is registered?\n"
|
|
|
|
"This is probably an internal programming error.");
|
|
|
|
ret = ARCHIVE_FATAL;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2004-02-09 23:22:54 +00:00
|
|
|
|
2009-04-17 00:42:45 +00:00
|
|
|
/* By default, always pad the uncompressed data. */
|
|
|
|
if (a->pad_uncompressed) {
|
|
|
|
tocopy = a->bytes_per_block -
|
|
|
|
(state->total_in % a->bytes_per_block);
|
|
|
|
while (tocopy > 0 && tocopy < (unsigned)a->bytes_per_block) {
|
|
|
|
SET_NEXT_IN(state, a->nulls);
|
|
|
|
state->stream.avail_in = tocopy < a->null_length ?
|
|
|
|
tocopy : a->null_length;
|
|
|
|
state->total_in += state->stream.avail_in;
|
|
|
|
tocopy -= state->stream.avail_in;
|
|
|
|
ret = drive_compressor(a, state, 0);
|
|
|
|
if (ret != ARCHIVE_OK)
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2004-02-09 23:22:54 +00:00
|
|
|
}
|
|
|
|
|
2009-04-17 00:42:45 +00:00
|
|
|
/* Finish compression cycle. */
|
|
|
|
if ((ret = drive_compressor(a, state, 1)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
/* Optionally, pad the final compressed block. */
|
|
|
|
block_length = state->stream.next_out - state->compressed;
|
|
|
|
|
|
|
|
/* Tricky calculation to determine size of last block. */
|
|
|
|
if (a->bytes_in_last_block <= 0)
|
|
|
|
/* Default or Zero: pad to full block */
|
|
|
|
target_block_length = a->bytes_per_block;
|
|
|
|
else
|
|
|
|
/* Round length to next multiple of bytes_in_last_block. */
|
|
|
|
target_block_length = a->bytes_in_last_block *
|
|
|
|
( (block_length + a->bytes_in_last_block - 1) /
|
|
|
|
a->bytes_in_last_block);
|
|
|
|
if (target_block_length > a->bytes_per_block)
|
|
|
|
target_block_length = a->bytes_per_block;
|
|
|
|
if (block_length < target_block_length) {
|
|
|
|
memset(state->stream.next_out, 0,
|
|
|
|
target_block_length - block_length);
|
|
|
|
block_length = target_block_length;
|
|
|
|
}
|
2004-02-09 23:22:54 +00:00
|
|
|
|
2009-04-17 00:42:45 +00:00
|
|
|
/* Write the last block */
|
|
|
|
bytes_written = (a->client_writer)(&a->archive, a->client_data,
|
|
|
|
state->compressed, block_length);
|
2004-02-09 23:22:54 +00:00
|
|
|
|
2009-04-17 00:42:45 +00:00
|
|
|
/* TODO: Handle short write of final block. */
|
|
|
|
if (bytes_written <= 0)
|
|
|
|
ret = ARCHIVE_FATAL;
|
|
|
|
else {
|
|
|
|
a->archive.raw_position += ret;
|
|
|
|
ret = ARCHIVE_OK;
|
|
|
|
}
|
2004-02-09 23:22:54 +00:00
|
|
|
|
2009-04-17 00:42:45 +00:00
|
|
|
/* Cleanup: shut down compressor, release memory, etc. */
|
2004-02-09 23:22:54 +00:00
|
|
|
cleanup:
|
2009-04-17 00:42:45 +00:00
|
|
|
switch (BZ2_bzCompressEnd(&(state->stream))) {
|
|
|
|
case BZ_OK:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER,
|
|
|
|
"Failed to clean up compressor");
|
|
|
|
ret = ARCHIVE_FATAL;
|
|
|
|
}
|
2004-02-09 23:22:54 +00:00
|
|
|
|
2009-04-17 00:42:45 +00:00
|
|
|
free(state->compressed);
|
|
|
|
free(state);
|
|
|
|
}
|
|
|
|
/* Free configuration data even if we were never fully initialized. */
|
|
|
|
free(a->compressor.config);
|
|
|
|
a->compressor.config = NULL;
|
2004-02-09 23:22:54 +00:00
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Utility function to push input data through compressor, writing
|
|
|
|
* full output blocks as necessary.
|
|
|
|
*
|
|
|
|
* Note that this handles both the regular write case (finishing ==
|
|
|
|
* false) and the end-of-archive case (finishing == true).
|
|
|
|
*/
|
|
|
|
static int
|
2007-03-03 07:37:37 +00:00
|
|
|
drive_compressor(struct archive_write *a, struct private_data *state, int finishing)
|
2004-02-09 23:22:54 +00:00
|
|
|
{
|
2004-11-05 05:26:30 +00:00
|
|
|
ssize_t bytes_written;
|
|
|
|
int ret;
|
2004-02-09 23:22:54 +00:00
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
if (state->stream.avail_out == 0) {
|
2007-03-03 07:37:37 +00:00
|
|
|
bytes_written = (a->client_writer)(&a->archive,
|
|
|
|
a->client_data, state->compressed,
|
|
|
|
state->compressed_buffer_size);
|
2004-11-05 05:26:30 +00:00
|
|
|
if (bytes_written <= 0) {
|
2004-02-09 23:22:54 +00:00
|
|
|
/* TODO: Handle this write failure */
|
|
|
|
return (ARCHIVE_FATAL);
|
2004-11-05 05:26:30 +00:00
|
|
|
} else if ((size_t)bytes_written < state->compressed_buffer_size) {
|
2004-02-09 23:22:54 +00:00
|
|
|
/* Short write: Move remainder to
|
|
|
|
* front and keep filling */
|
|
|
|
memmove(state->compressed,
|
2004-11-05 05:26:30 +00:00
|
|
|
state->compressed + bytes_written,
|
|
|
|
state->compressed_buffer_size - bytes_written);
|
2004-02-09 23:22:54 +00:00
|
|
|
}
|
|
|
|
|
2007-03-03 07:37:37 +00:00
|
|
|
a->archive.raw_position += bytes_written;
|
2004-02-09 23:22:54 +00:00
|
|
|
state->stream.next_out = state->compressed +
|
2004-11-05 05:26:30 +00:00
|
|
|
state->compressed_buffer_size - bytes_written;
|
|
|
|
state->stream.avail_out = bytes_written;
|
2004-02-09 23:22:54 +00:00
|
|
|
}
|
|
|
|
|
2007-12-30 04:58:22 +00:00
|
|
|
/* If there's nothing to do, we're done. */
|
|
|
|
if (!finishing && state->stream.avail_in == 0)
|
|
|
|
return (ARCHIVE_OK);
|
|
|
|
|
2004-02-09 23:22:54 +00:00
|
|
|
ret = BZ2_bzCompress(&(state->stream),
|
|
|
|
finishing ? BZ_FINISH : BZ_RUN);
|
|
|
|
|
|
|
|
switch (ret) {
|
|
|
|
case BZ_RUN_OK:
|
|
|
|
/* In non-finishing case, did compressor
|
|
|
|
* consume everything? */
|
|
|
|
if (!finishing && state->stream.avail_in == 0)
|
|
|
|
return (ARCHIVE_OK);
|
|
|
|
break;
|
|
|
|
case BZ_FINISH_OK: /* Finishing: There's more work to do */
|
|
|
|
break;
|
|
|
|
case BZ_STREAM_END: /* Finishing: all done */
|
|
|
|
/* Only occurs in finishing case */
|
|
|
|
return (ARCHIVE_OK);
|
|
|
|
default:
|
|
|
|
/* Any other return value indicates an error */
|
2007-03-03 07:37:37 +00:00
|
|
|
archive_set_error(&a->archive,
|
|
|
|
ARCHIVE_ERRNO_PROGRAMMER,
|
2007-12-30 04:58:22 +00:00
|
|
|
"Bzip2 compression failed;"
|
|
|
|
" BZ2_bzCompress() returned %d",
|
|
|
|
ret);
|
2004-02-09 23:22:54 +00:00
|
|
|
return (ARCHIVE_FATAL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-07-30 04:14:47 +00:00
|
|
|
|
|
|
|
#endif /* HAVE_BZLIB_H */
|