From a1579ba86df9787c9ff706580380e5474df5b808 Mon Sep 17 00:00:00 2001 From: Nicolas Pennequin Date: Sat, 4 Aug 2007 21:14:47 +0200 Subject: [PATCH] bufread: Make it behave correctly. * Correct the behaviour towards the end of the file (it simply wasn't detected). * Don't advance the buffer reading pointer. * Don't change h->available !! Tested successfully on target (gigabeat) and in the sim. --- testplugin.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/testplugin.c b/testplugin.c index 64457a5..13319ae 100644 --- a/testplugin.c +++ b/testplugin.c @@ -599,7 +599,7 @@ ssize_t bufread(int handle_id, size_t size, char *dest) if (h->available == 0 && h->filerem == 0) /* File is finished reading */ return 0; - buffered_data = MIN(size, h->available); + buffered_data = MIN(size, h->available - RINGBUF_SUB(h->ridx, h->data)); if (h->ridx + buffered_data > buffer_len) { @@ -609,8 +609,6 @@ ssize_t bufread(int handle_id, size_t size, char *dest) } else rb->memcpy(dest, &buffer[h->ridx], buffered_data); - h->ridx = RINGBUF_ADD(h->ridx, buffered_data); - h->available -= buffered_data; return buffered_data; } -- 2.11.4.GIT