From 3386dd7be90f4f4a23d36359f2052fa834fb20e7 Mon Sep 17 00:00:00 2001 From: Brandon Low Date: Wed, 28 Nov 2007 04:58:16 +0000 Subject: Fix FS8069, because Nico_P made it easy git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15840 a1c6a512-1295-4272-9138-f99709370657 --- apps/buffering.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'apps/buffering.c') diff --git a/apps/buffering.c b/apps/buffering.c index f0a50c274c..f5bc2eeb19 100644 --- a/apps/buffering.c +++ b/apps/buffering.c @@ -657,6 +657,7 @@ static bool buffer_handle(int handle_id) /* finished buffering the file */ close(h->fd); h->fd = -1; + call_buffering_callbacks(EVENT_HANDLE_FINISHED, h->id); } return true; @@ -1138,6 +1139,58 @@ ssize_t bufgetdata(int handle_id, size_t size, void **data) return size; } +ssize_t bufgettail(int handle_id, size_t size, void **data) +{ + size_t tidx; + + const struct memory_handle *h; + + h = find_handle(handle_id); + + if (!h) + return ERR_HANDLE_NOT_FOUND; + + if (h->filerem) + return ERR_HANDLE_NOT_DONE; + + /* We don't support tail requests of > guardbuf_size, for simplicity */ + if (size > GUARD_BUFSIZE) + return ERR_INVALID_VALUE; + + tidx = RINGBUF_SUB(h->widx, size); + + if (tidx + size > buffer_len) + { + size_t copy_n = tidx + size - buffer_len; + memcpy(guard_buffer, (unsigned char *)buffer, copy_n); + } + + *data = &buffer[tidx]; + return size; +} + +ssize_t bufcuttail(int handle_id, size_t size) +{ + struct memory_handle *h; + + h = find_handle(handle_id); + + if (!h) + return ERR_HANDLE_NOT_FOUND; + + if (h->filerem) + return ERR_HANDLE_NOT_DONE; + + if (h->available < size) + size = h->available; + + h->available -= size; + h->filesize -= size; + h->widx = RINGBUF_SUB(h->widx, size); + return size; +} + + /* SECONDARY EXPORTED FUNCTIONS ============================ -- cgit v1.2.3