2020-06-16 21:39:45 +00:00
|
|
|
#include "webfuse_provider/impl/slist.h"
|
2019-04-17 20:51:16 +00:00
|
|
|
#include <stddef.h>
|
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
void wfp_slist_init(
|
|
|
|
struct wfp_slist * list)
|
2019-04-17 20:51:16 +00:00
|
|
|
{
|
2019-04-26 18:50:57 +00:00
|
|
|
list->head.next = NULL;
|
|
|
|
list->last = &list->head;
|
2019-04-17 20:51:16 +00:00
|
|
|
}
|
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
bool wfp_slist_empty(
|
|
|
|
struct wfp_slist * list)
|
2019-04-17 20:51:16 +00:00
|
|
|
{
|
2019-04-26 18:50:57 +00:00
|
|
|
return (list->last == &list->head);
|
|
|
|
}
|
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
struct wfp_slist_item * wfp_slist_first(
|
|
|
|
struct wfp_slist * list)
|
2019-04-26 18:50:57 +00:00
|
|
|
{
|
|
|
|
return list->head.next;
|
2019-04-17 20:51:16 +00:00
|
|
|
}
|
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
void wfp_slist_append(
|
|
|
|
struct wfp_slist * list,
|
|
|
|
struct wfp_slist_item * item)
|
2019-04-17 20:51:16 +00:00
|
|
|
{
|
|
|
|
item->next = NULL;
|
2019-04-26 18:50:57 +00:00
|
|
|
list->last->next = item;
|
|
|
|
list->last = item;
|
2019-04-17 20:51:16 +00:00
|
|
|
}
|
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
struct wfp_slist_item * wfp_slist_remove_first(
|
|
|
|
struct wfp_slist * list)
|
2019-04-17 20:51:16 +00:00
|
|
|
{
|
2020-06-16 21:57:41 +00:00
|
|
|
return wfp_slist_remove_after(list, &list->head);
|
2019-04-17 20:51:16 +00:00
|
|
|
}
|
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
struct wfp_slist_item * wfp_slist_remove_after(
|
|
|
|
struct wfp_slist * list,
|
|
|
|
struct wfp_slist_item * prev)
|
2019-04-17 20:51:16 +00:00
|
|
|
{
|
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
struct wfp_slist_item * result = prev->next;
|
2019-04-26 18:50:57 +00:00
|
|
|
|
|
|
|
if (NULL != result)
|
2019-04-17 20:51:16 +00:00
|
|
|
{
|
2019-04-26 18:50:57 +00:00
|
|
|
prev->next = result->next;
|
|
|
|
|
|
|
|
if (list->last == result)
|
2019-04-17 20:51:16 +00:00
|
|
|
{
|
|
|
|
list->last = prev;
|
2019-04-26 18:50:57 +00:00
|
|
|
}
|
2019-04-17 20:51:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|