u/debug: Export debug_to_num function

This commit is contained in:
Mateo de Mayo 2023-02-10 18:02:35 -03:00 committed by Jakob Bornecrantz
parent 84ccf3a78e
commit a93dc650a1
2 changed files with 22 additions and 13 deletions

View file

@ -151,23 +151,29 @@ debug_get_tristate_option(const char *name)
return ret;
}
long
debug_string_to_num(const char *raw, long _default)
{
if (raw == NULL) {
return _default;
}
char *endptr;
long ret = strtol(raw, &endptr, 0);
// Restore the default value when no digits were found.
if (raw == endptr) {
ret = _default;
}
return ret;
}
long
debug_get_num_option(const char *name, long _default)
{
const char *raw = os_getenv(name);
long ret;
if (raw == NULL) {
ret = _default;
} else {
char *endptr;
ret = strtol(raw, &endptr, 0);
// Restore the default value when no digits were found.
if (raw == endptr) {
ret = _default;
}
}
long ret = debug_string_to_num(raw, _default);
if (debug_get_bool_option_print()) {
U_LOG_RAW("%s=%li (%s)", name, ret, raw == NULL ? "nil" : raw);

View file

@ -38,6 +38,9 @@ debug_get_tristate_option(const char *name);
bool
debug_get_bool_option(const char *name, bool _default);
long
debug_string_to_num(const char *string, long _default);
long
debug_get_num_option(const char *name, long _default);