ECONF_GETVALUE(3)
π ECONF_GETVALUE(3) β libeconf Manual π
okay bestie, sit down, we're learning libeconf today and honestly? it's giving β¨organizedβ¨. this is the page for econf_get<type>Value β aka the little family of functions that pull a value out of an econf configuration file and hand it to you in whatever type you asked for. no cap, this is the good stuff π¦
πΈ NAME πΈ
econf_get<type>Value β retrieve a value from an econf configuration file π
β¨ SYNOPSIS β¨
first things first, you gotta invite the library in:
#include <libeconf.h>
and here's the whole squad β eight of them, all matching the same vibe, just different types at the end π:
econf_err econf_getIntValue(econf_file *kf, const char *group,
const char *key, int *result);
econf_err econf_getInt64Value(econf_file *kf, const char *group,
const char *key, int64_t *result);
econf_err econf_getUIntValue(econf_file *kf, const char *group,
const char *key, unsigned int *result);
econf_err econf_getUInt64Value(econf_file *kf, const char *group,
const char *key, uint64_t *result);
econf_err econf_getFloatValue(econf_file *kf, const char *group,
const char *key, float *result);
econf_err econf_getDoubleValue(econf_file *kf, const char *group,
const char *key, double *result);
econf_err econf_getStringValue(econf_file *kf, const char *group,
const char *key, char **result);
econf_err econf_getBoolValue(econf_file *kf, const char *group,
const char *key, bool *result);
π DESCRIPTION π
so these functions go into the parsed config file object pointed to by kf and grab the value tied to one specific group + key combo. like a lil scavenger hunt but the treasure is data π
the group parameter is the section name in the config file. IMPORTANT: if group is NULL, the key gets looked up in the upper part of the file β you know, the part without any group declaration. it's the free-range section, the no-label zone π«Ά and key is just, well, the name of the entry you want.
when it works, the value gets converted into the right data type and dropped into the memory location that result points to. but bestie, listen β result is undefined if an error has occurred. undefined. not "kinda off", not "probably fine" β undefined. don't peek at it if things went bad, periodt π
for econf_getStringValue(), the string memory is dynamically allocated. that means it's yours now, and it's your job to free(3) it when you're done. and if an error happened? result is NULL. simple as that.
for econf_getBoolValue(), the function is chill about boolean strings and parses the common ones β like "true", "yes", "1", "false", "no", "0" β and it does not care about case. "TRUE"? "Yes"? all valid, all valid π
π₯ RETURN VALUE π₯
if it succeeds, you get ECONF_SUCCESS. we love a success story β¨
if it fails, you get a non-zero error code of type econf_err. no zero, no win β that's the deal.
π ERRORS π
okay here's the whole drama list, no skips:
ECONF_KEY_HAS_NULL_VALUEβ given key hasNULLvalue. the key exists, the value is justβ¦ nothing. ghosted πECONF_NOMEMβ memory allocation failed. (specifically applicable toeconf_getStringValue), since that's the one out here allocating πECONF_VALUE_CONVERSION_ERRORβ value cannot be converted. it was not the right type and it refused to pretend πECONF_NOKEYβ the specified key could not be found within the group. it's not there bestie, it's just not there πECONF_ARGUMENT_IS_NULL_VALUEβ given argument isNULL. somebody passed nothing where something was needed.ECONF_PARSE_ERRORβ parse error. (specifically applicable toeconf_getBooleanValue), so watch out for that one π§ECONF_ERRORβ general error. the catch-all, the "something happened", the shrug π
fr fr, always check that return value. ECONF_SUCCESS or it didn't happen.
π¦ SEE ALSO π¦
go read these next, they're all part of the same friend group: libeconf(3), econf_free(3), econf_errString(3).
π a lil sign-off π
this page came from libeconf and it's dated 2023-12-01 β so yeah, the date on this one is 2023-12-01, that's canon. go forth and retrieve your values, bestie, you're gonna eat πβ¨π«Ά
π¦ where this page comes from
- alpine 3.23: libeconf-doc 0.8.3-r0 Β· MIT
- alpine 3.24: libeconf-doc 0.8.3-r0 Β· MIT
- nixpkgs unstable: libeconf 0.8.6
- ubuntu stonking: libeconf-dev 0.8.4+dfsg1-1 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms