aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-05-11 00:18:36 +0200
committerThomas Voss <mail@thomasvoss.com> 2024-05-11 00:18:36 +0200
commit7d9c8cb5956cab41492c7b70011d7d637d4d2a4c (patch)
tree44d9767489fc5bd0b018d8e5f16e346661a285c6 /lib
parentb04989164df973eaf6565d1c9bf2505215a54604 (diff)
Implement dagrow()
Diffstat (limited to 'lib')
-rw-r--r--lib/dynarr/dagrow.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/dynarr/dagrow.c b/lib/dynarr/dagrow.c
new file mode 100644
index 0000000..8273efe
--- /dev/null
+++ b/lib/dynarr/dagrow.c
@@ -0,0 +1,17 @@
+#include <stdint.h>
+
+#include "dynarr.h"
+
+void *
+(dagrow)(void *da, size_t n, size_t elemsz, size_t align)
+{
+ dynarr(uint8_t) cpy;
+ memcpy(&cpy, da, sizeof(cpy));
+
+ if (n > cpy.cap) {
+ cpy.buf = cpy.alloc(cpy.ctx, cpy.buf, cpy.cap, n, elemsz, align);
+ cpy.cap = n;
+ }
+
+ return memcpy(da, &cpy, sizeof(cpy));
+}