From nobody Thu May 23 00:58:08 2024 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Vl8t93PBVz5LNlk; Thu, 23 May 2024 00:58:09 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Vl8t91Ml3z4m2N; Thu, 23 May 2024 00:58:09 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1716425889; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=TSnSCvqef1rppD8iW29G256bdpiwRC5lY6t6YnOW7pk=; b=QZ+CjWWxYvLrTb/R8r2VaW4R7PT5sC438WneiSYD7kEp+FEJsYc0Z4onnI0kc8u+x0/WTt WaBcrWn2L8HrHx1GjI+3bsG0At1+/5Rig/3cTlZTLfuF8MWtjDEOTOtwzo5qx65zN1POVl jvYitg2IM2QWhMKnCv6ugPZHwNNhhkcLrtXoYo+G4q9SS5eHKixYqhBWuxGtrmgbHBd390 OpJt7UtW1Hkdd6vsbVnQNWEXVYPURLhEWc2sm/1n1kgxYJ3w3uywn3WozbsAvwWZucOn5D nkWMWpGV+4lVaBylKye9NejKmeJO6IJQUmxFy9SjV7u7/hIiRiJAMC+vPWYg0Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1716425889; a=rsa-sha256; cv=none; b=iYoiIuxo6R/jqybipeUVaTukBX5QVB1bVhB9O50rElTLomnao4uE3cHrgxIilP4nlVTEcJ +Utk50xXC8+mETbgRitMqMihSHRJC3YmWZiMlnJYfazQJm4HA/QcZalAPJmSl6/Rq7scbE ncy3Jc71rFGrQQNA3hqkoOzz3V/zjyWaGoCx0eqQLcBiI48Vojw0O1nkx3vQ+5OAj9fxxI 065r7iyW6Prt19RKzijTekXQLh/OObzkL9k/mh+b8KsoA9VBI1hX4aVr2EKOqeraK1gs1a pI/1OoGImPlRtsGFXXnode2MZigC5EzdONMcItFpeJ/xJwryOo5Z7zAQdRXxvQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1716425889; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=TSnSCvqef1rppD8iW29G256bdpiwRC5lY6t6YnOW7pk=; b=DpN9uMjb1PuaOxM1XsSd0QKrd7CMTCCQe3L2p5AoYxy0F9YpF6Jg6j9uwF5RWfXK1bBibr 2MQJ0WYcMW5d7qLu5WxWKZFcDp9uRRlGTjFINmb1Lj+Tc9MAP1Ik50HX3hbBjMKKgOyry2 J55PBfmjDp6OX3GDMe0UvBvKmctb4EHowUuCplq4EDWnCz3h5TnTJBIK7TEiSCZb4R0qg4 Tw58iIMO/10wyIUW8YTsrHYzoCMokIxSlk1DfC6mRKpR2CYIvliAm88qcBH7tWdZThW7Tf lBHZtYyd1kBwaFBXpGSiEzB6AopAf3zP/9zHiDTfQ6L2OUNCHdyE9Bqo64Or+Q== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Vl8t90f1yzSYh; Thu, 23 May 2024 00:58:09 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 44N0w80D071988; Thu, 23 May 2024 00:58:08 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 44N0w8rk071985; Thu, 23 May 2024 00:58:08 GMT (envelope-from git) Date: Thu, 23 May 2024 00:58:08 GMT Message-Id: <202405230058.44N0w8rk071985@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Christos Margiolis Subject: git: 67c89b21b956 - main - mixer(3): Implement mixer_get_path() function List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: christos X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 67c89b21b95601c01bafe5a0c518d320a39111c0 Auto-Submitted: auto-generated The branch main has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=67c89b21b95601c01bafe5a0c518d320a39111c0 commit 67c89b21b95601c01bafe5a0c518d320a39111c0 Author: Christos Margiolis AuthorDate: 2024-05-23 00:57:36 +0000 Commit: Christos Margiolis CommitDate: 2024-05-23 00:57:36 +0000 mixer(3): Implement mixer_get_path() function This is better than hardcoding device paths in mixer applications. Sponsored by: The FreeBSD Foundation MFC after: 1 day Reviewed by: dev_submerge.ch Differential Revision: https://reviews.freebsd.org/D45275 --- lib/libmixer/Makefile | 1 + lib/libmixer/Symbol.map | 4 ++++ lib/libmixer/mixer.3 | 40 +++++++++++++++++++++++++++++++++++++--- lib/libmixer/mixer.c | 25 +++++++++++++++++++++++++ lib/libmixer/mixer.h | 1 + 5 files changed, 68 insertions(+), 3 deletions(-) diff --git a/lib/libmixer/Makefile b/lib/libmixer/Makefile index 6ca17a9d020d..3f8a4dad4a65 100644 --- a/lib/libmixer/Makefile +++ b/lib/libmixer/Makefile @@ -22,6 +22,7 @@ MLINKS+= mixer.3 mixer_get_dunit.3 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 index f16e13d66e4c..2ce39fd058ab 100644 --- a/lib/libmixer/Symbol.map +++ b/lib/libmixer/Symbol.map @@ -19,3 +19,7 @@ FBSD_1.7 { mixer_get_mode; mixer_get_nmixers; }; + +FBSD_1.8 { + mixer_get_path; +}; diff --git a/lib/libmixer/mixer.3 b/lib/libmixer/mixer.3 index a3593898ed68..c8a7ee1148a8 100644 --- 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 @@ Mixer library (libmixer, -lmixer) .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 @@ The 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 @@ The .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 @@ TAILQ_FOREACH(dp, &m->devs, devs) { (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 index 93ace1d0c69b..4abbed9b27d3 100644 --- a/lib/libmixer/mixer.c +++ b/lib/libmixer/mixer.c @@ -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); +} diff --git a/lib/libmixer/mixer.h b/lib/libmixer/mixer.h index cb9575c5f012..80a4b5c91a82 100644 --- a/lib/libmixer/mixer.h +++ b/lib/libmixer/mixer.h @@ -115,6 +115,7 @@ int mixer_get_dunit(void); 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