cfgfile: add section number of entries by index

rte_cfgfile_section_num_entries_by_index() is added to get the number of
entries of a section when multiple sections of the same name are
present.

Signed-off-by: Guduri Prathyusha <gprathyusha@caviumnetworks.com>
Reviewed-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
This commit is contained in:
Guduri Prathyusha 2017-04-27 12:21:40 +05:30 committed by Thomas Monjalon
parent aee62e906f
commit 3d2e0448eb
2 changed files with 33 additions and 0 deletions

View File

@ -408,7 +408,20 @@ rte_cfgfile_section_num_entries(struct rte_cfgfile *cfg,
return s->num_entries; return s->num_entries;
} }
int
rte_cfgfile_section_num_entries_by_index(struct rte_cfgfile *cfg,
char *sectionname, int index)
{
const struct rte_cfgfile_section *sect;
if (index < 0 || index >= cfg->num_sections)
return -1;
sect = cfg->sections[index];
snprintf(sectionname, CFG_NAME_LEN, "%s", sect->name);
return sect->num_entries;
}
int int
rte_cfgfile_section_entries(struct rte_cfgfile *cfg, const char *sectionname, rte_cfgfile_section_entries(struct rte_cfgfile *cfg, const char *sectionname,
struct rte_cfgfile_entry *entries, int max_entries) struct rte_cfgfile_entry *entries, int max_entries)

View File

@ -183,6 +183,26 @@ int rte_cfgfile_has_section(struct rte_cfgfile *cfg, const char *sectionname);
int rte_cfgfile_section_num_entries(struct rte_cfgfile *cfg, int rte_cfgfile_section_num_entries(struct rte_cfgfile *cfg,
const char *sectionname); const char *sectionname);
/**
* Get number of entries in given config file section
*
* The index of a section is the same as the index of its name in the
* result of rte_cfgfile_sections. This API can be used when there are
* multiple sections with the same name.
*
* @param cfg
* Config file
* @param sectionname
* Section name
* @param index
* Section index
* @return
* Number of entries in section on success, -1 otherwise
*/
int rte_cfgfile_section_num_entries_by_index(struct rte_cfgfile *cfg,
char *sectionname,
int index);
/** /**
* Get section entries as key-value pairs * Get section entries as key-value pairs
* *