X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Futil%2Fcontainer_slist.c;h=6b583258376ce101a49d76ec1072cc3f2564aeb5;hb=f4d040c0f0dd2fef3d73b1f4532c76219f760f75;hp=7b85dc87760780239eeab9720e1e030f64cc97fb;hpb=83b19539f4d322b43683f5838b72e9ec2c8e6073;p=oweals%2Fgnunet.git diff --git a/src/util/container_slist.c b/src/util/container_slist.c index 7b85dc877..6b5832583 100644 --- a/src/util/container_slist.c +++ b/src/util/container_slist.c @@ -250,10 +250,11 @@ GNUNET_CONTAINER_slist_clear (struct GNUNET_CONTAINER_SList *l) /** * Check if a list contains a certain element - * * @param l list * @param buf payload buffer to find * @param len length of the payload (number of bytes in buf) + * + * @return GNUNET_YES if found, GNUNET_NO otherwise */ int GNUNET_CONTAINER_slist_contains (const struct GNUNET_CONTAINER_SList *l, @@ -267,6 +268,32 @@ GNUNET_CONTAINER_slist_contains (const struct GNUNET_CONTAINER_SList *l, return GNUNET_NO; } +typedef int (*Comparator)(const void *, size_t, const void *, size_t); + +/** + * Check if a list contains a certain element + * + * @param l list + * @param buf payload buffer to find + * @param len length of the payload (number of bytes in buf) + * @param compare comparison function, should return 0 if compared elements match + * + * @return NULL if the 'buf' could not be found, pointer to the + * list element, if found + */ +void * +GNUNET_CONTAINER_slist_contains2 (const struct GNUNET_CONTAINER_SList *l, + const void *buf, size_t len, + Comparator compare) +{ + struct GNUNET_CONTAINER_SList_Elem *e; + + for (e = l->head; e != NULL; e = e->next) + if ((e->len == len) && (*compare)(buf, len, e->elem, e->len) == 0) + return e->elem; + return NULL; +} + /** * Count the elements of a list