Commit a30235ad authored by venaas's avatar venaas Committed by venaas

using linked lists instead of arrays

git-svn-id: https://svn.testnett.uninett.no/radsecproxy/trunk@147 e88ac4ed-0b26-0410-9574-a7f39faa03bf
parent 9114cdf0
CFLAGS = -g -Wall -pedantic -pthread
LDFLAGS = -lssl
OBJ = util.o debug.o radsecproxy.o
OBJ = util.o debug.o list.o radsecproxy.o
all: radsecproxy
......
......@@ -3,8 +3,10 @@ sbin_PROGRAMS = radsecproxy
radsecproxy_SOURCES = radsecproxy.c \
util.c \
debug.c \
list.c \
radsecproxy.h \
debug.h
debug.h \
list.h
radsecproxy_CFLAGS = -g -Wall -pedantic -pthread @SSL_CFLAGS@
radsecproxy_LDFLAGS = @SSL_LDFLAGS@
......
#include <stdlib.h>
#include <string.h>
#include "list.h"
/* allocates and initialises list structure; returns NULL if malloc fails */
struct list *list_create() {
struct list *list = malloc(sizeof(struct list));
if (list)
memset(list, 0, sizeof(struct list));
return list;
}
/* frees all memory associated with the list */
void list_destroy(struct list *list) {
struct list_node *node, *next;
for (node = list->first; node; node = next) {
free(node->data);
next = node->next;
free(node);
}
free(list);
}
/* appends entry to list; returns 1 if ok, 0 if malloc fails */
int list_add(struct list *list, void *data) {
struct list_node *node;
node = malloc(sizeof(struct list_node));
if (!node)
return 0;
node->next = NULL;
node->data = data;
if (list->first)
list->last->next = node;
else
list->first = node;
list->last = node;
return 1;
}
/* returns first node */
struct list_node *list_first(struct list *list) {
return list->first;
}
/* returns the next node after the argument */
struct list_node *list_next(struct list_node *node) {
return node->next;
}
struct list_node {
struct list_node *next;
void *data;
};
struct list {
struct list_node *first, *last;
};
/* allocates and initialises list structure; returns NULL if malloc fails */
struct list *list_create();
/* frees all memory associated with the list */
void list_destroy(struct list *list);
/* appends entry to list; returns 1 if ok, 0 if malloc fails */
int list_add(struct list *list, void *data);
/* returns first node */
struct list_node *list_first(struct list *list);
/* returns the next node after the argument */
struct list_node *list_next(struct list_node *node);
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment