10.2. configfile — Configuration file (INI-file)¶
The INI file format is an informal standard for configuration files for some platforms or software. INI files are simple text files with a basic structure composed of sections, properties, and values.
More information on Wikipedia.
10.2.1. File format description¶
- Line terminators:
\n,\r\nor\n\r. - Opening bracket (
[) at the beginning of a line indicates a section. The section name is all characters until a closing bracket (]). - A property line starts with its name, then a colon (
:) or equal sign (=), and then the value. - Semicolon (
;) or number sign (#) at the beginning of a line indicate a comment.
10.2.2. Example file¶
; last modified 1 April 2001 by John Doe
[owner]
name = John Doe
organization = Acme Widgets Inc.
[database]
; use IP address in case network name resolution is not working
server = 192.0.2.62
port = 143
file = "payroll.dat"
Source code: src/text/configfile.h, src/text/configfile.c
Test code: tst/text/configfile/main.c
Test coverage: src/text/configfile.c
- Version
- 7.0.0
Functions
-
int
configfile_init(struct configfile_t *self_p, char *buf_p, size_t size)¶ Initialize given configuration file object.
- Return
- zero(0) or negative error code.
- Parameters
self_p-Object to initialize.
buf_p-Configuration file contents as a NULL terminated string.
size-Size of the configuration file contents.
-
int
configfile_set(struct configfile_t *self_p, const char *section_p, const char *property_p, const char *value_p)¶ Set the value of given property in given section.
- Return
- zero(0) or negative error code.
- Parameters
self_p-Initialized parser.
section_p-Section to set the property from.
property_p-Property to set the value for.
value_p-NULL terminated value to set.
-
char *
configfile_get(struct configfile_t *self_p, const char *section_p, const char *property_p, char *value_p, int length)¶ Get the value of given property in given section.
- Return
- Value pointer or NULL on failure.
- Parameters
self_p-Initialized parser.
section_p-Section to get the property from.
property_p-Property to get the value for.
value_p-Value of given property in given section.
size-Size of the value buffer.
-
int
configfile_get_long(struct configfile_t *self_p, const char *section_p, const char *property_p, long *value_p)¶ Get the value of given property in given section, converted to an integer.
- Return
- zero(0) or negative error code.
- Parameters
self_p-Initialized parser.
section_p-Section to get the property from.
property_p-Property to get the value for.
value_p-Value of given property in given section.
-
int
configfile_get_float(struct configfile_t *self_p, const char *section_p, const char *property_p, float *value_p)¶ Get the value of given property in given section, converted to a float.
- Return
- zero(0) or negative error code.
- Parameters
self_p-Initialized parser.
section_p-Section to get the property from.
property_p-Property to get the value for.
value_p-Value of given property in given section.
-
struct
configfile_t¶