X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=lib%2Fshash.c;h=5257de12aad4c4df7acb03809224e1e0bdd70e0c;hb=5e4641a147c3e450a56b199b9066f1af75c2f779;hp=c35164bd92e277b98e5599c46f41f92485f909f5;hpb=07423999f1759af064316aa4c1a1f499322c5ddc;p=openvswitch diff --git a/lib/shash.c b/lib/shash.c index c35164bd..5257de12 100644 --- a/lib/shash.c +++ b/lib/shash.c @@ -67,15 +67,26 @@ shash_count(const struct shash *shash) /* It is the caller's responsibility to avoid duplicate names, if that is * desirable. */ struct shash_node * -shash_add(struct shash *sh, const char *name, void *data) +shash_add(struct shash *sh, const char *name, const void *data) { struct shash_node *node = xmalloc(sizeof *node); node->name = xstrdup(name); - node->data = data; + node->data = (void *) data; hmap_insert(&sh->map, &node->node, hash_name(name)); return node; } +bool +shash_add_once(struct shash *sh, const char *name, const void *data) +{ + if (!shash_find(sh, name)) { + shash_add(sh, name, data); + return true; + } else { + return false; + } +} + void shash_delete(struct shash *sh, struct shash_node *node) {