istream-seekable.c revision 032964c7cc6788188b63ae6270fc26cbd4a3ca26
/* Copyright (c) 2005-2012 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "buffer.h"
#include "read-full.h"
#include "write-full.h"
#include "istream-private.h"
#include "istream-concat.h"
#include "istream-seekable.h"
#include <unistd.h>
struct seekable_istream {
struct istream_private istream;
char *temp_path;
void *context;
unsigned int cur_idx;
int fd;
};
{
unsigned int i;
}
{
unsigned int i;
}
static void
{
unsigned int i;
}
{
const char *path;
const unsigned char *buffer;
int fd;
if (fd == -1)
return -1;
/* copy our currently read buffer to it */
i_close_fd(&fd);
return -1;
}
/* read back the data we just had in our buffer */
for (;;) {
break;
i_error("istream-seekable: Couldn't read back "
"in-memory input %s",
return -1;
}
}
return 0;
}
{
return -1;
}
/* full / error */
return -1;
}
/* go to next stream */
/* last one, EOF */
return -1;
}
/* see if stream has pending data */
if (size != 0)
return size;
}
return ret;
}
{
const unsigned char *data;
/* need to read more */
return FALSE;
if (size == 0) {
/* read more to buffer */
if (*ret_r <= 0)
return TRUE;
}
/* we should have more now. */
}
return TRUE;
}
{
void *data;
return -1;
}
return 0;
}
{
const unsigned char *data;
return ret;
/* copy everything to temp file and use it as the stream */
if (copy_to_temp_file(sstream) < 0) {
i_unreached();
return ret;
}
}
/* need to read more */
if (ret <= 0)
return ret;
/* save to our file */
if (ret <= 0) {
i_error("write_full(%s) failed: %m",
}
if (i_stream_seekable_write_failed(sstream) < 0)
return -1;
i_unreached();
return ret;
}
}
if (ret <= 0) {
} else {
ret = -2;
}
return ret;
}
static const struct stat *
{
/* we've already reached EOF and know the size */
}
/* we want to know the full size of the file, so read until
we're finished */
do {
if (ret == 0) {
i_panic("i_stream_stat() used for non-blocking "
"seekable stream %s offset %"PRIuUOFF_T,
}
}
/* using a file backed buffer, we can use real fstat() */
} else {
/* buffer is completely in memory */
}
}
struct istream *
void *context)
{
struct seekable_istream *sstream;
const unsigned char *data;
unsigned int count;
/* If all input streams are seekable, use concat istream instead */
break;
}
return i_stream_create_concat(input);
/* if any of the streams isn't blocking, set ourself also nonblocking */
}
/* initialize our buffer from first stream's pending data */
}