mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-11-02 09:01:48 -05:00
conf: add safe_strtoll_base() like safe_strtol_base()
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
parent
7ffe3d4162
commit
32d332b786
2 changed files with 9 additions and 6 deletions
13
src/conf.c
13
src/conf.c
|
|
@ -653,16 +653,17 @@ static int input_stdio_open(snd_input_t **inputp, const char *file,
|
|||
return err;
|
||||
}
|
||||
|
||||
static int safe_strtoll(const char *str, long long *val)
|
||||
int safe_strtoll_base(const char *str, long long *val, int base)
|
||||
{
|
||||
long long v;
|
||||
int endidx;
|
||||
char *end;
|
||||
long v;
|
||||
if (!*str)
|
||||
return -EINVAL;
|
||||
errno = 0;
|
||||
if (sscanf(str, "%lli%n", &v, &endidx) < 1)
|
||||
return -EINVAL;
|
||||
if (str[endidx])
|
||||
v = strtoll(str, &end, base);
|
||||
if (errno)
|
||||
return -errno;
|
||||
if (*end)
|
||||
return -EINVAL;
|
||||
*val = v;
|
||||
return 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue