aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/common/utils.c16
-rw-r--r--src/common/utils.h1
-rw-r--r--tests/common/check_utils.c27
3 files changed, 44 insertions, 0 deletions
diff --git a/src/common/utils.c b/src/common/utils.c
index f686222..4e90c77 100644
--- a/src/common/utils.c
+++ b/src/common/utils.c
@@ -74,6 +74,22 @@ bc_slist_prepend(bc_slist_t *l, void *data)
}
+bc_slist_t*
+bc_slist_append_list(bc_slist_t *l, bc_slist_t *n)
+{
+ if (l == NULL) {
+ return n;
+ }
+ if (n == NULL) {
+ return l;
+ }
+ bc_slist_t *tmp;
+ for (tmp = l; tmp->next != NULL; tmp = tmp->next);
+ tmp->next = n;
+ return l;
+}
+
+
void
bc_slist_free_full(bc_slist_t *l, bc_free_func_t free_func)
{
diff --git a/src/common/utils.h b/src/common/utils.h
index 94c3356..84ce066 100644
--- a/src/common/utils.h
+++ b/src/common/utils.h
@@ -31,6 +31,7 @@ typedef struct _bc_slist_t {
bc_slist_t* bc_slist_append(bc_slist_t *l, void *data);
bc_slist_t* bc_slist_prepend(bc_slist_t *l, void *data);
+bc_slist_t* bc_slist_append_list(bc_slist_t *l, bc_slist_t *n);
void bc_slist_free(bc_slist_t *l);
void bc_slist_free_full(bc_slist_t *l, bc_free_func_t free_func);
size_t bc_slist_length(bc_slist_t *l);
diff --git a/tests/common/check_utils.c b/tests/common/check_utils.c
index 471cd77..4efc1a5 100644
--- a/tests/common/check_utils.c
+++ b/tests/common/check_utils.c
@@ -54,6 +54,32 @@ test_slist_prepend(void **state)
static void
+test_slist_append_list(void **state)
+{
+ bc_slist_t *l = NULL;
+ assert_null(bc_slist_append_list(l, NULL));
+ l = bc_slist_append(l, (void*) bc_strdup("bola"));
+ l = bc_slist_append(l, (void*) bc_strdup("guda"));
+ bc_slist_t *t = bc_slist_append_list(l, NULL);
+ assert_true(l == t);
+ bc_slist_t *n = NULL;
+ n = bc_slist_append(n, (void*) bc_strdup("chunda"));
+ n = bc_slist_append(n, (void*) bc_strdup("asd"));
+ l = bc_slist_append_list(l, n);
+ assert_non_null(l);
+ assert_string_equal(l->data, "bola");
+ assert_non_null(l->next);
+ assert_string_equal(l->next->data, "guda");
+ assert_non_null(l->next->next);
+ assert_string_equal(l->next->next->data, "chunda");
+ assert_non_null(l->next->next->next);
+ assert_string_equal(l->next->next->next->data, "asd");
+ assert_null(l->next->next->next->next);
+ bc_slist_free_full(l, free);
+}
+
+
+static void
test_slist_free(void **state)
{
bc_slist_t *l = NULL;
@@ -1053,6 +1079,7 @@ main(void)
// slist
unit_test(test_slist_append),
unit_test(test_slist_prepend),
+ unit_test(test_slist_append_list),
unit_test(test_slist_free),
unit_test(test_slist_length),