From nobody Sat May 25 19:31:37 2024 X-Original-To: dev-commits-src-branches@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 4VmsV25Y8Bz5LT66; Sat, 25 May 2024 19:31:38 +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 4VmsV22Ll9z4jbq; Sat, 25 May 2024 19:31:38 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1716665498; 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=B7TLZkPLd08r2ZJz6A1pXZqh63MHh0MzteiAPweii+k=; b=H6x6vRqGsk1UBg/MzA3wQWSOIWOWoLKOan3xSrVHqW7WcUqFC4zwUs0tSw1QCYxehvDKA+ i3TnyDOE/G3a1peN+C5XlJP/wFP6eCfNyzKqrXKT2j3PwKkBMVvXy349FCB8rO8gPJZ9Xg oTzIv6/1QrWrJ4qufAzuwMWmRa77WE97dx6aHFPs3bdFNyIjlTXOdJ9r9rCndvUksaFM9l l8p+H6/ixxHiBUX3l7s92iKVEGKy/L4JFPR0FxfPlwy21tHzsGwhwyNtJOdMU2hPHGJVOM USP8smGBB88NbbEujPRAbAG4SV4QbW83xtQ33y6plqHZLDGwsBA4swcOJyds5A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1716665498; a=rsa-sha256; cv=none; b=r0ibBiBmvIcds9MoXHq7qxmfG+NVBfJhNhuc46OeRlmQ7Sio85ifYrNIJb9gz9WTrhTMDN 4MGmL0abQyAlUOppN3Xs0r5lqv4MtnN8i9SGN/opMMWfHYHQ4jdCmeT0IZDzSWPrwdzOC/ ylXm33B5agsifAl77KvOzSCX4cyEz3BSo9L4zjf4TMK9naUgI7oTb3FvU5NCjJeDEqjA5y OR/BvXch/cosMN3y2vhIJ6lcvQDVjHMumK4lWTX8DBN8ywElqnVQsvc8WaZKT2rJaB+H0t KmlokEJTuKVZbtsI48EqsSD580RtRUC1ptoh3V/jx+o0H3xQNVqlBj6SuNEpNQ== 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=1716665498; 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=B7TLZkPLd08r2ZJz6A1pXZqh63MHh0MzteiAPweii+k=; b=xCwycuCa2YT5ghTrePuKOSumVvCtxzHEbmXlmtYxgZsvBoxTaZnnzP5Vs+12eMO4h5STli CR40X6tFsxQBUvqpENx/mdxdBL569/sdaJjR98pT105ne05h6G6rXGFrnjN2zFHgxuhmZm 3pIU6t/RH6WjbXHQJ7j46rKrh5Q4mnCbmwKmtyj1bty/FeKSaHliW5rOHGv7+wNEXiQC7N kjitmSZaPf67uCF79Zl80cbeAT6i8Nf1Q5WXKsRYNIE7q8oA4RRV1Bf5MqCQp4pgxrUjAk S2zI7ML9OyezMDJ5OBNTzyKnc0MZgVJpnt7lD/dd05jHx5xU7F3g0Zh477exAQ== 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 4VmsV142CBzTPx; Sat, 25 May 2024 19:31:37 +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 44PJVbVH043481; Sat, 25 May 2024 19:31:37 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 44PJVbiH043478; Sat, 25 May 2024 19:31:37 GMT (envelope-from git) Date: Sat, 25 May 2024 19:31:37 GMT Message-Id: <202405251931.44PJVbiH043478@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Christos Margiolis Subject: git: 0a1eb394d7b6 - stable/14 - mixer(3): Implement mixer_get_path() function List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@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/stable/14 X-Git-Reftype: branch X-Git-Commit: 0a1eb394d7b6dcc32d1d7411873886a835900dbd Auto-Submitted: auto-generated The branch stable/14 has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=0a1eb394d7b6dcc32d1d7411873886a835900dbd commit 0a1eb394d7b6dcc32d1d7411873886a835900dbd Author: Christos Margiolis AuthorDate: 2024-05-23 00:57:36 +0000 Commit: Christos Margiolis CommitDate: 2024-05-25 19:31:05 +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 (cherry picked from commit 67c89b21b95601c01bafe5a0c518d320a39111c0) --- 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