aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils/slist.c
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2015-12-23 23:45:54 +0100
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2015-12-23 23:45:54 +0100
commit14e9d7b2299f15efb695b0202f9c1f6a9f7a4ba6 (patch)
tree31b3d9a6f9f6144b08b852d016b5b4bdfce553ef /src/utils/slist.c
parent8e62072d91193b4894adda9c40544c18c1a01f57 (diff)
downloadblogc-14e9d7b2299f15efb695b0202f9c1f6a9f7a4ba6.tar.gz
blogc-14e9d7b2299f15efb695b0202f9c1f6a9f7a4ba6.tar.bz2
blogc-14e9d7b2299f15efb695b0202f9c1f6a9f7a4ba6.zip
Revert "build: removing src/utils and replacing with squareball"
This reverts commit 950e6c9148eca244a89d18a21d4ae4e5c3d1c646.
Diffstat (limited to 'src/utils/slist.c')
-rw-r--r--src/utils/slist.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/utils/slist.c b/src/utils/slist.c
new file mode 100644
index 0000000..3d9b892
--- /dev/null
+++ b/src/utils/slist.c
@@ -0,0 +1,68 @@
+/*
+ * 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 LICENSE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif /* HAVE_CONFIG_H */
+
+#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, b_free_func_t free_func)
+{
+ 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;
+}