From b90fb7f78aca271243c26074ddd6587cce112a1e Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Mon, 16 May 2016 20:04:38 +0300 Subject: [PATCH] lib: Added o_stream_nsend_istream() --- src/lib/ostream.c | 21 +++++++++++++++++++++ src/lib/ostream.h | 4 ++++ 2 files changed, 25 insertions(+) diff --git a/src/lib/ostream.c b/src/lib/ostream.c index a15e9f99dc..0289d06608 100644 --- a/src/lib/ostream.c +++ b/src/lib/ostream.c @@ -374,6 +374,27 @@ int o_stream_send_istream(struct ostream *outstream, struct istream *instream) return ret; } +void o_stream_nsend_istream(struct ostream *outstream, struct istream *instream) +{ + switch (o_stream_send_istream(outstream, instream)) { + case 1: + break; + case 0: + outstream->real_stream->noverflow = TRUE; + break; + default: + if (outstream->stream_errno != 0) + break; + i_assert(instream->stream_errno != 0); + outstream->stream_errno = instream->stream_errno; + io_stream_set_error(&outstream->real_stream->iostream, + "nsend-istream: read(%s) failed: %s", + i_stream_get_name(instream), + o_stream_get_name(outstream)); + } + outstream->real_stream->last_errors_not_checked = TRUE; +} + int o_stream_pwrite(struct ostream *stream, const void *data, size_t size, uoff_t offset) { diff --git a/src/lib/ostream.h b/src/lib/ostream.h index 1c88179b0b..54d5bf6f7a 100644 --- a/src/lib/ostream.h +++ b/src/lib/ostream.h @@ -161,6 +161,10 @@ void o_stream_set_no_error_handling(struct ostream *stream, bool set); descriptor, even if the source and destination overlaps. If the file must be grown, you have to do it manually before calling this function. */ int o_stream_send_istream(struct ostream *outstream, struct istream *instream); +/* Same as o_stream_send_istream(), but assume that reads and writes will + succeed. If not, o_stream_nfinish() will fail with the correct error + message (even istream's). */ +void o_stream_nsend_istream(struct ostream *outstream, struct istream *instream); /* Write data to specified offset. Returns 0 if successful, -1 if error. */ int o_stream_pwrite(struct ostream *stream, const void *data, size_t size,