Coding style and fixes in snd_card_name() function...

This commit is contained in:
Jaroslav Kysela 1998-11-27 14:53:44 +00:00
parent ee5a757438
commit 2605e4d7dd

View file

@ -37,14 +37,16 @@ int snd_cards( void )
mask = snd_cards_mask();
for (idx = 0, count = 0; idx < SND_CARDS; idx++) {
if ( mask & (1 << idx) ) count++;
if (mask & (1 << idx))
count++;
}
return count;
}
/*
* 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)
@ -52,34 +54,45 @@ unsigned int snd_cards_mask( void )
int fd, idx;
unsigned int mask;
char filename[32];
static unsigned int save_mask = 0;
if (save_mask)
return save_mask;
for (idx = 0, mask = 0; idx < SND_CARDS; 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);
mask |= 1 << idx;
}
save_mask = mask;
return mask;
}
int snd_card_name(const char *string)
{
int card, cards;
int card, bitmask;
void *handle;
struct snd_ctl_hw_info info;
cards = snd_cards();
if ( cards <= 0 ) return -ENODEV;
if ( !string ) return -EINVAL;
bitmask = snd_cards_mask();
if (!bitmask)
return -ENODEV;
if (!string)
return -EINVAL;
if ((isdigit(*string) && *(string + 1) == 0) ||
(isdigit(*string) && isdigit(*(string + 1)) && *(string + 2) == 0)) {
sscanf(string, "%i", &card);
card--;
if ( card < 0 || card >= cards )
if (card < 0 || card > 31)
return -EINVAL;
if (card < 0 || !((1 << card) & bitmask))
return -EINVAL;
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)
continue;
if (snd_ctl_hw_info(handle, &info) < 0) {