diff options
author | Thomas Voss <mail@thomasvoss.com> | 2024-05-10 23:27:08 +0200 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2024-05-10 23:27:08 +0200 |
commit | 4f62899af7e97501ec081f9268d80ebf87150c2a (patch) | |
tree | a06862b71cc319d1fe351b86995e115ebb550e85 /lib | |
parent | c0d2a0be9c95cc38818810207986818b333bc1de (diff) |
Begin work on custom allocators in dynarr.h
Diffstat (limited to 'lib')
-rw-r--r-- | lib/dynarr/dapush.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/dynarr/dapush.c b/lib/dynarr/dapush.c new file mode 100644 index 0000000..11fde1b --- /dev/null +++ b/lib/dynarr/dapush.c @@ -0,0 +1,22 @@ +#include <errno.h> +#include <stdbit.h> +#include <stdint.h> +#include <string.h> + +#include "dynarr.h" + +void * +(dapush)(void *da, void *x, size_t sz, size_t align) +{ + dynarr(uint8_t) cpy; + memcpy(&cpy, da, sizeof(cpy)); + + if (++cpy.len > cpy.cap) { + size_t ncap = stdc_bit_ceil(cpy.len); + cpy.buf = cpy.alloc(cpy.ctx, cpy.buf, cpy.cap, ncap, sz, align); + cpy.cap = ncap; + } + + memcpy(cpy.buf + cpy.len * sz - sz, x, sz); + return memcpy(da, &cpy, sizeof(cpy)); +} |