diff options
Diffstat (limited to 'lib/dynarr/daextend.c')
-rw-r--r-- | lib/dynarr/daextend.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/dynarr/daextend.c b/lib/dynarr/daextend.c new file mode 100644 index 0000000..efa96d5 --- /dev/null +++ b/lib/dynarr/daextend.c @@ -0,0 +1,22 @@ +#include <errno.h> +#include <stdbit.h> +#include <stdint.h> +#include <string.h> + +#include "dynarr.h" + +void * +(daextend)(void *da, void *xs, size_t n, size_t sz, size_t align) +{ + dynarr(uint8_t) cpy; + memcpy(&cpy, da, sizeof(cpy)); + + if ((cpy.len += n) > 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 - n * sz, xs, n * sz); + return memcpy(da, &cpy, sizeof(cpy)); +} |