summaryrefslogtreecommitdiff
path: root/ringbuf.c
diff options
context:
space:
mode:
Diffstat (limited to 'ringbuf.c')
-rw-r--r--ringbuf.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/ringbuf.c b/ringbuf.c
index 797182ba..be82945e 100644
--- a/ringbuf.c
+++ b/ringbuf.c
@@ -59,8 +59,9 @@ ringbuf_write (ringbuf_t *p, char *bytes, size_t size) {
int
ringbuf_read (ringbuf_t *p, char *bytes, size_t size) {
if (p->remaining < size) {
- return -1;
+ size = p->remaining;
}
+ int rb = size;
if (p->size - p->cursor >= size) {
memcpy (bytes, p->bytes + p->cursor, size);
@@ -80,4 +81,5 @@ ringbuf_read (ringbuf_t *p, char *bytes, size_t size) {
p->cursor = size;
p->remaining -= size;
}
+ return rb;
}