#include <stdlib.h>
#include <list/list.h>
+#include <talloc/talloc.h>
int main(void)
STATIC_LIST(tester);
struct item *item;
struct item *tmp;
+ void *ctx;
int i;
+ ctx = talloc_new(NULL);
+
for (i = 0; i < 5; i++) {
- struct item *item = malloc(sizeof(struct item));
+ struct item *item = talloc(ctx, struct item);
item->value = i;
list_remove(&item->list);
}
+ /* we should see that the list is empty */
i = 0;
- fprintf(stderr, "-- list_for_each_entry --\n");
+ fprintf(stderr, "-- list_for_each_entry(empty) --\n");
list_for_each_entry(&tester, item, list) {
fprintf(stderr, "%d: %d: %p -> %p\n", i++, item->value, item, item->list.next);
}
+ if (i) {
+ fprintf(stderr, "Error: list should be empty\n");
+ return EXIT_FAILURE;
+ }
+
+ i = 0;
+ fprintf(stderr, "-- list_for_each_entry_safe(empty) --\n");
+ list_for_each_entry_safe(&tester, item, tmp, list) {
+ fprintf(stderr, "%d: %d: %p -> %p\n", i++, item->value, item, item->list.next);
+ }
+
+ if (i) {
+ fprintf(stderr, "Error: list should be empty\n");
+ return EXIT_FAILURE;
+ }
fprintf(stderr, "-- done --\n");
+
+ talloc_free(ctx);
+
return EXIT_SUCCESS;
}