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 has NULL value. the key exists, the value is just… nothing. ghosted πŸ™ˆ
  • ECONF_NOMEM β€” memory allocation failed. (specifically applicable to econf_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 is NULL. somebody passed nothing where something was needed.
  • ECONF_PARSE_ERROR β€” parse error. (specifically applicable to econf_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