libeconf(3)
π libeconf(3) π
okay so bestie, this is the libeconf manual page β manual section 3, library vibes only. two header files, one iconic library, and a whole lot of config file lore. let's get into it. π¦
β¨ NAME β¨
include/libeconf.hβ the public API for the econf library. the main character. πinclude/libeconf_ext.hβ the public extended API for the econf library. the bonus content. β¨
πΈ DESCRIPTION πΈ
okay so libeconf? it's a highly flexible and configurable library that parses and manages key=value configuration files. no cap. it reads configuration file snippets from a bunch of different directories and then stitches together the final configuration file for the application out of all of them. it's giving very much "build-a-config". π§
The first file is the vendor provided configuration file, and it lives in /usr/_vendordir_/_project_. Optionally, /run/_project_ is also supported, for ephemeral overrides (iykyk β those ones don't stick around).
Defining the _project_ sub directory is optional. lowkey optional. π
There are two methods of overriding these vendor settings, and this is where it gets juicy:
- Copy the file from
/usr/_vendordir_/_project_to/etc/_project_and modify the settings (see Example 1). - Alternatively, you can create a directory named
_file_._suffix_.d/within/etc/_project_, with drop-in files in the form_name_._suffix_(see Example 2).
These files contain only the changes of the specific settings the user is interested in β not the whole config, just the diff, bestie. π There can be several such drop-in files, and they are processed in lexicographic order of their filename (yes, alphabetically, in order, no skipping).
The first method is useful when you want to override the complete configuration file with your own one β in that case the vendor supplied configuration is ignored. π«
So, if /etc/_project_/_example_._suffix_ exists, then /usr/_vendor_/_project_/_example_._suffix_ and /run/_project_/_example_._suffix_ will not be read. The disadvantage is that changes to the vendor configuration file β due e.g. an package update β are ignored, and the user has to manually merge them. π that's the price of freedom, fr fr.
The other method will continue to use /usr/_vendor_/_project_/_example_._suffix_ as the base configuration file and merge all changes from /etc/_project_/_example_._suffix_.d/*._suffix_. So the user will automatically get improvements from the vendor, with the drawback that they could be incompatible with the user made changes. β οΈ
If there is a file with the same name in /usr/_vendor_/_project_/_example_._suffix_.d/ and in /etc/_project_/_example_._suffix_.d/*._suffix_., the file in /usr/_project_/_vendor_/_example_._suffix_.d/ will completely ignored. π (yes, really β the vendor one just loses.)
To disable a configuration file supplied by the vendor, the recommended way is to place a symlink to /dev/null in the configuration directory in /etc/_project_, with the same filename as the vendor configuration file. iconic trick, honestly. π
Optionally, schemes with only drop-ins and without a βmainβ configuration file will be supported too. In such schemes many drop-ins are loaded from a common directory in each hierarchy. For example, /usr/lib/<project>.d/*, /run/<project>.d/* and /etc/<project>.d/c.conf are all loaded and parsed in this scheme. π
π Example 1 π
If a /etc/_example_._suffix_ file exists:
/etc/_example_._suffix_/usr/_vendor_/_project_/_example_._suffix_.d/*._suffix_/run/_project_/_example_._suffix_.d/*._suffix_/etc/_project_/_example_._suffix_.d/*._suffix_
π¦ Example 2 π¦
The list of files and directories read if no /etc/_example_._suffix_ file exists:
/usr/_vendor_/_project_/_example_._suffix_if no/run/_project_/_example_._suffix_exist/usr/_vendor_/_project_/_example_._suffix_.d/*._suffix_/run/_project_/_example_._suffix_.d/*._suffix_/etc/_project_/_example_._suffix_.d/*._suffix_
β UAPI Configuration Files Specification β
The libeconf library fulfills all requirements defined by the Linux Userspace API (UAPI) Group chapter "Configuration Files Specification". π
See: https://uapi-group.org/specifications/specs/configuration_files_specification/
π Bindings π
- Python Documentation:
https://github.com/openSUSE/libeconf/blob/master/bindings/python3/docs/python-libeconf.3 - C# Documentation:
https://github.com/openSUSE/libeconf/blob/master/bindings/csharp/docs/README.md
β¨ SYNOPSIS β¨
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include 'libeconf.h'
#include 'libeconf_ext.h'
π Typedefs
typedef enum econf_err econf_err
typedef struct econf_file econf_file
typedef struct econf_ext_value econf_ext_value
πΈ Enumerations
enum econf_err { ECONF_SUCCESS = 0, ECONF_ERROR = 1, ECONF_NOMEM = 2,
ECONF_NOFILE = 3, ECONF_NOGROUP = 4, ECONF_NOKEY = 5, ECONF_EMPTYKEY
= 6, ECONF_WRITEERROR = 7, ECONF_PARSE_ERROR = 8,
ECONF_MISSING_BRACKET = 9, ECONF_MISSING_DELIMITER = 10,
ECONF_EMPTY_SECTION_NAME = 11, ECONF_TEXT_AFTER_SECTION = 12,
ECONF_FILE_LIST_IS_NULL = 13, ECONF_WRONG_BOOLEAN_VALUE = 14,
ECONF_KEY_HAS_NULL_VALUE = 15, ECONF_WRONG_OWNER = 16,
ECONF_WRONG_GROUP = 17, ECONF_WRONG_FILE_PERMISSION = 18,
ECONF_WRONG_DIR_PERMISSION = 19, ECONF_ERROR_FILE_IS_SYM_LINK = 20,
ECONF_PARSING_CALLBACK_FAILED = 21 }
libeconf error codes β bestie, these are your entire emotional support enum π
π¦ Functions
econf_err econf_readConfig (econf_file **key_file, const char *project, const char *usr_subdir, const char *config_name, const char *config_suffix, const char *delim, const char *comment)β literally the main character of this whole library π«Ά it evaluates key/values of a given configuration by reading and merging all needed/available files in three different directories (normally in/usr/etc,/runand/etc).econf_err econf_readConfigWithCallback (econf_file **key_file, const char *project, const char *usr_subdir, const char *config_name, const char *config_suffix, const char *delim, const char *comment, bool (*callback)(const char *filename, const void *data), const void *callback_data)β does the same thing aseconf_readConfig, no cap. The difference? you get to hand it a callback so you can, like, check every single parsed file. very your-vibe-your-rules β¨econf_err econf_readFile (econf_file **result, const char *file_name, const char *delim, const char *comment)β processes the file of the givenfile_nameand saves its contents into thekey_fileobject. simple. iconic.econf_err econf_readFileWithCallback (econf_file **result, const char *file_name, const char *delim, const char *comment, bool (*callback)(const char *filename, const void *data), const void *callback_data)β same energy aseconf_readFile, but the user can additionally define a callback in order to check the parsed file πeconf_err econf_mergeFiles (econf_file **merged_file, econf_file *usr_file, econf_file *etc_file)β merges the contents of twokey_filesobjects. friendship bracelet energy fr fr πeconf_err econf_newKeyFile (econf_file **result, char delimiter, char comment)β creates a brand neweconf_fileobject. fresh out the box πeconf_err econf_newIniFile (econf_file **result)β creates a neweconf_fileobject, but make it IniFile format πΈeconf_err econf_writeFile (econf_file *key_file, const char *save_to_dir, const char *file_name)β writes the content of aneconf_filestruct to the specified location. put it in writing, periodt βοΈchar * econf_getPath (econf_file *kf)β evaluates the path name of the regarding configuration file.econf_err econf_getGroups (econf_file *kf, size_t *length, char ***groups)β evaluates all group entries.econf_err econf_getKeys (econf_file *kf, const char *group, size_t *length, char ***keys)β evaluates all keys.econf_err econf_getIntValue (econf_file *kf, const char *group, const char *key, int32_t *result)β evaluates theint32value for a given group/key.econf_err econf_getInt64Value (econf_file *kf, const char *group, const char *key, int64_t *result)β evaluates theint64value for a given group/key.econf_err econf_getUIntValue (econf_file *kf, const char *group, const char *key, uint32_t *result)β evaluates theuint32value for a given group/key.econf_err econf_getUInt64Value (econf_file *kf, const char *group, const char *key, uint64_t *result)β evaluates theuint64value for a given group/key.econf_err econf_getFloatValue (econf_file *kf, const char *group, const char *key, float *result)β evaluates thefloatvalue for a given group/key.econf_err econf_getDoubleValue (econf_file *kf, const char *group, const char *key, double *result)β evaluates thedoublevalue for a given group/key.econf_err econf_getStringValue (econf_file *kf, const char *group, const char *key, char **result)β evaluates the string value for a given group/key.econf_err econf_getBoolValue (econf_file *kf, const char *group, const char *key, bool *result)β evaluates the bool value for a given group/key.econf_err econf_getIntValueDef (econf_file *kf, const char *group, const char *key, int32_t *result, int32_t def)β evaluates theint32value for a given group/key, with a default fallback π«Άeconf_err econf_getInt64ValueDef (econf_file *kf, const char *group, const char *key, int64_t *result, int64_t def)β evaluates theint64value for a given group/key, default included.econf_err econf_getUIntValueDef (econf_file *kf, const char *group, const char *key, uint32_t *result, uint32_t def)β evaluates theuint32value for a given group/key, plus a default.econf_err econf_getUInt64ValueDef (econf_file *kf, const char *group, const char *key, uint64_t *result, uint64_t def)β evaluates theuint64value for a given group/key, plus a default.econf_err econf_getFloatValueDef (econf_file *kf, const char *group, const char *key, float *result, float def)β evaluates thefloatvalue for a given group/key, plus a default.econf_err econf_getDoubleValueDef (econf_file *kf, const char *group, const char *key, double *result, double def)β evaluates thedoublevalue for a given group/key, plus a default.econf_err econf_getStringValueDef (econf_file *kf, const char *group, const char *key, char **result, char *def)β evaluates the string value for a given group/key, plus a default.econf_err econf_getBoolValueDef (econf_file *kf, const char *group, const char *key, bool *result, bool def)β evaluates the bool value for a given group/key, plus a default.econf_err econf_setIntValue (econf_file *kf, const char *group, const char *key, int32_t value)β sets anint32value for a given group/key.econf_err econf_setInt64Value (econf_file *kf, const char *group, const char *key, int64_t value)β sets anint64value for a given group/key.econf_err econf_setUIntValue (econf_file *kf, const char *group, const char *key, uint32_t value)β sets auint32value for a given group/key.econf_err econf_setUInt64Value (econf_file *kf, const char *group, const char *key, uint64_t value)β sets auint64value for a given group/key.econf_err econf_setFloatValue (econf_file *kf, const char *group, const char *key, float value)β sets afloatvalue for a given group/key.econf_err econf_setDoubleValue (econf_file *kf, const char *group, const char *key, double value)β sets adoublevalue for a given group/key.econf_err econf_setStringValue (econf_file *kf, const char *group, const char *key, const char *value)β sets a string value for a given group/key.econf_err econf_setBoolValue (econf_file *kf, const char *group, const char *key, const char *value)β sets a bool value for a given group/key.const char * econf_errString (const econf_err error)β converts aneconf_errtype to a string. translating the vibe check into words π¬void econf_errLocation (char **filename, uint64_t *line_nr)β info about where the error has happened. receipts, basically π§Ύvoid econf_freeArray (char **array)β frees an array of typechar**created byeconf_getGroups()oreconf_getKeys(). cleanup era π§Ήvoid econf_freeFile (econf_file *key_file)β frees memory allocated by e.g. β¦ (yes bestie, the sentence really does just trail off like that in the original, i'm not hiding anything from you π)char econf_comment_tag (econf_file *key_file)β returns the comment character tag of the giveneconf_fileobject.char econf_delimiter_tag (econf_file *key_file)β returns the delimiter character of the giveneconf_fileobject.void econf_set_comment_tag (econf_file *key_file, const char comment)β sets the comment character tag of the giveneconf_fileobject.void econf_set_delimiter_tag (econf_file *key_file, const char delimiter)β sets the delimiter character of the giveneconf_fileobject.econf_err econf_getExtValue (econf_file *kf, const char *group, const char *key, econf_ext_value **result)β evaluates more information for a given group/key. the deluxe version, the extra lore πvoid econf_freeExtValue (econf_ext_value *to_free)β frees a completeeconf_ext_valuestruct.econf_err econf_set_conf_dirs (const char **dir_postfix_list)β sets a list of directory structures (with order) which describes the directories in which the files have to be parsed. you're literally picking the order, main character behaviour β¨
π Detailed Description π
Public API for the econf library.
Definition in file libeconf.h and libeconf_ext.h.
π Typedef Documentation π
typedef struct econf_file econf_file
Container which includes all information about the configuration file(s). it's giving β¨everything bagelβ¨ but for config data π₯―
typedef struct econf_ext_value econf_ext_value
okay so this one is a whole lil bundle of lore, and every field matters:
char ** valuesβ values of a given key in form of an string array.char * fileβ path of the configuration file where this value has been read.uint64_t line_numberβ line number of the configuration key/value.char * comment_before_keyβ comment before the key/value entry.char * comment_after_valueβ comment after the value entry.
like, it knows where it came from, what line it's on, and what was being whispered about it before and after. iconic, honestly π
β Enumeration Type Documentation β
enum econf_err
libeconf error codes
Enumerator
ECONF_SUCCESSβ general purpose success code. slay! πECONF_ERRORβ generic Error.ECONF_NOMEMβ out of memory. πECONF_NOFILEβ config file not found.ECONF_NOGROUPβ group not found.ECONF_NOKEYβ key not found.ECONF_EMPTYKEYβ key has empty value.ECONF_WRITEERRORβ error creating or writing to a file.ECONF_PARSE_ERRORβ general syntax error in input file.ECONF_MISSING_BRACKETβ missing closing section bracket.ECONF_MISSING_DELIMITERβ missing delimiter.ECONF_EMPTY_SECTION_NAMEβ empty section name.ECONF_TEXT_AFTER_SECTIONβ text after section.ECONF_FILE_LIST_IS_NULLβ parsed file list isNULL.ECONF_WRONG_BOOLEAN_VALUEβ wrong boolean value (1/0true/falseyes/no)ECONF_KEY_HAS_NULL_VALUEβ given key hasNULLvalue.ECONF_WRONG_OWNERβ file has wrong owner.ECONF_WRONG_GROUPβ file has wrong group.ECONF_WRONG_FILE_PERMISSIONβ file has wrong file permissions.ECONF_WRONG_DIR_PERMISSIONβ file has wrong dir permissions.ECONF_ERROR_FILE_IS_SYM_LINKβ file is a sym link which is not permitted. π«ECONF_PARSING_CALLBACK_FAILEDβ user defined parsing callback has failed. π
β¨ Function Documentation β¨
π« econf_readConfig()
econf_err econf_readConfig (econf_file ** key_file, const char *project,
const char *usr_subdir, const char *config_name, const char
*config_suffix, const char *delim, const char *comment)
Bestie, this one is the main character. It evaluates the key/values of a config by reading and merging all the needed/available files from different directories. And the order it does that in? Iconic and very specific, so pay attention bestie:
- If
/etc/$project/$config_name.$config_suffixdoes exist:/etc/$project/$config_name.$config_suffix$usr_subdir/$project/$config_name.$config_suffix.d/*.$config_suffix/run/$project/$config_name.$config_suffix.d/*.$config_suffix/etc/$project/$config_name.$config_suffix.d/*.$config_suffix
- If
/etc/$project/$config_name.$config_suffixdoes NOT exist:- If
/run/$project/$config_name.$config_suffixdoes exist:/run/$project/$config_name.$config_suffix$usr_subdir/$project/$config_name.$config_suffix.d/*.$config_suffix/run/$project/$config_name.$config_suffix.d/*.$config_suffix/etc/$project/$config_name.$config_suffix.d/*.$config_suffix
- If
/run/$project/$config_name.$config_suffixdoes NOT exist:$usr_subdir/$project/$config_name.$config_suffix$usr_subdir/$project/$config_name.$config_suffix.d/*.$config_suffix/run/$project/$config_name.$config_suffix.d/*.$config_suffix/etc/$project/$config_name.$config_suffix.d/*.$config_suffix
- If
- If no main
$config_name.$config_suffixfile is defined, or it must not be parsed:$usr_subdir/$project.d/*.$config_suffix/run/$project.d/*.$config_suffix/etc/$project.d/*.$config_suffix
π«Ά Parameters
key_fileβ content of parsed file(s)projectβ name of the project used as subdirectory, can beNULLusr_subdirβ absolute path of the first directory (often"/usr/lib")config_nameβ basename of the configuration file. If it isNULL, drop-ins without a main configuration file will be parsed only.config_suffixβ suffix of the configuration file. Can also beNULL.delimβ delimiters of key/value e.g.'\t ='. Ifdelimcontains space characters AND none space characters, multiline values are not parseable.commentβ array of characters which define the start of a comment
π Returns
econf_err ECONF_SUCCESS or error code
π Example
Reading content in different cases in following order:
/etc/foo/example.conf does exist:
/etc/foo/example.conf/usr/lib/foo/example.conf.d/ *.conf/run/foo/example.conf.d/ *.conf/etc/foo/example.conf.d/ *.conf
/etc/foo/example.conf does NOT exist:
/run/foo/example.confdoes exist:/run/foo/example.conf/usr/lib/foo/example.conf.d/ *.conf/run/foo/example.conf.d/ *.conf/etc/foo/example.conf.d/ *.conf
/run/foo/example.confdoes NOT exist:/usr/lib/foo/example.conf/usr/lib/foo/example.conf.d/ *.conf/run/foo/example.conf.d/ *.conf/etc/foo/example.conf.d/ *.conf
#include "libeconf.h"
econf_file *key_file = NULL;
econf_err error;
error = econf_readConfig (&key_file,
"foo",
"/usr/lib",
"example",
"conf",
"=", "#");
econf_free (key_file);
π¦ econf_readConfigWithCallback()
econf_err econf_readConfigWithCallback (econf_file ** key_file, const char
*project, const char *usr_subdir, const char *config_name, const char
*config_suffix, const char *delim, const char *comment, bool
(*callback)(const char *filename, const void *data), const void
*callback_data)
Same energy as econf_readConfig β it evaluates key/values of a given configuration by reading and merging all needed/available files from different directories. Order is:
- If
/etc/$project/$config_name.$config_suffixdoes exist:/etc/$project/$config_name.$config_suffix$usr_subdir/$project/$config_name.$config_suffix.d/*.$config_suffix/run/$project/$config_name.$config_suffix.d/*.$config_suffix/etc/$project/$config_name.$config_suffix.d/*.$config_suffix
- If
/etc/$project/$config_name.$config_suffixdoes NOT exist:- If
/run/$project/$config_name.$config_suffixdoes exist:/run/$project/$config_name.$config_suffix$usr_subdir/$project/$config_name.$config_suffix.d/*.$config_suffix/run/$project/$config_name.$config_suffix.d/*.$config_suffix/etc/$project/$config_name.$config_suffix.d/*.$config_suffix
- If
/run/$project/$config_name.$config_suffixdoes NOT exist:$usr_subdir/$project/$config_name.$config_suffix$usr_subdir/$project/$config_name.$config_suffix.d/*.$config_suffix/run/$project/$config_name.$config_suffix.d/*.$config_suffix/etc/$project/$config_name.$config_suffix.d/*.$config_suffix
- If
- If no main
$config_name.$config_suffixfile is defined, or it must not be parsed:$usr_subdir/$project.d/*.$config_suffix/run/$project.d/*.$config_suffix/etc/$project.d/*.$config_suffix
For each parsed file the user defined function will be called in order, e.g. to check the correct file permissions. π
π«Ά Parameters
key_fileβ content of parsed file(s)projectβ name of the project used as subdirectory, can beNULLusr_subdirβ absolute path of the first directory (often"/usr/lib")config_nameβ basename of the configuration file. If it isNULL, drop-ins without a main configuration file will be parsed only.config_suffixβ suffix of the configuration file. Can also beNULL.delimβ delimiters of key/value e.g.'\t ='. Ifdelimcontains space characters AND none space characters, multiline values are not parseable.commentβ array of characters which define the start of a commentcallbackβ function which will be called for each file. This user defined function has the pathname as parameter and returnstrueif this file can be parsed. If not, the parsing of all files will be aborted andECONF_PARSING_CALLBACK_FAILEDwill be returned.callback_dataβ pointer which will be given to the callback function.
π Returns
econf_err ECONF_SUCCESS or error code
π Example
Reading content in different cases in following order:
/etc/foo/example.conf does exist:
/etc/foo/example.conf/usr/lib/foo/example.conf.d/ *.conf/run/foo/example.conf.d/ *.conf/etc/foo/example.conf.d/ *.conf
/etc/foo/example.conf does NOT exist:
/run/foo/example.confdoes exist:/run/foo/example.conf/usr/lib/foo/example.conf.d/ *.conf/run/foo/example.conf.d/ *.conf/etc/foo/example.conf.d/ *.conf
/run/foo/example.confdoes NOT exist:/usr/lib/foo/example.conf/usr/lib/foo/example.conf.d/ *.conf/run/foo/example.conf.d/ *.conf/etc/foo/example.conf.d/ *.conf
#include "libeconf.h"
bool checkFile(const char *filename, const void *data) {
/* checking code which returns true or false */
return true;
}
econf_file *key_file = NULL;
econf_err error;
error = econf_readConfigWithCallback (&key_file,
"foo",
"/usr/lib",
"example",
"conf",
"=", "#",
checkFile,
NULL);
econf_free (key_file);
π econf_readFile()
econf_err econf_readFile (econf_file ** result, const char * file_name,
const char * delim, const char * comment)
Process the file of the given file_name and save its contents into the key_file object. Slay. β¨
π«Ά Parameters
resultβ content of parsed filefile_nameβ absolute path of parsed filedelimβ delimiters of key/value e.g.'\t ='commentβ array of characters which define the start of a comment
π Returns
econf_err ECONF_SUCCESS or error code
π Usage
#include "libeconf.h"
econf_file *key_file = NULL;
econf_err error;
error = econf_readFile (&key_file, "/etc/test.conf", "=", "#");
econf_free (key_file);
Default behaviour if entries have the same name in one file: The first hit will be returned. Further entries will be ignored. This can be changed by setting the environment variableJOIN_SAME_ENTRIES(seeeconf_set_opt). In that case entries with the same name will be joined to one single entry.
π§ econf_readFileWithCallback()
econf_err econf_readFileWithCallback (econf_file ** result, const char *
file_name, const char * delim, const char * comment, bool
(*callback)(const char *filename, const void *data), const void
*callback_data)
Process the file of the given file_name and save its contents into the key_file object. The user defined function will be called in order, e.g. to check the correct file permissions. π
π«Ά Parameters
resultβ content of parsed filefile_nameβ absolute path of parsed filedelimβ delimiters of key/value e.g.'\t ='commentβ array of characters which define the start of a commentcallbackβ function which will be called for the given filename. This user defined function has the pathname as parameter and returnstrueif this file can be parsed. If not, the parsing will be aborted andECONF_PARSING_CALLBACK_FAILEDwill be returned.callback_dataβ pointer which will be given to the callback function.
π Returns
econf_err ECONF_SUCCESS or error code
π Usage
#include "libeconf.h"
bool checkFile(const char *filename, const void *data) {
/* checking code which returns true or false */
return true;
}
econf_file *key_file = NULL;
econf_err error;
error = econf_readFileWithCallback (&key_file, "/etc/test.conf", "=", "#", checkFile, NULL);
econf_free (key_file);
Default behaviour if entries have the same name in one file: The first hit will be returned. Further entries will be ignored. This can be changed by setting the environment variableJOIN_SAME_ENTRIES(seeeconf_set_opt). In that case entries with the same name will be joined to one single entry.
π econf_mergeFiles()
econf_err econf_mergeFiles (econf_file ** merged_file, econf_file *
usr_file, econf_file * etc_file)
Merge the contents of two key_files objects. Entries in etc_file will be preferred. π
Comment and delimiter tag will be taken from usr_file. This can be changed by calling the functions econf_set_comment_tag and econf_set_delimiter_tag. π
π«Ά Parameters
merged_fileβ merged datausr_fileβ First data block which has to be merged.etc_fileβ Second data block which has to be merged.
π Returns
econf_err ECONF_SUCCESS or error code
okay so here's the usage vibe when you're putting it all together:
Usage:
#include "libeconf.h"
econf_file *key_file_1 = NULL, *key_file_2 = NULL, *key_file_ret = NULL
econf_err error;
error = econf_readFile (&key_file1, "/usr/etc/test.conf", "=", "#");
error = econf_readFile (&key_file2, /etc/test.conf", "=", "#");
error = econf_mergeFiles (&key_file_ret, key_file_1, key_file_2);
econf_free (key_file_ret);
econf_free (key_file_1);
econf_free (key_file_2);
econf_newKeyFile
econf_err econf_newKeyFile (econf_file ** result, char delimiter, char
comment)
Bestie, this one creates a brand new econf_file object. It's giving main character energy β¨.
Parameters:
resultβ pointer to the allocatedeconf_fileobject. That's where it lives.delimiterβ delimiter of key/value, e.g.'='.commentβ character which defines the start of a comment.
Returns:
econf_errβECONF_SUCCESSor error code.
econf_newIniFile
econf_err econf_newIniFile (econf_file ** result)
Okay so this makes a new econf_file object in IniFile format. So the delimiter will be '=' and comments start with '#'. Periodt. π
Parameters:
resultβ pointer to the allocatedeconf_fileobject.
Returns:
econf_errβECONF_SUCCESSor error code.
econf_writeFile
econf_err econf_writeFile (econf_file * key_file, const char * save_to_dir,
const char * file_name)
This one writes the content of an econf_file struct to a specified location. No cap. π«Ά
Parameters:
key_fileβ data which has to be written.save_to_dirβ directory into which the file has to be written.file_nameβ filename (with suffix).
Returns:
econf_errβECONF_SUCCESSor error code.
econf_getPath
char* econf_getPath (econf_file * kf)
Evaluating path name β it's giving detective vibes π.
Parameters:
kfβ given/parsed data.
Returns:
- Absolute path name or an empty string if
kfis a result of already merged data (e.G. returned byeconf_readDirs).
econf_getGroups
econf_err econf_getGroups (econf_file * kf, size_t * length, char ***
groups)
Evaluating all group entries β collect them all like PokΓ©mon β¨.
Parameters:
kfβ given/parsed data.lengthβ length of the returned group array.groupsβ string array of evaluated groups.
Returns:
econf_errβECONF_SUCCESSor error code.
econf_getKeys
econf_err econf_getKeys (econf_file * kf, const char * group, size_t *
length, char *** keys)
Evaluating all keys β the way that this function just gathers them π .
Parameters:
kfβ given/parsed data.groupβ group name for which the keys have to be evaluated orNULLfor keys, which do not belong to a group.lengthβ length of the returned key array.keysβ string array of evaluated keys.
Returns:
econf_errβECONF_SUCCESSor error code.
econf_getIntValue
econf_err econf_getIntValue (econf_file * kf, const char * group, const char
* key, int32_t * result)
Evaluating int32 value for given group/key. Lowkey useful.
Parameters:
kfβ given/parsed data.groupβ desired group orNULLif there is no group defined.keyβ key for which the value is requested.resultβ determined value.
Returns:
econf_errβECONF_SUCCESSor error code.
econf_getInt64Value
econf_err econf_getInt64Value (econf_file * kf, const char * group, const
char * key, int64_t * result)
Evaluating int64 value for given group/key. Highkey same energy.
Parameters:
kfβ given/parsed data.groupβ desired group orNULLif there is no group defined.keyβ key for which the value is requested.resultβ determined value.
Returns:
econf_errβECONF_SUCCESSor error code.
econf_getUIntValue
econf_err econf_getUIntValue (econf_file * kf, const char * group, const
char * key, uint32_t * result)
Evaluating uint32 value for given group/key. Slay.
Parameters:
kfβ given/parsed data.groupβ desired group orNULLif there is no group defined.keyβ key for which the value is requested.resultβ determined value.
Returns:
econf_errβECONF_SUCCESSor error code.
econf_getUInt64Value
econf_err econf_getUInt64Value (econf_file * kf, const char * group, const
char * key, uint64_t * result)
Evaluating uint64 value for given group/key. Iconic.
Parameters:
kfβ given/parsed data.groupβ desired group orNULLif there is no group defined.keyβ key for which the value is requested.resultβ determined value.
Returns:
econf_errβECONF_SUCCESSor error code.
econf_getFloatValue
econf_err econf_getFloatValue (econf_file * kf, const char * group, const
char * key, float * result)
Evaluating float value for given group/key. It's giving precision π .
Parameters:
kfβ given/parsed data.groupβ desired group orNULLif there is no group defined.keyβ key for which the value is requested.resultβ determined value.
Returns:
econf_errβECONF_SUCCESSor error code.
econf_getDoubleValue
econf_err econf_getDoubleValue (econf_file * kf, const char * group, const
char * key, double * result)
Evaluating double value for given group/key. Double the trouble, double the slay β¨.
Parameters:
kfβ given/parsed data.groupβ desired group orNULLif there is no group defined.keyβ key for which the value is requested.resultβ determined value.
Returns:
econf_errβECONF_SUCCESSor error code.
econf_getStringValue
econf_err econf_getStringValue (econf_file * kf, const char * group, const
char * key, char ** result)
Evaluating string value for given group/key. The moment we've all been waiting for.
Parameters:
kfβ given/parsed data.groupβ desired group orNULLif there is no group defined.keyβ key for which the value is requested.resultβ a newly allocated string orNULLin error case.
Returns:
econf_errβECONF_SUCCESSor error code.
econf_getBoolValue
econf_err econf_getBoolValue (econf_file * kf, const char * group, const
char * key, bool * result)
Evaluating bool value for given group/key. True or false, bestie.
Parameters:
kfβ given/parsed data.groupβ desired group orNULLif there is no group defined.keyβ key for which the value is requested.resultβ determined value.
Returns:
econf_errβECONF_SUCCESSor error code.
econf_getIntValueDef
econf_err econf_getIntValueDef (econf_file * kf, const char * group, const
char * key, int32_t * result, int32_t def)
Evaluating int32 value for given group/key. If key is not found, the default value is returned and error is ECONF_NOKEY. No cap.
Parameters:
kfβ given/parsed data.groupβ desired group orNULLif there is no group defined.keyβ key for which the value is requested.resultβ determined value.defβ default value if the value has not been found.
Returns:
econf_errβECONF_SUCCESSor error code.
econf_getInt64ValueDef
econf_err econf_getInt64ValueDef (econf_file * kf, const char * group, const
char * key, int64_t * result, int64_t def)
Evaluating int64 value for given group/key. If key is not found, the default value is returned and error is ECONF_NOKEY. Periodt.
Parameters:
kfβ given/parsed data.groupβ desired group orNULLif there is no group defined.keyβ key for which the value is requested.resultβ determined value.defβ default value if the value has not been found.
Returns:
econf_errβECONF_SUCCESSor error code.
econf_getUIntValueDef
econf_err econf_getUIntValueDef (econf_file * kf, const char * group, const
char * key, uint32_t * result, uint32_t def)
Evaluating uint32 value for given group/key. If key is not found, the default value is returned and error is ECONF_NOKEY. Lowkey clutch.
Parameters:
kfβ given/parsed data.groupβ desired group orNULLif there is no group defined.keyβ key for which the value is requested.resultβ determined value.defβ default value if the value has not been found.
Returns:
econf_errβECONF_SUCCESSor error code.
econf_getUInt64ValueDef
econf_err econf_getUInt64ValueDef (econf_file * kf, const char * group,
const char * key, uint64_t * result, uint64_t def)
Evaluating uint64 value for given group/key. If key is not found, the default value is returned and error is ECONF_NOKEY. Slay.
Parameters:
kfβ given/parsed data.groupβ desired group orNULLif there is no group defined.keyβ key for which the value is requested.resultβ determined value.defβ default value if the value has not been found.
Returns:
econf_errβECONF_SUCCESSor error code.
econf_getFloatValueDef
econf_err econf_getFloatValueDef (econf_file * kf, const char * group, const
char * key, float * result, float def)
Evaluating float value for given group/key. If key is not found, the default value is returned and error is ECONF_NOKEY. It's giving fallback realness.
Parameters:
kfβ given/parsed data.groupβ desired group orNULLif there is no group defined.keyβ key for which the value is requested.resultβ determined value.defβ default value if the value has not been found.
Returns:
econf_errβECONF_SUCCESSor error code.
econf_getDoubleValueDef
econf_err econf_getDoubleValueDef (econf_file * kf, const char * group,
const char * key, double * result, double def)
Evaluating double value for given group/key. If key is not found, the default value is returned and error is ECONF_NOKEY. Double the fallback, double the vibe.
Parameters:
kfβ given/parsed data.groupβ desired group orNULLif there is no group defined.keyβ key for which the value is requested.resultβ determined value.defβ default value if the value has not been found.
Returns:
econf_errβECONF_SUCCESSor error code.
econf_getStringValueDef
econf_err econf_getStringValueDef (econf_file * kf, const char * group,
const char * key, char ** result, char * def)
Evaluating string value for given group/key. If key is not found, the default value is returned and error is ECONF_NOKEY. The way that this handles strings is iconic.
Parameters:
kfβ given/parsed data.groupβ desired group orNULLif there is no group defined.keyβ key for which the value is requested.resultβ returns a newly allocated string, even if 'default' is returned.defβ default value if the value has not been found.
Returns:
econf_errβECONF_SUCCESSor error code.
econf_getBoolValueDef
econf_err econf_getBoolValueDef (econf_file * kf, const char * group, const
char * key, bool * result, bool def)
Evaluating bool value for given group/key. If key is not found, the default value is returned and error is ECONF_NOKEY. True story.
Parameters:
kfβ given/parsed data.groupβ desired group orNULLif there is no group defined.keyβ key for which the value is requested.resultβ determined value.defβ default value if the value has not been found.
Returns:
econf_errβECONF_SUCCESSor error code.
econf_setIntValue
econf_err econf_setIntValue (econf_file * kf, const char * group, const char
* key, int32_t value)
Set int32 value for given group/key. Setting the vibe, no cap.
Parameters:
kfβ given/parsed data.groupβ desired group orNULLif there is no group defined.keyβ key for which the value has to be set.valueβ value which has to be set.
Returns:
econf_errβECONF_SUCCESSor error code.
econf_setInt64Value
econf_err econf_setInt64Value (econf_file * kf, const char * group, const char
* key, int64_t value)
Set int64 value for given group/key. Big numbers, big energy.
Parameters:
kfβ given/parsed data.groupβ desired group orNULLif there is no group defined.keyβ key for which the value has to be set.valueβ value which has to be set.
econf_err econf_setUIntValue (econf_file * kf, const char * group, const char * key, uint32_t value) π
bestie. this one sets a uint32 value for the group/key you point it at. tiny number, big energy. β¨
Parameters:
kfβ the given/parsed data, aka your whole config situationgroupβ the group you want, orNULLif there is no group definedkeyβ the key for which the value has to be setvalueβ the value which has to be set
Returns: econf_err β ECONF_SUCCESS or an error code
econf_err econf_setUInt64Value (econf_file * kf, const char * group, const char * key, uint64_t value) π
same vibe as above but the number is uint64, so it's the bigger sister. more digits, more slay. π₯
Parameters:
kfβ the given/parsed datagroupβ the group you want, orNULLif there is no group definedkeyβ the key for which the value has to be setvalueβ the value which has to be set
Returns: econf_err β ECONF_SUCCESS or an error code
econf_err econf_setFloatValue (econf_file * kf, const char * group, const char * key, float value) πΈ
sets a float value for the group/key. yes, decimals. yes, she's precise. π
Parameters:
kfβ the given/parsed datagroupβ the group you want, orNULLif there is no group definedkeyβ the key for which the value has to be setvalueβ the value which has to be set
Returns: econf_err β ECONF_SUCCESS or an error code
econf_err econf_setDoubleValue (econf_file * kf, const char * group, const char * key, double value) β¨
and now the double version. more precision, same group/key energy. ngl she ate. π¦
Parameters:
kfβ the given/parsed datagroupβ the group you want, orNULLif there is no group definedkeyβ the key for which the value has to be setvalueβ the value which has to be set
Returns: econf_err β ECONF_SUCCESS or an error code
econf_err econf_setStringValue (econf_file * kf, const char * group, const char * key, const char * value) π¬
sets a string value for the given group/key. the classic. the moment. the icon. π
Parameters:
kfβ the given/parsed datagroupβ the group you want, orNULLif there is no group definedkeyβ the key for which the value has to be setvalueβ the value which has to be set
Returns: econf_err β ECONF_SUCCESS or an error code
econf_err econf_setBoolValue (econf_file * kf, const char * group, const char * key, const char * value) π
sets a bool value for the given group/key. note the plot twist: the value here is a const char *, not an actual bool. that's just how she is. π
Parameters:
kfβ the given/parsed datagroupβ the group you want, orNULLif there is no group definedkeyβ the key for which the value has to be setvalueβ the value which has to be set
Returns: econf_err β ECONF_SUCCESS or an error code
const char* econf_errString (const econf_err error) π«Ά
converts an econf_err type into a string, fr fr. error code in, words out. translator behavior. π
Parameters:
errorβ error enum
Returns: human readable string
void econf_errLocation (char ** filename, uint64_t * line_nr) π
the receipts!! gives you info about where the error has happened. detective mode activated. π΅οΈ
Parameters:
filenameβ path of the last scanned fileline_nrβ number of the last handled line
void econf_freeArray (char ** array) π§Ή
frees an array of type char** that was created by econf_getGroups() or econf_getKeys(). clean up after yourself bestie, the memory is not gonna free itself. π
Parameters:
arrayβ array of strings
Returns: void
void econf_freeFile (econf_file * key_file) ποΈ
frees memory allocated by e.g. econf_readFile(), econf_readDirs(),... you know the drill.
Parameters:
key_fileβ allocated data
Returns: void
char econf_comment_tag (econf_file * key_file) π
returns the comment character tag of the given econf_file object. this tag will be taken while writing comments to file. she's telling you how she comments. π
Parameters:
key_fileβeconf_fileobject
Returns: char comment character tag
char econf_delimiter_tag (econf_file * key_file) β
returns the delimiter character of the given econf_file object. this delimiter will be taken while writing the data to file.
Parameters:
key_fileβeconf_fileobject
Returns: char delimiter of key/value
void econf_set_comment_tag (econf_file * key_file, const char comment) π
sets the comment character tag of the given econf_file object. this tag will be taken while writing comments to file. you're literally choosing her comment aesthetic.
Parameters:
key_fileβeconf_fileobjectcommentβ comment tag
void econf_set_delimiter_tag (econf_file * key_file, const char delimiter) βοΈ
sets the delimiter character of the given econf_file object. this delimiter will be taken while writing the data to file.
Parameters:
key_fileβeconf_fileobjectdelimiterβ delimiter of key/value
econf_err econf_getExtValue (econf_file * kf, const char * group, const char * key, econf_ext_value ** result) π₯
evaluating more information for the given group/key. extra lore, if you will. the extended cut. π¬
Parameters:
kfβ the given/parsed datagroupβ the group you want, orNULLif there is no group definedkeyβ the key for which the value is requestedresultβ a newly allocated struct orNULLin error case
Returns: econf_err β ECONF_SUCCESS or an error code
void econf_freeExtValue (econf_ext_value * to_free) π§Ό
frees a complete econf_ext_value struct. the whole thing, no crumbs left. π½οΈ
Parameters:
to_freeβ struct which has to be freed
Returns: void
econf_err econf_set_conf_dirs (const char **dir_postfix_list) π
sets a list of directory structures (with order) which describes the directories in which the files have to be parsed. order matters, it's giving main character sequencing. β
Parameters:
dir_postfix_listβ list of directory structures. E.G. with the given list:{"/conf.d/", ".d/", "/", NULL}files in the following directories will be parsed:<default_dirs>/<project_name>.<suffix>.d/<default_dirs>/<project_name>/conf.d/,<default_dirs>/<project_name>.d/,<default_dirs>/<project_name>/.The entry<default_dirs>/<project_name>.<suffix>.d/will be added automatically.
Returns: econf_err β ECONF_SUCCESS or an error code
π SEE ALSO π
econftool
and that's a wrap on libeconf(3), bestie!! πβ¨ this was Version 0.4.7, dated Thu Apr 8 2021, and honestly? iconic behavior. go forth and parse, you absolute legend. ππ¦πΈπ
π¦ where this page comes from
- debian trixie: libeconf-dev 0.7.7+dfsg1-1 Β· MIT
- fedora 43: libeconf-devel 0.7.9-2.fc43 Β· MIT
- fedora 43: libeconf-devel 0.7.9-2.fc43 Β· MIT
- fedora 44: libeconf-devel 0.7.9-3.fc44 Β· MIT
- fedora 44: libeconf-devel 0.7.9-3.fc44 Β· MIT
- opensuse-leap 16.0: libeconf-devel 0.7.9-160000.2.2 Β· MIT
- opensuse-leap 16.0: libeconf-devel 0.7.9-160000.2.2 Β· MIT
- opensuse-leap 16.0: libeconf-devel 0.7.9-160000.2.2 Β· MIT
- opensuse-leap 16.0: libeconf-devel 0.7.9-160000.2.2 Β· MIT
- ubuntu questing: libeconf-dev 0.7.7+dfsg1-1
- ubuntu resolute: libeconf-dev 0.7.7+dfsg1-1build1 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms