struct span_table *span_table_alloc(void) { struct htable *ht; ht = htable_alloc(128, ht_hash_string, ht_compare_string); if (!ht) { return NULL; } return (struct span_table*)ht; }
static struct htable *htable_from_str(const char *str) { struct htable *ht; char *cstr = NULL, *saveptr = NULL, *tok; int ret = ENOMEM; ht = htable_alloc(8, ht_hash_string, ht_compare_string); if (!ht) { goto done; } if (!str) { ret = 0; goto done; } cstr = strdup(str); if (!cstr) { goto done; } for (tok = strtok_r(cstr, ";", &saveptr); tok; tok = strtok_r(NULL, ";", &saveptr)) { char *key = NULL, *val = NULL; ret = parse_key_value(tok, &key, &val); if (ret) { goto done; } ret = htable_put(ht, key, val); if (ret) { goto done; } } ret = 0; done: if (ret) { htable_free(ht); ht = NULL; } free(cstr); return ht; }