From 837e80977cdd9fda61fb0789bfd6b64c7639c25a Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Wed, 28 Oct 2009 11:10:36 -0700 Subject: [PATCH] shash: New function shash_find_and_delete(). --- lib/shash.c | 13 +++++++++++++ lib/shash.h | 1 + 2 files changed, 14 insertions(+) diff --git a/lib/shash.c b/lib/shash.c index da33fe8b..5d8ecfa6 100644 --- a/lib/shash.c +++ b/lib/shash.c @@ -100,6 +100,19 @@ shash_find_data(const struct shash *sh, const char *name) return node ? node->data : NULL; } +void * +shash_find_and_delete(struct shash *sh, const char *name) +{ + struct shash_node *node = shash_find(sh, name); + if (node) { + void *data = node->data; + shash_delete(sh, node); + return data; + } else { + return NULL; + } +} + struct shash_node * shash_first(const struct shash *shash) { diff --git a/lib/shash.h b/lib/shash.h index 5794a20f..56f13bc7 100644 --- a/lib/shash.h +++ b/lib/shash.h @@ -46,6 +46,7 @@ struct shash_node *shash_add(struct shash *, const char *, void *); void shash_delete(struct shash *, struct shash_node *); struct shash_node *shash_find(const struct shash *, const char *); void *shash_find_data(const struct shash *, const char *); +void *shash_find_and_delete(struct shash *, const char *); struct shash_node *shash_first(const struct shash *); #endif /* shash.h */ -- 2.30.2