summaryrefslogtreecommitdiffstats
path: root/src/memblock.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/memblock.c')
-rw-r--r--src/memblock.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/memblock.c b/src/memblock.c
index 067243c5..79fe2977 100644
--- a/src/memblock.c
+++ b/src/memblock.c
@@ -78,3 +78,17 @@ void memblock_unref_fixed(struct memblock *b) {
b->type = MEMBLOCK_DYNAMIC;
}
+void memchunk_make_writable(struct memchunk *c) {
+ struct memblock *n;
+ assert(c && c->memblock && c->memblock->ref >= 1);
+
+ if (c->memblock->ref == 1)
+ return;
+
+ n = memblock_new(c->length);
+ assert(n);
+ memcpy(n->data, c->memblock->data+c->index, c->length);
+ memblock_unref(c->memblock);
+ c->memblock = n;
+ c->index = 0;
+}