aboutsummaryrefslogtreecommitdiff
path: root/lib/cbit/cqueue.c
diff options
context:
space:
mode:
authorcomex2015-08-17 01:48:39 -0400
committercomex2015-08-17 01:48:39 -0400
commit1099ec5560a3f8e7a44547f657c0eae8bcff17f2 (patch)
treee16cf06078886c124c3956c80dbc2a85fe26fac6 /lib/cbit/cqueue.c
parentformatting (diff)
downloadsubstitute-1099ec5560a3f8e7a44547f657c0eae8bcff17f2.tar.gz
stuff
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;
+}