From 16aaaa19a3ef4220726007d3e644ced0c9e06513 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 9 Sep 2019 01:08:34 +0200 Subject: Allow referencing code in imported file (right now for function calls, allow calling a function in another file) --- src/std/buffer.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/std/buffer.c') 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; } -- cgit v1.2.3