diff options
author | Thomas Voss <mail@thomasvoss.com> | 2024-10-16 04:03:25 +0200 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2024-10-16 04:03:25 +0200 |
commit | 8f771fb3c4a8af0f6d5be468651a61dd00aeecc2 (patch) | |
tree | 99651736e5cfb040d8c778a77be27fda16a901be /include | |
parent | 4fcb1ec318d74a454f6cfbefe018f35bbb32d6bf (diff) |
Add array_set_size()
Diffstat (limited to 'include')
-rw-r--r-- | include/array.h | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/include/array.h b/include/array.h index f8090cf..48f7b70 100644 --- a/include/array.h +++ b/include/array.h @@ -54,7 +54,18 @@ _mlib_array_hdr(void *p, ptrdiff_t align) } while (false) #define array_foreach(p, i) for (typeof(p) i = (p); i < (p) + array_len(p); i++) - + +[[_mlib_inline]] +static void +array_set_size(void *p, ptrdiff_t size, ptrdiff_t align) +{ + _mlib_arr_hdr_t *hdr = _mlib_array_hdr(p, alignof(typeof(*p))); + hdr->len = size; +} + +#define array_set_size(p, size) \ + array_set_size((p), (size), alignof(typeof(*(p)))) + void *(array_new)(allocator_t mem, ptrdiff_t nmemb, ptrdiff_t elemsz, ptrdiff_t align); void *(array_resz)(void *ptr, ptrdiff_t ncap, ptrdiff_t elemsz, ptrdiff_t align); |