parse-bool.c: add helpers to set bool/int iff valid boolean

This commit is contained in:
Johan Malm 2023-04-26 20:34:48 +01:00
parent 86cb62ed12
commit 1159947d09
3 changed files with 47 additions and 82 deletions

View file

@ -23,3 +23,22 @@ error_not_a_boolean:
return default_value;
}
void
set_bool(const char *str, bool *variable)
{
int ret = parse_bool(str, -1);
if (ret < 0) {
return;
}
*variable = ret;
}
void
set_bool_as_int(const char *str, int *variable)
{
int ret = parse_bool(str, -1);
if (ret < 0) {
return;
}
*variable = ret;
}