dovecot-2.2: lib: i_stream_get_data() should also reset eof=FALS...

dovecot at dovecot.org dovecot at dovecot.org
Thu Jun 19 12:02:00 UTC 2014


details:   http://hg.dovecot.org/dovecot-2.2/rev/0d072ade062d
changeset: 17511:0d072ade062d
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Jun 19 14:58:26 2014 +0300
description:
lib: i_stream_get_data() should also reset eof=FALSE if it truncates the output.

diffstat:

 src/lib/istream.c |  26 ++++++++++++++------------
 src/lib/istream.h |   9 ++++-----
 2 files changed, 18 insertions(+), 17 deletions(-)

diffs (100 lines):

diff -r 00df4f6b5222 -r 0d072ade062d src/lib/istream.c
--- a/src/lib/istream.c	Thu Jun 19 14:34:54 2014 +0300
+++ b/src/lib/istream.c	Thu Jun 19 14:58:26 2014 +0300
@@ -329,18 +329,14 @@
 	return _stream->get_size(_stream, exact, size_r);
 }
 
-bool i_stream_have_bytes_left(const struct istream *stream)
+bool i_stream_have_bytes_left(struct istream *stream)
 {
-	const struct istream_private *_stream = stream->real_stream;
-
-	return !stream->eof || _stream->skip != _stream->pos;
+	return i_stream_get_data_size(stream) > 0 || !stream->eof;
 }
 
 bool i_stream_is_eof(struct istream *stream)
 {
-	const struct istream_private *_stream = stream->real_stream;
-
-	if (_stream->skip == _stream->pos)
+	if (i_stream_get_data_size(stream) == 0)
 		(void)i_stream_read(stream);
 	return !i_stream_have_bytes_left(stream);
 }
@@ -464,9 +460,9 @@
 }
 
 const unsigned char *
-i_stream_get_data(const struct istream *stream, size_t *size_r)
+i_stream_get_data(struct istream *stream, size_t *size_r)
 {
-	const struct istream_private *_stream = stream->real_stream;
+	struct istream_private *_stream = stream->real_stream;
 
 	if (_stream->skip >= _stream->pos) {
 		*size_r = 0;
@@ -489,6 +485,12 @@
 		   own buffer instead of pointing to parent's buffer (but this
 		   causes data copying that is nearly always unnecessary). */
 		*size_r = 0;
+		/* if we had already read until EOF, mark the stream again as
+		   not being at the end of file. */
+		if (stream->stream_errno == 0) {
+			_stream->skip = _stream->pos = 0;
+			stream->eof = FALSE;
+		}
 		return NULL;
 	}
 
@@ -496,7 +498,7 @@
         return _stream->buffer + _stream->skip;
 }
 
-size_t i_stream_get_data_size(const struct istream *stream)
+size_t i_stream_get_data_size(struct istream *stream)
 {
 	size_t size;
 
@@ -504,10 +506,10 @@
 	return size;
 }
 
-unsigned char *i_stream_get_modifiable_data(const struct istream *stream,
+unsigned char *i_stream_get_modifiable_data(struct istream *stream,
 					    size_t *size_r)
 {
-	const struct istream_private *_stream = stream->real_stream;
+	struct istream_private *_stream = stream->real_stream;
 
 	if (_stream->skip >= _stream->pos || _stream->w_buffer == NULL) {
 		*size_r = 0;
diff -r 00df4f6b5222 -r 0d072ade062d src/lib/istream.h
--- a/src/lib/istream.h	Thu Jun 19 14:34:54 2014 +0300
+++ b/src/lib/istream.h	Thu Jun 19 14:58:26 2014 +0300
@@ -119,7 +119,7 @@
    set, 0 if size is unknown, -1 if error. */
 int i_stream_get_size(struct istream *stream, bool exact, uoff_t *size_r);
 /* Returns TRUE if there are any bytes left to be read or in buffer. */
-bool i_stream_have_bytes_left(const struct istream *stream) ATTR_PURE;
+bool i_stream_have_bytes_left(struct istream *stream);
 /* Returns TRUE if there are no bytes buffered and read() returns EOF. */
 bool i_stream_is_eof(struct istream *stream);
 /* Returns the absolute offset of the stream. This is the stream's current
@@ -140,12 +140,11 @@
 
 /* Returns pointer to beginning of read data, or NULL if there's no data
    buffered. */
-const unsigned char *
-i_stream_get_data(const struct istream *stream, size_t *size_r);
-size_t i_stream_get_data_size(const struct istream *stream);
+const unsigned char *i_stream_get_data(struct istream *stream, size_t *size_r);
+size_t i_stream_get_data_size(struct istream *stream);
 /* Like i_stream_get_data(), but returns non-const data. This only works with
    buffered streams (currently only file), others return NULL. */
-unsigned char *i_stream_get_modifiable_data(const struct istream *stream,
+unsigned char *i_stream_get_modifiable_data(struct istream *stream,
 					    size_t *size_r);
 /* Like i_stream_get_data(), but read more when needed. Returns 1 if more
    than threshold bytes are available, 0 if as much or less, -1 if error or


More information about the dovecot-cvs mailing list