diff options
author | dec05eba <dec05eba@protonmail.com> | 2019-09-09 01:08:34 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-07-25 14:36:46 +0200 |
commit | 16aaaa19a3ef4220726007d3e644ced0c9e06513 (patch) | |
tree | 6a7c2fc91bc362559b079afbb10dc247d7bcbae0 /src/std/buffer.c | |
parent | de48503aef098d855754ab6f85558402130188d7 (diff) |
Allow referencing code in imported file (right now for function calls, allow calling a function in another file)
Diffstat (limited to 'src/std/buffer.c')
-rw-r--r-- | src/std/buffer.c | 13 |
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; } |