1
0
mirror of https://github.com/falk-werner/webfuse synced 2024-10-27 20:34:10 +00:00
falk-werner_webfuse/lib/webfuse/impl/util/slist.c
2020-06-28 19:43:08 +02:00

57 lines
1.0 KiB
C

#include "webfuse/impl/util/slist.h"
#include <stddef.h>
void wf_impl_slist_init(
struct wf_slist * list)
{
list->head.next = NULL;
list->last = &list->head;
}
bool wf_impl_slist_empty(
struct wf_slist * list)
{
return (list->last == &list->head);
}
struct wf_slist_item * wf_impl_slist_first(
struct wf_slist * list)
{
return list->head.next;
}
void wf_impl_slist_append(
struct wf_slist * list,
struct wf_slist_item * item)
{
item->next = NULL;
list->last->next = item;
list->last = item;
}
struct wf_slist_item * wf_impl_slist_remove_first(
struct wf_slist * list)
{
return wf_impl_slist_remove_after(list, &list->head);
}
struct wf_slist_item * wf_impl_slist_remove_after(
struct wf_slist * list,
struct wf_slist_item * prev)
{
struct wf_slist_item * result = prev->next;
if (NULL != result)
{
prev->next = result->next;
if (list->last == result)
{
list->last = prev;
}
}
return result;
}