All pastes #2106951 Raw Edit

Something

public text v1 · immutable
#2106951 ·published 2012-01-28 04:08 UTC
rendered paste body
static int check_labels(struct label_list *labels)
{
    int rc = 0;
    struct label_list *top = labels;

    // check for and reject duplicates
    void *tree;
    while (labels) {
        struct label **node = tsearch(labels->label, &tree,
                by_label);

        if (*node != labels->label) {
            rc = 1;
            break; // take that, district !
        }

        labels = labels->next;
    }

    // delete from tree what we added to it
    while (top && tree) {
        tdelete(top->label, &tree, by_label);
        top = top->next;
    }
    return rc;
}