settings: Add settings_value_as_uint64() helper function

This commit is contained in:
Tobias Brunner
2015-11-11 15:39:49 +01:00
parent ee09094899
commit 8623ae9fc6
3 changed files with 58 additions and 0 deletions
+25
View File
@@ -537,6 +537,31 @@ METHOD(settings_t, get_int, int,
return settings_value_as_int(value, def);
}
/**
* Described in header
*/
inline u_int64_t settings_value_as_uint64(char *value, u_int64_t def)
{
u_int64_t intval;
char *end;
int base = 10;
if (value)
{
errno = 0;
if (value[0] == '0' && value[1] == 'x')
{ /* manually detect 0x prefix as we want to avoid octal encoding */
base = 16;
}
intval = strtoull(value, &end, base);
if (errno == 0 && *end == 0 && end != value)
{
return intval;
}
}
return def;
}
/**
* Described in header
*/