git / brickware / marrow.git - main

(45 minutes ago)commit 7790c99: Meh. Halfway vector implementation. Not happy with the name

tree / linserts.c

linserts.c

raw

/***
 * linserts.c
 */

#include <stdint.h>
#include <stdlib.h>
#include <string.h>

#include "./allocator.h"
#include "./vector.h"


int32_t
linserts(void *dest, const size_t length, const size_t num, const size_t size, const size_t index, const void *items, const size_t count)
{
    /* if list isn't large enough, fail */
    if ((length - num) < count) {
        return (VEC_ERR_NOSPACE);
    }

    /* shift data to the right */
    if (index < num) {
        memmove(VECITEM(dest, index + count, size),
                VECITEM(dest, index, size),
                size * (num - index));
    }

    memcpy(VECITEM(dest, index, size), items, count * size);
    return (VEC_OKAY);
}