mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-12-16 08:56:42 -05:00
Coding style and fixes in snd_card_name() function...
This commit is contained in:
parent
ee5a757438
commit
2605e4d7dd
1 changed files with 62 additions and 49 deletions
|
|
@ -37,14 +37,16 @@ int snd_cards( void )
|
||||||
|
|
||||||
mask = snd_cards_mask();
|
mask = snd_cards_mask();
|
||||||
for (idx = 0, count = 0; idx < SND_CARDS; idx++) {
|
for (idx = 0, count = 0; idx < SND_CARDS; idx++) {
|
||||||
if ( mask & (1 << idx) ) count++;
|
if (mask & (1 << idx))
|
||||||
|
count++;
|
||||||
}
|
}
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* this routine uses very ugly method...
|
* this routine uses very ugly method...
|
||||||
* need to do...
|
* need to do... (use only stat on /proc/asound?)
|
||||||
|
* now is information cached over static variable
|
||||||
*/
|
*/
|
||||||
|
|
||||||
unsigned int snd_cards_mask(void)
|
unsigned int snd_cards_mask(void)
|
||||||
|
|
@ -52,34 +54,45 @@ unsigned int snd_cards_mask( void )
|
||||||
int fd, idx;
|
int fd, idx;
|
||||||
unsigned int mask;
|
unsigned int mask;
|
||||||
char filename[32];
|
char filename[32];
|
||||||
|
static unsigned int save_mask = 0;
|
||||||
|
|
||||||
|
if (save_mask)
|
||||||
|
return save_mask;
|
||||||
for (idx = 0, mask = 0; idx < SND_CARDS; idx++) {
|
for (idx = 0, mask = 0; idx < SND_CARDS; idx++) {
|
||||||
sprintf(filename, SND_FILE_CONTROL, idx);
|
sprintf(filename, SND_FILE_CONTROL, idx);
|
||||||
if ( (fd = open( filename, O_RDWR )) < 0 ) continue;
|
if ((fd = open(filename, O_RDWR)) < 0)
|
||||||
|
continue;
|
||||||
close(fd);
|
close(fd);
|
||||||
mask |= 1 << idx;
|
mask |= 1 << idx;
|
||||||
}
|
}
|
||||||
|
save_mask = mask;
|
||||||
return mask;
|
return mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
int snd_card_name(const char *string)
|
int snd_card_name(const char *string)
|
||||||
{
|
{
|
||||||
int card, cards;
|
int card, bitmask;
|
||||||
void *handle;
|
void *handle;
|
||||||
struct snd_ctl_hw_info info;
|
struct snd_ctl_hw_info info;
|
||||||
|
|
||||||
cards = snd_cards();
|
bitmask = snd_cards_mask();
|
||||||
if ( cards <= 0 ) return -ENODEV;
|
if (!bitmask)
|
||||||
if ( !string ) return -EINVAL;
|
return -ENODEV;
|
||||||
|
if (!string)
|
||||||
|
return -EINVAL;
|
||||||
if ((isdigit(*string) && *(string + 1) == 0) ||
|
if ((isdigit(*string) && *(string + 1) == 0) ||
|
||||||
(isdigit(*string) && isdigit(*(string + 1)) && *(string + 2) == 0)) {
|
(isdigit(*string) && isdigit(*(string + 1)) && *(string + 2) == 0)) {
|
||||||
sscanf(string, "%i", &card);
|
sscanf(string, "%i", &card);
|
||||||
card--;
|
card--;
|
||||||
if ( card < 0 || card >= cards )
|
if (card < 0 || card > 31)
|
||||||
|
return -EINVAL;
|
||||||
|
if (card < 0 || !((1 << card) & bitmask))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
return card;
|
return card;
|
||||||
}
|
}
|
||||||
for ( card = 0; card < cards; card++ ) {
|
for (card = 0; card < 32; card++) {
|
||||||
|
if (!((1 << card) & bitmask))
|
||||||
|
continue;
|
||||||
if (snd_ctl_open(&handle, card) < 0)
|
if (snd_ctl_open(&handle, card) < 0)
|
||||||
continue;
|
continue;
|
||||||
if (snd_ctl_hw_info(handle, &info) < 0) {
|
if (snd_ctl_hw_info(handle, &info) < 0) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue