Exemple #1
0
struct config_value *config_value_create(struct config *co, const char *name, const char *value)
{
	debug(D_CONFIG, "Creating config entry for name '%s', value '%s', in section '%s'.", name, value, co->name);

	struct config_value *cv = calloc(1, sizeof(struct config_value));
	if(!cv) fatal("Cannot allocate config_value");

	cv->name = strdup(name);
	if(!cv->name) fatal("Cannot allocate config.name");
	cv->hash = simple_hash(cv->name);

	cv->value = strdup(value);
	if(!cv->value) fatal("Cannot allocate config.value");

	config_value_index_add(co, cv);

	// no need for string termination, due to calloc()

	struct config_value *cv2 = co->values;
	if(cv2) {
		while (cv2->next) cv2 = cv2->next;
		cv2->next = cv;
	}
	else co->values = cv;

	return cv;
}
Exemple #2
0
static inline struct config_value *config_value_create(struct config *co, const char *name, const char *value)
{
    debug(D_CONFIG, "Creating config entry for name '%s', value '%s', in section '%s'.", name, value, co->name);

    struct config_value *cv = callocz(1, sizeof(struct config_value));
    cv->name = strdupz(name);
    cv->hash = simple_hash(cv->name);
    cv->value = strdupz(value);

    config_value_index_add(co, cv);

    config_section_write_lock(co);
    struct config_value *cv2 = co->values;
    if(cv2) {
        while (cv2->next) cv2 = cv2->next;
        cv2->next = cv;
    }
    else co->values = cv;
    config_section_unlock(co);

    return cv;
}