From: Ben Pfaff Date: Wed, 27 Jun 2012 18:06:10 +0000 (-0700) Subject: smap: New function smap_steal(). X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=51c82a49d58daebe289e045fe44009d59b1f9236;p=openvswitch smap: New function smap_steal(). An upcoming commit will add a caller. Signed-off-by: Ben Pfaff --- 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 *);