Added a function for obtaining the next item on the list. This makes list iterations nicer, as the ->next pointer now is hidden within the list abstraction.

This commit is contained in:
adamdunkels 2010-06-15 18:54:27 +00:00
parent 01b1359b1f
commit a84cc7c8a0
2 changed files with 20 additions and 2 deletions

View file

@ -43,7 +43,7 @@
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: list.c,v 1.4 2010/04/30 07:18:24 adamdunkels Exp $
* $Id: list.c,v 1.5 2010/06/15 18:54:27 adamdunkels Exp $
*/
#include "lib/list.h"
@ -311,4 +311,20 @@ list_insert(list_t list, void *previtem, void *newitem)
}
}
/*---------------------------------------------------------------------------*/
/**
* \brief Get the next item following this item
* \param item A list item
* \returns A next item on the list
*
* This function takes a list item and returns the next
* item on the list, or NULL if there are no more items on
* the list. This function is used when iterating through
* lists.
*/
void *
list_item_next(void *item)
{
return item == NULL? NULL: ((struct list *)item)->next;
}
/*---------------------------------------------------------------------------*/
/** @} */

View file

@ -64,7 +64,7 @@
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: list.h,v 1.3 2009/05/06 15:07:35 adamdunkels Exp $
* $Id: list.h,v 1.4 2010/06/15 18:54:27 adamdunkels Exp $
*/
#ifndef __LIST_H__
#define __LIST_H__
@ -113,6 +113,8 @@ void list_copy(list_t dest, list_t src);
void list_insert(list_t list, void *previtem, void *newitem);
void * list_item_next(void *item);
#endif /* __LIST_H__ */
/** @} */