summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 4453841)
raw | patch | inline | side by side (parent: 4453841)
author | Sebastian Harl <sh@tokkee.org> | |
Wed, 1 Jan 2014 23:39:20 +0000 (00:39 +0100) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Wed, 1 Jan 2014 23:39:20 +0000 (00:39 +0100) |
src/include/utils/llist.h | patch | blob | history | |
src/utils/llist.c | patch | blob | history | |
t/utils/llist_test.c | patch | blob | history |
index 2742139f17db051d12b36c279889ff0c0bbfb48f..f33958a7550bffe3d0fab8d1195cd7483b5ee08c 100644 (file)
int
sdb_llist_iter_remove_current(sdb_llist_iter_t *iter);
+/*
+ * sdb_llist_len:
+ * Return the length (number of elements) of the list.
+ */
+size_t
+sdb_llist_len(sdb_llist_t *list);
+
#ifdef __cplusplus
} /* extern "C" */
#endif
diff --git a/src/utils/llist.c b/src/utils/llist.c
index 0a4665d09296c2387bcf1f369f81f5e751c20fa4..64f7d0c1bd9d4ba096d4878f9e64c198cfbff4f8 100644 (file)
--- a/src/utils/llist.c
+++ b/src/utils/llist.c
return 0;
} /* sdb_llist_iter_remove */
+size_t
+sdb_llist_len(sdb_llist_t *list)
+{
+ if (! list)
+ return 0;
+ return list->length;
+} /* sdb_llist_len */
+
/* vim: set tw=78 sw=4 ts=4 noexpandtab : */
diff --git a/t/utils/llist_test.c b/t/utils/llist_test.c
index ede8200a42a325d3f22707eb001febdc8ac9b51e..ae9655ac46ec46ace6410363adfdccb8e1b5466e 100644 (file)
--- a/t/utils/llist_test.c
+++ b/t/utils/llist_test.c
START_TEST(test_sdb_llist_append)
{
size_t i;
+
+ fail_unless(sdb_llist_len(list) == 0,
+ "sdb_llist_len(<empty list>) = %zu; expected: 0",
+ sdb_llist_len(list));
+
for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) {
int check = sdb_llist_append(list, &golden_data[i]);
fail_unless(check == 0,
fail_unless(golden_data[i].ref_cnt == 2,
"sdb_llist_append(%s) did not take ownership",
golden_data[i].name);
+ fail_unless(sdb_llist_len(list) == i + 1,
+ "sdb_llist_len(<empty list>) = %zu; expected: zu",
+ sdb_llist_len(list), i + 1);
}
}
END_TEST