From 30744c02e7923fd91d8d1f94c36abe976e8b0a46 Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Mon, 18 Aug 2008 16:57:18 +0200 Subject: [PATCH] alsactl: Allow card specification by device name (support for udev) Signed-off-by: Jaroslav Kysela --- alsactl/alsactl.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/alsactl/alsactl.c b/alsactl/alsactl.c index 552cfce..6c62ffc 100644 --- a/alsactl/alsactl.c +++ b/alsactl/alsactl.c @@ -82,9 +82,16 @@ int main(int argc, char *argv[]) {"version", 0, NULL, 'v'}, {NULL, 0, NULL, 0}, }; + char *devfiles[] = { + "/dev/snd/controlC", + "/dev/snd/pcmC", + "/dev/snd/midiC", + "/dev/snd/hwC", + NULL + }; char *cfgfile = SYS_ASOUNDRC; char *initfile = DATADIR "/init/00main"; - char *cardname; + char *cardname, **tmp, ncardname[16]; int removestate = 0; int res; @@ -143,6 +150,16 @@ int main(int argc, char *argv[]) } cardname = argc - optind > 1 ? argv[optind + 1] : NULL; + for (tmp = devfiles; cardname != NULL && tmp != NULL; tmp++) { + int len = strlen(*tmp); + if (!strncmp(cardname, *tmp, len)) { + long l = strtol(cardname + len, NULL, 0); + sprintf(ncardname, "%li", l); + cardname = ncardname; + break; + } + } + if (!strcmp(argv[optind], "init")) { res = init(initfile, cardname); } else if (!strcmp(argv[optind], "store")) {