Util: Adding a null value to a Configuration removes the value
Jeffrey Pfau jeffrey@endrift.com
Tue, 04 Nov 2014 23:47:31 -0800
1 files changed,
6 insertions(+),
2 deletions(-)
jump to
M
src/util/configuration.c
→
src/util/configuration.c
@@ -40,13 +40,17 @@ void ConfigurationSetValue(struct Configuration* configuration, const char* section, const char* key, const char* value) {
struct Table* currentSection = &configuration->root; if (section) { currentSection = HashTableLookup(&configuration->sections, section); - if (!currentSection) { + if (!currentSection && value) { currentSection = malloc(sizeof(*currentSection)); HashTableInit(currentSection, 0, _sectionDeinit); HashTableInsert(&configuration->sections, section, currentSection); } } - HashTableInsert(currentSection, key, strdup(value)); + if (value) { + HashTableInsert(currentSection, key, strdup(value)); + } else { + HashTableRemove(currentSection, key); + } } const char* ConfigurationGetValue(const struct Configuration* configuration, const char* section, const char* key) {