]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: i_stream_get_error() now returns "EOF" if stream_errno==0 and eof==TRUE.
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 11 Jan 2016 17:00:07 +0000 (19:00 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 11 Jan 2016 17:00:07 +0000 (19:00 +0200)
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)

src/lib/istream.c
src/lib/istream.h

index 2a122e234704686f59e3281b000968d94c93388b..187843a395eff127439f5d3f9d2047911cb6fd6b 100644 (file)
@@ -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 "<no error>";
+               return stream->eof ? "EOF" : "<no error>";
 
        for (s = stream; s != NULL; s = s->real_stream->parent) {
                if (s->stream_errno == 0)
index 61ac9789e378702763f7eb5ba30c221be26c6a87..d47d36bdb95a140eac4b88c54719bf3af7cb496f 100644 (file)
@@ -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 "<no error>". */
 const char *i_stream_get_error(struct istream *stream);
 
 /* Mark the stream and all of its parent streams closed. Any reads after this