summaryrefslogtreecommitdiffstats
path: root/libcnary/node_list.c
diff options
context:
space:
mode:
Diffstat (limited to 'libcnary/node_list.c')
-rw-r--r--libcnary/node_list.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/libcnary/node_list.c b/libcnary/node_list.c
index aee3bd6..f6c2c70 100644
--- a/libcnary/node_list.c
+++ b/libcnary/node_list.c
@@ -28,12 +28,14 @@
#include "node.h"
#include "node_list.h"
-void node_list_destroy(node_list_t* list) {
+void node_list_destroy(node_list_t list)
+{
free(list);
}
-node_list_t* node_list_create() {
- node_list_t* list = (node_list_t*)calloc(1, sizeof(node_list_t));
+node_list_t node_list_create()
+{
+ node_list_t list = (node_list_t)calloc(1, sizeof(struct node_list));
if (list == NULL) {
return NULL;
}
@@ -45,11 +47,12 @@ node_list_t* node_list_create() {
return list;
}
-int node_list_add(node_list_t* list, node_t* node) {
+int node_list_add(node_list_t list, node_t node)
+{
if (!list || !node) return -1;
// Find the last element in the list
- node_t* last = list->end;
+ node_t last = list->end;
// Setup our new node as the new last element
node->next = NULL;
@@ -72,17 +75,18 @@ int node_list_add(node_list_t* list, node_t* node) {
return 0;
}
-int node_list_insert(node_list_t* list, unsigned int node_index, node_t* node) {
+int node_list_insert(node_list_t list, unsigned int node_index, node_t node)
+{
if (!list || !node) return -1;
if (node_index >= list->count) {
return node_list_add(list, node);
}
// Get the first element in the list
- node_t* cur = list->begin;
+ node_t cur = list->begin;
unsigned int pos = 0;
- node_t* prev = NULL;
+ node_t prev = NULL;
if (node_index > 0) {
while (pos < node_index) {
@@ -120,15 +124,16 @@ int node_list_insert(node_list_t* list, unsigned int node_index, node_t* node) {
return 0;
}
-int node_list_remove(node_list_t* list, node_t* node) {
+int node_list_remove(node_list_t list, node_t node)
+{
if (!list || !node) return -1;
if (list->count == 0) return -1;
int node_index = 0;
- node_t* n;
+ node_t n;
for (n = list->begin; n; n = n->next) {
if (node == n) {
- node_t* newnode = node->next;
+ node_t newnode = node->next;
if (node->prev) {
node->prev->next = newnode;
if (newnode) {
@@ -153,4 +158,3 @@ int node_list_remove(node_list_t* list, node_t* node) {
}
return -1;
}
-