]> git.alsa-project.org Git - alsa-lib.git/commitdiff
Fix the return value of snd_card_load()
authorTakashi Iwai <tiwai@suse.de>
Tue, 28 Jun 2005 09:58:48 +0000 (09:58 +0000)
committerTakashi Iwai <tiwai@suse.de>
Tue, 28 Jun 2005 09:58:48 +0000 (09:58 +0000)
Fix the return value of snd_card_load() to follow the document,
0 = not present, 1 = preset.
The other parts calling snd_card_load() are fixed, too.

src/control/cards.c

index b775a62ca6c61ee61320cb9d3561f47fb734c690..f97610fd2f72790b82a747a46adbd0863a0a2c46 100644 (file)
@@ -61,9 +61,9 @@ int snd_card_load(int card)
 #endif
        if (open_dev >= 0) {
                close (open_dev);
-               return 0;
+               return 1;
        }
-       return open_dev ? 1 : 0;
+       return 0;
 }
 
 /**
@@ -85,7 +85,7 @@ int snd_card_next(int *rcard)
        card = *rcard;
        card = card < 0 ? 0 : card + 1;
        for (; card < 32; card++) {
-               if (!snd_card_load(card)) {
+               if (snd_card_load(card)) {
                        *rcard = card;
                        return 0;
                }
@@ -112,15 +112,16 @@ int snd_card_get_index(const char *string)
                return -EINVAL;
        if ((isdigit(*string) && *(string + 1) == 0) ||
            (isdigit(*string) && isdigit(*(string + 1)) && *(string + 2) == 0)) {
-               sscanf(string, "%i", &card);
+               if (sscanf(string, "%i", &card) != 1)
+                       return -EINVAL;
                if (card < 0 || card > 31)
                        return -EINVAL;
-               if (snd_card_load(card) >= 0)
+               if (snd_card_load(card))
                        return card;
-               return -EINVAL;
+               return -ENODEV;
        }
        for (card = 0; card < 32; card++) {
-               if (snd_card_load(card) < 0)
+               if (! snd_card_load(card))
                        continue;
                if (snd_ctl_hw_open(&handle, NULL, card, 0) < 0)
                        continue;