mixer

FreeBSD OSS mixer library implementation and a complete rewrite of mixer(8)
git clone git://git.margiolis.net/mixer.git
Log | Files | Refs | README

commit 03d70146d1eb749e65aaf90dbaf4f5cd32bc5268
parent 27b0d8918fc7ac9d9acf6ab626f836096d40d8d0
Author: Christos Margiolis <christos@margiolis.net>
Date:   Sun,  1 Aug 2021 17:11:49 +0300

fixed possible bug in mixer_add_ctl_s

Diffstat:
MMakefile | 0
Mmixer_lib/mixer.c | 22+++++++++++++---------
Mmixer_prog/mixer_prog.c | 4+++-
3 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/Makefile b/Makefile diff --git a/mixer_lib/mixer.c b/mixer_lib/mixer.c @@ -208,7 +208,7 @@ mixer_get_dev_byname(struct mixer *m, const char *name) } /* - * Add a mixer control to a device by passing all fields as arguments. + * Add a mixer control to a device. */ int mixer_add_ctl(struct mix_dev *parent_dev, int id, const char *name, @@ -217,6 +217,11 @@ mixer_add_ctl(struct mix_dev *parent_dev, int id, const char *name, { mix_ctl_t *ctl; + /* XXX: should we accept NULL name? */ + if (parent_dev == NULL) { + errno = EINVAL; + return (-1); + } if ((ctl = calloc(1, sizeof(mix_ctl_t))) == NULL) return (-1); ctl->parent_dev = parent_dev; @@ -225,24 +230,23 @@ mixer_add_ctl(struct mix_dev *parent_dev, int id, const char *name, (void)strlcpy(ctl->name, name, sizeof(ctl->name)); ctl->mod = mod; ctl->print = print; + TAILQ_INSERT_TAIL(&parent_dev->ctls, ctl, ctls); + parent_dev->nctl++; - return (mixer_add_ctl_s(ctl)); + return (0); } /* - * Add a mixer control to a device. + * Same as `mixer_add_ctl`. */ int mixer_add_ctl_s(mix_ctl_t *ctl) { - struct mix_dev *p = ctl->parent_dev; - - if (ctl == NULL || p == NULL || ctl->mod == NULL || ctl->print == NULL) + if (ctl == NULL) return (-1); - TAILQ_INSERT_TAIL(&p->ctls, ctl, ctls); - p->nctl++; - return (0); + return (mixer_add_ctl(ctl->parent_dev, ctl->id, ctl->name, + ctl->mod, ctl->print)); } /* diff --git a/mixer_prog/mixer_prog.c b/mixer_prog/mixer_prog.c @@ -267,7 +267,9 @@ printrecsrc(struct mixer *m, int oflag) printf(", "); printf("%s", dp->name); if (oflag) - printf(".recsrc=+%s", n ? " " : ""); + printf(".%s=+%s", + mixer_get_ctl(dp, C_SRC)->name, + n ? " " : ""); } } printf("\n");