aboutsummaryrefslogtreecommitdiff
path: root/lib/cbit/cqueue.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/cbit/cqueue.c')
-rw-r--r--lib/cbit/cqueue.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/cbit/cqueue.c b/lib/cbit/cqueue.c
new file mode 100644
index 0000000..aebc265
--- /dev/null
+++ b/lib/cbit/cqueue.c
@@ -0,0 +1,23 @@
+#include "circle.h"
+
+void cqueue_realloc_internal(struct cqueue_internal *ci,
+ size_t new_capacity_bytes) {
+ char *storage = (char *) malloc(new_capacity_bytes);
+ char *new_write_ptr;
+ if (c->write_ptr >= c->read_ptr) {
+ size_t diff = c->write_ptr - c->read_ptr;
+ memcpy(storage, c->read_ptr, diff);
+ new_write_ptr = storage + diff;
+ } else {
+ size_t diff1 = c->end - c->read_ptr;
+ size_t diff2 = c->write_ptr - c->start;
+ memcpy(storage, c->read_ptr, diff1);
+ char *tmp = storage + diff1;
+ memcpy(tmp, c->start, diff2);
+ new_write_ptr = tmp + diff2;
+ }
+ c->start = storage;
+ c->end = storage + new_capacity_bytes;
+ c->read_ptr = storage;
+ c->write_ptr = new_write_ptr;
+}