diff options
author | Simon Wilson <simonwilson@google.com> | 2012-03-08 10:15:08 -0800 |
---|---|---|
committer | Simon Wilson <simonwilson@google.com> | 2012-03-08 10:27:40 -0800 |
commit | b29ac1ab6b1f4d78017d652e850a96893347fc29 (patch) | |
tree | b1485ed7c365ad8d7827fb0ba1690d4c293dbd94 /mixer.c | |
parent | 174d874d977cc198a577369e5d161af34fbc0952 (diff) |
mixer: simplify string get APIs
Just like the pcm_get_error() API, simplify the mixer API
functions to return pointers to constant strings instead
of making copies of strings.
Diffstat (limited to 'mixer.c')
-rw-r--r-- | mixer.c | 25 |
1 files changed, 8 insertions, 17 deletions
@@ -193,13 +193,12 @@ struct mixer_ctl *mixer_get_ctl_by_name(struct mixer *mixer, const char *name) return NULL; } -int mixer_ctl_get_name(struct mixer_ctl *ctl, char *name, unsigned int size) +const char *mixer_ctl_get_name(struct mixer_ctl *ctl) { - if (!ctl || !name || (size == 0)) - return -EINVAL; + if (!ctl) + return NULL; - strncpy(name, (char *)ctl->info->id.name, size); - return 0; + return (const char *)ctl->info->id.name; } enum mixer_ctl_type mixer_ctl_get_type(struct mixer_ctl *ctl) @@ -392,24 +391,16 @@ unsigned int mixer_ctl_get_num_enums(struct mixer_ctl *ctl) return ctl->info->value.enumerated.items; } -int mixer_ctl_get_enum_string(struct mixer_ctl *ctl, unsigned int enum_id, - char *string, unsigned int size) +const char *mixer_ctl_get_enum_string(struct mixer_ctl *ctl, + unsigned int enum_id) { - struct snd_ctl_elem_value ev; int ret; if (!ctl || (ctl->info->type != SNDRV_CTL_ELEM_TYPE_ENUMERATED) || (enum_id >= ctl->info->value.enumerated.items)) - return -EINVAL; - - memset(&ev, 0, sizeof(ev)); - ev.id.numid = ctl->info->id.numid; - ret = ioctl(ctl->mixer->fd, SNDRV_CTL_IOCTL_ELEM_READ, &ev); - if (ret < 0) - return ret; - strncpy(string, (char *)ctl->ename[enum_id], size); + return NULL; - return 0; + return (const char *)ctl->ename[enum_id]; } int mixer_ctl_set_enum_by_string(struct mixer_ctl *ctl, const char *string) |