Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.
31 changes: 31 additions & 0 deletions src/config-ini.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,3 +297,34 @@ config_ini_get_section(config_ini_state_t *state, const char *name)

return NULL;
}

config_ini_section_t **
config_ini_get_sections(config_ini_state_t *state, const char *name)
{
config_ini_section_t **sections = malloc(1 * sizeof(config_ini_section_t*));
if (sections == NULL) {
perror("malloc");
return NULL;
}

int ptr = 0;
config_ini_section_t *section = state->sections;
while (section != NULL) {
if (strcasecmp(section->name, name) == 0) {
sections[ptr++] = section;

if ((ptr & -ptr) == ptr) {
sections = realloc(sections, (ptr << 1) * sizeof(config_ini_section_t*));
if (sections == NULL) {
perror("realloc");
return NULL;
}
}
}

section = section->next;
}

sections[ptr] = NULL;
return sections;
}
3 changes: 3 additions & 0 deletions src/config-ini.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,7 @@ void config_ini_free(config_ini_state_t *state);
config_ini_section_t *config_ini_get_section(config_ini_state_t *state,
const char *name);

config_ini_section_t **config_ini_get_sections(config_ini_state_t *state,
const char *name);

#endif /* ! REDSHIFT_CONFIG_INI_H */
Loading