renamed capwap directory to cw.
FossilOrigin-Name: 8a43dd9d05a4cb73210243ddd8df2a26f16c7ef2c4d4e36ab446de1f65d88223
This commit is contained in:
65
src/cw/mlist.c
Normal file
65
src/cw/mlist.c
Normal file
@ -0,0 +1,65 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
#include "mlist.h"
|
||||
|
||||
mlist_t *mlist_create(int (*cmp) (void *v1, void *v2))
|
||||
{
|
||||
mlist_t *l = malloc(sizeof(mlist_t));
|
||||
if (!l)
|
||||
return NULL;
|
||||
memset(l, 0, sizeof(mlist_t));
|
||||
l->cmp = cmp;
|
||||
return l;
|
||||
}
|
||||
|
||||
struct mlist_elem *mlist_append(mlist_t * l, void *data)
|
||||
{
|
||||
struct mlist_elem **n = &l->list;
|
||||
while (*n != NULL)
|
||||
n = &(*n)->next;
|
||||
*n = malloc(sizeof(struct mlist_elem));
|
||||
if (!*n)
|
||||
return NULL;
|
||||
|
||||
(*n)->data = data;
|
||||
(*n)->next = NULL;
|
||||
|
||||
return *n;
|
||||
}
|
||||
|
||||
struct mlist_elem *mlist_find(mlist_t * l, struct mlist_elem *start, void *data)
|
||||
{
|
||||
struct mlist_elem *e;
|
||||
if (start)
|
||||
e = start;
|
||||
else
|
||||
e = l->list;
|
||||
|
||||
while (e) {
|
||||
if (l->cmp(e->data, data) == 0)
|
||||
return e;
|
||||
e = e->next;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
struct mlist_elem *mlist_replace(mlist_t *l, struct mlist_elem *start, void *data)
|
||||
{
|
||||
struct mlist_elem *e;
|
||||
if (start)
|
||||
e = start;
|
||||
else
|
||||
e = l->list;
|
||||
|
||||
struct mlist_elem * f = mlist_find(l,e,data);
|
||||
if (!f)
|
||||
return NULL;
|
||||
|
||||
f->data = data;
|
||||
return f;
|
||||
}
|
||||
|
Reference in New Issue
Block a user