From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id 2F388376C for ; Mon, 4 Sep 2017 12:58:47 +0200 (CEST) Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Sep 2017 03:58:46 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.41,474,1498546800"; d="scan'208";a="147892952" Received: from bricha3-mobl3.ger.corp.intel.com ([10.237.221.24]) by fmsmga006.fm.intel.com with SMTP; 04 Sep 2017 03:58:44 -0700 Received: by (sSMTP sendmail emulation); Mon, 04 Sep 2017 11:58:44 +0100 Date: Mon, 4 Sep 2017 11:58:44 +0100 From: Bruce Richardson To: Guduri Prathyusha Cc: cristian.dumitrescu@intel.com, dev@dpdk.org Message-ID: <20170904105843.GA15316@bricha3-MOBL3.ger.corp.intel.com> References: <1493275900-4728-1-git-send-email-gprathyusha@caviumnetworks.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1493275900-4728-1-git-send-email-gprathyusha@caviumnetworks.com> Organization: Intel Research and =?iso-8859-1?Q?De=ACvel?= =?iso-8859-1?Q?opment?= Ireland Ltd. User-Agent: Mutt/1.8.3 (2017-05-23) Subject: Re: [dpdk-dev] [PATCH] librte_cfgfile: add section num entries by index X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 Sep 2017 10:58:48 -0000 On Thu, Apr 27, 2017 at 12:21:40PM +0530, Guduri Prathyusha wrote: > 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 Reviewed-by: Bruce Richardson Acked-by: Bruce Richardson > --- > lib/librte_cfgfile/rte_cfgfile.c | 13 +++++++++++++ > lib/librte_cfgfile/rte_cfgfile.h | 20 ++++++++++++++++++++ > 2 files changed, 33 insertions(+) > > diff --git a/lib/librte_cfgfile/rte_cfgfile.c b/lib/librte_cfgfile/rte_cfgfile.c > index b54a523..2588093 100644 > --- a/lib/librte_cfgfile/rte_cfgfile.c > +++ b/lib/librte_cfgfile/rte_cfgfile.c > @@ -408,7 +408,20 @@ int rte_cfgfile_close(struct rte_cfgfile *cfg) > 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); I don't like the fact that the section name is being overwritten here, but the behaviour is consistent with that done by the other "by_index()" functions, so it's probably better to keep this. In future a change to consider would be remove the sectionname entirely from the function arguments since it serves no purpose that I can see. > + > + return sect->num_entries; > +} > int > rte_cfgfile_section_entries(struct rte_cfgfile *cfg, const char *sectionname, > struct rte_cfgfile_entry *entries, int max_entries) > diff --git a/lib/librte_cfgfile/rte_cfgfile.h b/lib/librte_cfgfile/rte_cfgfile.h > index fa10d40..35dc419 100644 > --- a/lib/librte_cfgfile/rte_cfgfile.h > +++ b/lib/librte_cfgfile/rte_cfgfile.h > @@ -184,6 +184,26 @@ int rte_cfgfile_section_num_entries(struct rte_cfgfile *cfg, > 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 > * > * If multiple sections have the given name this function operates on the > -- > 1.7.9.5 >