diff --git a/lib/libmixer/Makefile b/lib/libmixer/Makefile --- a/lib/libmixer/Makefile +++ b/lib/libmixer/Makefile @@ -22,6 +22,7 @@ MLINKS+= mixer.3 mixer_set_dunit.3 MLINKS+= mixer.3 mixer_get_mode.3 MLINKS+= mixer.3 mixer_get_nmixers.3 +MLINKS+= mixer.3 mixer_get_path.3 MLINKS+= mixer.3 MIX_ISDEV.3 MLINKS+= mixer.3 MIX_ISMUTE.3 MLINKS+= mixer.3 MIX_ISREC.3 diff --git a/lib/libmixer/Symbol.map b/lib/libmixer/Symbol.map --- a/lib/libmixer/Symbol.map +++ b/lib/libmixer/Symbol.map @@ -19,3 +19,7 @@ mixer_get_mode; mixer_get_nmixers; }; + +FBSD_1.8 { + mixer_get_path; +}; diff --git a/lib/libmixer/mixer.h b/lib/libmixer/mixer.h --- a/lib/libmixer/mixer.h +++ b/lib/libmixer/mixer.h @@ -115,6 +115,7 @@ int mixer_set_dunit(struct mixer *, int); int mixer_get_mode(int); int mixer_get_nmixers(void); +int mixer_get_path(char *, size_t, int); __END_DECLS diff --git a/lib/libmixer/mixer.3 b/lib/libmixer/mixer.3 --- a/lib/libmixer/mixer.3 +++ b/lib/libmixer/mixer.3 @@ -40,6 +40,7 @@ .Nm mixer_set_dunit , .Nm mixer_get_mode , .Nm mixer_get_nmixers , +.Nm mixer_get_path , .Nm MIX_ISDEV , .Nm MIX_ISMUTE , .Nm MIX_ISREC , @@ -86,6 +87,8 @@ .Ft int .Fn mixer_get_nmixers "void" .Ft int +.Fn mixer_get_path "char * buf" "size_t size" "int unit" +.Ft int .Fn MIX_ISDEV "struct mixer *m" "int devno" .Ft int .Fn MIX_ISMUTE "struct mixer *m" "int devno" @@ -398,7 +401,21 @@ function returns the maximum mixer unit number. Although this might sound as incorrect behavior, given that one would expect "nmixers" to refer to the total number of active mixers, it is more intuitive -for applications that want to loop through all mixer devices. +for applications that want to loop through all mixer devices (see the +.Sx EXAMPLES +section). +.Pp +The +.Fn mixer_get_path +function writes the path of the mixer device specified in the +.Ar unit +argument to the buffer specified in +.Ar buf . +.Ar unit +can be either -1, in which case +.Fn mixer_get_path +will fetch the path of the default mixer, or between 0 and the maximum mixer +unit. .Pp The .Fn MIX_ISDEV @@ -470,9 +487,10 @@ .Fn mixer_set_mute , .Fn mixer_mod_recsrc , .Fn mixer_get_dunut , -.Fn mixer_set_dunit +.Fn mixer_set_dunit , +.Fn mixer_get_nmixers , and -.Fn mixer_get_nmixers +.Fn mixer_get_path functions return 0 or positive values on success and -1 on failure. .Pp The @@ -542,6 +560,22 @@ (void)mixer_close(m); .Ed +.Ss Loop through all mixer devices in the system +.Bd -literal +struct mixer *m; +char buf[NAME_MAX]; +int n; + +if ((n = mixer_get_nmixers()) < 0) + errx(1, "no mixers present in the system"); +for (i = 0; i < n; i++) { + (void)mixer_get_path(buf, sizeof(buf), i); + if ((m = mixer_open(buf)) == NULL) + continue; + ... + (void)mixer_close(m); +} +.Ed .Sh SEE ALSO .Xr queue 3 , .Xr sysctl 3 , diff --git a/lib/libmixer/mixer.c b/lib/libmixer/mixer.c --- a/lib/libmixer/mixer.c +++ b/lib/libmixer/mixer.c @@ -493,3 +493,28 @@ 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); +}