diff --git a/lib/libmixer/mixer.c b/lib/libmixer/mixer.c --- a/lib/libmixer/mixer.c +++ b/lib/libmixer/mixer.c @@ -69,21 +69,18 @@ struct mixer *m = NULL; struct mix_dev *dp; const char *names[SOUND_MIXER_NRDEVICES] = SOUND_DEVICE_NAMES; + char *p; int i; if ((m = calloc(1, sizeof(struct mixer))) == NULL) goto fail; if (name != NULL) { - /* `name` does not start with "/dev/mixer". */ - if (strncmp(name, BASEPATH, strlen(BASEPATH)) != 0) { - m->unit = -1; - } else { - /* `name` is "/dev/mixer" so, we'll use the default unit. */ - if (strncmp(name, BASEPATH, strlen(name)) == 0) - goto dunit; - m->unit = strtol(name + strlen(BASEPATH), NULL, 10); - } + /* XXX: should we remove `const` altogether? */ + p = basename((char *)name); + if (strncmp(p, "mixer", 5) == 0 && p[5] == '\0') + goto dunit; + (void)sscanf(p, "%*[^0123456789]%d", &m->unit); (void)strlcpy(m->name, name, sizeof(m->name)); } else { dunit: @@ -129,14 +126,13 @@ TAILQ_INSERT_TAIL(&m->devs, dp, devs); m->ndev++; } - - /* The default device is always "vol". */ m->dev = TAILQ_FIRST(&m->devs); return (m); fail: - if (m != NULL) - (void)mixer_close(m); + /* XXX: do we need this? */ + /*if (m != NULL)*/ + /*(void)mixer_close(m);*/ return (NULL); }