diff --git a/libringbuffer/include/ringbuffer/ringbuffer.h b/libringbuffer/include/ringbuffer/ringbuffer.h index 9252d0e..d7ca8d9 100644 --- a/libringbuffer/include/ringbuffer/ringbuffer.h +++ b/libringbuffer/include/ringbuffer/ringbuffer.h @@ -29,6 +29,12 @@ typedef struct ringbuffer ringbuffer_t; */ ringbuffer_t *rb_new(void *base, size_t size); +/* Check if ring buffer has data + * r - Buffer to check + * Returns Boolean representing if ringbuffer has data. + */ +int rb_has_data(ringbuffer_t *r); + /* Send a byte. * r - Buffer to send via. * c - Byte to send. diff --git a/libringbuffer/src/ringbuffer.c b/libringbuffer/src/ringbuffer.c index e4b8b0e..8ba8509 100644 --- a/libringbuffer/src/ringbuffer.c +++ b/libringbuffer/src/ringbuffer.c @@ -28,6 +28,11 @@ ringbuffer_t *rb_new(void *base, size_t size) return r; } +int rb_has_data(ringbuffer_t *r) +{ + return (r->base[r->offset] == 0); +} + void rb_transmit_byte(ringbuffer_t *r, unsigned char c) { /* We can't send 0s. */