X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=lib%2Fsmap.c;h=b81ac09c2509c46878c4c46eec1023ece877690f;hb=ad4c35fe2dd8edaab6331667021b6b8410abde90;hp=ff785981226425d7a42dd34e44e44d2ea617a295;hpb=51c82a49d58daebe289e045fe44009d59b1f9236;p=openvswitch diff --git a/lib/smap.c b/lib/smap.c index ff785981..b81ac09c 100644 --- a/lib/smap.c +++ b/lib/smap.c @@ -125,16 +125,29 @@ 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) +/* Deletes 'node' from 'smap'. + * + * If 'keyp' is nonnull, stores the node's key in '*keyp' and transfers + * ownership to the caller. Otherwise, frees the node's key. Similarly for + * 'valuep' and the node's value. */ +void +smap_steal(struct smap *smap, struct smap_node *node, + char **keyp, char **valuep) { - char *key = node->key; + if (keyp) { + *keyp = node->key; + } else { + free(node->key); + } + + if (valuep) { + *valuep = node->value; + } else { + free(node->value); + } hmap_remove(&smap->map, &node->node); free(node); - return key; } /* Removes all key-value pairs from 'smap'. */