kosmos/source/firmware/kernel/list.c

50 lines
673 B
C
Raw Permalink Normal View History

2016-07-28 19:02:54 +00:00
/*
* list.c
*
* Created on: Jul 27, 2016
* Author: tkl
*/
#include "stddef.h"
#include "list.h"
int list_init(struct list *head)
{
if(NULL == head)
return -1;
head->front = NULL;
head->rear = NULL;
return 0;
}
int list_add(struct list *head, struct list_node *node)
{
if((NULL == head) || (NULL == node))
return -1;
if(head->front == NULL) {
head->front = node;
head->rear = node;
}
else {
head->rear->next = node;
head->rear = node;
}
return 1;
}
2016-08-11 09:04:54 +00:00
int list_get_len(struct list *head)
{
int ret = 0;
if(NULL == head)
return -1;
struct list_node *it = head->front;
while(NULL != it) {
ret++;
it = it->next;
}
return ret;
}