changeset 7342:c1c977afe06c HEAD

Added support for seeking forwards in the stream.
author Timo Sirainen <tss@iki.fi>
date Tue, 04 Mar 2008 08:01:51 +0200
parents af998ae4254b
children 034e18a91a6b
files src/lib/istream-crlf.c
diffstat 1 files changed, 23 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib/istream-crlf.c	Tue Mar 04 07:54:53 2008 +0200
+++ b/src/lib/istream-crlf.c	Tue Mar 04 08:01:51 2008 +0200
@@ -151,11 +151,30 @@
 	return ret;
 }
 
-static void ATTR_NORETURN
-i_stream_crlf_seek(struct istream_private *stream ATTR_UNUSED,
-		   uoff_t v_offset ATTR_UNUSED, bool mark ATTR_UNUSED)
+static void
+i_stream_crlf_seek(struct istream_private *stream,
+		   uoff_t v_offset, bool mark ATTR_UNUSED)
 {
-	i_panic("crlf-istream: seeking unsupported currently");
+	size_t available;
+
+	if (stream->istream.v_offset > v_offset)
+		i_panic("crlf-istream: seeking unsupported currently");
+
+	while (stream->istream.v_offset < v_offset) {
+		(void)i_stream_crlf_read_crlf(stream);
+
+		available = stream->pos - stream->skip;
+		if (available == 0) {
+			stream->istream.stream_errno = ESPIPE;
+			return;
+		}
+		if (available <= v_offset - stream->istream.v_offset)
+			i_stream_skip(&stream->istream, available);
+		else {
+			i_stream_skip(&stream->istream,
+				      v_offset - stream->istream.v_offset);
+		}
+	}
 }
 
 static const struct stat *