/* * pair.c: Linked lists of key/value pairs. * $Header$ */ #include <config.h> #include "pair.h" #include <malloc.h> #include <string.h> pair *new_pair(const char *key, size_t len, const void *data) { struct pair *p; p = malloc(sizeof(struct pair)); /* Make a copy of the key. */ p->key = strdup(key); p->len = len; p->data = malloc(len); if (data) memcpy(p->data, data, len); p->next = NULL; return p; } void free_pair(pair *p) { free(p->key); free(p->data); if (p->next) free_pair(p->next); free(p); } pair *pair_with_key(pair *p, const char *key) { /* Right. In a real language, we'd do this with a tail-recursive * call and it'd be easy. But this is C. Fortunately, it's not * *too* hard... */ while (p) { if (!strcmp(p->key, key)) return p; p = p->next; } return NULL; } void set_pair_data(pair *p, size_t len, const void *data) { free(p->data); p->data = malloc(len); memcpy(p->data, data, len); p->len = len; }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 450 | sandy_currier |
Initial import of p4filter code. This contains a solaris2.6 binary but no others. |