src/chain.c
author Tero Marttila <terom@fixme.fi>
Thu, 07 May 2009 22:23:51 +0300
changeset 186 33ef336dbb4b
parent 171 b54f393c3df0
permissions -rw-r--r--
rework CMake scripts, particularly re make: Nothing to be done for `test'., integrate lcov now
#include "chain.h"

#include <stdlib.h>
#include <assert.h>

void *_chain_add (struct _chain_head *head, bool tail, size_t size)
{
    struct _chain_item *item;

    // sanity-check
    assert(size >= sizeof(item));

    // allocate the chain item
    if ((item = calloc(1, size)) == NULL)
        return NULL;
    
    // insert
    if (tail)
        TAILQ_INSERT_TAIL(head, item, _chain_list);
    else
        TAILQ_INSERT_HEAD(head, item, _chain_list);

    // ok
    return item;
}