changeset 7188:febb2592e616 HEAD

If EOF is triggered with keyboard (^D), make sure to return EOF for future reads as well.
author Timo Sirainen <tss@iki.fi>
date Fri, 25 Jan 2008 13:36:35 +0200
parents d9b87e3ce6c8
children 34057a03a357
files src/lib/istream-file.c
diffstat 1 files changed, 7 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib/istream-file.c	Tue Jan 22 09:33:40 2008 +0200
+++ b/src/lib/istream-file.c	Fri Jan 25 13:36:35 2008 +0200
@@ -18,6 +18,7 @@
 
 	unsigned int file:1;
 	unsigned int autoclose_fd:1;
+	unsigned int seen_eof:1;
 };
 
 static void i_stream_file_close(struct iostream_private *stream)
@@ -54,6 +55,10 @@
 			ret = pread(stream->fd, stream->w_buffer + stream->pos,
 				    size, stream->istream.v_offset +
 				    (stream->pos - stream->skip));
+		} else if (fstream->seen_eof) {
+			/* don't try to read() again. EOF from keyboard (^D)
+			   requires this to work right. */
+			ret = 0;
 		} else {
 			ret = read(stream->fd, stream->w_buffer + stream->pos,
 				   size);
@@ -64,6 +69,7 @@
 	if (ret == 0) {
 		/* EOF */
 		stream->istream.eof = TRUE;
+		fstream->seen_eof = TRUE;
 		return -1;
 	}
 
@@ -114,6 +120,7 @@
 	stream->istream.stream_errno = 0;
 	stream->istream.v_offset = v_offset;
 	stream->skip = stream->pos = 0;
+	fstream->seen_eof = FALSE;
 }
 
 static void i_stream_file_sync(struct istream_private *stream)