From 868f96c759b6650d88ff9f4fbc5c048302134248 Mon Sep 17 00:00:00 2001 From: Sebastien Blot Date: Wed, 20 Sep 2017 10:11:01 +0200 Subject: Initial import --- src/sp_list.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/sp_list.c (limited to 'src/sp_list.c') diff --git a/src/sp_list.c b/src/sp_list.c new file mode 100644 index 0000000..04154b7 --- /dev/null +++ b/src/sp_list.c @@ -0,0 +1,37 @@ +#include "sp_list.h" +#include +#include +#include "php_snuffleupagus.h" + +void sp_list_free(sp_node_t *node) { + while(node) { + sp_node_t *tmp = node->next; + pefree(node, 1); + node = tmp; + } +} + +sp_node_t *sp_new_list() { + sp_node_t *new = pecalloc(sizeof(*new), 1, 1); + new->next = new->data = new->head = NULL; + return new; +} + +void sp_list_insert(sp_node_t *list, void *data) { + if (list->head == NULL) { + list->data = data; + list->next = NULL; + list->head = list; + } else { + sp_node_t *new = pecalloc(sizeof(*new), 1, 1); + + new->data = data; + new->next = NULL; + new->head = list; + + while (list->next) { + list = list->next; + } + list->next = new; + } +} -- cgit v1.3