};
-/**
- * Handle to a singly linked list iterator
- */
-struct GNUNET_CONTAINER_SList_Iterator
-{
- /**
- * Linked list that we are iterating over.
- */
- struct GNUNET_CONTAINER_SList *list;
-
- /**
- * Last element accessed.
- */
- struct GNUNET_CONTAINER_SList_Elem *last;
-
- /**
- * Current list element.
- */
- struct GNUNET_CONTAINER_SList_Elem *elem;
-};
-
/**
* Create a new element that is to be inserted into the list
*/
static struct GNUNET_CONTAINER_SList_Elem *
create_elem (enum GNUNET_CONTAINER_SListDisposition disp, const void *buf,
- size_t len)
+ size_t len)
{
struct GNUNET_CONTAINER_SList_Elem *e;
if (disp == GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT)
- {
- e = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_SList_Elem) + len);
- memcpy (&e[1], buf, len);
- e->elem = (void *) &e[1];
- }
+ {
+ e = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_SList_Elem) + len);
+ memcpy (&e[1], buf, len);
+ e->elem = (void *) &e[1];
+ }
else
- {
- e = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_SList_Elem));
- e->elem = (void *) buf;
- }
+ {
+ e = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_SList_Elem));
+ e->elem = (void *) buf;
+ }
e->disp = disp;
e->len = len;
return e;
*/
void
GNUNET_CONTAINER_slist_add (struct GNUNET_CONTAINER_SList *l,
- enum GNUNET_CONTAINER_SListDisposition disp,
- const void *buf, size_t len)
+ enum GNUNET_CONTAINER_SListDisposition disp,
+ const void *buf, size_t len)
{
struct GNUNET_CONTAINER_SList_Elem *e;
*/
void
GNUNET_CONTAINER_slist_add_end (struct GNUNET_CONTAINER_SList *l,
- enum GNUNET_CONTAINER_SListDisposition disp,
- const void *buf, size_t len)
+ enum GNUNET_CONTAINER_SListDisposition disp,
+ const void *buf, size_t len)
{
struct GNUNET_CONTAINER_SList_Elem *e;
*/
void
GNUNET_CONTAINER_slist_append (struct GNUNET_CONTAINER_SList *dst,
- struct GNUNET_CONTAINER_SList *src)
+ struct GNUNET_CONTAINER_SList *src)
{
- struct GNUNET_CONTAINER_SList_Iterator *i;
+ struct GNUNET_CONTAINER_SList_Iterator i;
for (i = GNUNET_CONTAINER_slist_begin (src);
- GNUNET_CONTAINER_slist_end (i) != GNUNET_YES;
- GNUNET_CONTAINER_slist_next (i))
-
- {
- GNUNET_CONTAINER_slist_add (dst,
- (i->elem->disp ==
- GNUNET_CONTAINER_SLIST_DISPOSITION_STATIC)
- ? GNUNET_CONTAINER_SLIST_DISPOSITION_STATIC
- :
- GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT,
- i->elem->elem, i->elem->len);
- }
- GNUNET_CONTAINER_slist_iter_destroy (i);
+ GNUNET_CONTAINER_slist_end (&i) != GNUNET_YES;
+ GNUNET_CONTAINER_slist_next (&i))
+
+ {
+ GNUNET_CONTAINER_slist_add (dst,
+ (i.elem->disp ==
+ GNUNET_CONTAINER_SLIST_DISPOSITION_STATIC) ?
+ GNUNET_CONTAINER_SLIST_DISPOSITION_STATIC :
+ GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT,
+ i.elem->elem, i.elem->len);
+ }
+ GNUNET_CONTAINER_slist_iter_destroy (&i);
}
* @param l list
* @return iterator pointing to the beginning
*/
-struct GNUNET_CONTAINER_SList_Iterator *
+struct GNUNET_CONTAINER_SList_Iterator
GNUNET_CONTAINER_slist_begin (struct GNUNET_CONTAINER_SList *l)
{
- struct GNUNET_CONTAINER_SList_Iterator *ret;
+ struct GNUNET_CONTAINER_SList_Iterator ret;
- ret = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_SList_Iterator));
- ret->elem = l->head;
- ret->list = l;
+ memset (&ret, 0, sizeof (ret));
+ ret.elem = l->head;
+ ret.list = l;
return ret;
}
e = l->head;
while (e != NULL)
- {
- n = e->next;
- if (e->disp == GNUNET_CONTAINER_SLIST_DISPOSITION_DYNAMIC)
- GNUNET_free (e->elem);
- GNUNET_free (e);
- e = n;
- }
+ {
+ n = e->next;
+ if (e->disp == GNUNET_CONTAINER_SLIST_DISPOSITION_DYNAMIC)
+ GNUNET_free (e->elem);
+ GNUNET_free (e);
+ e = n;
+ }
l->head = NULL;
l->tail = NULL;
l->length = 0;
*/
int
GNUNET_CONTAINER_slist_contains (const struct GNUNET_CONTAINER_SList *l,
- const void *buf, size_t len)
+ const void *buf, size_t len)
{
struct GNUNET_CONTAINER_SList_Elem *e;
*/
void
GNUNET_CONTAINER_slist_insert (struct GNUNET_CONTAINER_SList_Iterator *before,
- enum GNUNET_CONTAINER_SListDisposition disp,
- const void *buf, size_t len)
+ enum GNUNET_CONTAINER_SListDisposition disp,
+ const void *buf, size_t len)
{
struct GNUNET_CONTAINER_SList_Elem *e;
*/
void *
GNUNET_CONTAINER_slist_get (const struct GNUNET_CONTAINER_SList_Iterator *i,
- size_t * len)
+ size_t * len)
{
if (len)
*len = i->elem->len;
* @param i iterator
*/
void
-GNUNET_CONTAINER_slist_iter_destroy (struct GNUNET_CONTAINER_SList_Iterator
- *i)
+GNUNET_CONTAINER_slist_iter_destroy (struct GNUNET_CONTAINER_SList_Iterator *i)
{
- GNUNET_free (i);
}
/* end of container_slist.c */