X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=lib%2Flibrte_cfgfile%2Frte_cfgfile.c;h=832fea829764108923992ed219397c8c07fda917;hb=1a5efe749959e14a3af6c962bdfb51dcc14e6929;hp=75625a28fca8307c4c6c40ded7c3e235e29da04f;hpb=c2189745c38d944e3b0e0c99066d67d7bc7e7744;p=dpdk.git diff --git a/lib/librte_cfgfile/rte_cfgfile.c b/lib/librte_cfgfile/rte_cfgfile.c index 75625a28fc..832fea8297 100644 --- a/lib/librte_cfgfile/rte_cfgfile.c +++ b/lib/librte_cfgfile/rte_cfgfile.c @@ -107,6 +107,22 @@ rte_cfgfile_load(const char *filename, int flags) memset(cfg->sections, 0, sizeof(cfg->sections[0]) * allocated_sections); + if (flags & CFG_FLAG_GLOBAL_SECTION) { + curr_section = 0; + allocated_entries = CFG_ALLOC_ENTRY_BATCH; + cfg->sections[curr_section] = malloc( + sizeof(*cfg->sections[0]) + + sizeof(cfg->sections[0]->entries[0]) * + allocated_entries); + if (cfg->sections[curr_section] == NULL) { + printf("Error - no memory for global section\n"); + goto error1; + } + + snprintf(cfg->sections[curr_section]->name, + sizeof(cfg->sections[0]->name), "GLOBAL"); + } + while (fgets(buffer, sizeof(buffer), f) != NULL) { char *pos = NULL; size_t len = strnlen(buffer, sizeof(buffer)); @@ -151,6 +167,7 @@ rte_cfgfile_load(const char *filename, int flags) sizeof(*cfg) + sizeof(cfg->sections[0]) * allocated_sections); if (n_cfg == NULL) { + curr_section--; printf("Error - no more memory\n"); goto error1; } @@ -198,6 +215,7 @@ rte_cfgfile_load(const char *filename, int flags) sizeof(sect->entries[0]) * allocated_entries); if (n_sect == NULL) { + curr_entry--; printf("Error - no more memory\n"); goto error1; } @@ -232,6 +250,9 @@ rte_cfgfile_load(const char *filename, int flags) return cfg; error1: + cfg->num_sections = curr_section + 1; + if (curr_section >= 0) + cfg->sections[curr_section]->num_entries = curr_entry + 1; rte_cfgfile_close(cfg); error2: fclose(f);