struct config *config_create(const char *section) { debug(D_CONFIG, "Creating section '%s'.", section); struct config *co = calloc(1, sizeof(struct config)); if(!co) fatal("Cannot allocate config"); co->name = strdup(section); if(!co->name) fatal("Cannot allocate config.name"); co->hash = simple_hash(co->name); co->values_index.compar = config_value_compare; config_index_add(co); // no need for string termination, due to calloc() struct config *co2 = config_root; if(co2) { while (co2->next) co2 = co2->next; co2->next = co; } else config_root = co; return co; }
static inline struct config *config_section_create(const char *section) { debug(D_CONFIG, "Creating section '%s'.", section); struct config *co = calloc(1, sizeof(struct config)); if(!co) fatal("Cannot allocate config"); co->name = strdup(section); if(!co->name) fatal("Cannot allocate config.name"); co->hash = simple_hash(co->name); avl_init_lock(&co->values_index, config_value_compare); config_index_add(co); config_global_write_lock(); struct config *co2 = config_root; if(co2) { while (co2->next) co2 = co2->next; co2->next = co; } else config_root = co; config_global_unlock(); return co; }