summaryrefslogtreecommitdiff
path: root/src/sp_list.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/sp_list.c')
-rw-r--r--src/sp_list.c37
1 files changed, 37 insertions, 0 deletions
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 @@
1#include "sp_list.h"
2#include <stdio.h>
3#include <stdlib.h>
4#include "php_snuffleupagus.h"
5
6void sp_list_free(sp_node_t *node) {
7 while(node) {
8 sp_node_t *tmp = node->next;
9 pefree(node, 1);
10 node = tmp;
11 }
12}
13
14sp_node_t *sp_new_list() {
15 sp_node_t *new = pecalloc(sizeof(*new), 1, 1);
16 new->next = new->data = new->head = NULL;
17 return new;
18}
19
20void sp_list_insert(sp_node_t *list, void *data) {
21 if (list->head == NULL) {
22 list->data = data;
23 list->next = NULL;
24 list->head = list;
25 } else {
26 sp_node_t *new = pecalloc(sizeof(*new), 1, 1);
27
28 new->data = data;
29 new->next = NULL;
30 new->head = list;
31
32 while (list->next) {
33 list = list->next;
34 }
35 list->next = new;
36 }
37}