Add utility function to store a value into a table.

This commit is contained in:
2018-04-26 20:59:12 -07:00
parent edcd5fc5ae
commit 51e9a11a1f
2 changed files with 31 additions and 0 deletions

View File

@@ -200,3 +200,25 @@ libab_result libab_create_function_list(libab_ref* into, libab_ref* type) {
return result;
}
libab_result libab_put_table_value(libab_table* table,
const char* key, libab_ref* value) {
libab_table_entry* entry;
libab_result result = LIBAB_SUCCESS;
if((entry = malloc(sizeof(*entry)))) {
entry->variant = ENTRY_VALUE;
libab_ref_copy(value, &entry->data_u.value);
} else {
result = LIBAB_MALLOC;
}
if(result == LIBAB_SUCCESS) {
result = libab_table_put(table, key, entry);
if(result != LIBAB_SUCCESS) {
libab_ref_free(&entry->data_u.value);
free(entry);
}
}
return result;
}