src/chain.c
author Tero Marttila <terom@fixme.fi>
Mon, 16 Mar 2009 00:09:53 +0200
branchbuild-cmake
changeset 61 4ba21936518a
parent 35 3715247e8f5a
child 69 6f298b6e0d5f
permissions -rw-r--r--
temporarily disable evsql stuff
#include "chain.h"

#include <stdlib.h>

err_t chain_add (struct chain_list *list, const void *chain, void *arg)
{
    struct chain_head *item;

    // allocate the chain item
    if ((item = calloc(1, sizeof(*item))) == NULL)
        return ERR_CALLOC;

    // store
    item->chain = chain;
    item->arg = arg;

    // append
    STAILQ_INSERT_TAIL(list, item, node);

    // ok
    return SUCCESS;
}

void chain_free (struct chain_list *list)
{
    // start from the first item
    struct chain_head *next = STAILQ_FIRST(list);

    // clean up any handler chains
    while (next) {
        struct chain_head *node = next;

        // update next
        next = STAILQ_NEXT(node, node);

        // free
        free(node);
    }
}