aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-10-16 04:03:25 +0200
committerThomas Voss <mail@thomasvoss.com> 2024-10-16 04:03:25 +0200
commit8f771fb3c4a8af0f6d5be468651a61dd00aeecc2 (patch)
tree99651736e5cfb040d8c778a77be27fda16a901be
parent4fcb1ec318d74a454f6cfbefe018f35bbb32d6bf (diff)
Add array_set_size()
-rw-r--r--include/array.h13
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);