ECONF_GETVALUEDEF(3)
β¨ ECONF_GETVALUEDEF β¨
okay bestie, gather round, because today we're talking about econf_get<type>ValueDef from the libeconf manual β page 3, the libeconf section, third one down π
πΈ NAME πΈ
econf_get<type>ValueDef β grab the value for a group + key you asked for, and if it's not there, just hand you the default instead. no drama, no tears π«Ά
π SYNOPSIS π
bestie, it's C, so of course we start with the include:
#include <libeconf.h>
and here come the whole squad, in order, no cap:
econf_err econf_getBoolValueDef(econf_file *kf, const char *group,
const char *key, bool *result, bool def);
econf_err econf_getDoubleValueDef(econf_file *kf, const char *group,
const char *key, double *result, double def);
econf_err econf_getFloatValueDef(econf_file *kf, const char *group,
const char *key, float *result, float def);
econf_err econf_getIntValueDef(econf_file *kf, const char *group,
const char *key, int32_t *result, int32_t def);
econf_err econf_getInt64ValueDef(econf_file *kf, const char *group,
const char *key, int64_t *result, int64_t def);
econf_err econf_getStringValueDef(econf_file *kf, const char *group,
const char *key, char **result, const char *def);
econf_err econf_getUInt64ValueDef(econf_file *kf, const char *group,
const char *key, uint64_t *result, uint64_t def);
econf_err econf_getUIntValueDef(econf_file *kf, const char *group,
const char *key, uint32_t *result, uint32_t def);
eight functions. bool, double, float, int32_t, int64_t, char **, uint64_t, uint32_t β the whole type buffet π₯
π DESCRIPTION π
so the vibe is this: these functions go look up the value for a specific group and key inside the econf_file structure you pass as kf. if that key exists, the value gets parsed and stored in result. if the key is not found? girl, no problem β the default value from def goes straight into result. no sad error-handling arc required π
about group: it's the section name in the config file, that's literally it. but plot twist β if group is NULL, the lookup happens in the upper part of the file, the bit that lives before any group declaration. and key? that's just the name of the entry you're tryna retrieve. simple.
now for econf_getStringValueDef specifically β memory gets allocated for the result string, even if the default value is what ends up getting used. so you, the caller, have to free it yourself with free(3). this is not a suggestion, bestie, it's giving "you own this now" π
and for econf_getBoolValue(): it parses the common boolean strings β think "true", "yes", "1", "false", "no", "0" β and it does not care about case. uppercase, lowercase, mixed, whatever, it ate and left no crumbs β¨
real talk though: these functions are essentially wrappers around the standard econf_get*Value functions. the whole point is convenience β you get a chill way to deal with missing keys without manually checking return codes for ECONF_NOKEY every single time. it's the low-effort, high-reward friend of the group π«Ά
π RETURN VALUE π
- key found and parsed all cute and successfully? you get
ECONF_SUCCESSback. slay β - key not found?
resultgets set todef, and the function returnsECONF_NOKEY. see, not a disaster, just a heads-up. - something went wrong β like the value can't be parsed, or the arguments are invalid? you get an error code back. and if you need to turn that code into something human-readable, hit up
econf_errString(3). π
π ERRORS π
here's the full roster of ways things can go sideways. know them, respect them:
ECONF_KEY_HAS_NULL_VALUEβ the given key has a NULL value. yeah. that one.ECONF_NOMEMβ memory allocation failed. (specifically applicable toeconf_getStringValueDef.)ECONF_VALUE_CONVERSION_ERRORβ the value cannot be converted.ECONF_NOKEYβ the specified key could not be found within the group.ECONF_ARGUMENT_IS_NULL_VALUEβ the given argument is NULL.ECONF_PARSE_ERRORβ parse error. (specifically applicable toeconf_getBooleanValueDef.)ECONF_ERRORβ general error. the catch-all. the "something happened" of it all π
π¦ SEE ALSO π¦
libeconf(3), econf_getValue(3), econf_setValue(3), econf_errString(3).
go read them, iykyk π
stay hydrated, keep your group pointers valid, and remember: free that string π
this has been the libeconf manual, page ECONF_GETVALUEDEF(3), libeconf edition, dated 2024-12-14. periodt. π
π¦ 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