[Bug 245156] audio/pulseaudio: parse /dev/sndstat correctly to get device name

bugzilla-noreply at freebsd.org bugzilla-noreply at freebsd.org
Mon Mar 30 07:06:18 UTC 2020


https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=245156

lightside <lightside at gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |gnome at FreeBSD.org
 Attachment #212854|                            |maintainer-approval?(gnome@
              Flags|                            |FreeBSD.org)

--- Comment #5 from lightside <lightside at gmx.com> ---
Created attachment 212854
  --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=212854&action=edit
Proposed patch (since 516738 revision, v1)

I created some testcase:
-8<--
#include <stdio.h>
#include <string.h>

int main() {
        const char *line = "pcm4: <Realtek (0x1168) (Rear Analog 5.1/2.0)>
(play/rec) default";
        int device;

        if (sscanf(line, "pcm%i: ", &device) != 1)
                return 0;
        {
                char *k = strchr(line, ':');
                k++;
                k += strspn(k, " <");
                char *e = strrchr(k, '>');

                if (!e)
                        return 0;

                const size_t len = strlen(k) - strlen(e);
                char m[len];
                strncpy(m, k, len);

                printf("pcm%d: %s\n", device, m);
                // pcm4: Realtek (0x1168) (Rear Analog 5.1/2.0)
        }
        {
                char *k = strrchr(line, '>');

                if (!k)
                        return 0;

                const size_t len = strlen(line) - strlen(k) + 1;
                char m[len];
                strncpy(m, line, len);

                printf("%s\n", m);
                // pcm4: <Realtek (0x1168) (Rear Analog 5.1/2.0)>
        }

        return 0;
}
-->8-

which outputs two variants for "pcm4: <Realtek (0x1168) (Rear Analog 5.1/2.0)>
(play/rec) default" line:
-8<--
pcm4: Realtek (0x1168) (Rear Analog 5.1/2.0)
pcm4: <Realtek (0x1168) (Rear Analog 5.1/2.0)>
-->8-

Attached patch for first variant.

-- 
You are receiving this mail because:
You are the assignee for the bug.
You are on the CC list for the bug.


More information about the freebsd-gnome mailing list