spa: add spa_atob() to convert a string to a boolean

This replaces the manual check for "true" and some (inconsistent) return value
of atoi. All those instances now require either "true" or "1" to parse as
true, any other value (including NULL) is boolean false.
This commit is contained in:
Peter Hutterer 2021-05-18 15:18:14 +10:00
parent 4e70799922
commit cdfd50e166
18 changed files with 58 additions and 34 deletions

View file

@ -82,6 +82,17 @@ static inline bool spa_atoi32(const char *str, int32_t *val, int base)
return true;
}
/**
* Convert \a str to a boolean. Allowed boolean values are "true" and a
* literal "1", anything else is false.
*
* \return true on success, false otherwise
*/
static inline bool spa_atob(const char *str)
{
return spa_streq(str, "true") || spa_streq(str, "1");
}
#ifdef __cplusplus
} /* extern "C" */
#endif