return NULL;
}
-static int pakfire_section_in_sections(char** sections, const char* section) {
+static int pakfire_section_in_sections(const char** sections, const char* section) {
if (!sections)
return 0;
- for (char** s = sections; *s; s++) {
+ for (const char** s = sections; *s; s++) {
if (strcmp(section, *s) == 0)
return 1;
}
return 0;
}
-char** pakfire_config_sections(struct pakfire_config* config) {
+const char** pakfire_config_sections(struct pakfire_config* config) {
struct pakfire_config_entry* entry = NULL;
- char** sections = NULL;
+ const char** sections = NULL;
size_t num_sections = 0;
STAILQ_FOREACH(entry, &config->entries, nodes) {
if (!sections)
return NULL;
- sections[num_sections - 1] = strdup(entry->section);
+ sections[num_sections - 1] = entry->section;
// Terminate the array
sections[num_sections] = NULL;
int r;
// Fetch a list of all available sections
- char** sections = pakfire_config_sections(config);
+ const char** sections = pakfire_config_sections(config);
// Dump the default section
r = pakfire_config_dump_section(config, "", f);
// Dump all sections
if (sections) {
- for (char** section = sections; *section; section++) {
+ for (const char** section = sections; *section; section++) {
r = pakfire_config_dump_section(config, *section, f);
if (r)
goto ERROR;
}
ERROR:
- if (sections) {
- for (char** section = sections; *section; section++)
- free(*section);
+ if (sections)
free(sections);
- }
return r;
}
FILE* pakfire_config_get_fopen(struct pakfire_config* config,
const char* section, const char* key);
-char** pakfire_config_sections(struct pakfire_config* config);
+const char** pakfire_config_sections(struct pakfire_config* config);
int pakfire_config_has_section(struct pakfire_config* config, const char* section);
int pakfire_config_read(struct pakfire_config* config, FILE* f);
}
int pakfire_repo_import(struct pakfire* pakfire, struct pakfire_config* config) {
- char** sections = pakfire_config_sections(config);
+ const char** sections = pakfire_config_sections(config);
// The configuration seems to be empty
if (!sections)
goto ERROR;
ERROR:
- for (char** section = sections; *section; section++)
- free(*section);
- free(sections);
+ if (sections)
+ free(sections);
return r;
}