From: Timo Sirainen Date: Mon, 11 Jan 2016 17:00:07 +0000 (+0200) Subject: lib: i_stream_get_error() now returns "EOF" if stream_errno==0 and eof==TRUE. X-Git-Tag: 2.2.22.rc1~371 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=46ce4d9273e6df12ef1912bbdb1c8b84b104f394;p=thirdparty%2Fdovecot%2Fcore.git lib: i_stream_get_error() now returns "EOF" if stream_errno==0 and eof==TRUE. This can be used to replace a lot of code like: input->stream_errno == 0 ? "EOF" : i_stream_get_error(input) with simply: i_stream_get_error(input) --- diff --git a/src/lib/istream.c b/src/lib/istream.c index 2a122e2347..187843a395 100644 --- a/src/lib/istream.c +++ b/src/lib/istream.c @@ -82,10 +82,11 @@ const char *i_stream_get_error(struct istream *stream) { struct istream *s; - /* we'll only return errors for streams that have stream_errno set. - we might be returning unintended error otherwise. */ + /* we'll only return errors for streams that have stream_errno set or + that have reached EOF. we might be returning unintended error + otherwise. */ if (stream->stream_errno == 0) - return ""; + return stream->eof ? "EOF" : ""; for (s = stream; s != NULL; s = s->real_stream->parent) { if (s->stream_errno == 0) diff --git a/src/lib/istream.h b/src/lib/istream.h index 61ac9789e3..d47d36bdb9 100644 --- a/src/lib/istream.h +++ b/src/lib/istream.h @@ -74,7 +74,8 @@ void i_stream_remove_destroy_callback(struct istream *stream, /* Return file descriptor for stream, or -1 if none is available. */ int i_stream_get_fd(struct istream *stream); -/* Returns error string for the last error. */ +/* Returns error string for the last error. It also returns "EOF" in case there + is no error, but eof is set. Otherwise it returns "". */ const char *i_stream_get_error(struct istream *stream); /* Mark the stream and all of its parent streams closed. Any reads after this