/* Copyright (c) 2010-2018 Dovecot authors, see the included COPYING file */
#include "lib.h"
#ifdef HAVE_BZLIB
#include "istream-private.h"
#include "istream-zlib.h"
#include <bzlib.h>
struct bzlib_istream {
};
bool close_parent)
{
}
if (close_parent)
}
{
"bzlib.read(%s): %s at %"PRIuUOFF_T,
if (zstream->log_errors)
}
{
const unsigned char *data;
int ret;
return -1;
}
/* we're here because we seeked back within the read buffer. */
}
return ret;
}
return -2; /* buffer full */
} else {
/* try to avoid compressing, so we can quickly seek backwards */
return -2; /* buffer full */
}
} else {
}
return -1;
}
if (size == 0) {
/* no more input */
return 0;
}
switch (ret) {
case BZ_OK:
break;
case BZ_PARAM_ERROR:
i_unreached();
case BZ_DATA_ERROR:
return -1;
case BZ_DATA_ERROR_MAGIC:
"wrong magic in header (not bz2 file?)");
return -1;
case BZ_MEM_ERROR:
case BZ_STREAM_END:
if (out_size == 0) {
return -1;
}
break;
default:
}
if (out_size == 0) {
/* read more input */
return i_stream_bzlib_read(stream);
}
return out_size;
}
{
int ret;
switch (ret) {
case BZ_OK:
break;
case BZ_MEM_ERROR:
case BZ_CONFIG_ERROR:
i_fatal("Wrong bzlib library version (broken compilation)");
case BZ_PARAM_ERROR:
i_fatal("bzlib: Invalid parameters");
default:
}
}
{
}
static void
{
if (v_offset < start_offset) {
/* have to seek backwards */
start_offset = 0;
}
/* seeking backwards within what's already cached */
} else {
/* read and cache forward */
do {
v_offset -
ret = -1;
break;
}
/* some failure, we've broken it */
i_error("bzlib_istream.seek(%s) failed: %s",
} else {
/* unexpected EOF. allow it since we may just
want to check if there's anything.. */
}
}
}
if (mark)
}
static int
{
return -1;
}
/* when exact=FALSE always return the parent stat's size, even if we
know the exact value. this is necessary because otherwise e.g. mbox
code can see two different values and think that a compressed mbox
file keeps changing. */
if (!exact)
return 0;
do {
return -1;
}
return 0;
}
{
/* a compressed file doesn't change unexpectedly,
don't clear our caches unnecessarily */
return;
}
}
}
{
i_stream_get_fd(input), 0);
}
#endif