dovecot-2.2: iostream-temp: Support o_stream_pwrite()

dovecot at dovecot.org dovecot at dovecot.org
Mon Jan 13 22:44:46 EET 2014


details:   http://hg.dovecot.org/dovecot-2.2/rev/3df6ebae9e5a
changeset: 17097:3df6ebae9e5a
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Jan 13 22:44:34 2014 +0200
description:
iostream-temp: Support o_stream_pwrite()

diffstat:

 src/lib/iostream-temp.c |  19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)

diffs (36 lines):

diff -r 436117bbac78 -r 3df6ebae9e5a src/lib/iostream-temp.c
--- a/src/lib/iostream-temp.c	Mon Jan 13 20:57:12 2014 +0200
+++ b/src/lib/iostream-temp.c	Mon Jan 13 22:44:34 2014 +0200
@@ -188,6 +188,24 @@
 			      instream, IO_BLOCK_SIZE);
 }
 
+static int
+o_stream_temp_write_at(struct ostream_private *stream,
+		       const void *data, size_t size, uoff_t offset)
+{
+	struct temp_ostream *tstream = (struct temp_ostream *)stream;
+
+	if (tstream->fd == -1) {
+		i_assert(stream->ostream.offset == tstream->buf->used);
+		buffer_write(tstream->buf, offset, data, size);
+		stream->ostream.offset = tstream->buf->used;
+	} else if (pwrite_full(tstream->fd, data, size, offset) < 0) {
+		stream->ostream.stream_errno = errno;
+		i_close_fd(&tstream->fd);
+		return -1;
+	}
+	return 0;
+}
+
 struct ostream *iostream_temp_create(const char *temp_path_prefix,
 				     enum iostream_temp_flags flags)
 {
@@ -197,6 +215,7 @@
 	tstream = i_new(struct temp_ostream, 1);
 	tstream->ostream.sendv = o_stream_temp_sendv;
 	tstream->ostream.send_istream = o_stream_temp_send_istream;
+	tstream->ostream.write_at = o_stream_temp_write_at;
 	tstream->ostream.iostream.close = o_stream_temp_close;
 	tstream->temp_path_prefix = i_strdup(temp_path_prefix);
 	tstream->flags = flags;


More information about the dovecot-cvs mailing list