diff options
author | dvdli <dvdli@google.com> | 2020-10-29 18:38:53 +0800 |
---|---|---|
committer | dvdli <dvdli@google.com> | 2020-10-29 18:38:53 +0800 |
commit | 877ccaf02b773ad7b995bacbfba8e1bdfe11b00d (patch) | |
tree | cc3f820ccf3df93bf8e074d8f77cd7c6f1a657b6 | |
parent | ee63fc9a456215d88de45881565b7dae71eafb48 (diff) |
AOSP CL "tinymix: fix setting enum str started with digits"
https://android.googlesource.com/platform/external/tinyalsa/+/f2d93a540297e75815eeb6644bf675cdae3be909
commit f2d93a540297e75815eeb6644bf675cdae3be909
author HW Lee <hwlee@google.com>
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 <hwlee@google.com>
-rw-r--r-- | utils/tinymix.c | 14 |
1 files changed, 12 insertions, 2 deletions
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); |