aboutsummaryrefslogtreecommitdiff
path: root/src/std/buffer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/std/buffer.c')
-rw-r--r--src/std/buffer.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/std/buffer.c b/src/std/buffer.c
index a482bb9..021fce8 100644
--- a/src/std/buffer.c
+++ b/src/std/buffer.c
@@ -94,6 +94,19 @@ void buffer_clear(Buffer *self) {
self->size = 0;
}
+int buffer_set_capacity(Buffer *self, usize new_capacity) {
+ if(am_realloc(self->data, new_capacity, (void**)&self->data) != ALLOC_OK)
+ return BUFFER_ALLOC_FAIL;
+
+ self->capacity = new_capacity;
+ if(self->size < self->capacity)
+ self->size = self->capacity;
+ /* Update list of buffers in the allocator with the new address of the buffer data */
+ if(self->allocator)
+ am_memcpy(self->allocator->mems.data + sizeof(void*) * self->allocator_index, &self->data, sizeof(void*));
+ return BUFFER_OK;
+}
+
void* buffer_begin(Buffer *self) {
return self->data;
}