aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils/slist.c
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2015-04-15 12:56:54 -0300
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2015-04-15 12:56:54 -0300
commit0b694d89cefae8e8ca3422bbdbfbca4d5920ac4b (patch)
tree212c4d2ac7e269cc9f03f2240e36f865d4ce2493 /src/utils/slist.c
parenta8e0fedb3f12ed1ceda7879944606c8e1e7d4a08 (diff)
downloadblogc-0b694d89cefae8e8ca3422bbdbfbca4d5920ac4b.tar.gz
blogc-0b694d89cefae8e8ca3422bbdbfbca4d5920ac4b.tar.bz2
blogc-0b694d89cefae8e8ca3422bbdbfbca4d5920ac4b.zip
initial structure
Diffstat (limited to 'src/utils/slist.c')
-rw-r--r--src/utils/slist.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/utils/slist.c b/src/utils/slist.c
new file mode 100644
index 0000000..e0c1a44
--- /dev/null
+++ b/src/utils/slist.c
@@ -0,0 +1,64 @@
+/*
+ * blogc: A blog compiler.
+ * Copyright (C) 2014-2015 Rafael G. Martins <rafael@rafaelmartins.eng.br>
+ *
+ * This program can be distributed under the terms of the BSD License.
+ * See the file COPYING.
+ */
+
+#include <stdlib.h>
+#include "utils.h"
+
+
+b_slist_t*
+b_slist_append(b_slist_t *l, void *data)
+{
+ b_slist_t *node = malloc(sizeof(b_slist_t));
+ if (node == NULL) {
+ l = NULL;
+ return l;
+ }
+ node->data = data;
+ node->next = NULL;
+ if (l == NULL)
+ l = node;
+ else {
+ b_slist_t *tmp;
+ for (tmp = l; tmp->next != NULL; tmp = tmp->next);
+ tmp->next = node;
+ }
+ return l;
+}
+
+
+void
+b_slist_free_full(b_slist_t *l, void (*free_func)(void *ptr))
+{
+ while (l != NULL) {
+ b_slist_t *tmp = l->next;
+ free_func(l->data);
+ free(l);
+ l = tmp;
+ }
+}
+
+
+void
+b_slist_free(b_slist_t *l)
+{
+ while (l != NULL) {
+ b_slist_t *tmp = l->next;
+ free(l);
+ l = tmp;
+ }
+}
+
+
+unsigned int
+b_slist_length(b_slist_t *l)
+{
+ unsigned int i;
+ b_slist_t *tmp;
+ for (tmp = l, i = 0; tmp != NULL; tmp = tmp->next, i++);
+ return i;
+}