diff options
author | Behdad Esfahbod <behdad@behdad.org> | 2009-09-14 16:07:17 -0400 |
---|---|---|
committer | Behdad Esfahbod <behdad@behdad.org> | 2009-09-15 21:26:42 -0400 |
commit | d6330cf885ff25c6607e0624c03f00daf15bb68b (patch) | |
tree | 16b56a0c55abb900a47461c0a162be48a43d1d44 /src | |
parent | 338d4a485f5b7609be1861aed6558693f90955c1 (diff) |
[stream] Add head()
Diffstat (limited to 'src')
-rw-r--r-- | src/vtestream-base.h | 7 | ||||
-rw-r--r-- | src/vtestream-file.h | 12 | ||||
-rw-r--r-- | 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 */ |