diff options
Diffstat (limited to 'lib/libmixer/mixer.c')
-rw-r--r-- | lib/libmixer/mixer.c | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/lib/libmixer/mixer.c b/lib/libmixer/mixer.c index d78ca6e0fc87..2be3a48eb755 100644 --- a/lib/libmixer/mixer.c +++ b/lib/libmixer/mixer.c @@ -87,7 +87,7 @@ mixer_open(const char *name) dunit: if ((m->unit = mixer_get_dunit()) < 0) goto fail; - (void)snprintf(m->name, sizeof(m->name), "/dev/mixer%d", m->unit); + (void)snprintf(m->name, sizeof(m->name), BASEPATH "%d", m->unit); } if ((m->fd = open(m->name, O_RDWR)) < 0) @@ -113,14 +113,14 @@ dunit: TAILQ_INIT(&m->devs); for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) { - if (!MIX_ISDEV(m, i)) + if (!MIX_ISDEV(m, i) && !MIX_ISREC(m, i)) continue; if ((dp = calloc(1, sizeof(struct mix_dev))) == NULL) goto fail; dp->parent_mixer = m; dp->devno = i; dp->nctl = 0; - if (_mixer_readvol(dp) < 0) + if (MIX_ISDEV(m, i) && _mixer_readvol(dp) < 0) goto fail; (void)strlcpy(dp->name, names[i], sizeof(dp->name)); TAILQ_INIT(&dp->ctls); @@ -493,3 +493,28 @@ mixer_get_nmixers(void) return (si.nummixers); } + +/* + * Get the full path to a mixer device. + */ +int +mixer_get_path(char *buf, size_t size, int unit) +{ + size_t n; + + if (!(unit == -1 || (unit >= 0 && unit < mixer_get_nmixers()))) { + errno = EINVAL; + return (-1); + } + if (unit == -1) + n = strlcpy(buf, BASEPATH, size); + else + n = snprintf(buf, size, BASEPATH "%d", unit); + + if (n >= size) { + errno = ENOMEM; + return (-1); + } + + return (0); +} |