Core: Add mCoreConfigGetBoolValue

This commit is contained in:
Vicki Pfau 2021-12-02 17:55:02 -08:00
parent 603de394d8
commit 58ddecb830
2 changed files with 19 additions and 0 deletions

View File

@ -78,6 +78,7 @@ bool mCoreConfigIsPortable(void);
#endif
const char* mCoreConfigGetValue(const struct mCoreConfig*, const char* key);
bool mCoreConfigGetBoolValue(const struct mCoreConfig*, const char* key, bool* value);
bool mCoreConfigGetIntValue(const struct mCoreConfig*, const char* key, int* value);
bool mCoreConfigGetUIntValue(const struct mCoreConfig*, const char* key, unsigned* value);
bool mCoreConfigGetFloatValue(const struct mCoreConfig*, const char* key, float* value);

View File

@ -89,6 +89,20 @@ static bool _lookupCharValue(const struct mCoreConfig* config, const char* key,
return true;
}
static bool _lookupBoolValue(const struct mCoreConfig* config, const char* key, bool* out) {
const char* charValue = _lookupValue(config, key);
if (!charValue) {
return false;
}
char* end;
long value = strtol(charValue, &end, 10);
if (*end) {
return false;
}
*out = value;
return true;
}
static bool _lookupIntValue(const struct mCoreConfig* config, const char* key, int* out) {
const char* charValue = _lookupValue(config, key);
if (!charValue) {
@ -314,6 +328,10 @@ const char* mCoreConfigGetValue(const struct mCoreConfig* config, const char* ke
return _lookupValue(config, key);
}
bool mCoreConfigGetBoolValue(const struct mCoreConfig* config, const char* key, bool* value) {
return _lookupBoolValue(config, key, value);
}
bool mCoreConfigGetIntValue(const struct mCoreConfig* config, const char* key, int* value) {
return _lookupIntValue(config, key, value);
}