4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #ifndef __INCLUDE_RTE_CFGFILE_H__
35 #define __INCLUDE_RTE_CFGFILE_H__
45 * RTE Configuration File
47 * This library allows reading application defined parameters from standard
48 * format configuration file.
53 #define CFG_NAME_LEN 64
57 #define CFG_VALUE_LEN 256
60 /** Configuration file */
63 /** Configuration file entry */
64 struct rte_cfgfile_entry {
65 char name[CFG_NAME_LEN]; /**< Name */
66 char value[CFG_VALUE_LEN]; /**< Value */
75 * Config file flags, Reserved for future use. Must be set to 0.
77 * Handle to configuration file on success, NULL otherwise
79 struct rte_cfgfile *rte_cfgfile_load(const char *filename, int flags);
82 * Get number of sections in config file
89 * Maximum section name length
91 * 0 on success, error code otherwise
93 int rte_cfgfile_num_sections(struct rte_cfgfile *cfg, const char *sec_name,
97 * Get name of all config file sections.
99 * Fills in the array sections with the name of all the sections in the file
100 * (up to the number of max_sections sections).
105 * Array containing section names after successful invocation. Each elemen
106 * of this array should be preallocated by the user with at least
107 * CFG_NAME_LEN characters.
108 * @param max_sections
109 * Maximum number of section names to be stored in sections array
111 * 0 on success, error code otherwise
113 int rte_cfgfile_sections(struct rte_cfgfile *cfg, char *sections[],
117 * Check if given section exists in config file
124 * TRUE (value different than 0) if section exists, FALSE (value 0) otherwise
126 int rte_cfgfile_has_section(struct rte_cfgfile *cfg, const char *sectionname);
129 * Get number of entries in given config file section
131 * If multiple sections have the given name this function operates on the
139 * Number of entries in section
141 int rte_cfgfile_section_num_entries(struct rte_cfgfile *cfg,
142 const char *sectionname);
144 /** Get section entries as key-value pairs
146 * If multiple sections have the given name this function operates on the
154 * Pre-allocated array of at least max_entries entries where the section
155 * entries are stored as key-value pair after successful invocation
157 * Maximum number of section entries to be stored in entries array
159 * 0 on success, error code otherwise
161 int rte_cfgfile_section_entries(struct rte_cfgfile *cfg,
162 const char *sectionname,
163 struct rte_cfgfile_entry *entries,
166 /** Get section entries as key-value pairs
168 * The index of a section is the same as the index of its name in the
169 * result of rte_cfgfile_sections. This API can be used when there are
170 * multiple sections with the same name.
177 * Pre-allocated string of at least CFG_NAME_LEN characters where the
178 * section name is stored after successful invocation.
180 * Pre-allocated array of at least max_entries entries where the section
181 * entries are stored as key-value pair after successful invocation
183 * Maximum number of section entries to be stored in entries array
185 * Number of entries populated on success, negative error code otherwise
187 int rte_cfgfile_section_entries_by_index(struct rte_cfgfile *cfg,
190 struct rte_cfgfile_entry *entries,
193 /** Get value of the named entry in named config file section
195 * If multiple sections have the given name this function operates on the
207 const char *rte_cfgfile_get_entry(struct rte_cfgfile *cfg,
208 const char *sectionname,
209 const char *entryname);
211 /** Check if given entry exists in named config file section
213 * If multiple sections have the given name this function operates on the
223 * TRUE (value different than 0) if entry exists, FALSE (value 0) otherwise
225 int rte_cfgfile_has_entry(struct rte_cfgfile *cfg, const char *sectionname,
226 const char *entryname);
228 /** Close config file
233 * 0 on success, error code otherwise
235 int rte_cfgfile_close(struct rte_cfgfile *cfg);