summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2011-05-27 13:49:07 (GMT)
committerTakashi Iwai <tiwai@suse.de>2011-05-27 13:49:07 (GMT)
commita4bb25877aac014137d9ded9ac214e1d0e8dd990 (patch)
tree49e63c24e8b920d83a360d0f6b0d3d1f5c65855f
parent0850e8ad63f2648cc977e10560f53b72506e8c3d (diff)
downloadsalsa-lib-a4bb25877aac014137d9ded9ac214e1d0e8dd990.tar.gz
salsa-lib-a4bb25877aac014137d9ded9ac214e1d0e8dd990.tar.xz
Refactoring codes in cards.c
-rw-r--r--src/cards.c46
1 files changed, 24 insertions, 22 deletions
diff --git a/src/cards.c b/src/cards.c
index b360a17..6861fec 100644
--- a/src/cards.c
+++ b/src/cards.c
@@ -49,10 +49,13 @@ int _snd_set_nonblock(int fd, int nonblock)
#define SND_FILE_CONTROL SALSA_DEVPATH "/controlC%i"
+#define fill_control_name(name, card) \
+ sprintf(name, SND_FILE_CONTROL, card);
+
int snd_card_load(int card)
{
char control[sizeof(SND_FILE_CONTROL) + 10];
- sprintf(control, SND_FILE_CONTROL, card);
+ fill_control_name(control, card);
return !access(control, R_OK);
}
@@ -81,37 +84,38 @@ int _snd_ctl_hw_open(snd_ctl_t **ctlp, int card)
return snd_ctl_open(ctlp, name, 0);
}
-static int get_card_info(int card, snd_ctl_card_info_t *info)
-{
- int err;
- snd_ctl_t *handle;
-
- memset(info, 0, sizeof(*info));
- err = _snd_ctl_hw_open(&handle, card);
- if (err < 0)
- return err;
- err = snd_ctl_card_info(handle, info);
- snd_ctl_close(handle);
- return err;
-}
-
-static int snd_card_load2(const char *control)
+static int load_card_info(const char *control, snd_ctl_card_info_t *info)
{
int open_dev;
- snd_ctl_card_info_t info;
+ memzero_valgrind(info, sizeof(*info));
open_dev = open(control, O_RDONLY);
if (open_dev < 0)
return -errno;
- if (ioctl(open_dev, SNDRV_CTL_IOCTL_CARD_INFO, &info) < 0) {
- int err = -errno;
+ if (ioctl(open_dev, SNDRV_CTL_IOCTL_CARD_INFO, info) < 0) {
close(open_dev);
- return err;
+ return -errno;
}
close(open_dev);
+ return 0;
+}
+
+static int snd_card_load2(const char *control)
+{
+ snd_ctl_card_info_t info;
+ int err = load_card_info(control, &info);
+ if (err < 0)
+ return err;
return info.card;
}
+static int get_card_info(int card, snd_ctl_card_info_t *info)
+{
+ char control[sizeof(SND_FILE_CONTROL) + 10];
+ fill_control_name(control, card);
+ return load_card_info(control, info);
+}
+
int snd_card_get_index(const char *string)
{
int card;
@@ -129,8 +133,6 @@ int snd_card_get_index(const char *string)
return -ENODEV;
}
for (card = 0; card < SALSA_MAX_CARDS; card++) {
- if (!snd_card_load(card))
- continue;
if (get_card_info(card, &info) < 0)
continue;
if (!strcmp((const char *)info.id, string))