diff --git a/list.c b/list.c index e3886a27..a123d0c2 100644 --- a/list.c +++ b/list.c @@ -24,7 +24,7 @@ coap_insert(coap_list_t **queue, coap_list_t *node, /* replace queue head if new node has to be added before the existing queue head */ q = *queue; - if ( order( node->data, q->data ) ) { + if ( order( node->data, q->data ) < 0) { node->next = q; *queue = node; return 1; @@ -34,7 +34,7 @@ coap_insert(coap_list_t **queue, coap_list_t *node, do { p = q; q = q->next; - } while ( q && ! order( node->data, q->data ) ); + } while ( q && order( node->data, q->data ) >= 0); /* insert new item */ node->next = q; diff --git a/list.h b/list.h index fa9f07d2..05fb60ca 100644 --- a/list.h +++ b/list.h @@ -15,7 +15,7 @@ typedef struct coap_linkedlistnode coap_list_t; /* adds node to given queue, ordered by specified order function */ int coap_insert(coap_list_t **queue, coap_list_t *node, - int (*order)(void *, void *node) ); + int (*order)(void *, void *) ); /* destroys specified node */ int coap_delete(coap_list_t *node); @@ -23,4 +23,11 @@ int coap_delete(coap_list_t *node); /* removes all items from given queue and frees the allocated storage */ void coap_delete_list(coap_list_t *queue); +/** + * Creates a new list node and adds the given data object. The memory allocated + * by data will be released by coap_delete() with the new node. Returns the + * new list node. + */ +coap_list_t *coap_new_listnode(void *data); + #endif /* _COAP_LIST_H_ */