topology: avoid to use the atoi() directly when expected

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
Jaroslav Kysela 2019-12-14 13:36:09 +01:00
parent 9e2bbccfcc
commit f373bf1f6e
9 changed files with 150 additions and 133 deletions

View file

@ -21,6 +21,35 @@
#include "list.h"
#include "tplg_local.h"
/*
* Get integer value
*/
int tplg_get_integer(snd_config_t *n, int *val, int base)
{
const char *str;
long lval;
int err;
switch (snd_config_get_type(n)) {
case SND_CONFIG_TYPE_INTEGER:
err = snd_config_get_integer(n, &lval);
if (err < 0)
return err;
if (lval < INT_MIN || lval > INT_MAX)
return -EINVAL;
*val = lval;
return err;
case SND_CONFIG_TYPE_STRING:
err = snd_config_get_string(n, &str);
if (err < 0)
return err;
*val = strtol(str, NULL, base);
return 0;
default:
return -EINVAL;
}
}
/*
* Parse compound
*/