conf: introduce safe_strtol_base()

It is useful to parse hexadecimal strings, too.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
Jaroslav Kysela 2021-11-02 10:41:07 +01:00
parent 0e2b167e93
commit f547b2e35f
3 changed files with 5 additions and 9 deletions

View file

@ -668,14 +668,14 @@ static int safe_strtoll(const char *str, long long *val)
return 0;
}
int safe_strtol(const char *str, long *val)
int safe_strtol_base(const char *str, long *val, int base)
{
char *end;
long v;
if (!*str)
return -EINVAL;
errno = 0;
v = strtol(str, &end, 0);
v = strtol(str, &end, base);
if (errno)
return -errno;
if (*end)