From 51c82a49d58daebe289e045fe44009d59b1f9236 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Wed, 27 Jun 2012 11:06:10 -0700 Subject: [PATCH] smap: New function smap_steal(). An upcoming commit will add a caller. Signed-off-by: Ben Pfaff --- lib/smap.c | 12 ++++++++++++ lib/smap.h | 3 ++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/smap.c b/lib/smap.c index e612ac7b..ff785981 100644 --- a/lib/smap.c +++ b/lib/smap.c @@ -125,6 +125,18 @@ smap_remove_node(struct smap *smap, struct smap_node *node) free(node); } +/* Deletes 'node' from 'sh'. Neither the node's key nor its value is freed; + * instead, ownership is transferred to the caller. Returns the node's key. */ +char * +smap_steal(struct smap *smap, struct smap_node *node) +{ + char *key = node->key; + + hmap_remove(&smap->map, &node->node); + free(node); + return key; +} + /* Removes all key-value pairs from 'smap'. */ void smap_clear(struct smap *smap) diff --git a/lib/smap.h b/lib/smap.h index 8510a376..13eec1c4 100644 --- a/lib/smap.h +++ b/lib/smap.h @@ -48,7 +48,8 @@ void smap_add_format(struct smap *, const char *key, const char *, ...) void smap_replace(struct smap *, const char *, const char *); void smap_remove(struct smap *, const char *); -void smap_remove_node(struct smap *smap, struct smap_node *); +void smap_remove_node(struct smap *, struct smap_node *); +char *smap_steal(struct smap *, struct smap_node *); void smap_clear(struct smap *); const char *smap_get(const struct smap *, const char *); -- 2.30.2