vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit 37fa44ed3e6d0cf2dacf7532324092e4c71454c1 parent ac93a434e2501461030a7a6cd4c851e85333b7c5 Author: Marc André Tanner <mat@brain-dump.org> Date: Wed, 19 Apr 2017 10:08:18 +0200 array: implement array_resize Diffstat:
| M | array.c | | | 8 | ++++++++ |
| M | array.h | | | 3 | +++ |
2 files changed, 11 insertions(+), 0 deletions(-)
diff --git a/array.c b/array.c @@ -135,3 +135,11 @@ bool array_truncate(Array *arr, size_t len) { } return false; } + +bool array_resize(Array *arr, size_t len) { + if (len <= arr->count) { + arr->len = len; + return true; + } + return false; +} diff --git a/array.h b/array.h @@ -58,5 +58,8 @@ size_t array_length(Array*); size_t array_capacity(Array*); /* remove all elements at index >= length, keep allocated memory */ bool array_truncate(Array*, size_t length); +/* change length if it is less than the current capacity, newly + * accesible elements preserve their previous values */ +bool array_resize(Array*, size_t length); #endif