summaryrefslogtreecommitdiff
path: root/src/rb.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/rb.c')
-rw-r--r--src/rb.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/rb.c b/src/rb.c
index ce269fb..a04d0cf 100644
--- a/src/rb.c
+++ b/src/rb.c
@@ -38,6 +38,23 @@ t_rb *rb_put(t_rb *rb, const void *src, size_t n)
{
size_t size;
+ size = rb_get_size(rb);
+ if (n >= size) {
+ /* we will override the whole ring buffer */
+
+ /* the first bytes of src will not be copied, anyway */
+ src += (n - size);
+
+ memcpy(rb->buffer, src , size);
+
+ /* hardcode the values */
+ rb->size_filled = size;
+ rb->off_w = 0;
+ rb->off_r = 0;
+
+ return rb;
+ }
+
/* loop until n bytes of src have been written */
while (n != 0) {
size = MIN(n, rb_get_size(rb) - rb->off_w);