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)
{
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)
/* 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