aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHW Lee <hwlee@google.com>2019-05-20 17:38:18 +0800
committerHW Lee <hwlee@google.com>2019-05-21 10:50:52 +0800
commitf2d93a540297e75815eeb6644bf675cdae3be909 (patch)
tree2d29ccd895e25e03eab083732f2618703e8b91da
parente84b02b2bfca1b51f743ad262ca0b62504d6c6b3 (diff)
downloadtinyalsa-android10-qpr2-release.tar.gz
For those value strings which are started with digits, they must be set as enum instead of index value. Test: with mixer control values started with digits like '48KHz' Change-Id: I1c70f5613a48d020d3248b71c1e4384f83e33d25 Signed-off-by: HW Lee <hwlee@google.com>
-rw-r--r--tinymix.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/tinymix.c b/tinymix.c
index fc62334..789c4af 100644
--- a/tinymix.c
+++ b/tinymix.c
@@ -125,6 +125,16 @@ int main(int argc, char **argv)
return ret;
}
+static int isnumber(const char *str) {
+ char *end;
+
+ if (str == NULL || strlen(str) == 0)
+ return 0;
+
+ strtol(str, &end, 0);
+ return strlen(end) == 0;
+}
+
static void tinymix_list_controls(struct mixer *mixer)
{
struct mixer_ctl *ctl;
@@ -195,7 +205,7 @@ static int tinymix_detail_control(struct mixer *mixer, const char *control,
unsigned int tlv_header_size = 0;
const char *space = g_tabs_only ? "\t" : " ";
- if (isdigit(control[0]))
+ if (isnumber(control))
ctl = mixer_get_ctl(mixer, atoi(control));
else
ctl = mixer_get_ctl_by_name(mixer, control);
@@ -339,7 +349,7 @@ static int tinymix_set_value(struct mixer *mixer, const char *control,
unsigned int num_ctl_values;
unsigned int i;
- if (isdigit(control[0]))
+ if (isnumber(control))
ctl = mixer_get_ctl(mixer, atoi(control));
else
ctl = mixer_get_ctl_by_name(mixer, control);
@@ -357,7 +367,7 @@ static int tinymix_set_value(struct mixer *mixer, const char *control,
return ENOENT;
}
- if (isdigit(values[0][0])) {
+ if (isnumber(values[0])) {
if (num_values == 1) {
/* Set all values the same */
int value = atoi(values[0]);