[vte] [stream] Add head()



commit d6330cf885ff25c6607e0624c03f00daf15bb68b
Author: Behdad Esfahbod <behdad behdad org>
Date:   Mon Sep 14 16:07:17 2009 -0400

    [stream] Add head()

 src/vtestream-base.h |    7 +++++++
 src/vtestream-file.h |   12 ++++++++++++
 src/vtestream.h      |    1 +
 3 files changed, 20 insertions(+), 0 deletions(-)
---
diff --git a/src/vtestream-base.h b/src/vtestream-base.h
index 8d5e86f..b79179a 100644
--- a/src/vtestream-base.h
+++ b/src/vtestream-base.h
@@ -36,6 +36,7 @@ typedef struct _VteStreamClass {
 	void (*read) (VteStream *stream, gsize offset, char *data, gsize len);
 	void (*truncate) (VteStream *stream, gsize offset);
 	void (*new_page) (VteStream *stream);
+	gsize (*head) (VteStream *stream);
 } VteStreamClass;
 
 static GType _vte_stream_get_type (void);
@@ -83,3 +84,9 @@ _vte_stream_new_page (VteStream *stream)
 {
 	VTE_STREAM_GET_CLASS (stream)->new_page (stream);
 }
+
+gsize
+_vte_stream_head (VteStream *stream)
+{
+	return VTE_STREAM_GET_CLASS (stream)->head (stream);
+}
diff --git a/src/vtestream-file.h b/src/vtestream-file.h
index 78a0234..f9b7d7c 100644
--- a/src/vtestream-file.h
+++ b/src/vtestream-file.h
@@ -231,6 +231,17 @@ _vte_file_stream_new_page (VteStream *astream)
 		_xtruncate (stream->fd[0], 0);
 }
 
+static gsize
+_vte_file_stream_head (VteStream *astream)
+{
+	VteFileStream *stream = (VteFileStream *) astream;
+
+	if (stream->fd[0])
+		return stream->offset[0] += lseek (stream->fd[0], 0, SEEK_END);
+	else
+		return stream->offset[0];
+}
+
 static void
 _vte_file_stream_class_init (VteFileStreamClass *klass)
 {
@@ -243,4 +254,5 @@ _vte_file_stream_class_init (VteFileStreamClass *klass)
 	klass->read = _vte_file_stream_read;
 	klass->truncate = _vte_file_stream_truncate;
 	klass->new_page = _vte_file_stream_new_page;
+	klass->head = _vte_file_stream_head;
 }
diff --git a/src/vtestream.h b/src/vtestream.h
index 649e8fe..ec45fcc 100644
--- a/src/vtestream.h
+++ b/src/vtestream.h
@@ -32,6 +32,7 @@ gsize _vte_stream_append (VteStream *stream, const char *data, gsize len);
 void _vte_stream_read (VteStream *stream, gsize offset, char *data, gsize len);
 void _vte_stream_truncate (VteStream *stream, gsize offset);
 void _vte_stream_new_page (VteStream *stream);
+gsize _vte_stream_head (VteStream *stream);
 
 
 /* Various streams */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]