istream-bzlib.c revision 0c799f899bbbb08315f1fe9df5e12a948c72aeba
/* Copyright (c) 2010 Dovecot authors, see the included COPYING file */
#include "lib.h"
#ifdef HAVE_BZLIB
#include "istream-internal.h"
#include "istream-zlib.h"
#include <bzlib.h>
struct bzlib_istream {
struct istream_private istream;
unsigned int marked:1;
unsigned int zs_closed:1;
};
{
}
}
{
const unsigned char *data;
int ret;
return -1;
}
/* try to keep at least CHUNK_SIZE available */
/* don't try to keep anything cached if we don't
have a seek mark. */
}
if (stream->max_buffer_size == 0 ||
/* lose our buffer cache */
}
return -2; /* buffer full */
}
}
/* need to read more data. try to read a full CHUNK_SIZE */
} else {
/* unexpected eof */
}
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:
case BZ_DATA_ERROR_MAGIC:
return -1;
case BZ_MEM_ERROR:
case BZ_STREAM_END:
if (size == 0) {
return -1;
}
break;
default:
}
if (size == 0) {
/* read more input */
return i_stream_bzlib_read(stream);
}
return 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 -
break;
}
} while (i_stream_bzlib_read(stream) >= 0);
/* some failure, we've broken it */
i_error("bzlib_istream.seek() failed: %s",
} else {
/* unexpected EOF. allow it since we may just
want to check if there's anything.. */
}
}
}
if (mark) {
}
}
static const struct stat *
{
return NULL;
return st;
do {
} while (i_stream_bzlib_read(stream) > 0);
return NULL;
}
}
{
}
{
struct bzlib_istream *zstream;
}
#endif