lib/stream: Add stream_discard, to discard read data from a stream

* stream.c: (stream_discard) Discard the already data from a stream, as
  indicated by the getp. Move remaining, unread data, to the beginning of
  the stream. get and end stream pointers are updated as appropriate.

  If all data has been consumed, then this behaves identically to
  stream_reset.
diff --git a/lib/stream.c b/lib/stream.c
index b50992d..ed677c1 100644
--- a/lib/stream.c
+++ b/lib/stream.c
@@ -960,6 +960,31 @@
   s->getp = s->endp = 0;
 }
 
+/* Discard read data (prior to the getp), and move the unread data
+ * to the beginning of the stream.
+ *
+ * See also stream_fifo_* functions, for another approach to managing
+ * streams.
+ */
+void
+stream_discard (struct stream *s)
+{
+  STREAM_VERIFY_SANE (s);
+  
+  if (s->getp == 0)
+    return;
+  
+  if (s->getp == s->endp)
+    {
+      stream_reset (s);
+      return;
+    }
+  
+  s->data = memmove (s->data, s->data + s->getp, s->endp - s->getp);
+  s->endp -= s->getp;
+  s->getp = 0;
+}
+
 /* Write stream contens to the file discriptor. */
 int
 stream_flush (struct stream *s, int fd)
diff --git a/lib/stream.h b/lib/stream.h
index 06b0ee1..9127bcd 100644
--- a/lib/stream.h
+++ b/lib/stream.h
@@ -218,6 +218,8 @@
 
 /* reset the stream. See Note above */
 extern void stream_reset (struct stream *);
+/* move unread data to start of stream, discarding read data */
+extern void stream_discard (struct stream *);
 extern int stream_flush (struct stream *, int);
 extern int stream_empty (struct stream *); /* is the stream empty? */