From 877ccaf02b773ad7b995bacbfba8e1bdfe11b00d Mon Sep 17 00:00:00 2001 From: dvdli Date: Thu, 29 Oct 2020 18:38:53 +0800 Subject: AOSP CL "tinymix: fix setting enum str started with digits" https://android.googlesource.com/platform/external/tinyalsa/+/f2d93a540297e75815eeb6644bf675cdae3be909 commit f2d93a540297e75815eeb6644bf675cdae3be909 author HW Lee tinymix: fix setting enum str started with digits 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 --- utils/tinymix.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'utils') diff --git a/utils/tinymix.c b/utils/tinymix.c index fdb774c..41ca269 100644 --- a/utils/tinymix.c +++ b/utils/tinymix.c @@ -146,6 +146,16 @@ int main(int argc, char **argv) return EXIT_SUCCESS; } +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, int print_all) { struct mixer_ctl *ctl; @@ -201,7 +211,7 @@ static void tinymix_detail_control(struct mixer *mixer, const char *control) int ret; char *buf = NULL; - if (isdigit(control[0])) + if (isnumber(control)) ctl = mixer_get_ctl(mixer, atoi(control)); else ctl = mixer_get_ctl_by_name(mixer, control); @@ -469,7 +479,7 @@ static int tinymix_set_value(struct mixer *mixer, const char *control, struct mixer_ctl *ctl; enum mixer_ctl_type type; - if (isdigit(control[0])) + if (isnumber(control)) ctl = mixer_get_ctl(mixer, atoi(control)); else ctl = mixer_get_ctl_by_name(mixer, control); -- cgit v1.2.3