src/chain.c
author Tero Marttila <terom@fixme.fi>
Thu, 28 May 2009 01:17:36 +0300
branchnew-lib-errors
changeset 219 cefec18b8268
parent 171 b54f393c3df0
permissions -rw-r--r--
some of the lib/transport stuff compiles
#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;
}