1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00
RIOT/sys/net/crosslayer/pkt/pkt.c
2015-02-08 18:52:16 +01:00

70 lines
1.2 KiB
C

/*
* Copyright (C) 2014 Martine Lenders <mlenders@inf.fu-berlin.de>
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @{
*
* @file pkt.c
*/
#include "pkt.h"
pktsize_t pkt_hlist_len(pkt_hlist_t *list)
{
pktsize_t len = 0;
while (list) {
len += list->header_len;
pkt_hlist_advance(&list);
}
return len;
}
pkt_hlist_t *pkt_hlist_remove_first(pkt_hlist_t **list)
{
pkt_hlist_t *res;
if (list == NULL || *list == NULL) {
return NULL;
}
res = *list;
*list = res->next;
res->next = NULL;
return res;
}
void pkt_hlist_remove(pkt_hlist_t **list, pkt_hlist_t *header)
{
if (list == NULL || *list == NULL || header == NULL) {
return;
}
if ((*list) == header) {
pkt_hlist_remove_first(list);
}
else {
pkt_hlist_t *ptr = (*list)->next, *prev = *list;
while (ptr != NULL) {
if (ptr == header) {
prev->next = ptr->next;
ptr->next = NULL;
}
pkt_hlist_advance(&ptr);
pkt_hlist_advance(&prev);
}
}
}
/** @} */